{"repo_name": "sapf", "file_name": "/sapf/src/Parser.cpp", "inference_info": {"prefix_code": "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Parser.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PARSER\n\nbool parseElem(Thread& th, P& code);\nbool parseWord(Thread& th, P& code);\nstatic void bindVar(Thread& th, P const& name, P& code);\n\nclass ParsingWhat\n{\n\tThread& th;\n\tint what;\npublic:\t\n\tParsingWhat(Thread& inThread, int newMode) : th(inThread), what(th.parsingWhat)\n\t{\n\t\tth.parsingWhat = newMode;\n\t} \n\t~ParsingWhat()\n\t{\n\t\tth.parsingWhat = what;\n\t}\n};\n\n\nstatic bool skipSpace(Thread& th)\n{\n\t//ScopeLog sl(\"skipSpace\");\n\tfor (;;) {\n\t\tint c = th.getc();\n\t\tif (c == ';') {\n\t\t\tc = th.getc();\n\t\t\twhile (c && c != '\\n') { c = th.getc(); }\n\t\t\tif (c == 0) { th.unget(1); return true; }\n\t\t}\n\t\tif (c == 0) { th.unget(1); return true; }\n\t\tbool skip = isspace(c) || iscntrl(c);\n\t\tif (!skip) { th.unget(1); break; }\n\t}\n\treturn false;\n}\n\nconst char* nonnamechars = \";()[]{}.`,:\\\"\\n\";\n\nstatic bool endOfWord(int c)\n{\n\treturn c == 0 || isspace(c) || strchr(nonnamechars, c) != nullptr;\n}\n\nstatic bool parseHexNumber(Thread& th, P& code)\n{\n\tconst char* start = th.curline();\n\tint64_t z = 0;\n\t\n\tth.getc();\n\tth.getc();\n\tint c = th.getc();\n\twhile(isxdigit(c)) {\n\t\tif (isdigit(c)) z = z*16 + c - '0';\n\t\telse z = z*16 + toupper(c) - 'A' + 10;\n\t\tc = th.getc();\n\t}\n\n\tif (!endOfWord(c)) {\n\t\t// even though it starts out like a number it continues as some other token\n\t\tth.unget(start);\n\t\treturn false;\n\t} else {\n\t\tth.unget(1);\n\t}\n\t\n\tcode->add(opPushImmediate, z);\n\t\n\treturn true;\n}\n\n\nstatic bool parseFloat(Thread& th, Z& result)\n{\t\n\t//ScopeLog sl(\"parseFloat\");\n\tconst char* start = th.curline();\n\tint c = th.getc();\n \n if (c == 'p' && th.c() == 'i') {\n th.getc();\n result = M_PI;\n return true;\n }\n \n\tif (c == '+' || c == '-') \n\t\tc = th.getc();\n\n\tint digits = 0;\n\tbool sawdot = false;\n\tfor ( ; ; ) {\n\t\tif (isdigit(c)) digits++;\n\t\telse if (c == '.') {\n\t\t\tif (sawdot) break;\n\t\t\tsawdot = true; \n\t\t}\n\t\telse break;\n\t\tc = th.getc(); \n\t}\n\tif (digits == 0) {\n\t\tth.unget(start);\n\t\treturn false;\n\t}\n\t\n\tif (c == 'e' || c == 'E') {\n\t\tc = th.getc();\n\t\tif (c == '+' || c == '-') \n\t\t\tc = th.getc();\n\t\twhile (isdigit(c)) { c = th.getc(); }\n\t}\n\n\tth.toToken(start, (int)(th.curline() - start));\n\t\n\tbool sawpi = false;\n\tbool sawmega = false;\n\tbool sawkilo = false;\n\tbool sawhecto = false;\n\tbool sawcenti = false;\n\tbool sawmilli = false;\n\tbool sawmicro = false;\n\t\n\t\n\tif (c == 'p' && th.c() == 'i') {\n\t\tsawpi = true;\n\t\tth.getc();\n\t} else if (c == 'M') {\n\t\tsawmega = true;\n\t} else if (c == 'k') {\n\t\tsawkilo = true;\n\t} else if (c == 'h') {\n\t\tsawhecto = true;\n\t} else if (c == 'c') {\n\t\tsawcenti = true;\n\t} else if (c == 'm') {\n\t\tsawmilli = true;\n\t} else if (c == 'u') {\n\t\tsawmicro = true;\n\t} else {\n\t\tth.unget(1);\n\t}\n\n\tdouble x = strtod(th.token, nullptr);\n\tif (sawpi) x *= M_PI;\n\telse if (sawmega) x *= 1e6;\n\telse if (sawkilo) x *= 1e3;\n\telse if (sawhecto) x *= 1e2;\n\telse if (sawcenti) x *= 1e-2;\n\telse if (sawmilli) x *= 1e-3;\n\telse if (sawmicro) x *= 1e-6;\n\n\tresult = x;\n\treturn true;\n}\n\nstatic bool parseNumber(Thread& th, Z& result)\n{\n\tconst char* start = th.curline();\n\n\tZ a, b;\n\tif (parseFloat(th, a)) {\n\t\tif (th.c() == '/') {\n\t\t\tth.getc();\n\t\t\tif (parseFloat(th, b) && endOfWord(th.c())) {\n\t\t\t\tresult = a/b;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (endOfWord(th.c())) {\n\t\t\tresult = a;\n\t\t\treturn true;\n\t\t}\n\t}\n\tth.unget(start);\n\treturn false;\n}\n\nstatic bool parseNumber(Thread& th, P& code)\n{\n Z x;\n if (parseNumber(th, x)) {\n \t\tcode->add(opPushImmediate, x);\n return true;\n }\n return false;\n}\n\nstatic bool parseSymbol(Thread& th, P& result);\nstatic bool parseItemList(Thread& th, P& code, int endbrace);\n\n\nstatic bool parseQuote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after quote\");\n\t\n\tV vname(name);\n\tcode->add(opPushImmediate, vname);\n\n\treturn true; \n}\n\nstatic bool parseBackquote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after backquote\");\n\n\n\tV vname(name);\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\tswitch (scope) {\n\t\tcase scopeLocal :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushLocalVar, val);\n\t\t\tbreak;\n\t\tcase scopeFunVar :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushFunVar, val);\n\t\t\tbreak;\n\t\tcase scopeBuiltIn :\n\t\t\tcode->add(opPushImmediate, val);\n\t\t\tbreak;\n\t\tcase scopeWorkspace :\n\t\t\tcode->add(opPushWorkspaceVar, vname);\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tpost(\"backquote error: \\\"%s\\\" is an undefined word\\n\", name->s);\n\t\t\tsyntaxError(\"undefined word\");\n\t}\n\n\treturn true; \n}\n\nstatic bool parseDot(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opDot, vname);\n\n\treturn true; \n}\n\nstatic bool parseComma(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opComma, vname);\n\n\treturn true; \n}\n\nstatic bool parseColon(Thread& th, P& code)\n{\n\tth.getc();\n\n P name;\n\n if (!parseSymbol(th, name)) \n syntaxError(\"expected symbol after colon\");\n \n code->keys.push_back(name);\n\n\treturn true;\n}\n\nstatic bool parseEachOp(Thread& th, P& code)\n{\n\t\n\tint64_t mask = 0;\n\tint level = 0;\n\n\tth.getc();\n\tint c = th.getc();\n\t\n\tif (c == '@') {\n\t\tmask = 1; \n\t\t++level;\n\t\tdo {\n\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '@');\n\t} else if (c >= '2' && c <= '9') {\n\t\tmask = 1LL << (c - '1');\n\t\tc = th.getc();\n\t} else if (c == '0' || c == '1') {\n\t\tdo { \n\t\t\tif (c == '1')\n\t\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '0' || c == '1');\n\t} else {\n\t\tmask = 1;\n\t}\n\tif (isdigit(c)) {\n\t\tsyntaxError(\"unexpected extra digit after @\");\n\t}\n\t\n\tth.unget(1);\n\n\tV v;\n\tv.i = mask;\n\t\n\tcode->add(opEach, v);\n\t\n\t\n\treturn true; \n}\n\n\nstatic bool parseNewForm(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingEnvir);\n\tP code2 = new Code(8);\n\tth.getc();\n\t\n\tparseItemList(th, code2, '}');\n\t\n\tif (code2->keys.size()) {\n\n\t\tP tmap = new TableMap(code2->keys.size());\n\t\t\n\t\tint i = 0;\n\t\tfor (Arg key : code2->keys) {\n tmap->put(i, key, key.Hash());\n\t\t\t++i;\n\t\t}\n\n\t\tcode2->keys.clear();\n\t\tcode2->add(opPushImmediate, V(tmap));\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\n\t\tcode->add(opNewForm, V(code2));\n\t} else {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opInherit, V(code2));\n\t}\n\t\t\t\n\treturn true;\n}\n\nstatic String* parseString(Thread& th);\n\nstatic bool parseStackEffect(Thread& th, int& outTakes, int& outLeaves)\n{\n\toutTakes = 0;\n\toutLeaves = 1;\n\tskipSpace(th);\n\tint c = th.c();\n\tif (!isdigit(c)) return true;\n\toutLeaves = 0;\n\t\n\twhile(isdigit(c)) {\n\t\toutTakes = outTakes * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\tif (c != '.') return false;\n\tc = th.getc();\n\twhile(isdigit(c)) {\n\t\toutLeaves = outLeaves * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\treturn true;\n}\n\nstatic bool parseLambda(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseLambda\");\n\tParsingWhat pw(th, parsingLambda);\n\tth.getc();\n\tstd::vector > args;\n\t\t\n\tSaveCompileScope scs(th);\n\t\n\tP cs = new InnerCompileScope(th.mCompileScope);\n\tth.mCompileScope = cs();\n\t\n\twhile (1) {\n\t\tP name;\n\t\tif (!parseSymbol(th, name)) break;\n\t\targs.push_back(name);\n\t\t\n\t\tint takes, leaves;\n\t\tif (!parseStackEffect(th, takes, leaves)) {\n\t\t\tsyntaxError(\"incorrectly formatted function argument stack effect annotation.\");\n\t\t}\n\t\t\n\t\tLocalDef def;\n\t\tdef.mName = name;\n\t\tdef.mIndex = cs->mLocals.size();\n\t\tdef.mTakes = takes;\n\t\tdef.mLeaves = leaves;\n\t\tcs->mLocals.push_back(def);\n\t}\n\t\n\tskipSpace(th);\n\t\n\tP help = parseString(th);\n\n\tskipSpace(th);\n\t\n\tint c = th.getc();\t\n\tif (c != '[') {\n post(\"got char '%c' %d\\n\", c, c);\n\t\tsyntaxError(\"expected open square bracket after argument list\");\n\t}\n\t\t\n\tP code2 = new Code(8);\t\n\tparseItemList(th, code2, ']');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\t\n\t\t\n\t// compile code to push all fun vars\n\tfor (size_t i = 0; i < cs->mVars.size(); ++i) {\n\t\tVarDef& def = cs->mVars[i];\n\t\tV vindex;\n\t\tvindex.i = def.mFromIndex;\n\t\t\n\t\tif (def.mFromScope == scopeLocal) {\n\t\t\tcode->add(opPushLocalVar, vindex);\n\t\t} else {\n\t\t\tcode->add(opPushFunVar, vindex);\n\t\t}\n\t}\n\tif (args.size() > USHRT_MAX || cs->mLocals.size() > USHRT_MAX || cs->mVars.size() > USHRT_MAX)\n\t{\n\t\tpost(\"Too many variables!\\n\");\n\t\tthrow errSyntax;\n\t}\n\n FunDef* def = new FunDef(th, code2, args.size(), cs->mLocals.size(), cs->mVars.size(), help);\n\tdef->mArgNames = args;\n\tcode->add(opPushFun, def);\n\n\treturn true;\n}\n\n#define COMPILE_PARENS 1\n\nstatic bool parseParens(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingParens);\n\tth.getc();\n\n#if COMPILE_PARENS\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ')');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\tcode->add(opParens, V(code2));\n#else\n\tparseItemList(th, code, ')');\n#endif\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseArray(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseArray\");\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewVList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilv));\n\t}\n\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseZArray(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewZList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilz));\n\t}\n\t\t\t\n\treturn true;\n}\n\nbool parseItemList(Thread& th, P& code, int endbrace)\n{\t\n\t//ScopeLog sl(\"parseItemList\");\n\t\n\twhile (1) {\n\t\tskipSpace(th);\n\t\tint c = th.c();\n\t\tif (c == endbrace) break;\n\t\tif (!parseElem(th, code)) {\n\t\t\tif (endbrace == ']') syntaxError(\"expected ']'\");\n\t\t\tif (endbrace == '}') syntaxError(\"expected '}'\");\n\t\t\tif (endbrace == ')') syntaxError(\"expected ')'\");\n\t\t}\n\t}\n\tth.getc(); // skip end brace\n\t\n\treturn true;\n}\n\n\nbool parseSymbol(Thread& th, P& result)\n{\n\t//ScopeLog sl(\"parseSymbol\");\n\tskipSpace(th);\n\tconst char* start = th.curline();\n\tint c = th.getc();\n\t\n\twhile(!endOfWord(c)) {\n\t\tc = th.getc();\n\t}\n\tth.unget(1);\n\n\tsize_t len = th.curline() - start;\n\tif (len == 0) return false;\n\n\tth.toToken(start, (int)len);\n\t\n\tresult = getsym(th.token);\n\n\treturn true;\n}\n\nstatic void bindVar(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->bindVar(th, name, index);\n\n\tV vname(name);\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tcode->add(opBindWorkspaceVar, vname);\n\t} else {\n\t\tval.i = index;\n\t\tcode->add(opBindLocal, val);\n\t}\n}\n\nstatic void bindVarFromList(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t varIndex;\n\tint scope = th.mCompileScope->bindVar(th, name, varIndex);\n\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tV vname(name);\n\t\tcode->add(opBindWorkspaceVarFromList, vname);\n\t} else {\n\t\tval.i = varIndex;\n\t\tcode->add(opBindLocalFromList, val);\n\t}\n}\n\nbool parseWord(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseWord\");\n\tP name;\n\n\tif (!parseSymbol(th, name)) return false;\n\t\t\n\tif (strcmp(name->cstr(), \"=\")==0) {\n\n\t\tskipSpace(th);\t\t\n\t\tif (th.c() == '(') {\n\t\t\tth.getc();\n\t\t\t// parse multiple assign\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ('\\n\");\n\t\t\t}\n\t\t\tfor (int64_t i = names.size()-1; i>=0; --i) {\n\t\t\t\tbindVar(th, names[i], code);\n\t\t\t}\n\t\t\tskipSpace(th);\n\t\t\tif (th.c() != ')') {\n\t\t\t\tsyntaxError(\"expected ')' after '= ('\\n\");\n\t\t\t}\n\t\t\tth.getc();\n\t\t\tcode->add(opNone, 0.);\n\t\t} else if (th.c() == '[') {\n\t\t\tth.getc();\n\t\t\t// parse assign from array\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ['\\n\");\n\t\t\t}\n\t\t\tfor (size_t i = 0; iadd(opNone, 0.);\n\t\t} else {\n\t\t\tP name2;\n\t\t\tif (!parseSymbol(th, name2)) {\n\t\t\t\tsyntaxError(\"expected a name after '='\\n\");\n\t\t\t}\n\t\t\tbindVar(th, name2, code);\n\t\t}\n\t} else {\n\t\tV val;\n\t\tsize_t index;\n\t\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\t\tV vname(name);\n\t\tswitch (scope) {\n\t\t\tcase scopeLocal :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallLocalVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeFunVar :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallFunVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeBuiltIn :\n\t\t\t\tcode->add(opCallImmediate, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeWorkspace :\n\t\t\t\tcode->add(opCallWorkspaceVar, vname);\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"\\\"%s\\\" is an undefined word\\n\", name->cstr());\n\t\t\t\tsyntaxError(\"undefined word\");\n\t\t\t\t\n\t\t}\n\n\t}\n\t\n\treturn true;\n}\n\nstatic bool parseString(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseString\");\n\tParsingWhat pw(th, parsingString);\n\t\n\tV string = parseString(th);\t\n\tcode->add(opPushImmediate, string);\n\n\treturn true;\n}\n\n", "suffix_code": "\n\nbool parseElem(Thread& th, P& code)\n{\t\n\tskipSpace(th);\n\tint c = th.c();\n\tif (c == 0)\n\t\treturn false;\n\tif (c == ']' || c == ')' || c == '}') {\n\t\tpost(\"unexpected '%c'.\\n\", c);\n\t\tthrow errSyntax;\n\t}\n\tif (c == '@')\n\t\t return parseEachOp(th, code);\n\tif (c == '(')\n\t\t return parseParens(th, code);\n\tif (c == '[')\n\t\t return parseArray(th, code);\n\tif (c == '{')\n\t\t return parseNewForm(th, code);\n\tif (c == '\\\\')\n\t\t return parseLambda(th, code);\n\tif (c == '\"')\n\t\treturn parseString(th, code);\n\tif (c == '\\'') \n\t\treturn parseQuote(th, code);\n\tif (c == '`') \n\t\treturn parseBackquote(th, code);\n\tif (c == ',') \n\t\treturn parseComma(th, code);\n\tif (c == ':')\n\t\treturn parseColon(th, code);\n\n\tif (c == '0' && th.d() == 'x') \n\t\treturn parseHexNumber(th, code) || parseWord(th, code);\n\n\tif (isdigit(c) || c == '+' || c == '-')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n \n if (c == 'p' && th.d() == 'i')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n\n\tif (c == '.')\n\t\treturn parseNumber(th, code) || parseDot(th, code);\n\n\n\tif (c == '#') {\n\t\tint d = th.d();\n\t\tif (!d) syntaxError(\"end of input after '#'\");\n\t\tif (d == '[') {\n\t\t\treturn parseZArray(th, code);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\treturn parseWord(th, code);\n}\n\n\nbool parseElems(Thread& th, P& code)\n{\n\tcode = new Code(8);\n\twhile (1) {\n\t\tif (!parseElem(th, code)) break;\n\t}\n\t\n\tcode->add(opReturn, 0.);\n\tcode->shrinkToFit();\n\t\t\n\treturn true;\n}\n\n/////////////////////////\n\n#pragma mark PRINTI\n\n#include \n\n///////////////////////// 1 2 3 4 5 6\n/////////////////////////1234567890123456789012345678901234567890123456789012345678901234\nconst char* s64Spaces = \" \";\nconst int kNumSpaces = 64;\n\nstatic void printSpaces(std::ostream& ost, int n)\n{\n\twhile (n >= kNumSpaces) {\n\t\tost << s64Spaces;\n\t\tn -= kNumSpaces;\n\t}\n\tif (n) {\n\t\tost << (s64Spaces + kNumSpaces - n);\n\t}\n}\n\nvoid printi(std::ostream& ost, int indent, const char* fmt, ...)\n{\n\tprintSpaces(ost, indent);\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n\nvoid prints(std::ostream& ost, const char* fmt, ...)\n{\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n//////////////////////////////////\n\n", "middle_code": "static String* parseString(Thread& th)\n{\n\tif (th.c() != '\"') return nullptr;\n\tParsingWhat pw(th, parsingString);\n\tth.getc();\n\tint c = th.getc();\n\tstd::string str;\n\twhile (true) {\n\t\tif (c == 0) {\n\t\t\tsyntaxError(\"end of input in string\");\n\t\t} else if (c == '\\\\' && th.c() == '\\\\') {\n\t\t\tth.getc();\n\t\t\tc = th.getc();\n\t\t\tswitch (c) {\n\t\t\t\tcase 'n' : str += '\\n'; break;\n\t\t\t\tcase 'r' : str += '\\r'; break;\n\t\t\t\tcase 'f' : str += '\\f'; break;\n\t\t\t\tcase 'v' : str += '\\v'; break;\n\t\t\t\tcase 't' : str += '\\t'; break;\n\t\t\t\tdefault : str += c; break;\n\t\t\t}\n\t\t\tc = th.getc();\n\t\t} else if (c == '\"') {\n\t\t\tif (th.c() == '\"') {\n\t\t\t\tc = th.getc();\n\t\t\t\tstr += '\"';\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tstr += c;\n\t\t\tc = th.getc();\n\t\t}\n\t}\n\treturn new String(str.c_str());\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/sapf/src/VM.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Opcode.hpp\"\n#include \"Parser.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nVM vm;\n\npthread_mutex_t gHelpMutex = PTHREAD_MUTEX_INITIALIZER;\n\nstd::atomic randSeedCounter = 77777;\n\nuint64_t timeseed()\n{\n\tstruct timeval tv;\n\tgettimeofday(&tv, 0);\n\tint32_t counter = ++randSeedCounter;\n\treturn Hash64(tv.tv_sec) + Hash64(tv.tv_usec) + Hash64(counter);\n}\n\n\nThread::Thread()\n :rate(vm.ar), stackBase(0), localBase(0),\n\tmWorkspace(new GForm()),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent)\n :rate(inParent.rate), stackBase(0), localBase(0),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent, P const& inFun)\n :rate(vm.ar), stackBase(0), localBase(0),\n fun(inFun),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::~Thread() {}\n\n//////////////////////\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV vparent = th.pop();\n\tP
form = asParent(th, vparent);\n\tth.push(form);\n}\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value)\n{\t\n\tP table = new Table(tmap);\n\tP form = new Form(table, parent);\n\ttable->put(0, value);\n\treturn form;\n}\n\nstatic void newForm_(Thread& th, Prim* prim)\n{\n\tTableMap* tmap = (TableMap*)th.pop().o();\n\tsize_t numArgs = tmap->mSize;\n\t\n\tV* args = &th.top() - numArgs + 1;\n\t\n\tP
table = new Table(tmap);\n\tV vparent = args[-1];\n\tP parent = asParent(th, vparent);\n\t\n\tP form = new Form(table, parent);\n\t\n\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\ttable->put(i, args[i]);\n\t}\n\t\n\tth.popn(numArgs+1);\n\t\n\tth.push(form);\n}\n\nstatic void newVList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilv;\n\t} else {\n\t\tseq = new List(itemTypeV, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\tth.push(seq);\t\t\n}\n\nstatic void newZList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilz;\n\t} else {\n\t\tseq = new List(itemTypeZ, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\t\n\tth.push(seq);\t\t\n}\n\n//////////////////////\n\n\nVM::VM()\n\t:\n\tprelude_file(NULL),\n\tlog_file(NULL),\n\t_ee(0),\n\t\t\n\tprintLength(20),\n\tprintDepth(8),\n\t\n\tar(kDefaultSampleRate, kDefaultZBlockSize),\n\tkr(ar, kDefaultControlBlockSize),\n\t\n\tVblockSize(kDefaultVBlockSize),\n\t\n#if COLLECT_MINFO\n\ttotalRetains(0),\n\ttotalReleases(0),\n\ttotalObjectsAllocated(0),\n\ttotalObjectsFreed(0),\n\ttotalSignalGenerators(0),\n\ttotalStreamGenerators(0)\n#endif\n{\n\tinitElapsedTime();\n\t\n\t_ee = new Form(0, NULL);\n\t\t\n\tbuiltins = new GTable();\n\t\n\t// add built in funs\n\t\t\n\t_nilz = new List(itemTypeZ);\n\t_nilv = new List(itemTypeV);\n\t\n\t_anilz = _nilz->mArray;\n\t_anilv = _nilv->mArray;\n\t\n\tnewForm = new Prim(newForm_, 0., 0, 1, NULL, NULL);\n\tinherit = new Prim(inherit_, 0., 0, 1, NULL, NULL);\n\n\tnewVList = new Prim(newVList_, 0., 0, 1, NULL, NULL);\n\tnewZList = new Prim(newZList_, 0., 0, 1, NULL, NULL);\n}\n\nVM::~VM()\n{\n}\n\n#if USE_LIBEDIT\nstatic const char* prompt(EditLine *e) \n{\n return \"sapf> \";\n}\nstatic const char* promptParen(EditLine *e) \n{\n return \"(sapf> \";\n}\nstatic const char* promptSquareBracket(EditLine *e) \n{\n return \"[sapf> \";\n}\nstatic const char* promptCurlyBracket(EditLine *e) \n{\n return \"{sapf> \";\n}\nstatic const char* promptLambda(EditLine *e) \n{\n return \"\\\\sapf> \";\n}\nstatic const char* promptString(EditLine *e) \n{\n return \"\\\"sapf> \";\n}\n#endif\n\nvoid Thread::getLine()\n{\t\n\tif (fromString) return;\n\tswitch (parsingWhat) {\n\t\tdefault: case parsingWords : el_set(el, EL_PROMPT, &prompt); break;\n\t\tcase parsingString : el_set(el, EL_PROMPT, &promptString); break;\n\t\tcase parsingParens : el_set(el, EL_PROMPT, &promptParen); break;\n\t\tcase parsingLambda : el_set(el, EL_PROMPT, &promptLambda); break;\n\t\tcase parsingArray : el_set(el, EL_PROMPT, &promptSquareBracket); break;\n\t\tcase parsingEnvir : el_set(el, EL_PROMPT, &promptCurlyBracket); break;\n\t}\n\tline = el_gets(el, &linelen);\n\tlinepos = 0;\n\tif (strncmp(line, \"quit\", 4)==0 || strncmp(line, \"..\", 2)==0) { line = NULL; throw errUserQuit; }\n\tif (line && linelen) {\n\t\thistory(myhistory, &ev, H_ENTER, line);\n\t\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\t\tif (logfilename) {\n\t\t\tFILE* logfile = fopen(logfilename, \"a\");\n\t\t\tlogTimestamp(logfile);\n\t\t\tfwrite(line, 1, strlen(line), logfile);\n\t\t\tfclose(logfile);\n\t\t}\n\t}\n}\n\nvoid Thread::logTimestamp(FILE* logfile)\n{\n\ttimeval tv;\n\tgettimeofday(&tv, NULL);\n\tif (previousTimeStamp == 0 || tv.tv_sec - previousTimeStamp > 3600) {\n\t\tpreviousTimeStamp = tv.tv_sec;\n\t\tchar date[32];\n\t\tctime_r(&tv.tv_sec, date);\n\t\tfprintf(logfile, \";;;;;;;; %s\", date);\n\t\tfflush(logfile);\n\t}\n}\n\nchar Thread::getc() { \n\tif (fromString) {\n\t\tif (line == NULL) return 0;\n\t\treturn line[linepos++];\n\t} else {\n\t\twhile (1) {\t\n\t\t\tif (line == NULL) {\n\t\t\t\tgetLine();\n\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t} else if (line[linepos] == 0) {\n\t\t\t\tif (parsingWhat == parsingWords) {\n\t\t\t\t\treturn 0;\n\t\t\t\t} else {\n\t\t\t\t\tgetLine();\n\t\t\t\t\tif (linelen == 0 || strcmp(line, \"\\n\") == 0) {\n\t\t\t\t\t\tline = NULL;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn line[linepos++];\n\t\t\t}\n\t\t}\n\t}\n\treturn 0; // never gets here, but compiler too dumb to figure this out.\n}\n\nvoid Thread::repl(FILE* infile, const char* inLogfilename)\n{\n\tThread& th = *this;\n\n\tlogfilename = inLogfilename;\n\t\n\tpreviousTimeStamp = 0;\n\n#if USE_LIBEDIT\n\tel = el_init(\"sc\", stdin, stdout, stderr);\n\tel_set(el, EL_PROMPT, &prompt);\n\tel_set(el, EL_EDITOR, \"emacs\");\n\tel_set(el, EL_BIND, \"-s\", \"\\t\", \" \", NULL);\n\n\tmyhistory = history_init();\n\tif (myhistory == 0) {\n\t\tpost(\"history could not be initialized\\n\");\n\t\treturn;\n\t}\n\n\tconst char* envHistoryFileName = getenv(\"SAPF_HISTORY\");\n\tif (envHistoryFileName) {\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s\", envHistoryFileName);\n\t} else {\n\t\tconst char* homeDir = getenv(\"HOME\");\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s/sapf-history.txt\", homeDir);\n\t}\n\thistory(myhistory, &ev, H_SETSIZE, 800);\n\thistory(myhistory, &ev, H_LOAD, historyfilename);\n\thistory(myhistory, &ev, H_SETUNIQUE, 1);\n\tel_set(el, EL_HIST, history, myhistory);\n#endif\n\t\n\tfflush(infile);\n\tbool running = true;\n\n\tpost(\"Type 'helpall' to get a list of all built-in functions.\\n\");\n\tpost(\"Type 'quit' to quit.\\n\");\n\t\n\tdo {\n\t\ttry {\n\t\t\tif (stackDepth()) {\n\t\t\t\tprintStack();\n\t\t\t\tpost(\"\\n\");\n\t\t\t}\n\t\t} catch (int err) {\n\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"\\nunknown error\\n\");\n\t\t}\n\t\t\t\t\n\t\ttry {\n\t\t\t// PARSE\n\t\t\t{\n\t\t\t\tP compiledFun;\n\t\t\t\tif (compile(NULL, compiledFun, true)) {\n\t\t\t\t// EVAL\n\t\t\t\t\tcompiledFun->runREPL(th);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (V& v) {\n post(\"error: \");\n v.print(th);\n\t\t\tpost(\"\\n\");\n\t\t} catch (int err) {\n\t\t\tif (err == errUserQuit) {\n\t\t\t\tpost(\"good bye\\n\");\n\t\t\t\trunning = false;\n\t\t\t} else if (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"error: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"not enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"unknown error\\n\");\n\t\t}\n\n\t} while (running);\n\t\n\n#if USE_LIBEDIT\n\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\thistory_end(myhistory);\n\tel_end(el);\n#endif\n}\n\n\ntemplate \nclass AutoFree\n{\n\tT* p;\npublic:\n\tAutoFree(T* _p) : p(_p) {}\n\t~AutoFree() { free(p); }\n\t\n\tT* operator()() { return p; }\n\tT* operator*() { return p; }\n\tT* operator->() { return p; }\n};\n\nvoid loadFile(Thread& th, const char* filename)\n{\n post(\"loading file '%s'\\n\", filename);\n\tFILE* f = fopen(filename, \"r\");\n\tif (!f) {\n\t\tpost(\"could not open '%s'\\n\", filename);\n\t\treturn;\n\t}\n\n\tfseek(f, 0, SEEK_END);\n\tint64_t fileSize = ftell(f);\n\tfseek(f, 0, SEEK_SET);\n\t\n\tAutoFree buf = (char*)malloc(fileSize + 1);\n\tconst char* p = buf();\n\tfread(buf(), 1, fileSize, f);\n\tbuf()[fileSize - 1] = 0;\n\t\t\n\ttry {\n\t\t{\n\t\t\tP compiledFun;\n\t\t\tif (th.compile(p, compiledFun, true)) {\n\t\t\t\tpost(\"compiled OK.\\n\");\n\t\t\t\tcompiledFun->run(th);\n\t\t\t\tpost(\"done loading file\\n\");\n\t\t\t}\n\t\t}\n } catch (V& v) {\n post(\"error: \");\n v.print(th);\n post(\"\\n\");\n\t} catch (int err) {\n\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t} else {\n\t\t\tpost(\"error: %d\\n\", err);\n\t\t}\n\t} catch (std::bad_alloc& xerr) {\n\t\tpost(\"not enough memory\\n\");\n\t} catch (...) {\n\t\tpost(\"unknown error\\n\");\n\t}\n}\n\nvoid Thread::printStack()\n{\n\tbool between = false;\n\tsize_t n = stackDepth();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &stack[stackBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid Thread::printLocals()\n{\n\tbool between = false;\n\tsize_t n = numLocals();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &local[localBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid VM::setSampleRate(double inSampleRate)\n{\n\tar = Rate(inSampleRate, ar.blockSize);\n\tkr = Rate(ar, kDefaultControlBlockSize);\n}\n\nV VM::def(Arg key, Arg value)\n{\n\tbuiltins->putImpure(key, value); \n V dummy;\n assert(builtins->getInner(key, dummy));\n\treturn value;\n}\n\nV VM::def(const char* name, Arg value)\n{\n\tdef(V(getsym(name)), value);\n\treturn value;\n}\n\nV VM::def(const char* name, int takes, int leaves, PrimFun pf, const char* help, Arg value, bool setNoEach)\n{\n\tV aPrim = new Prim(pf, value, takes, leaves, name, help);\n\tdef(name, aPrim);\n\t\n\tif (setNoEach) aPrim.SetNoEachOps();\n\t\n\tif (help)\n\t\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\t\t\n\treturn aPrim;\n}\n\nV VM::defmcx(const char* name, int numArgs, PrimFun pf, const char* help, Arg value)\n{\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = mcx(numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\nV VM::defautomap(const char* name, const char* mask, PrimFun pf, const char* help, Arg value)\n{\n\tint numArgs = (int)strlen(mask);\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = automap(mask, numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\n\n#pragma mark STACK\n\n#define POPREFTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPFUNTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\nPOPREFTYPEDEF(Ref);\nPOPTYPEDEF(ZRef);\nPOPTYPEDEF(String);\nPOPTYPEDEF(List);\nPOPFUNTYPEDEF(Fun);\nPOPTYPEDEF(Form);\n\nvoid Thread::ApplyIfFun(V& v)\n{\n if (v.isFunOrPrim()) {\n SaveStack ss(*this);\n v.apply(*this);\n v = pop();\n }\n}\n\n\nV Thread::popZInList(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn() && !p.isVList()) {\n\t\twrongType(msg, \"Real or Signal or List of Reals or Signals\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popZIn(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef() || p.isZRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn()) {\n\t\twrongType(msg, \"Real or Signal\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popValue()\n{\n\tV p = pop().deref();\n ApplyIfFun(p);\n\treturn p;\n}\n\nP Thread::popVList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isVList()) {\n\t\twrongType(msg, \"Stream\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nP Thread::popZList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isZList()) {\n\t\twrongType(msg, \"Signal\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nint64_t Thread::popInt(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Real\", v);\n\t\n\tdouble f = v.f;\n\tint64_t i;\n\tif (f >= (double)LLONG_MAX) i = LLONG_MAX;\n\telse if (f <= (double)LLONG_MIN) i = LLONG_MIN;\n\telse i = (int64_t)f;\n\treturn i;\n}\n\ndouble Thread::popFloat(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Float\", v);\n\treturn v.f;\n}\n\nvoid Thread::tuck(size_t n, Arg v)\n{\n\tstack.push_back(V(0.));\n\tV* sp = &stack.back();\n\t\n\tfor (size_t i = 0; i < n; ++i)\n\t\tsp[-i] = sp[-i-1];\n\t\n\tsp[-n] = v;\n}\n\n///////////////////////////////////////\n\nbool Thread::compile(const char* inString, P& compiledFun, bool inTopLevel)\n{\t\n\tThread& th = *this;\n\tSaveCompileScope scs(th);\n\tif (inTopLevel) {\n\t\tmCompileScope = new TopCompileScope();\n\t} else {\n\t\tmCompileScope = new InnerCompileScope(new TopCompileScope());\n\t}\n\t\n\tP code;\n\tsetParseString(inString);\n\tgetLine();\n\tbool ok = parseElems(th, code);\n\tif (!ok || !code) {\n\t\tpost(\"parse error. %d\\n\", ok);\n\t\treturn false;\n\t}\n\t\t\n\tcompiledFun = new Fun(*this, new FunDef(*this, code, 0, th.mCompileScope->numLocals(), th.mCompileScope->numVars(), NULL));\n\t\n\treturn true;\n}\n\nint TopCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = CompileScope::directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) return scope;\n\n\tfor (size_t i = 0; i < mWorkspaceVars.size(); ++i) {\n\t\tif (mWorkspaceVars[i].mName() == inName()) {\n\t\t\treturn scopeWorkspace;\n\t\t}\n\t}\n\t\n\tV value;\n\tif (th.mWorkspace->get(th, inName(), value)) {\n\t\treturn scopeWorkspace;\n\t} else if (vm.builtins->get(th, inName, value)) {\n\t\toutBuiltIn = value;\n\t\treturn scopeBuiltIn;\n\t}\n\n\treturn scopeUndefined;\n}\n\n\nint CompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tfor (size_t i = 0; i < mLocals.size(); ++i) {\n\t\tif (mLocals[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeLocal;\n\t\t}\n\t}\n\tfor (size_t i = 0; i < mVars.size(); ++i) {\n\t\tif (mVars[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeFunVar;\n\t\t}\n\t}\n\t\n\treturn scopeUndefined;\n}\n\n\nint TopCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint InnerCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) \n\t\treturn scope;\n\n\tsize_t outerIndex;\n\tscope = mNext->indirectLookup(th, inName, outerIndex, outBuiltIn);\n\tif (scope == scopeUndefined) \n\t\treturn scopeUndefined;\n\t\n\tif (scope == scopeLocal || scope == scopeFunVar) {\n\t\tVarDef def;\n\t\tdef.mName = inName;\n\t\tdef.mIndex = mVars.size();\n\t\tdef.mFromScope = scope;\n\t\tdef.mFromIndex = outerIndex;\n\t\toutIndex = mVars.size();\n\t\tmVars.push_back(def);\n\t\treturn scopeFunVar;\n\t}\n\t\n\treturn scope;\n}\n\nint TopCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope != scopeUndefined && scope != scopeBuiltIn) \n\t\treturn scope; // already defined\n\t\t\n\tWorkspaceDef def;\n\tdef.mName = inName;\n\tmWorkspaceVars.push_back(def);\n\n\treturn scopeWorkspace;\n}\n\nint CompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope == scopeFunVar) {\n\t\tpost(\"Name %s is already in use in this scope as a free variable.\\n\", inName->cstr());\n\t\tthrow errSyntax;\n\t}\n\t\n\tif (scope == scopeUndefined) {\t\t\n\t\tLocalDef def;\n\t\tdef.mName = inName;\n\t\toutIndex = def.mIndex = mLocals.size();\n\t\tmLocals.push_back(def);\n\t}\n\treturn scopeLocal;\n}\n\nint InnerCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn innerBindVar(th, inName, outIndex);\n}\n\nCompileScope* ParenCompileScope::nextNonParen() const\n{\n\tCompileScope* scope = mNext();\n\twhile (scope->isParen()) {\n\t\tscope = scope->mNext();\n\t}\n\treturn scope;\n}\n\nint ParenCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->indirectLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\nint ParenCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\n//////////////////////\n\n\n\n\n"], ["/sapf/src/Object.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Object.hpp\"\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"MathOps.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n\nvoid post(const char* fmt, ...)\n{\n va_list vargs;\n va_start(vargs, fmt);\n vprintf(fmt, vargs);\n}\n\nvoid zprintf(std::string& out, const char* fmt, ...)\n{\n\tchar s[1024];\n\tva_list args;\n\tva_start(args, fmt);\n\tvsnprintf(s, 1024, fmt, args);\n\tout += s;\n}\n\n#pragma mark ERROR HANDLING\n\n\nThread gDummyThread;\n\n[[noreturn]] void notFound(Arg key)\n{\n\tpost(\"notFound \");\n\tkey.print(gDummyThread); // keys are either symbols or numbers neither of which will use the thread argument to print.\n\tpost(\"\\n\");\n\tthrow errNotFound;\n}\n\n[[noreturn]] void wrongType(const char* msg, const char* expected, Arg got)\n{\n\tpost(\"error: wrong type for %s . expected %s. got %s.\\n\", msg, expected, got.TypeName());\n\tthrow errWrongType;\n}\n\n[[noreturn]] void syntaxError(const char* msg)\n{\n\tpost(\"syntax error: %s\\n\", msg);\n\tthrow errSyntax;\n}\n\n[[noreturn]] void indefiniteOp(const char* msg1, const char* msg2)\n{\n\tpost(\"error: operation on indefinite object %s%s\\n\", msg1, msg2);\n\tthrow errIndefiniteOperation;\n}\n\n#pragma mark OBJECT\n\n\nObject::Object()\n\t: scratch(0), elemType(0), finite(false), flags(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nObject::~Object()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\nvoid Ref::set(Arg inV)\n{\n\tO oldval = nullptr;\n\tif (inV.isObject()) {\n\t\tO newval = inV.o();\n\t\n\t\tnewval->retain();\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = newval;\n\t\t}\n\t} else {\n\t\tZ newval = inV.f;\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = nullptr;\n\t\t\tz = newval;\n\t\t}\n\t}\n\tif (oldval)\n\t\toldval->release();\n}\n\nvoid ZRef::set(Z inZ)\n{\n\tz = inZ;\n}\n\nV Ref::deref() const\n{\n\tV out;\n\t{\n\t\tSpinLocker lock(mSpinLock);\n\t\tif (o) {\n\t\t\tout = o;\n\t\t\tif (o) o->retain();\n\t\t}\n\t\telse out = z;\n\t}\n\treturn out;\n}\n\nV ZRef::deref() const\n{\n\treturn z;\n}\n\nZ Object::derefz() const\n{\n\treturn asFloat();\n}\n\nZ ZRef::derefz() const\n{\n\treturn z;\n}\n\n\nForm::Form(P
const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nvolatile int64_t gTreeNodeSerialNumber;\n\nGForm::GForm(P const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nGForm::GForm(P const& inNext)\n\t: Object(), mNextForm(inNext)\n{ \n\tmTable = new GTable();\n}\n\nP consForm(P const& inTable, P const& inNext) { return new GForm(inTable, inNext); }\nP consForm(P
const& inTable, P const& inNext) { return new Form(inTable, inNext); }\n\nvoid Object::apply(Thread& th) {\n\tth.push(this);\n}\n\nclass PushFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nclass PushREPLFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushREPLFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushREPLFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nvoid Fun::runREPL(Thread& th)\n{\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushREPLFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::run(Thread& th)\n{\t\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.setStackBase();\n\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::apply(Thread& th) \n{ \n\tint numArgs = NumArgs();\n\n\tif (th.stackDepth() < (size_t)numArgs) {\n\t\tthrow errStackUnderflow;\n\t}\n\n\tif (NoEachOps()) {\n\t\trun(th);\n\t} else {\n\t\tif (th.stackDepth()) {\n\t\t\tbool haveEachOps = false;\n\t\t\tV* args = &th.top() - numArgs + 1;\n\n\t\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, numArgs, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\trun(th);\n\t\t\t}\n\t\t} else {\n\t\t\trun(th);\n\t\t}\n\t}\n}\n\nFun::Fun(Thread& th, FunDef* def)\n\t: mDef(def), mWorkspace(def->Workspace())\n{\n\tif (NumVars()) {\n\t\tmVars.insert(mVars.end(), th.stack.end() - NumVars(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumVars(), th.stack.end());\n\t}\n}\n\nFunDef::FunDef(Thread& th, P const& inCode, uint16_t inNumArgs, uint16_t inNumLocals, uint16_t inNumVars, P const& inHelp) \n\t: mCode(inCode), mNumArgs(inNumArgs), mNumLocals(inNumLocals), mNumVars(inNumVars), \n mWorkspace(th.mWorkspace),\n mHelp(inHelp)\n{\n}\n\nFun::~Fun()\n{\n}\n\nvoid Prim::apply(Thread& th) \n{\n\tapply_n(th, mTakes);\n}\n\nvoid Prim::apply_n(Thread& th, size_t n)\n{ \n\tif (th.stackDepth() < n)\n\t\tthrow errStackUnderflow;\n\t\n\tif (NoEachOps()) {\n\t\tprim(th, this); \n\t} else {\n\t\n\t\tif (n) {\n\t\t\tV* args = &th.top() - n + 1;\n\n\t\t\tbool haveEachOps = false;\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, (int)n, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\tprim(th, this); \n\t\t\t}\n\t\t} else {\n\t\t\tprim(th, this); \n\t\t}\n\t}\n}\n\nbool Form::get(Thread& th, Arg key, V& value) const\n{\n const Form* e = this;\n\tint64_t hash = key.Hash();\n do {\n if (e->mTable->getWithHash(th, key, hash, value)) {\n return true;\n }\n e = (Form*)e->mNextForm();\n } while (e);\n return false;\n}\n\n\nV Form::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\nbool GForm::get(Thread& th, Arg key, V& value) const\n{\n const GForm* e = this;\n do {\n if (e->mTable->get(th, key, value)) {\n return true;\n }\n e = (GForm*)e->mNextForm();\n } while (e);\n return false;\n}\n\nGForm* GForm::putImpure(Arg key, Arg value)\n{\n\tif (mTable->putImpure(key, value)) return this;\n\treturn putPure(key, value);\n}\n\nGForm* GForm::putPure(Arg inKey, Arg inValue)\n{\n\tint64_t inKeyHash = inKey.Hash();\n\treturn new GForm(mTable->putPure(inKey, inKeyHash, inValue), mNextForm);\n}\n\nV GForm::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\n\nGTable* GTable::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n auto tree = mTree.load();\n\tif (tree) {\n\t\treturn new GTable(tree->putPure(inKey, inKeyHash, inValue));\n\t} else {\n\t\tint64_t serialNo = ++gTreeNodeSerialNumber;\n\t\treturn new GTable(new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n\t}\n}\n\nTreeNode* TreeNode::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n\tif (inKeyHash == mHash && inKey.Identical(mKey)) {\n\t\treturn new TreeNode(mKey, mHash, inValue, mSerialNumber, mLeft, mRight);\n\t} \n auto left = mLeft.load();\n auto right = mRight.load();\n if (inKeyHash < mHash) {\n if (left) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left->putPure(inKey, inKeyHash, inValue), right);\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr), right);\n }\n\t} else {\n if (right) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, right->putPure(inKey, inKeyHash, inValue));\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n }\n\t}\n}\n\nstatic bool TreeNodeEquals(Thread& th, TreeNode* a, TreeNode* b)\n{\n while (1) {\n if (!a) return !b;\n if (!b) return false;\n \n if (!a->mKey.Equals(th, b->mKey)) return false;\n if (!a->mValue.Equals(th, b->mValue)) return false;\n if (a->mLeft == 0) {\n if (b->mLeft != 0) return false;\n } else {\n if (b->mLeft == 0) return false;\n if (!TreeNodeEquals(th, a->mLeft, b->mLeft)) return false;\n }\n a = a->mRight;\n b = b->mRight;\n }\n}\n\nbool GTable::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isGTable()) return false;\n\tif (this == v.o()) return true;\n\tGTable* that = (GTable*)v.o();\n return TreeNodeEquals(th, mTree.load(), that->mTree.load());\n}\n\nvoid GTable::print(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tzprintf(out, \" \");\n\t\tp->mValue.print(th, out);\n\t\tzprintf(out, \" :\");\n\t\tp->mKey.print(th, out);\n\t\tzprintf(out, \"\\n\");\n\t}\n}\n\nvoid GTable::printSomethingIWant(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tif (p->mValue.leaves() != 0 && p->mValue.leaves() != 1) {\n\t\t\tzprintf(out, \" \");\n\t\t\tp->mKey.print(th, out);\n\t\t\tzprintf(out, \" : \");\n\t\t\tp->mValue.print(th, out);\n\t\t\tzprintf(out, \"\\n\");\n\t\t}\n\t}\n}\n\nbool GTable::get(Thread& th, Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nbool GTable::getInner(Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nV GTable::mustGet(Thread& th, Arg inKey) const\n{\n\tV value;\n\tif (get(th, inKey, value)) return value;\n\t\n\tthrow errNotFound;\n}\n\nbool GTable::putImpure(Arg inKey, Arg inValue)\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tvolatile std::atomic* treeNodePtr = &mTree;\n\twhile (1) {\n\t\tTreeNode* tree = treeNodePtr->load();\n\t\tif (tree == nullptr) {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n\t\t\tTreeNode* newNode = new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr);\n\t\t\tnewNode->retain();\n TreeNode* nullNode = nullptr;\n if (treeNodePtr->compare_exchange_weak(nullNode, newNode)) {\n break;\n }\n newNode->release();\n\t\t} else {\n\t\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\t\tif (treeKeyHash == inKeyHash) {\n\t\t\t\treturn false; // cannot rebind an existing value.\n\t\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\t\ttreeNodePtr = &tree->mLeft;\n\t\t\t} else {\n\t\t\t\ttreeNodePtr = &tree->mRight;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\n\nvoid TreeNode::getAll(std::vector >& vec)\n{\n\tP node = this;\n\tdo {\n\t\tvec.push_back(node);\n auto left = node->mLeft.load();\n\t\tif (left) left->getAll(vec);\n\t\tnode = node->mRight.load();\n\t} while (node());\n}\n\nstatic bool compareTreeNodes(P const& a, P const& b)\n{\n\treturn a->mSerialNumber < b->mSerialNumber;\n}\n\nstd::vector > GTable::sorted() const\n{\n\tstd::vector > vec;\n auto tree = mTree.load();\n\tif (tree) {\n\t\ttree->getAll(vec);\n\t\tsort(vec.begin(), vec.end(), compareTreeNodes);\n\t}\n\treturn vec;\n}\n\n/////////\n\n\nV List::unaryOp(Thread& th, UnaryOp* op)\n{\n\tif (isVList())\n\t\treturn new List(new UnaryOpGen(th, op, this));\n\telse\n\t\treturn new List(new UnaryOpZGen(th, op, this));\n\t\t\n}\n\nV List::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a)\n{\n\tif (isVList())\n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nV List::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a)\n{\n\treturn op->makeVList(th, _a, this);\n}\n\nV List::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a)\n{\n\tif (isVList()) \n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nvoid V::apply(Thread& th)\n{\n\tif (o) {\n\t\to->apply(th);\n\t} else {\n\t\tth.push(*this);\n\t}\n}\n\nV V::deref()\n{\n\tif (o) {\n\t\treturn o->deref();\n\t} else {\n\t\treturn *this;\n\t}\n}\n\nV V::mustGet(Thread& th, Arg key) const\n{\n\tif (o) {\n\t\treturn o->mustGet(th, key);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nbool V::get(Thread& th, Arg key, V& value) const\n{\n\tif (o) {\n\t\treturn o->get(th, key, value);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nint V::Hash() const \n{\n\tif (o) {\n\t\treturn o->Hash();\n\t} else {\n union {\n double f;\n uint64_t i;\n } u;\n u.f = f;\n\t\treturn (int)::Hash64(u.i);\n\t}\n}\n\nV V::unaryOp(Thread& th, UnaryOp* op) const\n{\n\treturn !o ? V(op->op(f)) : o->unaryOp(th, op);\n}\n\nV V::binaryOp(Thread& th, BinaryOp* op, Arg _b) const\n{\n\treturn !o ? _b.binaryOpWithReal(th, op, f) : o->binaryOp(th, op, _b);\n}\n\nV V::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a) const\n{\n\treturn !o ? V(op->op(_a, f)) : o->binaryOpWithReal(th, op, _a);\n}\n\nV V::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeVList(th, _a, *this) : o->binaryOpWithVList(th, op, _a);\n}\n\nV V::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeZList(th, _a, *this) : o->binaryOpWithZList(th, op, _a);\n}\n\nvoid Object::printDebug(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::printShort(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"#%s\", TypeName());\n\tout += s; \n}\n\nvoid Object::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %p}\", TypeName(), this);\n\tout += s; \n}\n\nvoid Prim::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\nvoid Prim::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\n\nvoid Ref::print(Thread& th, std::string& out, int depth)\n{\n\tV v = deref();\n\tv.print(th, out, depth);\n\tzprintf(out, \" R\");\n\t\n}\n\nvoid ZRef::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%g ZR\", z);\t\n}\n\nvoid String::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%s\", (char*)s);\n}\n\nvoid String::printDebug(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"\\\"%s\\\"\", (char*)s);\n}\n\nvoid GForm::print(Thread& th, std::string& out, int depth)\n{\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n zprintf(out, \"new\\n\");\n\t} else {\n\t\tzprintf(out, \"New\\n\");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n}\n\nvoid Form::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"{...} \");\n\t\treturn;\n\t}\n\t\n\tzprintf(out, \"{\");\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n\t\tzprintf(out, \" \");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n\t\n\tzprintf(out, \"}\");\n}\n\n\nvoid EachOp::print(Thread& th, std::string& out, int inDepth)\n{\n\tv.print(th, out, inDepth);\n\tzprintf(out, \" \");\n\t\n\t// try to print as concisely as possible.\n\tif (mask == 1) {\n\t\tzprintf(out, \"@\");\n\t} else if (ONES(mask) == 1 && 1 + CTZ(mask) <= 9) {\n\t\tzprintf(out, \"@%d\", 1 + CTZ(mask));\n\t} else if (CTZ(mask) == 0) {\n\t\tint n = CTZ(~mask);\n\t\twhile (n--) \n\t\t\tzprintf(out, \"@\");\n\t} else {\n\t\tzprintf(out, \"@\");\n\t\tint32_t m = mask;\n\t\twhile (m) {\n\t\t\tzprintf(out, \"%c\", '0' + (m&1));\n\t\t\tm >>= 1;\n\t\t}\n\t}\n}\n\n\nvoid Code::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"#Code{...}\");\n\t\treturn;\n\t}\n\n\tzprintf(out, \"#Code %d{\\n\", size());\n\tOpcode* items = getOps();\n\tfor (int i = 0; i < size(); ++i) {\n\t\tzprintf(out, \"%4d %s \", i, opcode_name[items[i].op]);\n\t\titems[i].v.printShort(th, out, depth+1);\n\t\tout += \"\\n\";\n\t}\n\tzprintf(out, \"}\\n\");\n}\n\nvoid List::print(Thread& th, std::string& out, int depth)\n{\n\tif (isV()) {\n\t\tzprintf(out, \"[\");\n\t} else {\n\t\tzprintf(out, \"#[\");\n\t}\n\t\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"...]\");\n\t\treturn;\n\t}\n\t\n\tbool once = true;\n\tList* list = this;\n\t\n\tfor (int i = 0; list && i < vm.printLength;) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tfor (int j = 0; j < a->size() && i < vm.printLength; ++j, ++i) {\n\t\t\tif (!once) zprintf(out, \" \");\n\t\t\tonce = false;\n\t\t\tif (a->isV()) {\n\t\t\t\ta->v()[j].print(th, out, depth+1);\n\t\t\t} else {\n\t\t\t\n\t\t\t\tzprintf(out, \"%g\", a->z()[j]);\n\t\t\t}\n\t\t}\n\t\tif (i >= vm.printLength) {\n\t\t\tzprintf(out, \" ...]\");\n\t\t\treturn;\n\t\t}\n\t\tlist = list->nextp();\n\t}\n\tif (list && list->mNext) {\n\t\tzprintf(out, \" ...]\");\n\t} else {\n\t\tzprintf(out, \"]\");\n\t}\n}\n\nvoid V::print(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->print(th, out, depth);\n}\n\nvoid V::printShort(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printShort(th, out, depth);\n}\n\nvoid V::printDebug(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printDebug(th, out, depth);\n}\n\n\nvoid V::print(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printShort(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printDebug(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nGen::Gen(Thread& th, int inItemType, bool inFinite)\n\t: mDone(false), mOut(0), mBlockSize(inItemType == itemTypeV ? vm.VblockSize : th.rate.blockSize)\n{\n\telemType = inItemType;\n\tsetFinite(inFinite);\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t++vm.totalStreamGenerators;\n\telse\n\t\t++vm.totalSignalGenerators;\n#endif\n}\n\nGen::~Gen()\n{\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t--vm.totalStreamGenerators;\n\telse\n\t\t--vm.totalSignalGenerators;\n#endif\n}\n\nvoid Gen::end() \n{\n\tsetDone();\n\tmOut->end();\n}\n\n\nvoid Gen::produce(int shrinkBy)\n{\n\tmOut->mArray->addSize(-shrinkBy);\n\tmOut = mOut->nextp();\n}\n\nvoid List::end()\n{\n\tassert(mGen);\n\tmNext = nullptr;\n\tmGen = nullptr;\n\tmArray = vm.getNilArray(elemType);\n}\n\nV* List::fulfill(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next();\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nZ* List::fulfillz(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next;\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nvoid List::link(Thread& th, List* inList)\n{\n\tassert(mGen);\n\tif (!inList) return;\n\tinList->force(th);\n\tmNext = inList->mNext;\n\tmArray = inList->mArray;\n\tmGen = nullptr;\n}\n\nvoid List::force(Thread& th)\n{\t\n\tSpinLocker lock(mSpinLock);\n\tif (mGen) {\n\t\tP gen = mGen; // keep the gen from being destroyed out from under pull().\n\t\tif (gen->done()) {\n\t\t\tgen->end();\n\t\t} else {\n\t\t\tgen->pull(th);\n\t\t}\n\t\t// mGen should be NULL at this point because one of the following should have been called: fulfill, link, end.\n\t}\n}\n\nint64_t List::length(Thread& th)\n{\n\tif (!isFinite())\n\t\tindefiniteOp(\"size\", \"\");\n\t\n\tList* list = this;\n\t\n\tint64_t sum = 0;\n\twhile (list) {\n\t\tlist->force(th);\n\t\t\n\t\tsum += list->mArray->size();\n\t\tlist = list->nextp();\n\t}\n\t\n\treturn sum;\n}\n\nArray::~Array()\n{\n\tif (isV()) {\n\t\tdelete [] vv;\n\t} else {\n\t\tfree(p);\n\t}\n}\n\nvoid Array::alloc(int64_t inCap)\n{\n\tif (mCap >= inCap) return;\n\tmCap = inCap;\n\tif (isV()) {\n\t\tV* oldv = vv;\n\t\tvv = new V[mCap];\n\t\tfor (int64_t i = 0; i < size(); ++i) \n\t\t\tvv[i] = oldv[i];\n\t\tdelete [] oldv;\n\t} else {\n\t\tp = realloc(p, mCap * elemSize());\n\t}\n}\n\nvoid Array::add(Arg inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = inItem;\n\telse zz[mSize++] = inItem.asFloat();\n}\n\nvoid Array::addAll(Array* a)\n{\n\tif (!a->mSize)\n\t\treturn;\n\t\t\n\tint64_t newSize = mSize + a->size();\n\tif (newSize > mCap)\n\t\talloc(NEXTPOWEROFTWO(newSize));\n\t\n\tif (isV()) {\n\t\tif (a->isV()) {\n\t\t\tV* x = vv + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t} else {\n\t\t\tV* x = vv + size();\n\t\t\tZ* y = a->zz;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t}\n\t} else {\n\t\tif (a->isV()) {\n\t\t\tZ* x = zz + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i].asFloat();\n\t\t} else {\n\t\t\tmemcpy(zz + mSize, a->zz, a->mSize * sizeof(Z));\n\t\t}\n\t}\n\tmSize = newSize;\n}\n\nvoid Array::addz(Z inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = V(inItem);\n\telse zz[mSize++] = inItem;\n}\n\nvoid Array::put(int64_t inIndex, Arg inItem)\n{\n\tif (isV()) vv[inIndex] = inItem;\n\telse zz[inIndex] = inItem.asFloat();\n}\n\nvoid Array::putz(int64_t inIndex, Z inItem)\n{\n\tif (isV()) vv[inIndex] = V(inItem);\n\telse zz[inIndex] = inItem;\n}\n\nIn::In()\n\t: mList(nullptr), mOffset(0), mConstant(0.), mIsConstant(true)\n{\n}\n\nVIn::VIn()\n{\n\tset(0.);\n}\n\nVIn::VIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nZIn::ZIn()\n{\n\tset(0.);\n}\n\nZIn::ZIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nBothIn::BothIn()\n{\n\tset(0.);\n}\n\nBothIn::BothIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nvoid VIn::set(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid VIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid BothIn::set(Arg inValue)\n{\n\tif (inValue.isList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setv(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid ZIn::set(Arg inValue)\n{\n\tif (inValue.isZList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nbool VIn::operator()(Thread& th, int& ioNum, int& outStride, V*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant;\n\t\treturn false;\n\t}\n\t\n\tif (mList) {\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n int num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->v() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n }\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant;\n\tmDone = true;\n\treturn true;\n}\n\nbool ZIn::operator()(Thread& th, int& ioNum, int& outStride, Z*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant.f;\n\t\treturn false;\n\t}\n\tif (mList) {\n\t\tif (mOnce) {\n\t\t\tmOnce = false;\n\t\t}\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n\t\t\tint num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->z() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n\t}\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant.f;\n ioNum = 0;\n\tmDone = true;\n\treturn true;\n}\n\nvoid dumpList(List const* list)\n{\n\tfor (int i = 0; list; ++i, list = list->nextp()) {\n\t\tprintf(\" List %d %p mGen %p\\n\", i, list, list->mGen());\n\t\tprintf(\" List %d %p mNext %p\\n\", i, list, list->nextp());\n\t\tprintf(\" List %d %p mArray %p %d\\n\", i, list, list->mArray(), (int)(list->mArray() ? list->mArray->size() : 0));\n\t}\n}\n\nbool VIn::link(Thread& th, List* inList)\n{\n\tif (!mList) return false;\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tV* out = inList->fulfill_link(n, mList->next());\n\t\t\t\tV* in = mList->mArray->v() + mOffset;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = in[i];\n\t\t\t\t}\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nbool ZIn::link(Thread& th, List* inList)\n{\t\n\tif (!mList) return false;\n\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tZ* out = inList->fulfillz_link(n, mList->next());\n\t\t\t\tZ* in = mList->mArray->z() + mOffset;\n\t\t\t\tmemcpy(out, in, n * sizeof(Z));\n\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nvoid In::advance(int inNum)\n{\n\tif (mList) {\n\t\tmOffset += inNum;\n\t\tif (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n\t\t\tmOffset = 0;\n\t\t}\n\t}\n}\n\nbool VIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::peek(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset];\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\telse\n\t\t\t\tv = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.asFloat();\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tz = mList->mArray->v()[mOffset++].asFloat();\n\t\t\telse\n\t\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onei(Thread& th, int64_t& i)\n{\n\tZ z = 0.;\n\tbool result = onez(th, z);\n\ti = (int64_t)floor(z);\n\treturn result;\n}\n\nbool ZIn::bench(Thread& th, int& ioNum)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, Z* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, float* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nvoid ZIn::hop(Thread& th, int framesToAdvance)\n{\n\tP list = mList;\n\tint offset = mOffset;\n\twhile (list && framesToAdvance) {\n\t\tlist->force(th);\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tif (avail >= framesToAdvance) {\n\t\t\toffset += framesToAdvance;\n\t\t\tmList = list;\n\t\t\tmOffset = offset;\n\t\t\treturn;\n\t\t}\n\t\tframesToAdvance -= avail;\n\t\toffset = 0;\n\t\tlist = list->next();\n\t\tif (!list) {\n\t\t\tmList = nullptr;\n\t\t\tmOffset = 0;\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nbool ZIn::fillSegment(Thread& th, int inNum, Z* outBuffer)\n{\n\tint framesToFill = inNum;\n\tif (mIsConstant) {\n\t\tZ z = mConstant.f;\n\t\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\treturn false;\n\t}\n\n\tP list = mList;\n\tint offset = mOffset;\n\tZ* out = outBuffer;\n\twhile (list) {\n\t\tlist->force(th);\n\t\tassert(list->mArray);\n\t\t\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tint numToFill = std::min(framesToFill, avail);\n\n\t\t// copy\n\t\tZ* in = list->mArray->z() + offset;\n\t\tmemcpy(out, in, numToFill * sizeof(Z));\n\t\tout += numToFill;\n\t\tframesToFill -= numToFill;\n\t\t\n\t\tif (framesToFill == 0)\n\t\t\treturn false;\n\t\t\n\t\tlist = list->next();\n\t\toffset = 0;\n\t}\n\t\n\tZ z = mConstant.f;\n\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\n\tmDone = true;\n\treturn true;\n}\n\n\nbool ZIn::mix(Thread& th, int& ioNum, Z* outBuffer)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0; i < n; ++i)\t{\n\t\t\toutBuffer[i] += *a;\n\t\t\ta += astride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nclass Comma : public Gen\n{\n\tVIn _a;\n\tV key;\npublic:\n\tComma(Thread& th, Arg a, Arg inKey) : Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {} \n\t\n\tvirtual const char* TypeName() const override { return \"Comma\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->comma(th, key);\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\nclass Dot : public Gen\n{\n\tVIn _a;\n\tV key;\n\tV defaultValue;\npublic:\n\tDot(Thread& th, Arg a, Arg inKey, Arg inDefaultValue)\n\t\t\t\t\t: Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Dot\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tV v = defaultValue;\n\t\t\t\t\t\ta->dot(th, key, v);\n\t\t\t\t\t\tout[i] = v;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\n\nV List::comma(Thread& th, Arg key)\n{\n\treturn new List(new Comma(th, this, key));\n}\n\nbool List::dot(Thread& th, Arg key, V& ioValue)\n{\n\tioValue = new List(new Dot(th, this, key, ioValue));\n\treturn true;\n}\n\nbool List::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isList()) return false;\n\tList* that = (List*)v.o();\n\tif (!isFinite())\n\t\tindefiniteOp(\"\", \"equals : a\");\n\tif (!that->isFinite())\n\t\tindefiniteOp(\"\", \"equals : b\");\n\t\n\tif (elemType != that->elemType) return false;\n\t\n\tif (isVList()) {\n\t\tVIn _a(this);\n\t\tVIn _b(that);\n\t\t\n\t\tV *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = kDefaultVBlockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n \n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (!a->Equals(th, *b)) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t\t\n\t} else {\n\t\tZIn _a(this);\n\t\tZIn _b(that);\n\t\t\n\t\tZ *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = th.rate.blockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (*a != *b) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t}\n\n}\n\nList::List(int inItemType) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, 0))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\nList::List(int inItemType, int64_t inCap) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, inCap))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\n\n\nList::List(P const& inGen) \n\t: mNext(nullptr), mGen(inGen), mArray(0)\n{\n\telemType = inGen->elemType;\n\tsetFinite(inGen->isFinite());\n\tinGen->setOut(this);\n}\n\nList::List(P const& inArray) \n\t: mNext(nullptr), mGen(nullptr), mArray(inArray)\n{\n\telemType = inArray->elemType;\n\tsetFinite(true);\n}\n\nList::List(P const& inArray, P const& inNext) \n\t: mNext(inNext), mGen(0), mArray(inArray)\n{\n\tassert(!mNext || mArray->elemType == mNext->elemType);\n\telemType = inArray->elemType;\n\tsetFinite(!mNext || mNext->isFinite());\n}\n\nList::~List()\n{\n\t// free as much tail as possible at once in order to prevent stack overflow.\n\tP list = mNext;\n\tmNext = nullptr;\n\twhile (list) {\n\t\tif (list->getRefcount() > 1) break;\n\t\tP next = list->mNext;\n\t\tlist->mNext = nullptr;\n\t\tlist = next;\n\t}\n}\n\nint64_t List::fillz(Thread& th, int64_t n, Z* z)\n{\n\tint64_t k = 0;\n\tP list = this;\n\twhile(list && k < n) {\n\t\tlist->force(th);\n\t\t\n\t\tint64_t m = std::min((n-k), list->mArray->size());\n\t\tfor (int64_t i = 0; i < m; ++i) {\n\t\t\tz[k++] = list->mArray->_atz(i);\n\t\t}\n\t\tlist = list->mNext;\n\t}\n\treturn k;\n}\n\n\nList* List::pack(Thread& th)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packz(Thread& th)\n{\n force(th);\n\tif (isPacked() && isZ())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(itemTypeZ, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::pack(Thread& th, int limit)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\t\t\n\t\tif (cap > limit) return nullptr;\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packSome(Thread& th, int64_t& limit)\n{\n force(th);\n\tif (isPacked()) {\n\t\tlimit = std::min(limit, length(th));\n\t\treturn this;\n\t}\n\t\t\n\tP list = this;\n\tint64_t count = 0;\n\twhile(list && count < limit) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcount += list->mArray->size();\t\n\t\t\t\t\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, count);\n\t\n\tlist = this;\n\tcount = 0;\n\twhile(list && count < limit) {\n\t\ta->addAll(list->mArray());\n\t\tcount += list->mArray->size();\t\n\t\tlist = list->mNext;\n\t}\n\tlimit = std::min(limit, count);\n\t\n\treturn new List(a);\n}\n\nvoid List::forceAll(Thread& th)\n{\n\tList* list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\tlist = list->nextp();\n\t}\n}\n\nV V::msgSend(Thread& th, Arg receiver)\n{\n\tif (!o) {\n\t\treturn *this;\n\t} else {\n\t\treturn o->msgSend(th, receiver);\n\t}\n}\n\nV Prim::msgSend(Thread& th, Arg receiver)\n{\n\tSaveStack ss(th, Takes());\n\tth.push(receiver);\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\nV Fun::msgSend(Thread& th, Arg receiver)\n{\n\tth.push(receiver);\n\tSaveStack ss(th, NumArgs());\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\t\nTableMap::TableMap(size_t inSize)\n\t: mSize(inSize)\n{\n\tif (inSize == 0) {\n\t\tmMask = 0;\n\t\tmIndices = nullptr;\n\t\tmKeys = nullptr;\n\t} else {\n\t\tsize_t n = 2*NEXTPOWEROFTWO((int64_t)mSize);\n\t\tmMask = n-1;\n\t\tmIndices = new size_t[n]();\n\t\tmKeys = new V[mSize];\n\t}\n}\n\nTableMap::TableMap(Arg inKey)\n\t: mSize(1)\n{\n\tmMask = 1;\n\tmIndices = new size_t[2]();\n\tmKeys = new V[mSize];\n\t\n\tmKeys[0] = inKey;\n\tmIndices[inKey.Hash() & 1] = 1;\n}\n\n\nTableMap::~TableMap()\n{\n\tdelete [] mKeys;\n\tdelete [] mIndices;\n}\n\nbool TableMap::getIndex(Arg inKey, int64_t inKeyHash, size_t& outIndex)\n{\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\tV* keys = mKeys;\n\twhile(1) {\n\t\tsize_t index = indices[i];\n\t\tif (index == 0)\n\t\t\treturn false;\n\t\tsize_t index2 = index - 1;\n\t\tif (inKey.Identical(keys[index2])) {\n\t\t\toutIndex = index2;\n\t\t\treturn true;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nvoid TableMap::put(size_t inIndex, Arg inKey, int64_t inKeyHash)\n{\n\tmKeys[inIndex] = inKey;\n\t\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\t\n\twhile(1) {\n\t\tif (indices[i] == 0) {\n\t\t\tindices[i] = inIndex + 1;\n\t\t\treturn;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nTable::Table(P const& inMap)\n\t: mMap(inMap), mValues(new V[mMap->mSize])\n{\n}\n\nTable::~Table()\n{\n\tdelete [] mValues;\n}\n\nbool Table::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isTable()) return false;\n\tif (this == v.o()) return true;\n\tTable* that = (Table*)v.o();\n\tsize_t size = mMap->mSize;\n\tif (size != that->mMap->mSize)\n\t\treturn false;\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tV key = mMap->mKeys[i];\n\t\tV thatValue;\n\t\tif (!that->getWithHash(th, key, key.Hash(), thatValue))\n\t\t\treturn false;\n\t\tif (!mValues[i].Equals(th, thatValue))\n\t\t\treturn false;\n\t}\n return true;\n}\n\nbool Table::getWithHash(Thread& th, Arg key, int64_t hash, V& value) const\n{\n\tsize_t index;\n\tif (!mMap->getIndex(key, hash, index))\n\t\treturn false;\n\tvalue = mValues[index];\n\treturn true;\n}\n\nvoid Table::put(size_t inIndex, Arg inValue)\n{\n\tmValues[inIndex] = inValue;\n}\n\nvoid Table::print(Thread& th, std::string& out, int depth)\n{\n\tfor (size_t i = 0; i < mMap->mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmMap->mKeys[i].print(th, out, depth+1);\n\t\tzprintf(out, \" \");\n\t\tmValues[i].print(th, out, depth+1);\n\t}\n}\n\nvoid TableMap::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"{\");\n\tfor (size_t i = 0; i < mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmKeys[i].print(th, out, depth+1);\n\t}\n\tzprintf(out, \"}\");\n}\n\n\nstatic P chase_z(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\n\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\n\t\t\treturn new List(a2, list->next());\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm._nilz;\n\t}\n\t\n\treturn list;\n}\n\nstatic P chase_v(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"chase : list\", \"\");\n\t}\n\t\n\tint64_t length = list->length(th);\n\t\n\tP result = new List(itemTypeV, length);\n\tP array = result->mArray;\n\tV* out = array->v();\n\t\n\tint64_t i = 0;\n\t\n\twhile (list) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tV* in = a->v();\n\t\t\n\t\tfor (int64_t j = 0; j < asize; ++j, ++i) {\n\t\t\tout[i] = in[j].chase(th, n);\n\t\t}\n\n\t\tlist = list->next();\n\t}\n\t\n\treturn list;\n}\n\nV List::chase(Thread& th, int64_t n)\n{\n\tif (isVList()) {\n\t\treturn chase_v(th, this, n);\n\t} else {\n\t\treturn chase_z(th, this, n);\n\t}\n}\n\nP Form::chaseForm(Thread& th, int64_t n)\n{\n\tP nextForm = mNextForm() ? mNextForm->chaseForm(th, n) : nullptr;\n\treturn new Form(mTable->chaseTable(th, n), nextForm);\n}\n\nP
Table::chaseTable(Thread& th, int64_t n)\n{\n\tP
result = new Table(mMap);\n\t\n\tsize_t size = mMap->mSize;\n\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tresult->mValues[i] = mValues[i].chase(th, n);\n\t}\n\t\n\treturn result;\n}\n\n\n\nvoid Plug::setPlug(Arg inV)\n{\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid Plug::setPlug(const VIn& inVIn, int inChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inVIn;\n\t}\n}\n\nvoid Plug::getPlug(VIn& outVIn, int& outChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\toutVIn = in;\n\toutChangeCount = mChangeCount;\n}\n\n\nvoid ZPlug::setPlug(Arg inV) {\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid ZPlug::setPlug(const ZIn& inZIn, int inChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inZIn;\n\t}\n}\n\nvoid ZPlug::getPlug(ZIn& outZIn, int& outChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\toutZIn = in;\n\toutChangeCount = mChangeCount;\n}\n"], ["/sapf/src/CoreOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Parser.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// stack shufflers\n#pragma mark STACK OPS\n\nstatic void clear_(Thread& th, Prim* prim)\n{\n\tth.clearStack();\n}\n\nstatic void cleard_(Thread& th, Prim* prim)\n{\n\tV v = th.top();\n\tth.clearStack();\n\tth.push(v);\n}\n\nstatic void stackDepth_(Thread& th, Prim* prim)\n{\n\tth.push(th.stackDepth());\n}\n\nstatic void ba_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[0] = sp[-1];\n\tsp[-1] = b;\n}\n\nstatic void bac_(Thread& th, Prim* prim) \n{\n\t// swapd\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = a;\n\tsp[0] = c;\n}\n\nstatic void cab_(Thread& th, Prim* prim)\n{\n\t// rrot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = a;\n\tsp[0] = b;\n}\n\nstatic void bca_(Thread& th, Prim* prim)\n{\n\t// rot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = c;\n\tsp[0] = a;\n}\n\nstatic void cba_(Thread& th, Prim* prim)\n{\n\t// reverse top 3\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n}\n\nstatic void aaa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n\tth.push(v);\n}\n\nstatic void aba_(Thread& th, Prim* prim)\n{\n\t// over\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tth.push(sp[-1]);\n}\n\nstatic void bab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\n\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n}\n\nstatic void aabb_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n\tth.push(b);\t\n}\n\nstatic void abab_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(a);\t\n\tth.push(b);\t\n}\n\nstatic void nip_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[-1] = b;\n\tth.pop();\n}\n\n\nstatic void pop_(Thread& th, Prim* prim)\n{\n\tth.pop();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark INHERIT\n\nstatic bool hasItem(int64_t size, Table** a, Table* item)\n{\n\tfor (int64_t i = 0; iIdentical(item))\n\t\t\treturn true;\n\t}\n\treturn false;\n}\n\nstatic void Envir_merge2(Thread& th, int64_t asize, Table** a, int64_t bsize, Table** b, int64_t& csize, Table** c0)\n{\n\n\tTable** c = c0;\n\tTable** aend = a + asize;\n\tTable** bend = b + bsize;\n\twhile (a < aend && b < bend) {\t\n\t\tif ((*a)->Identical(*b)) {\n\t\t\t*c++ = *a++;\n\t\t\tb++;\n\t\t} else if (!hasItem(bend-b-1, b+1, *a)) {\n\t\t\t*c++ = *a++;\n\t\t} else if (!hasItem(aend-a-1, a+1, *b)) {\n\t\t\t*c++ = *b++;\n\t\t} else {\n\t\t\tthrow errInconsistentInheritance;\n\t\t}\n\t}\n\twhile (a < aend) { *c++ = *a++; }\n\twhile (b < bend) { *c++ = *b++; }\n\tcsize = c - c0;\n}\n\t\nstatic int64_t Envir_toVec(O list, int64_t maxSize, Table** vec)\n{\n\tint64_t i = 0;\n\tfor (; list && i < maxSize-1;) {\n\t\tvec[i++] = ((Form*)list)->mTable();\n\t\tlist = ((Form*)list)->mNextForm();\n\t}\n\treturn i;\n}\n\nstatic P Envir_fromVec(int64_t size, Table** a)\n{\n\tif (size == 0) return vm._ee;\n\t\n\tP list;\n\tfor (int64_t i = size-1; i >= 0; --i) {\n\t\tlist = consForm(a[i], list);\n\t}\n\treturn list;\n}\n\n\nP linearizeInheritance(Thread& th, size_t numArgs, V* args)\n{\n\tif (numArgs == 0) return vm._ee;\n\tif (numArgs == 1) {\n\t\tif (args[0].isForm()) {\n\t\t\treturn (Form*)args[0].asObj();\n\t\t} else {\n\t\t\treturn vm._ee;\n\t\t}\n\t}\n\t\n\tconst size_t maxSize = 1024;\n\tTable* t[3][maxSize];\n\t\n\tint ai = 0;\n\tint bi = 1;\n\tint ci = 2;\n\n\tint64_t asize = Envir_toVec(args[0].asObj(), maxSize, t[ai]);\n\tfor (size_t i = 1; i < numArgs; ++i) {\n\t\tint64_t bsize = Envir_toVec(args[i].asObj(), maxSize, t[bi]);\n\t\tint64_t csize;\n\t\tEnvir_merge2(th, asize, t[ai], bsize, t[bi], csize, t[ci]);\n\t\tint temp = ci;\n\t\tci = ai;\n\t\tai = temp;\n\t\tasize = csize;\n\t}\n\treturn Envir_fromVec(asize, t[ai]);\n}\n\nP asParent(Thread& th, V& v)\n{\n\tP parent;\n\tif (v.isReal()) {\n\t\tparent = nullptr;\n\t} else if (v.isForm()) {\n\t\tif (v.o() == vm._ee()) parent = nullptr;\n\t\telse parent = (Form*)v.o();\n\t} else if (v.isFunOrPrim()) {\n\t\tSaveStack save(th);\n\t\tv.apply(th);\n\t\t\n\t\tsize_t n = th.stackDepth();\n\t\tV* args = &th.top() - (n - 1);\n\n\t\tparent = linearizeInheritance(th, n, args);\n\t\n\t\tth.popn(n);\n\t} else if (v.isVList()) {\n\t\tif (!v.isFinite())\n\t\t\tindefiniteOp(\"\", \"{} : parent\");\n\t\t\t\n\t\tP const& a = ((List*)v.o())->mArray;\n\t\tsize_t n = a->size();\n\t\tparent = linearizeInheritance(th, n, a->v());\n\t} else {\n\t\twrongType(\"new : parent\", \"Form, Fun or VList\", v);\n\t\treturn NULL; // never gets here, but otherwise gcc warns about parent uninitialized.\n\t}\n\treturn parent;\n}\n\nstruct Binding\n{\n\tV key;\n\tBothIn value;\n};\n\nstruct Bind : public Gen\n{\n\tP mMap;\n\tP mParent;\n\tstd::vector _bindings;\n\t\n\tBind(Thread& th, P& parent, P const& bindings, bool inIsFinite) \n\t\t: Gen(th, itemTypeV, inIsFinite), mParent(parent)\n\t{\n\t\tint64_t m = bindings->length(th);\n\t\tfor (int64_t i = 0; i+1 < m; i += 2) {\n\t\t\tBinding b;\n\t\t\tb.key = bindings->at(i);\n\t\t\tb.value.set(bindings->at(i+1));\n\t\t\t_bindings.push_back(b);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Bind\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tint n = framesToFill;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tP e = consForm(new Table(mMap), mParent);\n\t\t\t\n\t\t\tint64_t m = _bindings.size();\n\t\t\tfor (int64_t j = 0; j < m; ++j) {\n\t\t\t\tBinding& b = _bindings[j];\n\t\t\t\tV val;\n\t\t\t\tif (b.value.one(th, val)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\te->put(j, val); // ok, single threaded mutation\n\t\t\t}\n\t\t\t\n\t\t\tout[i] = e;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark REF OPS\n\n\nstatic void ref_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tV ref = new Ref(value);\n\tth.push(ref);\n}\n\nstatic void zref_(Thread& th, Prim* prim)\n{\n\tZ z = th.popFloat(\"zref : value\");\n\tth.push(new ZRef(z));\n}\n\n\nstatic void set_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tif (ref.isRef()) {\n\t\tV value = th.pop();\n\t\t((Ref*)ref.o())->set(value);\n\t} else if (ref.isZRef()) {\n\t\tZ value = th.popFloat(\"set : value\");\n\t\t((ZRef*)ref.o())->set(value);\n\t} else if (ref.isPlug()) {\n\t\tV value = th.pop();\n\t\t((Plug*)ref.o())->setPlug(value);\n\t} else if (ref.isZPlug()) {\n\t\tV value = th.popZIn(\"set : value\");\n\t\t((ZPlug*)ref.o())->setPlug(value);\n\t} else if (ref.isVList() && ref.isFinite()) {\n\t\tV value = th.pop();\n\t\tP refList = ((List*)ref.o())->pack(th);\n\t\tP refArray = refList->mArray;\n\t\tV* refs = refArray->v();\n\t\tif (value.isVList() && value.isFinite()) {\n\t\t\tP valueList = ((List*)value.o())->pack(th);\n\t\t\tP valueArray = valueList->mArray;\n\t\t\tV* vals = valueArray->v();\n\t\t\tsize_t n = std::min(refArray->size(), valueArray->size());\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(vals[i]);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t} else {\n\t\t\tsize_t n = refArray->size();\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(value);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"set : ref\", \"Ref, ZRef, Plug or ZPlug\", ref);\n\t}\n}\n\nstatic void get_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tth.push(ref.deref());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// printing ops\n#pragma mark PRINTING\n\nstatic void pr_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().print(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void prdebug_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().printDebug(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void cr_(Thread& th, Prim* prim)\n{\n\tpost(\"\\n\");\n}\n\nstatic void tab_(Thread& th, Prim* prim)\n{\n\tpost(\"\\t\");\n}\n\nstatic void sp_(Thread& th, Prim* prim)\n{\n\tpost(\" \");\n}\n\nstatic void prstk_(Thread& th, Prim* prim)\n{\n\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n}\n\n\nstatic void printLength_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printLength);\n}\n\nstatic void printDepth_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printDepth);\n}\n\nstatic void printTotalItems_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printTotalItems);\n}\n\nstatic void setPrintLength_(Thread& th, Prim* prim)\n{\n\tvm.printLength = (int)th.popInt(\"setPrintLength : length\");\n}\n\nstatic void setPrintDepth_(Thread& th, Prim* prim)\n{\n\tvm.printDepth = (int)th.popInt(\"setPrintDepth : depth\");\n}\n\nstatic void setPrintTotalItems_(Thread& th, Prim* prim)\n{\n\tvm.printTotalItems = (int)th.popInt(\"setPrintTotalItems : numItems\");\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// string ops\n#pragma mark STRINGS\n\nstatic void str_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.print(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void debugstr_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.printDebug(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void strcat_(Thread& th, Prim* prim)\n{\n\tP sep = th.popString(\"strcat : separator\");\n\tP list = th.popVList(\"strcat : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strcat : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tif (i != 0) s += sep->s;\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\nstatic void strlines_(Thread& th, Prim* prim)\n{\n\tP list = th.popVList(\"strlines : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strlines : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t\ts += \"\\n\";\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// loops\n#pragma mark LOOPS\n\nstatic void while_(Thread& th, Prim* prim)\n{\n\tV body = th.pop();\n\tV test = th.pop();\n\twhile (1) {\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\ttest.apply(th);\n\t\t\tif (th.pop().isTrue()) break;\n\t\t}\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\tbody.apply(th);\n\t\t}\n\t}\n}\n\n\nstatic void eachDoer(Thread& th, int level, uint32_t mask, BothIn& in, V& fun)\n{\n\tint nextLevel = level - 1;\n\tif (level == 0) {\n\t\twhile (1) {\n\t\t\tSaveStack ss(th);\n\t\t\tV v;\n\t\t\tif (in.one(th, v)) \n\t\t\t\treturn;\n\n\t\t\tth.push(v);\n\t\t\tfun.apply(th);\n\t\t}\n\t} else {\n\t\tint bit = 1 << level;\n\n\t\twhile (1) {\n\t\t\tV argv;\n\t\t\tif (in.one(th, argv))\n\t\t\t\treturn;\n\n\t\t\tbool isConstant = !(argv.isList() && (mask & bit));\n\t\t\t\n\t\t\tif (isConstant) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(argv);\n\t\t\t\tfun.apply(th);\n\t\t\t} else {\n\t\t\t\tBothIn subin;\n\t\t\t\tV v = argv;\n\t\t\t\tif (mask & bit) {\n\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\t\t\t\n\t\t\t\t\tsubin.set(v);\n\t\t\t\t} else {\n\t\t\t\t\tsubin.setConstant(v);\n\t\t\t\t}\n\t\t\t\n\t\t\t\teachDoer(th, nextLevel, mask, subin, fun);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstatic void do_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tV item = th.pop();\n\t\n\tif (item.isEachOp()) {\n\t\tP p = (EachOp*)item.o();\n\t\tif (!p->v.isFinite())\n\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\n\t\tBothIn in(p->v);\n\t\tint numLevels = p->mask <= 1 ? 0 : LOG2CEIL(p->mask) - 1;\n\t\teachDoer(th, numLevels, p->mask, in, f);\n\t} else if (item.isList()) {\n\t\n\t\tP s = (List*)item.o();\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"do\", \"\");\n\n\t\tif (s->isVList()) {\n\t\t\tVIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = kDefaultVBlockSize;\n\t\t\t\tint astride;\n\t\t\t\tV *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tZIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = th.rate.blockSize;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"do : list\", \"List\", item);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark CONDITIONALS\n\nstatic void equals_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(a.Equals(th, b));\n}\n\nstatic void less_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) < 0);\n}\n\nstatic void greater_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) > 0);\n}\n\nstatic void if_(Thread& th, Prim* prim)\n{\n\tV elseCode = th.pop();\n\tV thenCode = th.pop();\n\tV test = th.pop();\n\tif (test.isTrue()) {\n\t\tthenCode.apply(th);\n\t} else {\n\t\telseCode.apply(th);\n\t}\n}\n\nstatic void dip_(Thread& th, Prim* prim)\n{\n V temp = th.pop();\n V fun = th.pop();\n fun.apply(th);\n th.push(temp);\n}\n\nstatic void not_(Thread& th, Prim* prim)\n{\n\tV p = th.pop();\n\tth.pushBool(p.isFalse());\n}\n\nstatic void protect_(Thread& th, Prim* prim)\n{\n\tV protectCode = th.pop();\n\tV tryCode = th.pop();\n\n\t\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tprotectCode.apply(th);\n\t\tthrow;\n\t}\n\n\tprotectCode.apply(th);\n}\n\nstatic void try_(Thread& th, Prim* prim)\n{\n\tV catchCode = th.pop();\n\tV tryCode = th.pop();\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tcatchCode.apply(th);\n\t\tthrow;\n\t}\n}\n\nstatic void throw_(Thread& th, Prim* prim)\n{\n\tthrow -1;\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ENVIR OPS\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.push(asParent(th, v));\n}\n\nstatic void pushWorkspace_(Thread& th, Prim* prim)\n{\n\tth.mWorkspace = consForm(new GTable(), th.mWorkspace);\n}\n\nstatic void popWorkspace_(Thread& th, Prim* prim)\n{\n if (!th.mWorkspace->mNextForm()) {\n post(\"Must not pop top level workspace!\\n\");\n return;\n }\n\tth.mWorkspace = th.mWorkspace->mNextForm;\n}\n\n\nstatic void has_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV list = th.pop();\n\t\n\tV value;\n\tbool has = list.get(th, key, value);\n\tth.pushBool(has);\n}\n\nstatic void keys_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(keys[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\nstatic void values_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(vals[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\n\nstatic void kv_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"values : e\")->mTable;\n\t\n\tP ka = new Array(itemTypeV, t->mMap->mSize);\n\tP va = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\tka->add(keys[i]);\n\t\tva->add(vals[i]);\n\t}\n\n\tth.push(new List(ka));\n\tth.push(new List(va));\n}\n\nstatic void local_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"local : e\")->mTable;\n\t\n\tth.push(new Form(t));\n}\n\nstatic void parent_(Thread& th, Prim* prim)\n{\n\tP form = th.popForm(\"values : e\");\n\t\n\tth.push(form->mNextForm ? form->mNextForm : vm._ee);\n}\n\nstatic void dot_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV e = th.pop();\n\t\t\n\tif (!key.isVList()) {\n\t\tV v;\n\t\te.dot(th, key, v);\n\t\tth.push(v);\n\t} else {\n\t\tif (!key.isFinite())\n\t\t\tindefiniteOp(\"dot : key\", \"\");\n\t\tList* ks = (List*)key.o();\n\t\tks = ks->pack(th);\n\n\t\tP ka = ks->mArray;\n\t\tint64_t size = ka->size();\n\t\tP va = new Array(itemTypeV, size);\n\t\tva->setSize(size);\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tV v;\n\t\t\te.dot(th, key, v);\n\t\t\tth.push(v);\n\t\t}\n\t\tth.push(new List(va));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark APPLY\n\nstatic void noeach_(Thread& th, Prim* prim)\n{\n\tV fun = th.top();\n\t\n\tfun.SetNoEachOps();\n}\n\nstatic void apply_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tv.apply(th);\n}\n\nstatic void applyEvent_(Thread& th, Prim* prim)\n{\n\tP fun = th.popFun(\"!e : fun\");\n\tP form = th.popForm(\"!e : form\");\n\t\n\tfor (auto const& name : fun->mDef->mArgNames) {\n\t\tV argValue;\n\t\tif (!form->dot(th, name, argValue)) {\n\t\t\tnotFound(name);\n\t\t}\n\t\tth.push(argValue);\n\t}\n\t\n\tfun->apply(th);\n}\n\nstatic void type_(Thread& th, Prim* prim)\n{\n\tth.push(getsym(th.pop().TypeName()));\n}\n\nstatic void load_(Thread& th, Prim* prim)\n{\n\tP filename = th.popString(\"load : filename\");\n\tloadFile(th, filename->s);\n}\n\nstatic void compile_(Thread& th, Prim* prim)\n{\n\tP s = th.popString(\"compile : string\");\n\tconst char* ss = s->s;\n\t\n\tP fun;\n\tif (!th.compile(ss, fun, false)) {\n\t\tth.push(0.);\n\t} else {\n\t\tth.push(fun);\n\t}\n}\n\nstatic void y_combinator_call_(Thread& th, Prim* prim)\n{\n\tth.push(prim);\n\tprim->v.apply(th);\n}\n\nstatic void Y_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tif (f.takes() < 1) {\n\t\tpost(\"Y : fun. function must take at least one argument.\\n\");\n\t\tthrow errFailed;\n\t}\n\tth.push(new Prim(y_combinator_call_, f, f.takes()-1, f.leaves(), NULL, NULL));\n}\n\n\nstatic void* gofun(void* ptr)\n{\n Thread* th = (Thread*)ptr;\n th->fun->run(*th);\n delete th;\n return NULL;\n}\n\nstatic void go_(Thread& th, Prim* prim)\n{\n P fun = th.popFun(\"go : fun\");\n \n Thread* newThread = new Thread (th, fun); \n \n pthread_t pt;\n pthread_create(&pt, NULL, gofun, newThread);\n}\n\nstatic void sleep_(Thread& th, Prim* prim)\n{\n Z t = th.popFloat(\"sleep : secs\");\n \n usleep((useconds_t)floor(1e6 * t + .5));\n}\n\n#if COLLECT_MINFO\nstatic void minfo_(Thread& th, Prim* prim)\n{\n\tpost(\"signal generators %qd\\n\", vm.totalSignalGenerators.load());\n\tpost(\"stream generators %qd\\n\", vm.totalStreamGenerators.load());\n\tpost(\"objects live %qd\\n\", vm.totalObjectsAllocated.load() - vm.totalObjectsFreed.load());\n\tpost(\"objects allocated %qd\\n\", vm.totalObjectsAllocated.load());\n\tpost(\"objects freed %qd\\n\", vm.totalObjectsFreed.load());\n\tpost(\"retains %qd\\n\", vm.totalRetains.load());\n\tpost(\"releases %qd\\n\", vm.totalReleases.load());\n}\n#endif\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark SAMPLE RATES\n\nstatic void sr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate);\n}\n\nstatic void nyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate * .5);\n}\n\nstatic void isr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invSampleRate);\n}\n\nstatic void rps_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.radiansPerSample);\n}\n\nstatic void inyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invNyquistRate);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark HELP\n\nstatic void listdump_(Thread& th, Prim* prim)\n{\t\n\tP list = th.popList(\"listdump : seq\");\n\t\n\tpost(\"[\\n\");\n\twhile (list()) {\n\t\tpost(\"list %p %p %d\\n\", list(), list->mArray(), list->mArray() ? (int)list->mArray->size() : -1);\n\t\tlist = list->next();\n\t}\n\tpost(\"]\\n\");\n}\n\nstatic void help_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\n\tconst char* mask = v.GetAutoMapMask();\n\tconst char* help = v.OneLineHelp();\n\t\n\tif (mask) {\n\t\tpost(\"@%s \", mask);\n\t}\n\tif (help) {\n\t\tpost(\"%s\\n\", help);\n\t} else {\n\t\tpost(\"no help available.\\n\");\n\t}\n\n}\n\nstatic void helpbifs_(Thread& th, Prim* prim)\n{\n post(\"\\nBUILT IN FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.bifHelp.size(); ++i) {\n\t\tstd::string& s = vm.bifHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpLine_(Thread& th, Prim* prim)\n{\n\tP str = th.popString(\"helpLine : string\");\n\tvm.addUdfHelp(str->s);\n}\n\nstatic void helpudfs_(Thread& th, Prim* prim)\n{\n post(\"\\nUSER DEFINED FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.udfHelp.size(); ++i) {\n\t\tstd::string& s = vm.udfHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpall_(Thread& th, Prim* prim)\n{\n helpbifs_(th, prim);\n helpudfs_(th, prim);\n}\n\n\nstatic void prelude_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.prelude_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.prelude_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no prelude file.\\n\");\n\t}\n}\n\nstatic void examples_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* examples_file = getenv(\"SAPF_EXAMPLES\");\n\tif (examples_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", examples_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no examples file.\\n\");\n\t}\n}\n\nstatic void readme_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* readme_file = getenv(\"SAPF_README\");\n\tif (readme_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", readme_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no readme file.\\n\");\n\t}\n}\n\nstatic void logfile_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.log_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.log_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no log file.\\n\");\n\t}\n}\n\nstatic void trace_(Thread& th, Prim* prim)\n{\n\tvm.traceon = th.pop().isTrue();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PLUGS\n\nstruct PlugOut : Gen\n{\n\tP _plug;\n\t\n\tPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeV, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"PlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tVIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\nstruct ZPlugOut : Gen\n{\n\tP _plug;\n\t\n\tZPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeZ, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"ZPlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\n\nstatic void plug_(Thread& th, Prim* prim)\n{\n\tV in = th.pop();\n\tP plug = new Plug(in);\n\tth.push(new List(new PlugOut(th, plug)));\n\tth.push(plug);\n}\n\nstatic void zplug_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tif (value.isVList() && value.isFinite()) {\n\t\tP valueList = ((List*)value.o())->pack(th);\n\t\tP valueArray = valueList->mArray;\n\t\tV* vals = valueArray->v();\n\t\tsize_t n = valueArray->size();\n\t\t\n\t\tP plugList = new List(itemTypeV, n);\n\t\tP outList = new List(itemTypeV, n);\n\t\t\n\t\tP plugArray = plugList->mArray;\n\t\tP outArray = outList->mArray;\n\t\t\n\t\tplugArray->setSize(n);\n\t\toutArray->setSize(n);\n\t\t\n\t\tV* plugItems = plugArray->v();\n\t\tV* outItems = outArray->v();\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(vals[i]);\n\t\t\tzplug_(th, prim);\n\t\t\tplugItems[i] = th.pop();\n\t\t\toutItems[i] = th.pop();\n\t\t}\n\t\t\n\t\tth.push(outList);\n\t\tth.push(plugList);\n\t} else if (value.isZIn()) {\n\t\tP plug = new ZPlug(value);\n\t\tth.push(new List(new ZPlugOut(th, plug)));\n\t\tth.push(plug);\n\t} else {\n\t\twrongType(\"zplug : ref\", \"VList or UGen input\", value);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark GLOB\n\n#include \n\nstatic void glob_(Thread& th, Prim* prim)\n{\n\tP pat = th.popString(\"glob : pattern\");\n\t\n\tglob_t g;\n\tmemset(&g, 0, sizeof(g));\n\tglob(pat->s, GLOB_MARK, nullptr, &g);\n\t\n\tP a = new Array(itemTypeV, g.gl_matchc);\n\tfor (int i = 0; i < g.gl_matchc; ++i) {\n\t\ta->add(new String(g.gl_pathv[i]));\n\t}\n\tglobfree(&g);\n\t\n\tth.push(new List(a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD CORE OPS\n\n\n#define DEFN(NAME, N, FUN, HELP) \tvm.def(NAME, N, 1, FUN, HELP);\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEF2(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddCoreOps();\nvoid AddCoreOps()\n{\n\t// stack ops\n\tvm.addBifHelp(\"\\n*** stack ops ***\");\n\tDEFnoeach(clear, 0, 0, \"(... -->) clears everything off the stack.\");\n\tDEFnoeach(cleard, 0, 1, \"(... a --> a) clears all but the top item from the stack.\")\n\tDEFnoeach(stackDepth, 0, 1, \"(--> n) returns the size of the stack.\")\n\t\n\tDEFnoeach(aa, 1, 2, \"(a --> a a) push the top item on stack again.\")\n\tDEFnoeach(aaa, 1, 3, \"(a --> a a a) push the top item on stack two more times.\")\n\tDEFnoeach(ba, 2, 2, \"(a b --> b a) swap top two items.\")\n\t\n\tDEFnoeach(bac, 3, 3, \"(a b c --> b a c) reorder items on stack.\")\n\tDEFnoeach(cba, 3, 3, \"(a b c --> c b a) reorder items on stack.\")\n\tDEFnoeach(bca, 3, 3, \"(a b c --> b c a) reorder items on stack.\")\n\tDEFnoeach(cab, 3, 3, \"(a b c --> c a b) reorder items on stack.\")\n\n\tDEFnoeach(bab, 2, 3, \"(a b --> b a b) reorder items on stack.\")\n\tDEFnoeach(aba, 2, 3, \"(a b --> a b a) reorder items on stack.\")\n\n\tDEFnoeach(aab, 2, 3, \"(a b --> a a b) reorder items on stack.\")\n\tDEFnoeach(aabb, 2, 4, \"(a b --> a a b b) reorder items on stack.\")\n\tDEFnoeach(abab, 2, 4, \"(a b --> a b a b) reorder items on stack.\")\n\n\tDEFnoeach(nip, 2, 1, \"(a b --> b) remove second item on stack.\")\n\tDEFnoeach(pop, 1, 0, \"(a -->) remove top item on stack.\")\n\t\n\t// loops\n\tvm.addBifHelp(\"\\n*** loops ***\");\n\t//DEFnoeach(while, 2, \"(A B --> ..) While applying A returns true, apply B.\")\n\tDEFnoeach(do, 2, 0, \"(list \\\\item[..] -->) applies the function to each item of a finite list. Useful for side effects like printing or file writing.\")\n\n\t// conditional ops\n\tvm.addBifHelp(\"\\n*** conditional ops ***\");\n\tDEF(equals, 2, \"(a b --> bool) returns 1 if a and b are structurally equivalent. If the data structures are cyclic then this may never terminate.\")\n\tDEF(less, 2, \"(a b --> bool) returns 1 if a is less than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF(greater, 2, \"(a b --> bool) returns 1 if a is greater than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF2(if, 3, -1, \"(A B C --> ..) if A is true then apply B else apply C.\")\n\n\tDEF(not, 1, \"(A --> bool) returns 0 if A is true and 1 if A is false.\")\n\t//DEF2(dip, 1, -1, \"(x A --> ..) pops x from stack, applies A, pushes x back on stack.\")\n\n\tDEFnoeach(try, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied.\")\n\tDEFnoeach(throw, 0, 0, \"(a -->) throw an exception.\")\n\tDEFnoeach(protect, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied and the exception is rethrown. Otherwise function B is applied and control continues as normal.\")\n\n\t// form ops\n\tvm.addBifHelp(\"\\n*** form ops ***\");\n\tDEFAM(has, kk, \"(form key --> bool) return whether a form contains the key.\")\n \n\tDEFAM(keys, k, \"(form --> keys) return an array of the keys of the form.\")\n\tDEFAM(values, k, \"(form --> values) return an array of the values of the form.\")\n\tDEFAM(kv, k, \"(form --> keys values) return two arrays of the keys and values of the form.\") /// !!!! returns two values. can't be auto mapped.\n\tDEFAM(local, k, \"(form --> local) return the head of the prototype inheritance list.\")\n\tDEFAM(parent, k, \"(form --> parent) return the tail of the prototype inheritance list.\")\n\tDEFAM(dot, ka, \"(form key --> item) return the value for the key.\")\n \n DEFnoeach(pushWorkspace, 0, 0, \"(-->) pushes a new outer scope onto the workspace. New bindings will be made in the new outer scope.\");\n DEFnoeach(popWorkspace, 0, 0, \"(-->) pops a scope from the workspace. All bindings in the outer scope will be forgotten.\");\n\t\n\tvm.addBifHelp(\"\\n*** ref ops ***\");\n\tDEFAM(get, k, \"(r --> a) return the value store in a ref.\")\n\tDEFnoeach(set, 1, 0, \"(a r -->) store the value a in the ref r.\")\n\tvm.def(\"R\", 1, 1, ref_, \"(a --> r) create a new Ref with the inital value a\");\n\tvm.def(\"ZR\", 1, 1, zref_, \"(z --> r) create a new ZRef with the inital value z. A ZRefs is a mutable reference to a real number.\");\n\tvm.def(\"P\", 1, 2, plug_, \"(a --> out in) create a new stream plug pair with the inital value a\");\n\tvm.def(\"ZP\", 1, 2, zplug_, \"(a --> out in) create a new signal plug pair with the inital value a.\");\n\t\n\t\n\t//DEF(bind, 2, \"deprecated\")\n\t\n\t// apply ops\n\tvm.addBifHelp(\"\\n*** function ops ***\");\n\tDEF(Y, 1, \"(funA --> funB) Y combinator. funB calls funA with the last argument being funB itself. Currently the only way to do recursion. \\n\\t\\te.g. \\\\x f [x 2 < \\\\[1] \\\\[ x x -- f *] if] Y = factorial 7 factorial --> 5040\")\n\tDEF(noeach, 1, \"(fun --> fun) sets a flag in the function so that it will pass through arguments with @ operators without mapping them.\")\n\tvm.def(\"!\", 1, -1, apply_, \"(... f --> ...) apply the function to its arguments, observing @ arguments as appropriate.\");\n\tvm.def(\"!e\", 2, -1, applyEvent_, \"(form fun --> ...) for each argument in the function, find the same named fields in the form and push those values as arguments to the function.\");\n\tDEF(compile, 1, \"(string --> fun) compile the string and return a function.\")\n\t\n\tvm.addBifHelp(\"\\n*** printing ops ***\");\n\tDEFnoeach(printLength, 0, 1, \"(--> length) return the number of items printed for lists.\");\n\tDEFnoeach(printDepth, 0, 1, \"(--> depth) return the number of levels of nesting printed for lists.\");\n\tDEFnoeach(setPrintLength, 1, 0, \"(length --> ) set the number of items printed for lists.\");\n\tDEFnoeach(setPrintDepth, 1, 0, \"(depth -->) set the number of levels of nesting printed for lists.\");\n\t\n\tDEFnoeach(pr, 1, 0, \"(A -->) print the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(prdebug, 1, 0, \"(A -->) print debug version of the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(cr, 0, 0, \"(-->) print a carriage return.\")\n\tDEFnoeach(sp, 0, 0, \"(-->) print a space character.\")\n\tDEFnoeach(tab, 0, 0, \"(-->) print a tab.\")\n\tDEFnoeach(prstk, 0, 0, \"(-->) print the stack.\")\n\n#if COLLECT_MINFO\n\tDEFnoeach(minfo, 0, 0, \"(-->) print memory management info.\")\n#endif\n\tDEFnoeach(listdump, 1, 0, \"(list -->) prints information about a list.\");\n\n\tvm.addBifHelp(\"\\n*** string ops ***\");\n\tDEF(str, 1, \"(x --> string) convert x to a string.\");\n\tDEF(debugstr, 1, \"(x --> string) convert x to a debug string.\");\n\tDEFAM(strcat, ak, \"(list separator --> string) convert elements of list to a string with separator string between each.\");\n\tDEF(strlines, 1, \"(list --> string) convert elements of list to a newline separated string.\");\n\tDEFAM(glob, k, \"(pattern --> paths) return a list of file path names that match.\");\n\n\tvm.addBifHelp(\"\\n*** sample rate ops ***\");\n\tDEFnoeach(sr, 0, 1, \"(--> sampleRate) returns the sample rate. samples per second. \")\n\tDEFnoeach(nyq, 0, 1, \"(--> sampleRate/2) returns the nyquist rate\")\n\tDEFnoeach(isr, 0, 1, \"(--> 1/sampleRate) returns the inverse sample rate\")\n\tDEFnoeach(inyq, 0, 1, \"(--> 2/sampleRate) returns the inverse nyquist rate.\")\n\tDEFnoeach(rps, 0, 1, \"(--> 2pi/sampleRate) returns the radians per sample\")\n\n\n\tvm.addBifHelp(\"\\n*** help ops ***\");\n\n\tDEFnoeach(help, 1, 0, \"(fun -->) prints help for a function.\");\n\tDEFnoeach(helpbifs, 0, 0, \"(-->) prints help for all built in functions.\");\n\tDEFnoeach(helpudfs, 0, 0, \"(-->) prints help for all user defined functions.\");\n\tDEFnoeach(helpall, 0, 0, \"(-->) prints help for all built in and user defined functions.\");\n DEF(helpLine, 1, \"(string -->) add a line to the user defined function help.\");\n\t\n\tvm.addBifHelp(\"\\n*** thread ops ***\");\n DEFnoeach(go, 1, 0, \"(fun -->) launches the function in a new thread.\");\n DEFnoeach(sleep, 1, 0, \"(seconds -->) sleeps the current thread for the time given.\");\n\n\tvm.addBifHelp(\"\\n*** misc ***\");\n\tDEF(type, 1, \"(a --> symbol) return a symbol naming the type of the value a.\")\n\tDEFnoeach(trace, 1, 0, \"(bool -->) turn tracing on/off in the interpreter.\")\n\n\tvm.addBifHelp(\"\\n*** text files ***\");\n\tDEFnoeach(load, 1, 0, \"(filename -->) compiles and executes a text file.\")\t\n\tDEFnoeach(prelude, 0, 0, \"(-->) opens the prelude file in the default text editor.\")\n\tDEFnoeach(examples, 0, 0, \"(-->) opens the examples file in the default text editor.\")\n\tDEFnoeach(logfile, 0, 0, \"(-->) opens the log file in the default text editor.\")\n\tDEFnoeach(readme, 0, 0, \"(-->) opens the README file in the default text editor.\")\n\n}\n\n"], ["/sapf/src/StreamOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n#include \"dsp.hpp\"\n#include \"SoundFiles.hpp\"\n\nconst Z kOneThird = 1. / 3.;\n\n// list ops\n#pragma mark LIST OPS\n\nstatic void finite_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.pushBool(v.isFinite());\n}\n\nstatic void size_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (v.isList() && !v.isFinite()) \n\t\tth.push(INFINITY);\n\telse \n\t\tth.push(v.length(th));\n}\n\n\nstatic void rank_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tint rank = 0;\n\twhile (a.isVList()) {\n\t\t++rank;\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\t\n\tth.push(rank);\n}\n\nstatic void shape_(Thread& th, Prim* prim)\n{\n\tP shape = new Array(itemTypeZ, 4);\n\t\n\tV a = th.pop();\n\t\n\twhile (a.isVList()) {\n\t\tZ len;\n\t\tif (a.isFinite()) {\n\t\t\tlen = a.length(th);\n\t\t} else {\n\t\t\tlen = INFINITY;\n\t\t}\n\t\tshape->addz(len);\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\tth.push(new List(shape));\n}\n\nstatic void bub_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tP seq = new List(itemTypeV, 1);\n\tseq->add(a);\n\tth.push(seq);\n}\n\nstatic void nbub_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbub : n\");\n\tV a = th.pop();\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\n\t\tP seq = new List(itemTypeV, 1);\n\t\tseq->add(a);\n\t\ta = seq;\n\t}\n\tth.push(a);\n}\n\ntemplate \nstatic void tupleN_(Thread& th, Prim* prim)\n{\n\tP seq = new List(itemTypeV, N);\n\tP arr = seq->mArray;\n\tarr->setSize(N);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v = th.pop();\n\t\tarr->put(N-1-i, v);\n\t}\n\tth.push(seq);\n}\n\ntemplate \nstatic void untupleN_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"unN : s\");\n\t\n\tBothIn in(s);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v;\n\t\tif (in.one(th, v)) {\n\t\t\tpost(\"too few items in list for un%d\", N);\n\t\t\tthrow errFailed;\n\t\t}\n\t\tth.push(v);\n\t}\n}\n\nstatic void reverse_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"reverse : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"reverse\", \"\");\n\t\t\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t}\n\tth.push(s2);\n}\n\ntemplate \nvoid copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[i];\n}\n\ntemplate \nvoid reverse_copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[-i];\n}\n\nstatic List* makeMirror(P const& a, int64_t n, int64_t nr, int64_t roff)\n{\n\tint type = a->elemType;\n\tint64_t size = n + nr;\n\tList* s = new List(type, size);\n\tArray* b = s->mArray();\n\t\n\tb->setSize(size);\n\tif (type == itemTypeV) {\n\t\tV* p = b->v();\n\t\tV* q = a->v();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t} else {\n\t\tZ* p = b->z();\n\t\tZ* q = a->z();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t}\n\treturn s;\n}\n\nstatic void mirror(Thread& th, int w, P s)\n{\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"mirror\", \"\");\n\n\ts = s->pack(th);\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\tint64_t n2 = n-2;\n\t\n\tswitch (w) {\n\t\tcase 0 : {\n\t\t\tif (n < 3) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n2, n2));\n\t\t} break;\n\t\tcase 1 : {\n\t\t\tif (n < 2) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n1, n2));\n\t\t} break;\n\t\tcase 2 : {\n\t\t\tif (n == 0) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n, n1));\n\t\t} break;\n\t}\n}\n\nstatic void mirror0_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror0 : s\");\n\tmirror(th, 0, s);\n}\n\nstatic void mirror1_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror1 : s\");\n\tmirror(th, 1, s);\n}\n\nstatic void mirror2_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror2 : s\");\n\tmirror(th, 2, s);\n}\n\nstatic void rot_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"rot : r\");\n\tP s = th.popList(\"rot : s\");\n\t\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"rot\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->wrapAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->wrapAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void shift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"shift : r\");\n\tP s = th.popList(\"shift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"shift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->at(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->atz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void clipShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"clipShift : r\");\n\tP s = th.popList(\"clipShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->clipAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->clipAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void foldShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"foldShift : r\");\n\tP s = th.popList(\"foldShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->foldAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->foldAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void muss_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"muss : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"muss\", \"\");\n \n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int64_t i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t}\n\tth.push(s2);\n}\n\n\n\n\n\nV do_at(Thread& th, P const& a, Arg i);\nV do_wrapAt(Thread& th, P const& a, Arg i);\nV do_foldAt(Thread& th, P const& a, Arg i);\nV do_clipAt(Thread& th, P const& a, Arg i);\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\n\nclass AtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"AtGenVV\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_at(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->at(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->atz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tWrapAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_wrapAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass FoldAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tFoldAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_foldAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass ClipAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tClipAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_clipAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Z degkey(Z degree, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ fidegree = floor(degree + .5);\n\t//Z frac = degree - fidegree;\n\tint idegree = (int)fidegree;\n\tint modDegree = (int)sc_imod(idegree, degreesPerCycle);\n\t//return frac + scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n\treturn scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n}\n\n\nstatic Z keydeg(Z key, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ cycles, cyckey;\n\tsc_fdivmod(key, cycleWidth, cycles, cyckey);\n\t\n\tZ frac = scale->atz(0) + cycleWidth - cyckey;\n\tZ mindiff = std::abs(frac);\n\tint idegree = 0;\n\tfor (int i = 0; i < degreesPerCycle; ++i) {\n\t\tfrac = std::abs(cyckey - scale->atz(i));\n\t\tif (frac < mindiff) {\n\t\t\tmindiff = frac;\n\t\t\tidegree = i;\n\t\t}\n\t}\n\t\n\treturn idegree + cycles * degreesPerCycle;\n}\n\nclass DegKeyVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _degree;\npublic:\n\n\tDegKeyVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_degkey(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _key;\npublic:\n\n\tKeyDegVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_keydeg(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Gen* newAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new AtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new AtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new AtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newWrapAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new WrapAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new WrapAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new WrapAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newDegKeyGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new DegKeyVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new DegKeyVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new DegKeyZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newKeyDegGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new KeyDegVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new KeyDegVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new KeyDegZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newFoldAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new FoldAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new FoldAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new FoldAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newClipAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new ClipAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new ClipAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new ClipAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nV do_at(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->at(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newAtGen(th, a, b));\n\t} else wrongType(\"at : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_wrapAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->wrapAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newWrapAtGen(th, a, b));\n\t} else wrongType(\"wrapAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn degkey(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newDegKeyGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"degkey : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn keydeg(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newKeyDegGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"keydeg : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_foldAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->foldAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newFoldAtGen(th, a, b));\n\t} else wrongType(\"foldAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_clipAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->clipAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newClipAtGen(th, a, b));\n\t} else wrongType(\"clipAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nstatic void at_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"at : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"at\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_at(th, a, i);\n\tth.push(v);\n}\n\nstatic void wrapAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"wrapAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"wrapAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_wrapAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void degkey_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"degkey : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"degkey\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"degkey : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_degkey(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void keydeg_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"keydeg : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"keydeg\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"keydeg : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_keydeg(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void foldAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"foldAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_foldAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void clipAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"clipAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_clipAt(th, a, i);\n\tth.push(v);\n}\n\n\n#pragma mark CONVERSION\n\n\nstruct VGen : public Gen\n{\n\tZIn _a;\n\t\n\tVGen(Thread& th, Arg a) : Gen(th, itemTypeV, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct ZGen : public Gen\n{\n\tVIn _a;\n\t\n\tZGen(Thread& th, Arg a) : Gen(th, itemTypeZ, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->asFloat();\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic P stringToZList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeZ, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tz[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P stringToVList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeV, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tv[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P vlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"stream to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)v[i].asFloat());\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic P zlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"signal to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)z[i]);\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic void V_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isZList()) {\n\t\tGen* g = new VGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToVList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void Z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tGen* g = new ZGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToZList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void unspell_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(vlistToString(th, list));\n\t} else if (a.isZList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(zlistToString(th, list));\n\t} else if (a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\twrongType(\"unspell : list\", \"List or String\", a);\n\t}\n}\n\n\n\n#pragma mark NUMERIC SERIES\n\n\nstruct Ever : public Gen\n{\n\tV _val;\n\n\tEver(Thread& th, Arg val) : Gen(th, itemTypeV, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Ever\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV v = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = v;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Everz : public Gen\n{\n\tZ _val;\n\n\tEverz(Thread& th, Z val) : Gen(th, itemTypeZ, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Everz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ z = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = z;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_recip;\nextern UnaryOp* gUnaryOpPtr_cb;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstruct By : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tBy(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"By\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Byz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tByz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Byz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Grow : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tGrow(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Grow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Growz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tGrowz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Growz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart *= step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLine : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tCubicLine(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLine\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV cubed = _start.unaryOp(th, gUnaryOpPtr_cb);\t\n\t\t\tout[i] = cubed;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tCubicLinez(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start*start*start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Inv : public Gen\n{\n\tV _start;\n\n\tInv(Thread& th) : Gen(th, itemTypeV, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Inv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV vone = 1.;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\tout[i] = vout;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Invz : public Gen\n{\n\tZ _start;\n\n\tInvz(Thread& th) : Gen(th, itemTypeZ, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Invz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. / start;\n\t\t\tstart += 1.;\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NInv : public Gen\n{\n\tV _start;\n\tint64_t _n;\n\n\tNInv(Thread& th, int64_t n) : Gen(th, itemTypeV, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tV vone = 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\t\tout[i] = vout;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NInvz : public Gen\n{\n\tZ _start;\n\tint64_t _n;\n\n\tNInvz(Thread& th, int64_t n) : Gen(th, itemTypeZ, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInvz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = 1. / start;\n\t\t\t\tstart += 1.;\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NBy : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNBy(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NBy\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NByz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\t\n\tNByz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NByz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\n\nstruct NGrow : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNGrow(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NGrowz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNGrowz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrowz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart *= step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NCubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNCubicLinez(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NCubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start*start*start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct Fib : public Gen\n{\n\tV _a;\n\tV _b;\n \n\tFib(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fib\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV a = _a;\n out[i] = a;\n _a = _b;\n _b = a.binaryOp(th, gBinaryOpPtr_plus, _b);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Fibz : public Gen\n{\n\tZ _a;\n\tZ _b;\n \n\tFibz(Thread& th, Z a, Z b) : Gen(th, itemTypeZ, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fibz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n int n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ a = _a;\n\t\tZ b = _b;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = a;\n Z aa = a;\n a = b;\n b += aa;\n\t\t}\n\t\t_a = a;\n\t\t_b = b;\n\t\tmOut = mOut->nextp();\n }\n};\n\nstatic void L_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tth.push(new List(new Ever(th, th.pop())));\n\t}\n}\n\nstatic void L1_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tP list = new List(itemTypeV, 1);\n\t\tlist->add(th.pop());\n\t\tth.push(list);\n\t}\n}\n\nstatic void ever_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\t\n\tGen* g = new Ever(th, value);\n\tth.push(new List(g));\n}\n\nstatic void everz_(Thread& th, Prim* prim)\n{\n\tZ value = th.popFloat(\"everz : value\");\n\t\n\tGen* g = new Everz(th, value);\n\tth.push(new List(g));\n}\n\nstatic void by_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new By(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nby_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"nby : n\");\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void to_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"to : end\");\n\tZ start = th.popFloat(\"to : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void toz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"toz : end\");\n\tZ start = th.popFloat(\"toz : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv : end\");\n\tZ start = th.popFloat(\"lindiv : start\");\n\tint64_t n = th.popInt(\"lindiv : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindivz : end\");\n\tZ start = th.popFloat(\"lindivz : start\");\n\tint64_t n = th.popInt(\"lindivz : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv : end\");\n\tZ start = th.popFloat(\"expdiv : start\");\n\tint64_t n = th.popInt(\"expdiv : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdivz : end\");\n\tZ start = th.popFloat(\"expdivz : start\");\n\tint64_t n = th.popInt(\"expdivz : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1 : end\");\n\tZ start = th.popFloat(\"lindiv1 : start\");\n\tint64_t n = th.popInt(\"lindiv1 : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1z : end\");\n\tZ start = th.popFloat(\"lindiv1z : start\");\n\tint64_t n = th.popInt(\"lindiv1z : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1 : end\");\n\tZ start = th.popFloat(\"expdiv1 : start\");\n\tint64_t n = th.popInt(\"expdiv1 : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1z : end\");\n\tZ start = th.popFloat(\"expdiv1z : start\");\n\tint64_t n = th.popInt(\"expdiv1z : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void line_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"line : end\");\n\tZ start = th.popFloat(\"line : start\");\n\tZ dur = th.popFloat(\"line : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, (int64_t)n);\n\tth.push(new List(g));\n}\n\nstatic void xline_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"xline : end\");\n\tZ start = th.popFloat(\"xline : start\");\n\tZ dur = th.popFloat(\"xline : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\n\tGen* g;\n\tif (sc_sgn(start) != sc_sgn(end) || start == 0. || end == 0.) {\n\t\tstart = sc_sgn(start) * pow(fabs(start), kOneThird);\n\t\tend = sc_sgn(end) * pow(fabs(end), kOneThird);\n\t\tZ step = (end - start) / n;\t\t\n\t\tg = new NCubicLinez(th, start, step, (int64_t)n);\n\t} else {\n\t\tZ step = pow(end/start, 1. / n);\n\t\tg = new NGrowz(th, start, step, (int64_t)n);\n\t}\n\tth.push(new List(g));\n}\n\n\nstatic void grow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new Grow(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"ngrow : n\");\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void byz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"byz : step\");\n\tZ start = th.popFloat(\"byz : start\");\n\t\n\tGen* g = new Byz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nbyz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"nbyz : step\");\n\tZ start = th.popFloat(\"nbyz : start\");\n\tint64_t n = th.popInt(\"nbyz : n\");\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void growz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"growz : step\");\n\tZ start = th.popFloat(\"growz : start\");\n\t\n\tGen* g = new Growz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrowz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"ngrowz : step\");\n\tZ start = th.popFloat(\"ngrowz : start\");\n\tint64_t n = th.popInt(\"ngrowz : n\");\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void ord_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negs_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void nat_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evens_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void odds_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 2.);\n\tth.push(new List(g));\n}\n\n\nstatic void invs_(Thread& th, Prim* prim)\n{\n\tGen* g = new Inv(th);\n\tth.push(new List(g));\n}\n\nstatic void invz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Invz(th);\n\tth.push(new List(g));\n}\n\nstatic void ninvs_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvs : n\");\n\tGen* g = new NInv(th, n);\n\tth.push(new List(g));\n}\n\nstatic void ninvz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvz : n\");\n\tGen* g = new NInvz(th, n);\n\tth.push(new List(g));\n}\n\n\nstatic void ordz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void natz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evenz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void oddz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 2.);\n\tth.push(new List(g));\n}\n\nstatic void fib_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Fib(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void fibz_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"fibz : b\");\n\tZ a = th.popFloat(\"fibz : a\");\n\t\n\tGen* g = new Fibz(th, a, b);\n\tth.push(new List(g));\n}\n\nstruct Ints : public Gen\n{\n\tZ _a;\n \n\tInts(Thread& th) : Gen(th, itemTypeV, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Ints\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Intz : public Gen\n{\n\tZ _a;\n \n\tIntz(Thread& th) : Gen(th, itemTypeZ, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Intz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstatic void ints_(Thread& th, Prim* prim)\n{\n\tGen* g = new Ints(th);\n\tth.push(new List(g));\n}\n\nstatic void intz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Intz(th);\n\tth.push(new List(g));\n}\n\n#include \"primes.hpp\"\n\nstruct Primes : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimes(Thread& th) : Gen(th, itemTypeV, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primes\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct Primez : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimez(Thread& th) : Gen(th, itemTypeZ, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primez\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n } else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n if (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\n\nstatic void primes_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primes(th);\n\tth.push(new List(g));\n}\n\nstatic void primez_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primez(th);\n\tth.push(new List(g));\n}\n\n\n#pragma mark ORDERING\n\n\nclass Perms : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPerms(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_at(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Perms\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeV, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tV* outItems = arr->v();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nclass Permz : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPermz(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_atz(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Permz\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeZ, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tZ* outItems = arr->z();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nstatic void perms_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"perms : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"perms : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Perms(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permz : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Permz(th, arr);\n\tth.push(new List(g));\n}\n\n\n\nclass PermsWithRepeatedItems : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItems(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_at(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItems\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\n\nclass PermsWithRepeatedItemsZ : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItemsZ(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_atz(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItemsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\nstatic void permswr_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"permswr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permswr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItems(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permzwr_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permzwr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permzwr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItemsZ(th, arr);\n\tth.push(new List(g));\n}\n\n\nstruct Repeat : Gen\n{\n V _a;\n\tint64_t _m;\n \n\tRepeat(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n V a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct RepeatFun : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFun(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _b(0.), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct InfRepeatFun : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFun(Thread& th, Arg a) : Gen(th, itemTypeV, false), _a(a), _b(0.) {}\n\t \n\tvirtual const char* TypeName() const override { return \"InfRepeatFun\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n \n};\n\nstruct Repeatz : Gen\n{\n Z _a;\n\tint64_t _m;\n \n\tRepeatz(Thread& th, Z a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Repeatz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n Z a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct RepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFunz(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _b(0.), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"RepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop().asFloat();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct InfRepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFunz(Thread& th, Arg a) : Gen(th, itemTypeZ, false), _a(a), _b(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"InfRepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop().asFloat();\n\t\t}\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct RCyc : public Gen\n{\n\tV _ref;\n\tP _a0;\n\tP _a;\n\n\tRCyc(Thread& th, Arg ref, P const& a) : Gen(th, a->elemType, false), _ref(ref), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"RCyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tV v = _ref.deref();\n\t\t\tif (v.isList()) {\n\t\t\t\t_a0 = (List*)v.o();\n\t\t\t}\n\t\t\t_a = _a0;\n\t\t}\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Cyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\n\tCyc(Thread& th, P const& a) : Gen(th, a->elemType, false), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) _a = _a0;\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NCyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\tint64_t _n;\n\t\n\tNCyc(Thread& th, int64_t n, P const& a) : Gen(th, a->elemType, true), _a0(a), _a(a), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tif (_n <= 1) {\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\t_a = _a0;\n\t\t\t\t--_n;\n\t\t\t}\n\t\t}\n\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void repeat_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"X : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFun(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Ever(th, a);\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFun(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeat(th, a, n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstatic void repeatz_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"XZ : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFunz(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Everz(th, a.asFloat());\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFunz(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeatz(th, a.asFloat(), n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstruct Silence : Gen\n{\n\tint64_t _m;\n \n\tSilence(Thread& th, int64_t m) : Gen(th, itemTypeZ, true), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Silence\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n\t\t\tmemset(out, 0, n * sizeof(Z));\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstatic void mum_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"mum : duration\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\tif (isinf(t) || (n <= 0 && t > 0.)) {\n\t\tth.push(new List(new Everz(th, 0.)));\n\t} else {\n\t\tGen* g = new Silence(th, n);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstatic void cyc_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\t\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP s = (List*)v.o();\n\t\n\n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n \n\tGen* g = new Cyc(th, s);\n\tth.push(new List(g));\n}\n\n\nstatic void rcyc_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tV v = ref.deref();\n\tif (!v.isList()) {\n\t\twrongType(\"rcyc : ref get\", \"List\", v);\n\t}\n\t\n\tP list = (List*)v.o();\n\t\n\tGen* g = new RCyc(th, ref, list);\n\tth.push(new List(g));\n}\n\n\nstatic void ncyc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ncyc : n\");\n\tP s = th.popList(\"ncyc : seq\");\n \n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n\t\n\tif (n <= 0) {\n\t\tth.push(vm.getNil(s->elemType));\t\t\n\t} else {\n\t\tGen* g = new NCyc(th, n, s);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstruct Append : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAppend(Thread& th, P const& a, Arg b, bool inFinite) : Gen(th, a->elemType, inFinite), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Append\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t\tmOut = mOut->nextp();\n\t\t} else {\n\t\t\tif (_b.isFunOrPrim()) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\t_b.apply(th);\n\t\t\t\t_b = th.pop();\n\t\t\t}\n\t\t\tif (!_b.isList()) {\n\t\t\t\tpost(\"$ : b is not a sequence '%s'\\n\", _b.TypeName());\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tList* b = (List*)_b.o();\n\t\t\tif (elemType != b->elemType) {\n\t\t\t\tpost(\"$ : b item type doesn't match\\n\");\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetDone();\n\t\t\tmOut->link(th, b);\n\t\t}\n\t}\n};\n\n\nstruct Cat : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\n\tCat(Thread& th, Arg a, P const& b) : Gen(th, itemTypeV, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"Cat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isVList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct CatZ : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\n\t// this makes the assumption that all of the sublists of b are finite! if they are not then this will not prevent infinite loops.\n\tCatZ(Thread& th, Arg a, P const& b) : Gen(th, itemTypeZ, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"CatZ\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isZList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\t\t\t\n};\n\n#include \n\nstruct Flat : Gen\n{\n\tstd::stack in; // stack of list continuations\n\n\tFlat(Thread& th, Arg inA) : Gen(th, itemTypeV, inA.isFinite())\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList()) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Flatten : Gen\n{\n\tstd::stack in; // stack of list continuations\n\tsize_t depth;\n\t\n\tFlatten(Thread& th, Arg inA, size_t inDepth) : Gen(th, itemTypeV, inA.isFinite()), depth(inDepth)\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList() && in.size() <= depth) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Keep : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tKeep(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keep\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Take : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tTake(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Take\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeat(th, 0., _n));\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Keepz : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tKeepz(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keepz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Takez : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tTakez(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Takez\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeatz(th, 0., _n));\n setDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstatic void append_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tif (a.isString() && b.isString()) {\n\t\tstd::string s;\n\t\ta.print(th, s);\n\t\tb.print(th, s);\n\t\tth.push(new String(s.c_str()));\n\t} else if (a.isList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(new List(new Append(th, list, b, leastFinite(a,b))));\n\t} else {\n\t\twrongType(\"$ : a\", \"List or String\", a);\n\t}\n}\n\nstruct AppendSubs : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tAppendSubs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AppendSubs\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tif (!a->isList())\n\t\t\t\t\t\twrongType(\"$$ : *a\", \"List\", *a);\n\t\t\t\t\t\n\t\t\t\t\tList* aa = (List*)a->o();\n\t\t\t\t\t\t\n\t\t\t\t\tout[i] = new List(new Append(th, aa, *b, mostFinite(*a,*b)));\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void appendSubs_(Thread& th, Prim* prim)\n{\n\tV b = th.popVList(\"$$ : b\");\n\tV a = th.popVList(\"$$ : a\");\n\t\n th.push(new List(new AppendSubs(th, a, b)));\n}\n\nstatic void cat_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP b = (List*)v.o();\n\n\tb->force(th);\n\tif (b->isEnd()) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\tVIn a_(b);\n\tV a;\n\tif (a_.one(th, a)) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\t\n\t\n\t//V a = b->mArray->v()[0];\n\t\n\tif (a.isString()) {\n\t\tif (!b->isFinite())\n\t\t\tindefiniteOp(\"$/ : list of strings\", \"\");\n\t\t\n\t\tstd::string s;\n\n\t\tVIn in_(b);\n\t\twhile (true) {\n\t\t\tV in;\n\t\t\tif (in_.one(th, in)) {\n\t\t\t\tth.push(new String(s.c_str()));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tin.print(th, s);\n\t\t}\n\t\t\n\t} else if (!a.isList()) {\n\t\twrongType(\"$/ : b\", \"List\", a);\n\t}\n\t\t\n\tGen* g;\n\tif (a.isVList()) g = new Cat(th, a, b);\n\telse g = new CatZ(th, a, b);\n\tth.push(new List(g));\n\n}\n\nstatic void flat_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\n\tif (a.isVList()) th.push(new List(new Flat(th, a)));\n\telse th.push(a);\n}\n\nstatic void flatten_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"flatten : n\");\n\tV a = th.pop();\n\t\n\tif (a.isVList()) th.push(new List(new Flatten(th, a, n)));\n\telse th.push(a);\n}\n\nstatic void N_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"N : n\");\n\tV v = th.pop();\n\t\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void NZ_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"NZ : n\");\n\tV v = th.pop();\n\t\n if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void T_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"T : t\");\n\tV v = th.pop();\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void take_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"take : n\");\n\tP s = th.popList(\"take : s\");\n\n Gen* g;\n\tif (n > 0) {\n\t\tif (s->isVList()) \n\t\t\tg = new Take(th, n, s);\n\t\telse\n\t\t\tg = new Takez(th, n, s);\n\t\tth.push(new List(g));\n } else if (n < 0) {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"take\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tList* s2 = new List(s->elemType, n);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(n);\n\t\tif (s->isVList()) {\n\t\t\tV* p = s2->mArray->v();\n\t\t\tV* q = s->mArray->v();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tfor (int64_t i = 0; i < offset; ++i) p[i] = 0.;\n\t\t\t\tfor (int64_t i = 0, j = offset; i < size; ++i, ++j) p[j] = q[i];\n\t\t\t} else {\n\t\t\t\tfor (int64_t i = 0, j = size - n; i < n; ++i, ++j) p[i] = q[j];\n\t\t\t}\n\t\t} else {\n\t\t\tZ* p = s2->mArray->z();\n\t\t\tZ* q = s->mArray->z();\n\t\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tmemset(p, 0, offset * elemSize);\n\t\t\t\tmemcpy(p + offset, q, size * elemSize);\n\t\t\t} else {\n\t\t\t\tmemcpy(p, q + size - n, n * elemSize);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t\t\n\t} else {\n\t\tif (s->isVList())\n\t\t\tth.push(vm._nilv);\n\t\telse \n\t\t\tth.push(vm._nilz);\n\t\treturn;\n\t\t\n\t}\n}\n\n\n\n\nstatic void skip_positive_(Thread& th, P& list, int64_t n)\n{\n\tif (n <= 0) return;\n\n\tint itemType = list->elemType;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\t\t\tif (list->isVList()) {\n\t\t\t\tfor (int64_t i = 0, j = n; i < remain; ++i, ++j) {\n\t\t\t\t\ta2->v()[i] = a->v()[j];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\t\t\t}\n\t\t\tlist = new List(a2, list->next());\n\t\t\treturn;\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm.getNil(itemType);\n\t}\n}\n\nstatic void skip_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"skip : n\");\n\tP s = th.popList(\"skip : s\");\n\n\tif (n <= 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\n\nstatic void skipT_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\">T : t\");\n\tP s = th.popList(\">T : s\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\nstruct Hops : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHops(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"Hops\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\t\t\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tint64_t hop;\n\t\t\t\tif (_hop.onei(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tskip_positive_(th, _a, hop);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct HopTs : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHopTs(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"HopTs\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tZ hop;\n\t\t\t\tif (_hop.onez(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * hop);\n\t\t\t\t\tskip_positive_(th, _a, n);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void hops_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"N>> : list\");\n\n\tth.push(new List(new Hops(th, n, s)));\n}\n\nstatic void hopTs_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"T>> : list\");\n\n\tth.push(new List(new HopTs(th, n, s)));\n}\n\n\n\n\nstatic void drop_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"drop : n\");\n\tP s = th.popList(\"drop : s\");\n\n\tif (n == 0) {\n\t\tth.push(s);\n\t} else if (n > 0) {\n\t\tskip_positive_(th, s, n);\n\t\tth.push(s);\n\t} else {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"drop\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tint64_t remain = std::max(0LL, size - n);\n\t\tif (remain <= 0) {\n\t\t\tth.push(vm.getNil(s->elemType));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tP s2 = new List(s->elemType, remain);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(remain);\n\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\tif (s->isVList()) {\n\t\t\tV* y = s->mArray->v();\n\t\t\tV* x = s2->mArray->v();\n\t\t\tfor (int64_t i = 0; i < remain; ++i) {\n\t\t\t\tx[i] = y[i];\n\t\t\t}\n\t\t} else {\n\t\t\tmemcpy(s2->mArray->z(), s->mArray->z(), remain * elemSize);\n\t\t}\n\t}\n}\n\nstatic void choff_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"choff : n\");\n\tint64_t c = th.popInt(\"choff : c\");\n\tV a = th.pop();\n\t\n\tP s2 = new List(itemTypeV, n);\n\ts2->mArray->setSize(n);\n\t\n\tif (a.isVList()) {\n\t\tif (!a.isFinite())\n\t\t\tindefiniteOp(\"choff : a\", \"\");\n\t\t\t\n\t\tP aa = ((List*)a.o())->pack(th);\n\t\tint64_t m = aa->length(th);\n\t\tint64_t mn = std::min(m,n);\n\t\tfor (int64_t i = 0; i < mn; ++i) {\n\t\t\tint64_t j = sc_imod(i+c, n);\n\t\t\ts2->mArray->put(j, aa->at(i));\n\t\t}\n\t} else {\n\t\tc = sc_imod(c, n);\n\t\ts2->mArray->put(c, a);\n\t}\n\t\t\n\tth.push(s2);\n}\n\nstatic int64_t countWhileTrue(Thread& th, List* list)\n{\n int64_t n = 0;\n while (list) {\n list->force(th);\n\n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n if (a->at(i).isTrue()) ++n;\n else return n;\n }\n list = list->nextp();\n }\n\treturn n;\n}\n\nstatic void skipWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"skipWhile : s\");\n\n if (f.isList()) {\n int64_t n = countWhileTrue(th, (List*)f.o());\n skip_positive_(th, s, n);\n\t\tth.push(s);\n } else {\n \n List* list = s();\n\n while (1) {\n list->force(th);\n if (list->isEnd()) {\n th.push(vm.getNil(s->elemType));\n return;\n }\n \n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n V v;\n {\n SaveStack ss(th);\n th.push(a->at(i));\n\t\t\t\t\tf.apply(th);\n v = th.pop();\n }\n if (v.isFalse()) {\n if (i == 0) {\n th.push(list);\n } else {\n int64_t remain = asize - i;\n Array* a2 = new Array(s->elemType, remain);\n th.push(new List(a2, list->next()));\n a2->setSize(remain);\n\t\t\t\t\t\tif (a->isV()) {\n\t\t\t\t\t\t\tfor (int64_t j = 0; j < remain; ++j) a2->v()[j] = a->v()[j+i];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmemcpy(a2->v(), a->v() + i, remain * a->elemSize());\n\t\t\t\t\t\t}\n }\n return;\n }\n }\n list = list->nextp();\n }\n th.push(list);\n }\n}\n\n\nstruct KeepWhile : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tKeepWhile(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhile\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZ : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tKeepWhileZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileVZ : Gen\n{\n\tVIn _a;\n\tZIn _b;\n\t\n\tKeepWhileVZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileVZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a;\n\t\t\tZ *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZV : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\t\n\tKeepWhileZV(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZV\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a;\n\t\t\tV *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstatic void keepWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"keepWhile : s\");\n\t\n\tif (s->isZ()) {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhileZV(th, s, f)));\n\t\t}\n\t} else {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileVZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhile(th, s, f)));\n\t\t}\n\t} \n}\n\n\nstruct Tog : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Togz : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tTogz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Togz\"; }\n \t\t\t \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill / 2;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t*out++ = *a;\n\t\t\t\t\t*out++ = *b;\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= 2*n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tog_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Tog(th, a, b)));\n}\n\nstatic void togz_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Togz(th, a, b)));\n}\n\n\n\nstruct Tog1 : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog1(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog1\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\n\nstruct Hang : Gen\n{\n\tP _a;\n\tV _b;\n\n\tHang(Thread& th, P const& a) : Gen(th, itemTypeV, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hang\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->v()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tV* out = mOut->fulfill(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Hangz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tHangz(Thread& th, P const& a) : Gen(th, itemTypeZ, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hangz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->z()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void hang_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"hang : a\");\n\t\n\tif (a->isV())\n\t\tth.push(new List(new Hang(th, a)));\n\telse\n\t\tth.push(new List(new Hangz(th, a)));\n}\n\nstatic void hangz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"hangz : a\");\n\t\n\tth.push(new List(new Hangz(th, a)));\n}\n\n\nstatic void histo_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"histo : n\");\n\tP a = th.popList(\"histo : list\");\n\n\tif (!a->isFinite()) {\n\t\tindefiniteOp(\"histo : list\", \"\");\n\t}\n\t\n\ta = a->pack(th);\n\t\n\tint64_t size = a->mArray->size();\n\t\n\tPoutList = new List(itemTypeZ, n);\n\toutList->mArray->setSize(n);\n\tZ* out = outList->mArray->z();\n\tmemset(out, 0, sizeof(Z) * n);\n\t\n\tZ n1 = n - 1;\n\tif (a->isZ()) {\n\t\tZ* in = a->mArray->z();\n\t\t\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i], 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t} else {\n\t\tV* in = a->mArray->v();\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i].asFloat(), 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t}\n\t\n\tth.push(outList);\n\t\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark MAP FILTER REDUCE\n\n\nstruct Stutter : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tStutter(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutter\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = aa_;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, aa_) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(aa_);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Stutterz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\tZ aa_;\n\t\n\tStutterz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutterz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a = aa_;\n\t\twhile (framesToFill) {\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\taa_ = a;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void filter_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.popList(\"? : a\");\n\n\tif (a.isVList()) {\n\t\tth.push(new List(new Stutter(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Stutterz(th, a, b)));\n\t}\n}\n\n\nstruct Change : Gen\n{\n\tVIn _a;\n\tV _prev;\n\t\n\tChange(Thread& th, Arg a) : Gen(th, itemTypeV, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Change\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n V a;\n for (int i = 0; framesToFill; ) {\n if (_a.one(th, a)) {\n setDone();\n break;\n }\n if (!a.Equals(th, _prev)) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Changez : Gen\n{\n\tZIn _a;\n\tZ _prev;\n\t\n\tChangez(Thread& th, Arg a) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Changez\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n Z a;\n for (int i = 0; framesToFill; ) {\n if (_a.onez(th, a)) {\n setDone();\n break;\n }\n if (a != _prev) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void change_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"change : a\");\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Change(th, a)));\n\t} else {\n\t\tth.push(new List(new Changez(th, a)));\n\t}\n}\n\nstatic void changez_(Thread& th, Prim* prim)\n{\n\tV a = th.popZList(\"change : a\");\n \n th.push(new List(new Changez(th, a)));\n}\n\nstruct Spread : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tSpread(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spread\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tV a = aa_;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Spreadz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\t\n\tSpreadz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spreadz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n \n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void spread_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Spread(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Spreadz(th, a, b)));\n\t}\n}\n\nstatic void spreadz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"spreadz : b\");\n\tV a = th.popZIn(\"spreadz : a\");\n \n th.push(new List(new Spreadz(th, a, b)));\n}\n\nstruct Expand : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tExpand(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expand\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tV a;\n\t\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Expandz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tExpandz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expandz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tZ a;\n\t\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void expand_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Expand(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Expandz(th, a, b)));\n\t}\n}\n\nstatic void expandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"expandz : b\");\n\tV a = th.popZIn(\"expandz : a\");\n \n th.push(new List(new Expandz(th, a, b)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Clump : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tClump(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clump\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeV, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV a;\n\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->add(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Clumpz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tClumpz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clumpz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeZ, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a;\n\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->addz(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void clump_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Clump(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Clumpz(th, a, b)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ShortAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tShortAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ShortAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tShortAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void shortas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new ShortAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new ShortAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"shortas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tV last;\npublic:\n\t\n\tLongAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\n\tZ last;\npublic:\n\t\n\tLongAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"longas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs0 : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tLongAs0(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tV zero(0.);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = zero;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAs0Z : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tLongAs0Z(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0Z\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas0_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs0(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAs0Z(th, a, b)));\n\t} else {\n\t\twrongType(\"longas0 : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \"Play.hpp\"\n\nstatic void play_(Thread& th, Prim* prim)\n{\n\tV v = th.popList(\"play : list\");\n\tplayWithAudioUnit(th, v);\n}\n\nstatic void record_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tV v = th.popList(\"record : list\");\n\trecordWithAudioUnit(th, v, filename);\n}\n\nstatic void stop_(Thread& th, Prim* prim)\n{\n\tstopPlaying();\n}\n\nstatic void stopDone_(Thread& th, Prim* prim)\n{\n\tstopPlayingIfDone();\n}\n\n\nstatic void interleave(int stride, int numFrames, double* in, float* out)\n{\n\tfor (int f = 0, k = 0; f < numFrames; ++f, k += stride)\n\t\tout[k] = in[f];\n}\n\nstatic void deinterleave(int numChans, int numFrames, float* in, double** out)\n{\n\tswitch (numChans) {\n\t\tcase 1 : \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, ++k) {\n\t\t\t\tout[0][f] = in[k];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 2 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=2) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3 : // e.g. W X Y \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=3) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 4 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=4) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 5 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=5) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 6 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=6) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t\tout[5][f] = in[k+5];\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f) {\n\t\t\t\tfor (int c = 0; c < numChans; ++c, ++k) {\n\t\t\t\t\tout[c][f] = in[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nstatic const size_t gSessionTimeMaxLen = 256;\nchar gSessionTime[gSessionTimeMaxLen];\n\n#include \n\nstatic void setSessionTime()\n{\n\ttime_t t;\n\ttm tt;\n\ttime(&t);\n\tlocaltime_r(&t, &tt);\n\tsnprintf(gSessionTime, gSessionTimeMaxLen, \"%04d-%02d%02d-%02d%02d%02d\",\n\t\ttt.tm_year+1900, tt.tm_mon+1, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec);\n}\n\n\nstatic void sfwrite_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.popList(\">sf : channels\");\n\t\n\tsfwrite(th, v, filename, false);\n}\n\nstatic void sfwriteopen_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.pop();\n\n\tsfwrite(th, v, filename, true);\n}\n\n\nstatic void sfread_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.popString(\"sf> : filename\");\n\t\t\n\tsfread(th, filename, 0, -1);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstatic void bench_(Thread& th, Prim* prim)\n{\n\tZIn in[kMaxSFChannels];\n\t\t\n\tint numChannels = 0;\n\t\n\tV v = th.popList(\"bench : channels\");\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin[0].set(v);\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin[i].set(va);\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tdouble t0 = elapsedTime();\n\tbool done = false;\n\tint64_t framesFilled = 0;\n\twhile (!done) {\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].bench(th, n);\n\t\t\tif (imdone) done = true;\n\t\t\tframesFilled += n;\n\t\t}\n\t}\n\tdouble t1 = elapsedTime();\n\t\n\tdouble secondsOfCPU = t1-t0;\n\tdouble secondsOfAudio = (double)framesFilled * th.rate.invSampleRate;\n\tdouble percentOfRealtime = 100. * secondsOfCPU / secondsOfAudio;\n\t\n\tpost(\"bench:\\n\");\n\tpost(\" %f seconds of audio.\\n\", secondsOfAudio);\n\tpost(\" %f seconds of CPU.\\n\", secondsOfCPU);\n\tpost(\" %f %% of real time.\\n\", percentOfRealtime);\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#include \"Spectrogram.hpp\"\n\nstd::atomic gSpectrogramFileCount = 0;\n\nstatic void sgram_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tZ dBfloor = fabs(th.popFloat(\"sgram : dBfloor\"));\n\tP list = th.popZList(\"sgram : signal\");\n\t\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"sgram : signal - indefinite number of frames\", \"\");\n\t}\n\n\tchar path[1024];\n\tif (filename.isString()) {\n\t\tconst char* sgramDir = getenv(\"SAPF_SPECTROGRAMS\");\n\t\tif (!sgramDir || strlen(sgramDir)==0) sgramDir = \"/tmp\";\n\t\tsnprintf(path, 1024, \"%s/%s-%d.jpg\", sgramDir, ((String*)filename.o())->s, (int)floor(dBfloor + .5));\n\t} else {\n\t\tint32_t count = ++gSpectrogramFileCount;\n\t\tsnprintf(path, 1024, \"/tmp/sapf-%s-%04d.jpg\", gSessionTime, count);\n\t}\n\n\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\tint64_t n = array->size();\n\tdouble* z = array->z();\n\tspectrogram((int)n, z, 3200, 11, path, -dBfloor);\n\t\n\t{\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\t\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double kaiser_alpha(double atten)\n{\n\tdouble alpha = 0.;\n\tif (atten > 50.) \n\t\talpha = .1102 * (atten - 8.7);\n\telse if (atten >= 21.)\n\t\talpha = .5842 * pow(atten - 21., .4) + .07886 * (atten - 21.);\n\treturn alpha;\n}\n\nstatic void kaiser(size_t m, double *s, double alpha)\n{\n\tif (m == 0) return;\n\tif (m == 1) {\n\t\ts[0] = 1.;\n\t\treturn;\n\t}\n\tsize_t n = m-1;\n\tdouble p = n / 2.;\n\tdouble rp = 1. / p;\n\tdouble rb = 1. / bessi0(alpha);\n\t\n\tfor (size_t i = 0; i < m; ++i) {\n\t\tdouble x = (i-p) * rp;\n\t\ts[i] = rb * bessi0(alpha * sqrt(1. - x*x));\n\t}\n}\n\nstatic void kaiser_(Thread& th, Prim* prim)\n{\n\tZ atten = fabs(th.popFloat(\"kaiser : stopband attenuation\"));\n\tint64_t n = th.popInt(\"kaiser : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tZ alpha = kaiser_alpha(atten);\n\tkaiser(n, out->mArray->z(), alpha);\n\t\n\tth.push(out);\n}\n\n\nstatic void hanning_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hann_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void hamming_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hamm_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void blackman_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_blkman_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Segment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tBothIn length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tSegment(Thread& th, Arg in, Arg hop, Arg length)\n : Gen(th, itemTypeV, mostFinite(in, hop, length)), in_(in), hop_(hop), length_(length),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Segment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zlength, zhop;\n\t\t\tif (length_.onez(th, zlength)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint length = (int)floor(sr_ * zlength + .5);\n\t\t\tP segment = new List(itemTypeZ, length);\n\t\t\tsegment->mArray->setSize(length);\n\t\t\tbool nomore = in_.fillSegment(th, length, segment->mArray->z());\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n \n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void seg_(Thread& th, Prim* prim)\n{\n\tV length = th.pop();\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n\tth.push(new List(new Segment(th, in, hop, length)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct WinSegment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tP window_;\n int length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tWinSegment(Thread& th, Arg in, Arg hop, P const& window)\n : Gen(th, itemTypeV, mostFinite(in, hop)), in_(in), hop_(hop), window_(window),\n length_((int)window_->size()),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WinSegment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zhop;\n\t\t\t\n\t\t\tP segment = new List(itemTypeZ, length_);\n\t\t\tsegment->mArray->setSize(length_);\n Z* segbuf = segment->mArray->z();\n\t\t\tbool nomore = in_.fillSegment(th, (int)length_, segbuf);\n vDSP_vmulD(segbuf, 1, window_->z(), 1, segbuf, 1, length_);\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void wseg_(Thread& th, Prim* prim)\n{\n\tP window = th.popZList(\"wseg : window\");\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n window = window->pack(th);\n \n\tth.push(new List(new WinSegment(th, in, hop, window->mArray)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void fft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"fft : imag\");\n\tP inReal = th.popZList(\"fft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"fft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"fft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"fft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"fft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\n\tfft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\n\nstatic void ifft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"ifft : imag\");\n\tP inReal = th.popZList(\"ifft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"ifft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"ifft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"ifft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"ifft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\tifft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\nstruct Add : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAdd(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Add\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tV* out = mOut->fulfill(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Addz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tAddz(Thread& th, P const& a, Z b) : Gen(th, itemTypeZ, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Addz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tZ* out = mOut->fulfillz(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void add_(Thread& th, Prim* prim)\n{\n\tV item = th.pop();\n\tP list = th.popList(\"add : list\");\n\tif (list->isZ()) {\n\t\tth.push(new List(new Addz(th, list, item.asFloat())));\n\t} else {\n\t\tth.push(new List(new Add(th, list, item)));\n\t}\n}\n\nstatic void empty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size==0);\n}\n\nstatic void nonempty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size!=0);\n}\n\nstatic void head_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tBothIn in(list);\n\tV v;\n\tif (in.one(th, v)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tth.push(v);\n}\n\nstatic void tail_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tskip_positive_(th, list, 1);\n\tth.push(list);\n}\n\nstatic void uncons_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tlist->force(th);\n\n\tBothIn in(list);\n\tV head;\n\tif (in.one(th, head)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tskip_positive_(th, list, 1);\n\t\n\tth.push(list);\n\tth.push(head);\n}\n\nclass Cons : public Gen\n{\n\tV fun;\npublic:\n\tCons(Thread& th, Arg inFun) : Gen(th, itemTypeV, false), fun(inFun) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Cons\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tSaveStack ss(th);\n\t\tfun.apply(th);\n\t\tV v = th.pop();\n\t\tif (v.isList()) {\n\t\t\tsetDone();\n\t\t\tmOut->link(th, (List*)v.o());\n\t\t} else {\n\t\t\tend();\n\t\t}\n\t}\n};\n\nstatic V cons(Thread& th, Arg head, Arg tail)\n{\n\tif (tail.isFunOrPrim()) {\n\t\tP array = new Array(itemTypeV, 1);\n\t\tarray->add(head);\n\t\treturn new List(array, new List(new Cons(th, tail)));\n\t} else if (tail.isList()) {\n\t\n\t\tP list = (List*)tail.o();\n\t\t\n\t\tlist->force(th);\n\t\t\t\n\t\tint64_t size = list->mArray->size();\n\n\t\tP array = list->mArray;\n\t\tP newArray = new Array(list->ItemType(), size+1);\n\n\t\tP newList = new List(newArray, list->next());\n\n\t\tnewArray->add(head);\n\n\t\tif (list->isZ()) {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tZ z = array->atz(i);\n\t\t\t\tnewArray->add(z);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tV v = array->at(i);\n\t\t\t\tnewArray->add(v);\n\t\t\t}\n\t\t}\n\n\t\treturn newList;\n\t} else {\n\t\twrongType(\"cons : list\", \"List or Fun\", tail);\n\t}\n}\n\nstatic void cons_(Thread& th, Prim* prim)\n{\n\tV head = th.pop();\n\tV tail = th.pop();\n\t\n\tth.push(cons(th, head, tail));\n}\n\nstatic void pack_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"pack : list\");\n\tth.push(list->pack(th));\n}\n\nstatic void packed_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"packed : list\");\n\tth.pushBool(list->isPacked());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n \n\tScan(Thread& th, Arg list, Arg fun, Arg val) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan(th, list, fun, value)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan1 : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n\tbool once_;\n \n\tScan1(Thread& th, Arg list, Arg fun) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), once_(true) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (once_) {\n\t\t\tonce_ = false;\n\t\t\tif (list_.one(th, val_)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = val_;\n\t\t\t--framesToFill;\n\t\t}\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan1(th, list, fun)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Iter : Gen\n{\n V fun_;\n V val_;\n Z index = 0.;\n\t\n\tIter(Thread& th, Arg fun, Arg val) : Gen(th, itemTypeV, true), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Iter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct NIter : Gen\n{\n V fun_;\n V val_;\n\tint64_t n_;\n Z index = 0.;\n \n\tNIter(Thread& th, Arg fun, Arg val, int64_t n) : Gen(th, itemTypeV, false), fun_(fun), val_(val), n_(n) {}\n\t \n\tvirtual const char* TypeName() const override { return \"NIter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (n_ <= 0) {\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tn_ -= n;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void iter_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new Iter(th, fun, value)));\n}\n\nstatic void itern_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"itern : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new NIter(th, fun, value, n)));\n}\n\n\n\nstatic void reduce_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\n\nstatic void reduce1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\tV value;\n\tif (in_.one(th, value)) {\n\t\tth.push(value);\n\t\treturn;\n\t}\n\t\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\nstatic void chain_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"chain : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\n\tbool pushIndex = fun.takes() == 2;\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(value);\n\t\tif (pushIndex) th.push(i);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n\tth.push(value);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Merge : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMerge(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Merge\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \nstruct MergeZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeByKey : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V key_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeByKey(Thread& th, Arg a, Arg b, Arg key) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), key_(key) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeByKey\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tV a, b;\n\t\t\t\tbool aok = aa.dot(th, key_, a);\n\t\t\t\tbool bok = bb.dot(th, key_, b);\n\t\t\t\tif (!aok || !bok) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tflag = ::Compare(th, a, b) < 0;\n\t\t\t\tif (flag) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeCmp : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmp(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmp\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\twhich = left;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\nstruct MergeCmpZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmpZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmpZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = right;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\n\nstatic void merge_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"merge : b\");\n\tV a = th.popList(\"merge : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tif (fun.isString()) {\n\t\t\tth.push(new List(new MergeByKey(th, a, b, fun)));\n\t\t} else {\n\t\t\tth.push(new List(new Merge(th, a, b, fun)));\n\t\t}\n\t} else {\n\t\tpost(\"merge : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\nstatic void mergec_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"mergec : b\");\n\tV a = th.popList(\"mergec : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeCmpZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new MergeCmp(th, a, b, fun)));\n\t} else {\n\t\tpost(\"mergec : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n//evmerge\n\nextern P s_dt;\nextern P s_out;\nP s_dur;\n\nP dtTableMap;\nP restTableMap;\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value);\n\nstatic P makeRestEvent(Z dt)\n{\n\tP
table = new Table(restTableMap);\n\ttable->put(0, V(0.));\n\ttable->put(1, V(dt));\n\ttable->put(2, V(dt));\n\treturn new Form(table);\n}\n\nstruct MergeEvents : Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tZ nextATime = 0.;\n\tZ nextBTime;\n\t\n\tMergeEvents(Thread& th, Arg a, Arg b, Z t) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), nextBTime(t)\n\t{\n\t}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeEvents\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\t{\n\t\t\t\tif (nextATime <= nextBTime) {\n\t\t\t\t\tV aa;\n\t\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\t\tif (nextATime < nextBTime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextBTime - nextATime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tV a;\n\t\t\t\t\tbool aok = aa.dot(th, s_dt, a);\n\t\t\t\t\tif (!aok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dta = a.asFloat();\n\t\t\t\t\tZ dt = std::min(dta, nextBTime - nextATime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, aa), dtTableMap, dt);\n\t\t\t\t\tnextATime += dta;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tV bb;\n\t\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\t\tif (nextBTime < nextATime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextATime - nextBTime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tV b;\n\t\t\t\t\tbool bok = bb.dot(th, s_dt, b);\n\t\t\t\t\tif (!bok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dtb = b.asFloat();\n\t\t\t\t\tZ dt = std::min(dtb, nextATime - nextBTime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, bb), dtTableMap, dt);\n\t\t\t\t\tnextBTime += dtb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstatic void evmerge_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evmerge : t\");\n\tV b = th.popVList(\"evmerge : b\");\n\tV a = th.popVList(\"evmerge : a\");\n\tth.push(new List(new MergeEvents(th, a, b, t)));\n}\n\nstatic void evrest_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evrest : t\");\n\tth.push(makeRestEvent(t));\n}\n\nstatic void evdelay_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evdelay : t\");\n\tV a = th.popVList(\"evdelay : a\");\n\tth.push(cons(th, makeRestEvent(t), a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CompareFun\n{\npublic:\n\tCompareFun() {}\n\tvirtual ~CompareFun() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) = 0;\n};\n\nclass VLess : public CompareFun\n{\npublic:\n\tVLess() {}\n\t~VLess() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) < 0; }\n};\n\nclass VGreater : public CompareFun\n{\npublic:\n\tVGreater() {}\n\t~VGreater() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) > 0; }\n};\n\nclass VCompareF : public CompareFun\n{\n\tV fun;\npublic:\n\tVCompareF(V inFun) : fun(inFun) {}\n\t~VCompareF() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\n\n\nclass ZCompareFun\n{\npublic:\n\tZCompareFun() {}\n\tvirtual ~ZCompareFun() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) = 0;\n};\n\nclass ZLess : public ZCompareFun\n{\npublic:\n\tZLess() {}\n\t~ZLess() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a < b; }\n};\n\nclass ZCompareF : public ZCompareFun\n{\n\tV fun;\npublic:\n\tZCompareF(V inFun) : fun(inFun) {}\n\t~ZCompareF() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\nclass ZGreater : public ZCompareFun\n{\npublic:\n\tZGreater() {}\n\t~ZGreater() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a > b; }\n};\n\n\nstatic void merge(Thread& th, int64_t an, V* a, int64_t bn, V* b, V* c, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, int64_t bn, Z* b, Z* c, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, V* tmp, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* tmp, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const V* in, V* out, CompareFun* compare)\n{\n\tV* tmp = new V[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const Z* in, Z* out, ZCompareFun* compare)\n{\n\tZ* tmp = new Z[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void merge(Thread& th, int64_t an, V* a, Z* az, int64_t bn, V* b, Z* bz, V* c, Z* cz, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, Z* az, int64_t bn, Z* b, Z* bz, Z* c, Z* cz, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, Z* az, V* c, Z* cz, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* az, Z* c, Z* cz, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\n\nstatic void grade(Thread& th, int64_t n, const V* in, Z* zout, CompareFun* compare)\n{\n\tV* out = new V[n];\n\tV* tmp = new V[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void grade(Thread& th, int64_t n, const Z* in, Z* zout, ZCompareFun* compare)\n{\n\tZ* out = new Z[n];\n\tZ* tmp = new Z[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void sort_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void sortf_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"sort : fun\");\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(list->ItemType(), n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void sort_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void gradef_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"grade : fun\");\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFN(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP);\n#define DEFNnoeach(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP, V(0.), true);\n\nvoid AddStreamOps();\nvoid AddStreamOps()\n{\n\tinitFFT();\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\ts_dur = getsym(\"dur\");\n\tdtTableMap = new TableMap(V(s_dt));\n\trestTableMap = new TableMap(3);\n\trestTableMap->put(0, s_out, s_out->Hash());\n\trestTableMap->put(1, s_dur, s_dur->Hash());\n\trestTableMap->put(2, s_dt, s_dt->Hash());\n\t\n\tvm.addBifHelp(\"\\n*** list conversion ***\");\n\tDEF(V, 1, 1, \"(signal --> stream) converts a signal or string to a stream.\")\n\tDEF(Z, 1, 1, \"(series --> signal) converts a stream or string to a signal.\")\t\n\tDEF(L, 1, 1, \"(anything --> stream) streams are returned as is. anything else is made into an infinite stream of itself.\")\n\tDEF(L1, 1, 1, \"(anything --> stream) streams are returned as is. anything else is wrapped in a one item list.\")\n\tDEF(unspell, 1, 1, \"(sequence --> string) converts a stream of numbers or a signal to a string.\")\n\n\tvm.addBifHelp(\"\\n*** basic list operations ***\");\n\n\tDEF(size, 1, 1, \"(seq --> num) Return the length of a sequence if it is finite. Returns inf if the sequence is of indefinite length (It may not actually be infinitely long).\")\n\tDEF(rank, 1, 1, \"(a --> n) Return the rank of an object. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(shape, 1, 1, \"(a --> [n..]) Return the shape of an object. Axes of indefinite length are represented by inf. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(finite, 1, 1, \"(seq --> bool) Returns 1 if the sequence is finite, 0 if indefinite.\")\n\n\tDEF(empty, 1, 1, \"(list --> bool) returns whether the list is empty.\")\n\tDEF(nonempty, 1, 1, \"(list --> bool) returns whether the list is nonempty.\")\n\tDEF(head, 1, 1, \"(list --> item) returns first item of list. fails if list is empty.\")\n\tDEF(tail, 1, 1, \"(list --> list) returns the rest of the list after the first item. fails if list is empty.\")\n\tDEF(add, 2, 1, \"(list item --> list) returns a new list with the item added to the end.\")\t\n\tDEF(cons, 2, 1, \"(list item --> list) returns a new list with the item added to the front.\")\t\n\tDEF(uncons, 1, 2, \"(list --> tail head) returns the tail and head of a list. fails if list is empty.\")\n\tDEF(pack, 1, 1, \"(list --> list) returns a packed version of the list.\");\n\tDEF(packed, 1, 1, \"(list --> bool) returns whether the list is packed.\");\n\n\tvm.addBifHelp(\"\\n*** list generation ***\");\n\n\tDEFnoeach(ord, 0, 1, \"(--> series) return an infinite series of integers ascending from 1.\")\n\tDEFnoeach(nat, 0, 1, \"(--> series) return an infinite series of integers ascending from 0.\")\n\tDEFnoeach(invs, 0, 1, \"(--> series) return an infinite series of reciprocals. equivalent to ord 1/\")\n\tDEFnoeach(negs, 0, 1, \"(--> series) return an infinite series of integers descending from -1.\")\n\tDEFnoeach(evens, 0, 1, \"(--> series) return an infinite series of ascending non-negative even integers.\")\n\tDEFnoeach(odds, 0, 1, \"(--> series) return an infinite series of ascending non-negative odd integers.\")\n\tDEFnoeach(ints, 0, 1, \"(--> series) return the infinite series [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primes, 0, 1, \"(--> series) returns a finite series of prime numbers up to 1000039.\")\n\tDEFAM(fib, kk, \"(a b --> series) returns a fibonacci series starting with the two numbers given.\") \n\n\tDEFnoeach(ordz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 1.\")\n\tDEFnoeach(natz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 0.\")\n\tDEFnoeach(invz, 0, 1, \"(--> signal) return an infinite signal of reciprocals. equivalent to ordz 1/\")\n\tDEFnoeach(negz, 0, 1, \"(--> signal) return an infinite signal of integers descending from -1.\")\n\tDEFnoeach(evenz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative even integers.\")\n\tDEFnoeach(oddz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative odd integers.\")\n\tDEFnoeach(intz, 0, 1, \"(--> signal) return the infinite signal [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primez, 0, 1, \"(--> signal) returns a finite signal of prime numbers up to 1000039.\")\t\n\tDEFMCX(fibz, 2, \"(a b --> signal) returns a fibonacci signal starting with the two numbers given.\")\n\n\tDEFAM(ninvs, k, \"(n --> stream) return a finite stream of n reciprocals. equivalent to n 1 1 nby 1/\")\n\tDEFMCX(ninvz, 1, \"(n --> signal) return a finite signal of n reciprocals. equivalent to n 1 1 nbyz 1/\")\n\t\n\tDEF(ever, 1, 1, \"(value --> series) return an infinite stream of value.\")\n\tDEFAM(by, kk, \"(start step --> series) return an infinite arithmetic series.\") \n\tDEFAM(nby, kkk, \"(n start step --> series) return a finite arithmetic series.\") \n\tDEFAM(grow, kk, \"(start step --> series) return an infinite geometric series.\") \n\tDEFAM(ngrow, kkk, \"(start step --> series) return a finite geometric series.\") \n\tDEFAM(to, kk, \"(a b --> series) return a finite series from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFMCX(everz, 1, \"(value --> signal) return an infinite signal of value.\")\n\tDEFMCX(byz, 2, \"(start step --> series) return an infinite arithmetic series as a signal.\") \n\tDEFMCX(nbyz, 3, \"(start step --> series) return a finite arithmetic series as a signal.\") \n\tDEFMCX(growz, 2, \"(start step --> series) return an infinite geometric series as a signal.\") \n\tDEFMCX(ngrowz, 3, \"(start step --> series) return a finite geometric series as a signal.\") \n\tDEFMCX(toz, 2, \"(a b --> series) return a finite signal from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFAM(lindiv, kkk, \"(n start end --> series) returns a series of n equal steps from start to end.\") \n\tDEFAM(expdiv, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start to end.\") \n\tDEFMCX(lindivz, 3, \"(n start end --> series) returns a signal of n equal steps from start to end.\") \n\tDEFMCX(expdivz, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start to end.\") \n\n\tDEFAM(lindiv1, kkk, \"(n start end --> series) returns a series of n equal steps from start up to but not including end.\") \n\tDEFAM(expdiv1, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start up to but not including end.\") \n\tDEFMCX(lindiv1z, 3, \"(n start end --> series) returns a signal of n equal steps from start up to but not including end.\") \n\tDEFMCX(expdiv1z, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start up to but not including end.\") \n\n\tDEFMCX(line, 3, \"(dur start end --> z) return a signal ramping linearly from start to end in dur seconds.\") // mcx\n\tDEFMCX(xline, 3, \"(dur start end --> z) return a signal ramping exponentially from start to end in dur seconds.\") // mcx\n\n\tvm.addBifHelp(\"\\n*** list reduction operations ***\");\n\tDEFAM(reduce, aak, \"(list value fun --> value) applies fun to each item in list and the current value to get a new value. returns the ending value.\")\n\tDEFAM(reduce1, ak, \"(list fun --> value) like reduce except that the initial value is the first item in the list.\")\n\n\tDEFAM(scan, aak, \"(list value fun --> list) applies fun to each item in list and the current value to get a new value, which is added to the output list.\")\n\tDEFAM(scan1, ak, \"(list fun --> list) like scan except that the initial value is the first item in the list.\")\n\tDEFAM(iter, ak, \"(value fun --> list) returns an infinite list of repeated applications of fun to value.\")\n\tDEFAM(itern, akk, \"(value fun n --> list) returns a list of n repeated applications of fun to value.\")\n \t\n\tDEFAM(chain, akk, \"(value fun n --> list) returns the result of n repeated applications of fun to value.\")\n \n\tvm.addBifHelp(\"\\n*** list ordering operations ***\");\n\tDEF(cyc, 1, 1, \"(list --> list) makes a finite list become cyclic.\")\n\tDEFAM(ncyc, ak, \"(n list --> list) concatenates n copies of a finite list.\")\n\tDEF(rcyc, 1, 1, \"(ref --> list) gets a new list from ref each time list is exhausted.\")\n\n\tvm.defautomap(\"X\", \"ak\", repeat_, \"(value n --> stream) makes a list containing n copies of value. If value is a function, then the results of applying the function with an integer count argument is used as the contents of the output list.\");\n\tvm.defmcx(\"XZ\", 2, repeatz_, \"(value n --> signal) returns a signal with value repeated n times.\");\n\tvm.defmcx(\"mum\", 1, mum_, \"(t --> signal) returns a signal of t seconds of silence.\");\n\n\tvm.def(\"$\", 2, 1, append_, \"(listA listB --> out) returns the concatenation of listA and listB.\");\n\tvm.defmcx(\"$z\", 2, append_, \"(signalA signalB --> signal) returns the concatenation of signalA and signalB.\");\n\t\n\tvm.def(\"$$\", 2, 1, appendSubs_, \"(listA listB --> out) return the concatenation of the sublists of listA and listB. equivalent to (listA @ listB @ $)\");\n\tvm.def(\"$/\", 1, 1, cat_, \"(list --> out) returns the concatenation of the sub-lists of the input list.\");\n\tDEF(flat, 1, 1, \"(list --> list) flattens a list.\")\n\tDEFAM(flatten, ak, \"(list n --> list) makes a list n levels flatter.\")\n\tvm.defautomap(\"keep\", \"ak\", N_, \"(list n --> list) returns a list of the first n items of the input list.\");\n\t\n\tDEFAM(T, zk, \"(signal t --> signal) returns a signal of the first t seconds of the input signal.\");\n\tvm.defautomap(\"T>\", \"zk\", skipT_, \"(signal t --> signal) skips the first t seconds of the input signal.\");\n\tvm.defautomap(\"N>\", \"ak\", skip_, \"(list n --> list) skips the first n items of the input list.\");\n\tvm.def(\"N>>\", 2, 1, hops_, \"(list hops --> listOfLists) returns a list of tails of the input list. equivalent to (list (hops 0 | L 0 cons +\\\\) N>).\");\n\tvm.defautomap(\"T>>\", \"za\", hopTs_, \"(signal hops --> listOfSignals) returns a list of tails of the input list. equivalent to (signal (hops 0 | L 0 cons +\\\\) T>).\");\n\tDEFAM(N, ak, \"(list n --> list) returns a list of the first n items of the input list.\") \n\tDEFAM(NZ, zk, \"(signal n --> signal) returns a signal of the first n items of the input signal. automaps over streams.\") \n\t\n\tDEFAM(skip, ak, \"(list n --> list) skips the first n items of the input list.\") \n\n\tDEFAM(take, ak, \"(list n --> list) returns a list of the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\tDEFAM(drop, ak, \"(list n --> list) skips the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\t\n\tDEFAM(choff, akk, \"(channel(s) c n --> out) takes a finite list of channels or a single signal and places it into an array of n channels beginning at offset c. Other channels are set to zero.\");\n\n\tDEF(tog, 2, 1, \"(a b --> series) return a series alternating between a and b.\")\n\tDEFMCX(togz, 2, \"(a b --> signal) return a signal alternating between a and b.\")\n\tDEF(sel, 2, 1, \"(a j --> out) select. a is a list of lists. out[i] is a[j][i]\")\n\tDEF(sell, 2, 1, \"(a j --> out) lazy select. a is a list of lists. out[i] is the next value from a[j].\")\n\n\tvm.def(\"?\", 2, 1, filter_, \"(a b --> out) the output list contains a[i] repeated b[i] times. If b is a list of booleans (1 or 0) then this functions as a filter.\");\n\tDEF(spread, 2, 1, \"(a n --> out) inserts n[i] zeroes after a[i].\")\t\n\tDEFMCX(spreadz, 2, \"(a n --> signal) inserts n[i] zeroes after a[i]. automaps over stream inputs.\")\t\n\n\tDEF(change, 1, 1, \"(a --> b) eliminates sequential duplicates in a signal or stream.\")\t\n\tDEFMCX(changez, 1, \"(a --> b) eliminates sequential duplicates in a signal. automaps over streams.\")\t\n\tDEF(expand, 2, 1, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out.\")\t\n\tDEFMCX(expandz, 2, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out. automaps over stream inputs.\")\t\n\n\tDEF(clump, 2, 1, \"(a n --> out) groups elements from list a into sub-lists of size n.\")\t\n\tDEF(hang, 1, 1, \"(a --> out) repeats the last value of a finite list indefinitely.\")\t\n\tDEFMCX(hangz, 1, \"(a --> out) repeats the last value of a finite signal indefinitely. automaps over streams.\")\t\n\tDEFAM(histo, ak, \"(a n --> out) makes a histogram of the finite stream a.\")\t\n\tvm.defautomap(\"histoz\", \"zk\", histo_, \"(a n --> out) makes a histogram of the finite signal a. automaps over streams.\");\n\n\tDEF(keepWhile, 2, 1, \"(a b --> out) return items from a while items from b are true.\")\n\tDEF(skipWhile, 2, 1, \"(a b --> out) skip items from a while items from b are true.\")\n\t\n\tDEF(flop, 1, 1, \"(a --> b) returns the transpose of the list of lists a. At least one of the dimensions must be finite.\")\t\n\tDEF(flops, 1, 1, \"(a --> b) like flop, but signals are treated as scalars and not flopped.\")\n\tDEF(flop1, 1, 1, \"(a --> b) like flop, but if list a is not a list of lists then it is wrapped in a list. compare: [[1 2 3][[4 5] 6 7]] @ flop $/ with: [[1 2 3][[4 5] 6 7]] @ flop1 $/\")\t\n\tDEF(lace, 1, 1, \"(a --> b) returns the concatenation of the transpose of the list of lists a.\")\t\n\tDEFAM(merge, aak, \"(a b fun --> c) merges two lists according to the function given. The function should work like <.\")\n\tDEFAM(mergec, aak, \"(a b fun --> c) merges two lists without duplicates according to the function given. The function should work like cmp.\")\n\t\n\tDEF(perms, 1, 1, \"(a --> b) returns a list of all permutations of the input list.\")\n\tDEFMCX(permz, 1, \"(a --> b) returns a list of all permutations of the input signal. automaps over streams.\")\n\t\n\tDEF(permswr, 1, 1, \"(a --> b) returns a list of all unique permutations of an input stream with repeated elements.\")\n\tDEFMCX(permzwr, 1, \"(a --> b) returns a returns a list of all unique permutations of an input signal with repeated elements. automaps over streams.\")\n\t\n\tDEF(shortas, 2, 1, \"(a b --> a') makes list a as short as list b.\")\n\tDEF(longas, 2, 1, \"(a b --> a') makes list a as long as list b by repeating the last item.\")\n\tDEF(longas0, 2, 1, \"(a b --> a') makes list a as long as list b by appending zeroes.\")\n\n\t// array ops\n\n\tvm.addBifHelp(\"\\n*** list ops ***\");\n\n\tDEF(bub, 1, 1, \"(a --> [a]) makes the top item on the stack into a one item list. i.e. puts a bubble around it.\")\n\tDEF(nbub, 2, 1, \"(a n --> [[..[a]..]]) embeds the top item in N one item lists.\")\n\n\tvm.def(\"2ple\", 2, 1, tupleN_<2>, \"(a b --> [a b]) make a pair from the top two stack items.\");\n\tvm.def(\"3ple\", 3, 1, tupleN_<3>, \"(a b c --> [a b c]) make a triple from the top three stack items.\");\n\tvm.def(\"4ple\", 4, 1, tupleN_<4>, \"(a b c d --> [a b c d]) make a quadriple from the top four stack items.\");\n\tvm.def(\"5ple\", 5, 1, tupleN_<5>, \"(a b c d e --> [a b c d e]) make a quintuple from the top five stack items.\");\n\tvm.def(\"6ple\", 6, 1, tupleN_<6>, \"(a b c d e f --> [a b c d e f]) make a sextuple from the top six stack items.\");\n\tvm.def(\"7ple\", 7, 1, tupleN_<7>, \"(a b c d e f g --> [a b c d e f g]) make a septuple from the top seven stack items.\");\n\tvm.def(\"8ple\", 8, 1, tupleN_<8>, \"(a b c d e f g h --> [a b c d e f g h]) make an octuple from the top eight stack items.\");\n\t\n\tvm.defautomap(\"2ples\", \"kk\", tupleN_<2>, \"(a b --> [[a0 b0][a1 b1]..[aN bN]]) make a sequence of pairs from the sequences a and b.\");\n\tvm.defautomap(\"3ples\", \"kkk\", tupleN_<3>, \"(a b c --> [[a0 b0 c0][a1 b1 c1]..[aN bN cN]]) make a sequence of triples from the sequences a, b and c.\");\n\tvm.defautomap(\"4ples\", \"kkkk\", tupleN_<4>, \"(a b c d --> seq) make a sequence of quadruples from the sequences a, b, c and d.\");\n\tvm.defautomap(\"5ples\", \"kkkkk\", tupleN_<5>, \"(a b c d e --> seq) make a sequence of quintuples from the sequences a through e.\");\n\tvm.defautomap(\"6ples\", \"kkkkkk\", tupleN_<6>, \"(a b c d e f--> seq) make a sequence of sextuples from the sequences a through f.\");\n\tvm.defautomap(\"7ples\", \"kkkkkkk\", tupleN_<7>, \"(a b c d e f g--> seq) make a sequence of septuples from the sequences a through g.\");\n\tvm.defautomap(\"8ples\", \"kkkkkkkk\", tupleN_<8>, \"(a b c d e f g h --> seq) make a sequence of octuples from the sequences a through h.\");\n\n\tDEFNnoeach(\"un2\", 1, 2, untupleN_<2>, \"([a0 a1 .. aN-1] --> a0 a1) Push two items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un3\", 1, 3, untupleN_<3>, \"([a0 a1 .. aN-1] --> a0 a1 a2) Push three items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un4\", 1, 4, untupleN_<4>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3) Push four items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un5\", 1, 5, untupleN_<5>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3 a4) Push five items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un6\", 1, 6, untupleN_<6>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a5) Push six items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un7\", 1, 7, untupleN_<7>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a6) Push seven items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un8\", 1, 8, untupleN_<8>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a7) Push eight items from a sequence onto the stack.\")\n\n\tDEF(reverse, 1, 1, \"(a --> b) reverses a finite sequence.\")\n\tDEF(mirror0, 1, 1, \"(a --> b) cyclic mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2]\")\n\tDEF(mirror1, 1, 1, \"(a --> b) odd mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2 1]\")\n\tDEF(mirror2, 1, 1, \"(a --> b) even mirror of a sequence. [1 2 3 4] --> [1 2 3 4 4 3 2 1]\")\n\tDEFAM(rot, ak, \"(seq M --> seq') rotation of a sequence by M places. M > 0 moves right.\") \n\tDEFAM(shift, ak, \"(seq M --> seq') shift of a sequence by M places. zeroes are shifted in to fill vacated positions.\") \n\tDEFAM(clipShift, ak, \"(seq M --> seq') shift of a sequence by M places. the end value is copied in to fill vacated positions.\") \n\tDEFAM(foldShift, ak, \"(seq M --> seq') shift of a sequence by M places. values from the cyclic mirrored sequence are copied in to fill vacated positions.\") \n\tDEF(muss, 1, 1, \"(a --> b) puts a finite sequence into a random order.\")\n\n\tDEF(at, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return zero.\") \n\tDEF(wrapAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the value at the end point.\") \n\tDEF(foldAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the items from the cyclic sequence.\") \n\tDEF(clipAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return items from the cyclic mirrored sequence.\") \n\tDEF(degkey, 2, 1, \"(degree scale --> converts scale degree(s) to keys, given a scale\");\n\tDEF(keydeg, 2, 1, \"(key scale --> converts key(s) to scale degree(s), given a scale\");\n\n\t\n\tDEF(sort, 1, 1, \"(in --> out) ascending order sort of the input list.\");\n\tDEFAM(sortf, ak, \"(in fun --> out) sort of the input list using a compare function.\");\n\tDEFN(\"sort>\", 1, 1, sort_gt_, \"(in --> out) descending order sort of the input list.\");\n\t\n\tDEF(grade, 1, 1, \"(in --> out) ascending order sorted indices of the input list.\");\n\tDEFAM(gradef, ak, \"(in fun --> out) sorted indices of the input list using a compare function.\");\n\tDEFN(\"grade>\", 1, 1, grade_gt_, \"(in --> out) descending order sorted indices of the input list.\");\n\n\tvm.addBifHelp(\"\\n*** event list operations ***\");\n\tDEFAM(evmerge, aak, \"(a b t --> c) merges event list 'b' with delay 't' with event list 'a' according to their delta times\")\n\tDEFAM(evdelay, ak, \"(a t --> c) delay an event list by adding a preceeding rest of duration 't'\")\n\tDEFAM(evrest, aak, \"(t --> c) returns a rest event for duration 't'.\")\n\t\n\tvm.addBifHelp(\"\\n*** dsp operations ***\");\n\t\n\tDEFMCX(kaiser, 2, \"(n stopBandAttenuation --> out) returns a signal filled with a kaiser window with the given stop band attenuation.\")\n\tDEFMCX(hanning, 1, \"(n --> out) returns a signal filled with a Hanning window.\")\n\tDEFMCX(hamming, 1, \"(n --> out) returns a signal filled with a Hamming window.\")\n\tDEFMCX(blackman, 1, \"(n --> out) returns a signal filled with a Blackman window.\")\n\tDEFMCX(fft, 2, \"(re im --> out) returns the complex FFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\tDEFMCX(ifft, 2, \"(re im --> out) returns the complex IFFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\n\tDEFAM(seg, zaa, \"(in hops durs --> out) divide input signal in to a stream of signal segments of given duration stepping by hop time.\")\n\tDEFAM(wseg, zaz, \"(in hops window --> out) divide input signal in to a stream of windowed signal segments of lengths equal to the window length, stepping by hop time.\")\n\n\tvm.addBifHelp(\"\\n*** audio I/O operations ***\");\n\tDEF(play, 1, 0, \"(channels -->) plays the audio to the hardware.\")\n\tDEF(record, 2, 0, \"(channels filename -->) plays the audio to the hardware and records it to a file.\")\n\tDEFnoeach(stop, 0, 0, \"(-->) stops any audio playing.\")\n\tvm.def(\"sf>\", 1, 0, sfread_, \"(filename -->) read channels from an audio file. not real time.\");\n\tvm.def(\">sf\", 2, 0, sfwrite_, \"(channels filename -->) writes the audio to a file.\");\n\tvm.def(\">sfo\", 2, 0, sfwriteopen_, \"(channels filename -->) writes the audio to a file and opens it in the default application.\");\n\t//vm.def(\"sf>\", 2, sfread_);\n\tDEF(bench, 1, 0, \"(channels -->) prints the amount of CPU required to compute a segment of audio. audio must be of finite duration.\")\t\n\tvm.def(\"sgram\", 3, 0, sgram_, \"(signal dBfloor filename -->) writes a spectrogram to a file and opens it.\");\n\n\tsetSessionTime();\n\n}\n\n"], ["/sapf/src/Opcode.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Opcode.hpp\"\n#include \"clz.hpp\"\n\nconst char* opcode_name[kNumOpcodes] = \n{\n\t\"BAD OPCODE\",\n\t\"opNone\",\n\t\"opPushImmediate\",\n\t\"opPushLocalVar\",\n\t\"opPushFunVar\",\n\t\"opPushWorkspaceVar\",\n\t\n\t\"opPushFun\",\n\n\t\"opCallImmediate\",\n\t\"opCallLocalVar\",\n\t\"opCallFunVar\",\n\t\"opCallWorkspaceVar\",\n\n\t\"opDot\",\n\t\"opComma\",\n\t\"opBindLocal\",\n\t\"opBindLocalFromList\",\n\t\"opBindWorkspaceVar\",\n\t\"opBindWorkspaceVarFromList\",\n\t\n\t\"opParens\",\n\t\"opNewVList\",\n\t\"opNewZList\",\n\t\"opNewForm\",\n\t\"opInherit\",\n\t\"opEach\",\n\t\"opReturn\"\n};\n\n\nstatic void printOpcode(Thread& th, Opcode* c)\n{\n\tV& v = c->v;\n\tpost(\"%p %s \", c, opcode_name[c->op]);\n\tswitch (c->op) {\n\t\tcase opPushImmediate :\n\t\tcase opPushWorkspaceVar :\n\t\tcase opPushFun : \n\t\tcase opCallImmediate :\n\t\tcase opCallWorkspaceVar :\n\t\tcase opDot :\n\t\tcase opComma :\n\t\tcase opInherit :\n\t\tcase opNewForm :\n\t\tcase opBindWorkspaceVar :\n\t\tcase opBindWorkspaceVarFromList :\n\t\tcase opParens :\n\t\tcase opNewVList : \n\t\tcase opNewZList : \n\t\t\tv.printShort(th);\n\t\t\tbreak;\n\t\t\t\n\t\tcase opPushLocalVar :\n\t\tcase opPushFunVar :\n\t\tcase opCallLocalVar :\n\t\tcase opCallFunVar :\n\t\tcase opBindLocal :\n\t\tcase opBindLocalFromList :\n\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\tbreak;\n\t\tcase opEach :\n\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\tbreak;\n\t\t\n\t\tcase opNone :\n\t\tcase opReturn : \n\t\t\tbreak;\n\t\t\n\t\tdefault :\n\t\t\tpost(\"BAD OPCODE\\n\");\n\t}\n\tpost(\"\\n\");\n}\n\nvoid Thread::run(Opcode* opc)\n{\n\tThread& th = *this;\n\ttry {\n\t\tfor (;;++opc) {\n\n\t\t\tV& v = opc->v;\n\n\t\t\tif (vm.traceon) {\n\t\t\t\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n\t\t\t\tprintOpcode(th, opc);\n\t\t\t}\n\n\t\t\tswitch (opc->op) {\n\t\t\t\tcase opNone :\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushImmediate :\n\t\t\t\t\tpush(v);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushLocalVar :\n\t\t\t\t\tpush(getLocal(v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFunVar :\n\t\t\t\t\tpush(fun->mVars[v.i]);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushWorkspaceVar :\n\t\t\t\t\tpush(fun->Workspace()->mustGet(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFun : {\n\t\t\t\t\t\tpush(new Fun(th, (FunDef*)v.o()));\n\t\t\t\t\t} break;\n\t\t\t\t\t\n\t\t\t\tcase opCallImmediate :\n\t\t\t\t\tv.apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallLocalVar :\n\t\t\t\t\tgetLocal(v.i).apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallFunVar :\n\t\t\t\t\tfun->mVars[v.i].apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallWorkspaceVar :\n\t\t\t\t\tfun->Workspace()->mustGet(th, v).apply(th);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase opDot : {\n\t\t\t\t\tV ioValue;\n\t\t\t\t\tif (!pop().dot(th, v, ioValue))\n\t\t\t\t\t\tnotFound(v);\n\t\t\t\t\tpush(ioValue);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase opComma :\n\t\t\t\t\tpush(pop().comma(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opBindLocal :\n\t\t\t\t\tgetLocal(v.i) = pop();\n\t\t\t\t\tbreak;\n\t\t\t\tcase opBindWorkspaceVar : {\n V value = pop();\n if (value.isList() && !value.isFinite()) {\n post(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n } else if (value.isFun()) {\n\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n } break;\n \n\t\t\t\tcase opBindLocalFromList :\n\t\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\t\t{\n\t\t\t\t\tV list = pop();\n\t\t\t\t\tBothIn in(list);\n\t\t\t\t\twhile (1) {\n\t\t\t\t\t\tif (opc->op == opNone) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tV value;\n\t\t\t\t\t\t\tif (in.one(th, value)) {\n\t\t\t\t\t\t\t\tpost(\"not enough items in list for = [..]\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (opc->op == opBindLocalFromList) {\n\t\t\t\t\t\t\t\tgetLocal(opc->v.i) = value;\n\t\t\t\t\t\t\t} else if (opc->op == opBindWorkspaceVarFromList) {\n\t\t\t\t\t\t\t\tv = opc->v;\n\t\t\t\t\t\t\t\tif (value.isList() && !value.isFinite()) {\n\t\t\t\t\t\t\t\t\tpost(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n\t\t\t\t\t\t\t\t} else if (value.isFun()) {\n\t\t\t\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++opc;\n\t\t\t\t\t}\n\t\t\t\t} break;\n\t\t\t\tcase opParens : {\n\t\t\t\t\t\tParenStack ss(th);\n\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewVList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newVList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewZList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newZList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opInherit : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tif (depth < 1) {\n\t\t\t\t\t\t\t\tresult = vm._ee;\n\t\t\t\t\t\t\t} else if (depth > 1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvm.inherit->apply_n(th, 1);\n\t\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewForm : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tTableMap* tmap = (TableMap*)th.top().o();\n\t\t\t\t\t\t\tsize_t numArgs = tmap->mSize;\n\t\t\t\t\t\t\tif (depth == numArgs+1) {\n\t\t\t\t\t\t\t\t// no inheritance, must insert zero for parent.\n\t\t\t\t\t\t\t\tth.tuck(numArgs+1, V(0.));\n\t\t\t\t\t\t\t} else if (depth < numArgs+1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"fewer arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errStackUnderflow;\n\t\t\t\t\t\t\t} else if (depth > numArgs+2) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvm.newForm->apply_n(th, numArgs+2);\n\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opEach :\n\t\t\t\t\tpush(new EachOp(pop(), (int)v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\tcase opReturn : return;\n\t\t\t\t\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t\t\t\tthrow errInternalError;\n\t\t\t}\n\t\t}\n\t} catch (...) {\n\t\tpost(\"backtrace: %s \", opcode_name[opc->op]);\n\t\topc->v.printShort(th);\n\t\tpost(\"\\n\");\n\t\tthrow;\n\t}\n}\n\nCode::~Code() { }\n\nvoid Code::shrinkToFit()\n{\n\tstd::vector(ops.begin(), ops.end()).swap(ops);\n}\n\nvoid Code::add(int _op, Arg v)\n{\n\tops.push_back(Opcode(_op, v));\n}\n\nvoid Code::add(int _op, double f)\n{\n\tadd(_op, V(f));\n}\n\nvoid Code::addAll(const P &that)\n{\n\tfor (Opcode& op : that->ops) {\n\t\tops.push_back(op);\n\t}\n}\n\nvoid Code::decompile(Thread& th, std::string& out)\n{\n\tfor (Opcode& c : ops) {\n\t\tV& v = c.v;\n\t\tswitch (c.op) {\n\t\t\tcase opPushImmediate : {\n\t\t\t\tstd::string s;\n\t\t\t\tv.printShort(th, s);\n\t\t\t\tout += s;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase opPushWorkspaceVar :\n\t\t\tcase opPushFun : \n\t\t\tcase opCallImmediate :\n\t\t\tcase opCallWorkspaceVar :\n\t\t\tcase opDot :\n\t\t\tcase opComma :\n\t\t\tcase opInherit :\n\t\t\tcase opNewForm :\n\t\t\tcase opBindWorkspaceVar :\n\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\tcase opParens :\n\t\t\tcase opNewVList : \n\t\t\tcase opNewZList : \n\t\t\t\tv.printShort(th);\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\tcase opPushLocalVar :\n\t\t\tcase opPushFunVar :\n\t\t\tcase opCallLocalVar :\n\t\t\tcase opCallFunVar :\n\t\t\tcase opBindLocal :\n\t\t\tcase opBindLocalFromList :\n\t\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\tcase opEach :\n\t\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase opNone :\n\t\t\tcase opReturn : \n\t\t\t\tbreak;\n\t\t\t\n\t\t\tdefault :\n\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t}\n\t}\n}\n\n"], ["/sapf/src/UGen.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n\nstruct MulAdd : public ThreeInputUGen\n{\n\tMulAdd(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MulAdd\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = *a * *b + *c;\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_neg;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_minus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstatic void madd_(Thread& th, Prim* prim)\n{\n\tV c = th.popZIn(\"*+ : c\");\n\tV b = th.popZIn(\"*+ : b\");\n\tV a = th.popZIn(\"*+ : a\");\n\n\tif (a.isReal() && b.isReal() && c.isReal()) {\n\t\tth.push(a.f * b.f + c.f);\n\t} else {\n\t\tif (c.isReal()) {\n\t\t\tif (c.f == 0.) {\n\t\t\t\tif (a.isReal() && a.f == 1.) { th.push(b); return; }\n\t\t\t\tif (b.isReal() && b.f == 1.) { th.push(a); return; }\n\t\t\t\tif (a.isReal() && a.f == -1.) { th.push(b.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tif (b.isReal() && b.f == -1.) { th.push(a.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tth.push(a.binaryOp(th, gBinaryOpPtr_mul, b)); return;\n\t\t\t}\n\t\t}\n\t\tif (a.isReal()) {\n\t\t\tif (a.f == 0.) { th.push(c); return; }\n\t\t\tif (a.f == 1.) { th.push(b.binaryOp(th, gBinaryOpPtr_plus, c)); return; }\n\t\t\tif (a.f == -1.) { th.push(b.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tif (b.isReal()) {\n\t\t\tif (b.f == 0.) { th.push(c); return; } \n\t\t\tif (b.f == 1.) { th.push(a.binaryOp(th, gBinaryOpPtr_plus, c)); return; } \n\t\t\tif (b.f == -1.) { th.push(a.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tth.push(new List(new MulAdd(th, a, b, c)));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Fadeout : Gen\n{\n\tZIn _a;\n\tint64_t _sustainTime;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadeout(Thread& th, Arg a, Z sustainTime, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_sustainTime = (int64_t)floor(th.rate.sampleRate * sustainTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_sustainTime = std::max(1LL, _sustainTime);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadeout\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_sustainTime <= 0) {\n\t\t\tif (_fadeTime <= 0) {\n\t\t\t\tend();\n\t\t\t} else {\n\t\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t\t_fadeTime -= framesToFill;\n\t\t\t\twhile (framesToFill) {\n\t\t\t\t\tint n = framesToFill;\n\t\t\t\t\tint astride;\n\t\t\t\t\tZ *a;\n\t\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\t setDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t_amp = amp;\n\t\t\t\t\t\t_a.advance(n);\n\t\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\t\tout += n;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t produce(framesToFill);\n\t\t\t}\n\t\t} else {\n int framesToFill = (int)std::min(_sustainTime, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _sustainTime -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\n\nstruct Fadein : Gen\n{\n\tZIn _a;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadein(Thread& th, Arg a, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = .001;\n\t\t_fade = pow(1000., 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadein\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_fadeTime <= 0) {\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t} else {\n\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t_fadeTime -= framesToFill;\n\t\t\twhile (framesToFill) {\n\t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t setDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t}\n\t\t\t}\n\t\t produce(framesToFill);\n\t\t}\n\t}\n};\n\nstatic void fadeout_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadeout : fadeTime\");\n\tZ sustain = th.popFloat(\"fadeout : sustainTime\");\n\tV in = th.popZIn(\"fadeout : in\");\n\n\tth.push(new List(new Fadeout(th, in, sustain, fade)));\n}\n\nstatic void fadein_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadein : fadeTime\");\n\tV in = th.popZIn(\"fadein : in\");\n\n\tth.push(new List(new Fadein(th, in, fade)));\n}\n\nstruct Endfade : Gen\n{\n\tZIn _a;\n\tint64_t _startupTime;\n\tint64_t _holdTime;\n\tint64_t _holdTimeRemaining;\n\tint64_t _fadeTime;\n\tZ _amp, _fade, _threshold;\n\t\n\tEndfade(Thread& th, Arg a, Z startupTime, Z holdTime, Z fadeTime, Z threshold) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_startupTime = (int64_t)floor(th.rate.sampleRate * startupTime + .5);\n\t\t_holdTime = (int64_t)floor(th.rate.sampleRate * holdTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_startupTime = std::max(0LL, _startupTime);\n\t\t_holdTime = std::max(1LL, _holdTime);\n\t\t_holdTimeRemaining = _holdTime;\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_threshold = threshold;\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Endfade\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (_startupTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _startupTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_startupTime -= n;\n\t\t\t\t}\n\t\t\t} else if (_holdTimeRemaining > 0) {\n \t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint framesFilled = 0;\n\t\t\t\t\tfor (int i = 0; i < n && _holdTimeRemaining > 0; ++i) {\n\t\t\t\t\t\tZ z = *a;\n\t\t\t\t\t\tif (std::abs(z) >= _threshold) {\n\t\t\t\t\t\t\t_holdTimeRemaining = _holdTime;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t--_holdTimeRemaining;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t++framesFilled;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(framesFilled);\n\t\t\t\t\tframesToFill -= framesFilled;\n\t\t\t\t\tout += framesFilled;\n\t\t\t\t}\n\t\t\t} else if (_fadeTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _fadeTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_fadeTime -= n;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void endfade_(Thread& th, Prim* prim)\n{\n\tZ threshold = th.popFloat(\"endfade : threshold\");\n\tZ fade = th.popFloat(\"endfade : fadeTime\");\n\tZ hold = th.popFloat(\"endfade : holdTime\");\n\tZ startup = th.popFloat(\"endfade : startupTime\");\n\tV in = th.popZIn(\"endfade : in\");\n\n\tth.push(new List(new Endfade(th, in, startup, hold, fade, threshold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Imps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, invdur_;\n\tZ freqmul_;\n\tbool once;\n\n\tImps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate), once(false)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Imps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tonce = true;\n\t\t\t\t}\n\n\t\t\t\tif (once) {\n\t\t\t\t\tout[i] = val_;\n\t\t\t\t\tonce = false;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\t\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Steps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\n\tSteps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Steps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Gates : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn hold_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, hdur_;\n\tZ freqmul_;\n\n\tGates(Thread& th, Arg durs, Arg vals, Arg hold, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, hold)), durs_(durs), vals_(vals), hold_(hold), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Gates\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_) || hold_.onez(th, hdur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = phase_ < hdur_ ? val_ : 0.;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Lines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, slope_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Lines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tslope_ = (newval_ - oldval_) / dur_;\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_ + slope_ * phase_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct XLines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, ratio_, step_;\n\tZ phase_, dur_, invdur_, freq_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tXLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"XLines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t\t//oldval_ = oldval_ * pow(ratio_, phase_ * invdur_);\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = pow(ratio_, freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\toldval_ *= step_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_ * pow(ratio_, phase_ * invdur_);\n\n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\trate += rateStride;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Curves : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn curves_;\n\tZIn rate_;\n\tZ oldval_, newval_, step_;\n\tZ phase_, dur_, curve_, invdur_, freq_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tCurves(Thread& th, Arg durs, Arg vals, Arg curves, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, curves)), durs_(durs), vals_(vals), curves_(curves), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Curves\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tdur_ = std::max(dur_, 1e-4);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n //!! not correct\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n \n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n \n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Cubics : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tCubics(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Cubics\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tc0 = y1;\n\t\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n/*\nd = duration of accelerando in beats\na = duration of accelerando in seconds\n\nr0 = starting tempo in beats per second\nr1 = ending tempo in beats per second\n\nc = (r1 - r0) / d\n\nduration of accelerando in seconds\na = log(r1/r0) / c\n\ntempo for next sample\nr(0) = r0\nr(n) = r(n-1) * exp(c / sr)\n\nbeat for next sample\nb(n) = r(n)/c - r0/c\n\nb(0) = 0\nb(n) = b(n-1) + r(n)/sr \n\n*/\n\n\nstruct Tempo : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ beat_ = 0.;\n\tZ dur_ = 0.;\n\tZ lastTime_ = 0.;\n\tZ nextTime_ = 0.;\n\tZ invsr_;\n\tZ c_, r0_, r1_;\n\tbool once = true;\n\n\tTempo(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Tempo\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t// numerically it would be better to subtract off dur each time, but we need to recreate the same loss of precision over time\n\t\t\t\t// as will be experienced from an integration of tempo occuring outside of this generator. otherwise there would be a drift\n\t\t\t\t// between when tempo changes occur and the beat time as integrated from the tempo.\n\t\t\t\twhile (beat_ >= nextTime_) {\n\t\t\t\t\tdo {\n\t\t\t\t\t\tr0_ = r1_;\n\t\t\t\t\t\tif (vals_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tc_ = (r1_ - r0_) / dur_;\n\t\t\t\t\tlastTime_ = nextTime_;\n\t\t\t\t\tnextTime_ += dur_;\n\t\t\t\t}\n\n\t\t\t\tZ tempo = *rate * (r0_ + (beat_ - lastTime_) * c_);\n\t\t\t\tout[i] = tempo;\n\t\t\t\tbeat_ += tempo * invsr_;\n\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Beats : public Gen\n{\n\tZIn tempo_;\n\tZ beat_ = 0.;\n\tZ invsr_;\n\n\tBeats(Thread& th, Arg tempo) : Gen(th, itemTypeZ, tempo.isFinite()), tempo_(tempo),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Beats\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ beat = beat_;\n\t\twhile (framesToFill) {\n\t\t\tZ* tempo;\n\t\t\tint n = framesToFill;\n\t\t\tint tempoStride;\n\t\t\tif (tempo_(th, n, tempoStride, tempo)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tZ invsr = invsr_;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = beat;\n\t\t\t\tbeat += *tempo * invsr;\n\t\t\t\ttempo += tempoStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttempo_.advance(n);\n\t\t}\n\t\tbeat_ = beat;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct ADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn rate_;\n\tint stage_ = 0;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ noteOff_;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tZ beat_ = 0.;\n\tbool once = true;\n\tint sustainStage_;\n\n\tADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg rate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\trate_(rate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\t\tnoteOff_ = durs_[sustainStage_];\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"ADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (1) {\n\t\t\t\t\tif (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else if (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ < NumStages){\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tbeat_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct GatedADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn gate_;\n\tint stage_ = NumStages;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\tint sustainStage_;\n\n\tGatedADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg gate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\tgate_(gate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"GatedADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* gate;\n\t\t\tint n = framesToFill;\n\t\t\tint gateStride;\n\t\t\tif (gate_(th, n, gateStride, gate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n Z g = *gate;\n gate += gateStride;\n if (stage_ >= NumStages) {\n // waiting for trigger\n if (*gate > 0.) {\n stage_ = 0;\n } else {\n out[i] = 0.;\n --framesToFill;\n continue;\n }\n }\n\t\t\t\twhile (1) { \n if (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else if (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tgate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void imps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"imps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Imps(th, durs, vals, rate)));\n}\n\nstatic void steps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"steps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Steps(th, durs, vals, rate)));\n}\n\nstatic void gates_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"gates : rate\");\n\tV hold = th.pop();\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Gates(th, durs, vals, hold, rate)));\n}\n\nstatic void lines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Lines(th, durs, vals, rate)));\n}\n\nstatic void xlines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"xlines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new XLines(th, durs, vals, rate)));\n}\n\nstatic void cubics_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"cubics : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Cubics(th, vals, rate)));\n}\n\nstatic void curves_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"curves : rate\");\n\tV durs = th.pop();\n\tV param = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Curves(th, durs, vals, param, rate)));\n}\n\nstatic void tempo_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"tempo : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Tempo(th, vals, rate)));\n}\n\nstatic void beats_(Thread& th, Prim* prim)\n{\n\tV tempo = th.popZIn(\"beats : tempo\");\n\n\tth.push(new List(new Beats(th, tempo)));\n}\n\nstatic void adsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"adsr : tempo\");\n\tZ noteDur = th.popFloat(\"adsr : noteDur\");\n\tZ amp = th.popFloat(\"adsr : amp\");\n\n\tP list = th.popList(\"adsr : [attack decay sustain release]\");\n\tconst int kNumADSRStages = 4;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"adsr : [attack decay sustain release] list should have 4 elements.\");\n\t}\n\t\t\n\tZ relTime = env[3];\n\tZ susLvl = env[2];\n\tZ dcyTime = env[1];\n\tZ atkTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 2)));\n}\n\nstatic void dadsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dadsr : tempo\");\n\tZ noteDur = th.popFloat(\"dadsr : noteDur\");\n\tZ amp = th.popFloat(\"dadsr : amp\");\n\n\tP list = th.popList(\"dadsr : [delay attack decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 5;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack decay sustain release] list should have 5 elements.\");\n\t}\n\t\n\tZ relTime = env[4];\n\tZ susLvl = env[3];\n\tZ dcyTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 3)));\n}\n\nstatic void dahdsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dahdsr : tempo\");\n\tZ noteDur = th.popFloat(\"dahdsr : noteDur\");\n\tZ amp = th.popFloat(\"dahdsr : amp\");\n\n\tP list = th.popList(\"dahdsr : [delay attack hold decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 6;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack hold decay sustain release] list should have 6 elements.\");\n\t}\n\t\n\tZ relTime = env[5];\n\tZ susLvl = env[4];\n\tZ dcyTime = env[3];\n\tZ hldTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, hldTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., 0., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 4)));\n}\n\n\n\n\nstruct K2A : public Gen\n{\n\tint n_;\n\tint remain_;\n\tZ slopeFactor_;\n\tBothIn vals_;\n\tZ oldval_, newval_, slope_;\n\tbool once = true;\n\n\tK2A(Thread& th, int n, Arg vals) : Gen(th, itemTypeZ, vals.isFinite()), vals_(vals),\n\t\tn_(n), remain_(0), slopeFactor_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2A\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, oldval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tif (vals_.onez(th, newval_) ) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tslope_ = slopeFactor_ * (newval_ - oldval_);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = oldval_;\n\t\t\t\toldval_ += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct K2AC : public Gen\n{\n\tBothIn vals_;\n\tint n_;\n\tint remain_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ slope_;\n\tbool once = true;\n\n\tK2AC(Thread& th, int n, Arg vals)\n\t\t: Gen(th, itemTypeZ, vals.isFinite()), vals_(vals), n_(n), remain_(0),\n\t\tphase_(0), slope_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2AC\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tx = 0.;\n\t\t\t\ty0 = y1;\n\t\t\t\ty1 = y2;\n\t\t\t\ty2 = y3;\n\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tc0 = y1;\n\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\t\t\t\tx += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void k2a_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV a = th.popZIn(\"kr : signal\");\n\t\n\tth.push(new List(new K2A(th, n, a)));\n}\n\nstatic void k2ac_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"krc : n\");\n\tV a = th.popZIn(\"krc : signal\");\n\t\n\tth.push(new List(new K2AC(th, n, a)));\n}\n\nP gK2A;\nP gK2AC;\n\nstatic void kr_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"kr : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2A->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\nstatic void krc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"krc : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, (int)n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2AC->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFNoise0 : public Gen\n{\n\tZIn rate_;\n\tZ val_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise0(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise0\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\tval_ = r.drand2();\n\t\t\t\t}\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise1 : public Gen\n{\n\tZIn rate_;\n\tZ oldval_, newval_;\n\tZ slope_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise1(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\tnewval_ = oldval_ = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise1\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\tnewval_ = r.drand2();\n\t\t\t\t\tslope_ = newval_ - oldval_;\n\t\t\t\t}\n\t\t\t\tout[i] = oldval_ + slope_ * x;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise3 : public Gen\n{\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise3(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\ty1 = r.drand2();\n\t\ty2 = r.drand2();\n\t\ty3 = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise3\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\ty3 = r.drand2() * 0.8; // 0.8 because cubic interpolation can overshoot up to 1.25 if inputs are -1,1,1,-1.\n\t\t\t\t\tc0 = y1;\n\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void lfnoise0_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise0 : freq\");\n\n\tth.push(new List(new LFNoise0(th, rate)));\n}\n\nstatic void lfnoise1_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise1 : freq\");\n\n\tth.push(new List(new LFNoise1(th, rate)));\n}\n\nstatic void lfnoise3_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise3 : freq\");\n\n\tth.push(new List(new LFNoise3(th, rate)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\ntemplate \nstruct SymmetricEnv : public Gen\n{\n\tZ xinc;\n\tZ x;\n\tint64_t n_;\n\t\n\tSymmetricEnv(Thread& th, Z dur, Z scale) : Gen(th, itemTypeZ, true), x(-scale)\n\t{\n\t\tZ n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\tn_ = (int64_t)n;\n\t\txinc = 2. * scale / n;\n\t}\n\t\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tZ* out = mOut->fulfillz(n);\n\t\tstatic_cast(this)->F::calc(n, out);\n\t\tmOut = mOut->nextp();\n\t\tn_ -= n;\n\t\tif (n_ == 0) {\n\t\t\tend();\n\t\t}\n\t}\n};\n\ntemplate \nstruct TriggeredSymmetricEnv : public Gen\n{\n\tZIn trig_;\n\tBothIn dur_;\n\tBothIn amp_;\n\tZ xinc;\n\tZ x;\n\tZ scale_;\n\tZ ampval_;\n\tint64_t n_ = 0;\n\t\n\tTriggeredSymmetricEnv(Thread& th, Arg trig, Arg dur, Arg amp, Z scale)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), dur_(dur), amp_(amp), scale_(scale)\n\t{\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (n_) {\n\t\t\t\tn = (int)std::min((int64_t)n, n_);\n\t\t\t\tstatic_cast(this)->F::calc(n, ampval_, out);\n\t\t\t\tn_ -= n;\n\t\t\t\ttrig += n * trigStride;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tZ dur;\n\t\t\t\t\t\tif (dur_.onez(th, dur)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tx = -scale_;\n\t\t\t\t\t\tZ zn = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\t\t\t\t\tn_ = (int64_t)zn;\n\t\t\t\t\t\txinc = 2. * scale_ / zn;\n\t\t\t\t\t\tint n2 = (int)std::min((int64_t)(n-i), n_);\n\t\t\t\t\t\tstatic_cast(this)->F::calc(n2, ampval_, out+i);\n\t\t\t\t\t\tn_ -= n2;\n\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\ti += n2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct TriggeredSignal : public Gen\n{\n\tZIn trig_;\n\tZIn list_;\n\tBothIn amp_;\n\tV in_;\n\tZ ampval_;\n\tbool waiting_ = true;\n\tZ counter_ = 0.;\n\t\n\tTriggeredSignal(Thread& th, Arg trig, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), amp_(amp), in_(in)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"TriggeredSignal\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!waiting_) {\n\t\t\t\tZ* list;\n\t\t\t\tint listStride;\n\t\t\t\tif (list_(th, n, listStride, list)) {\n\t\t\t\t\twaiting_ = true;\n\t\t\t\t\tgoto waiting;\n\t\t\t\t}\n\t\t\t\tZ amp = ampval_;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = amp * *list;\n\t\t\t\t\tlist += listStride;\n\t\t\t\t}\n\t\t\t\tlist_.advance(n);\n\t\t\t} else {\n\t\twaiting:\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tV in = in_;\n\t\t\t\t\t\tif (in.isFunOrPrim()) {\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tth.push(counter_);\n\t\t\t\t\t\t\t\tin.apply(th);\n\t\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tin = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcounter_ += 1.;\n\t\t\t\t\t\tlist_.set(in);\n\t\t\t\t\t\tZ* list;\n\t\t\t\t\t\tint listStride;\n\t\t\t\t\t\tint n2 = n-i;\n\t\t\t\t\t\tif (list_(th, n2, listStride, list)) {\n\t\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tZ amp = ampval_;\n\t\t\t\t\t\t\tfor (int j = i; j < i+n2; ++j) {\n\t\t\t\t\t\t\t\tout[j] = amp * *list;\n\t\t\t\t\t\t\t\tlist += listStride;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\t\ti += n2;\n\t\t\t\t\t\t\tlist_.advance(n2);\n\t\t\t\t\t\t\twaiting_ = i < n;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tsig_(Thread& th, Prim* prim)\n{\n\tV amp = th.pop();\n\tV in = th.pop();\n\tV trig = th.popZIn(\"tsig : trig\");\n\n\tth.push(new List(new TriggeredSignal(th, trig, in, amp)));\n}\n\nstruct ParEnv : public SymmetricEnv\n{\n\tParEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"ParEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void parenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"parenv : dur\");\n\n\tth.push(new List(new ParEnv(th, dur)));\n}\n\nstruct TParEnv : public TriggeredSymmetricEnv\n{\n\tTParEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TParEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tparenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tparenv : amp\");\n\tV dur = th.popZIn(\"tparenv : dur\");\n\tV trig = th.popZIn(\"tparenv : trig\");\n\n\tth.push(new List(new TParEnv(th, trig, dur, amp)));\n}\n\nstruct QuadEnv : public SymmetricEnv\n{\n\tQuadEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"QuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2*x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void quadenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"quadenv : dur\");\n\n\tth.push(new List(new QuadEnv(th, dur)));\n}\n\nstruct TQuadEnv : public TriggeredSymmetricEnv\n{\n\tTQuadEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TQuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2*x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tquadenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tquadenv : amp\");\n\tV dur = th.popZIn(\"tquadenv : dur\");\n\tV trig = th.popZIn(\"tquadenv : trig\");\n\n\tth.push(new List(new TQuadEnv(th, trig, dur, amp)));\n}\n\n\nstruct OctEnv : public SymmetricEnv\n{\n\tOctEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"OctEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\t\n\t\t\tout[i] = 1. - x4*x4;\n\t\t\t\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void octenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"octenv : dur\");\n\n\tth.push(new List(new OctEnv(th, dur)));\n}\n\nstruct TOctEnv : public TriggeredSymmetricEnv\n{\n\tTOctEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TOctEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\tout[i] = amp * (1. - x4*x4);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void toctenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toctenv : amp\");\n\tV dur = th.popZIn(\"toctenv : dur\");\n\tV trig = th.popZIn(\"toctenv : trig\");\n\n\tth.push(new List(new TOctEnv(th, trig, dur, amp)));\n}\n\nstruct TriEnv : public SymmetricEnv\n{\n\tTriEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TriEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. - fabs(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trienv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trienv : dur\");\n\n\tth.push(new List(new TriEnv(th, dur)));\n}\n\nstruct TTriEnv : public TriggeredSymmetricEnv\n{\n\tTTriEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTriEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * (1. - fabs(x));\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrienv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrienv : amp\");\n\tV dur = th.popZIn(\"ttrienv : dur\");\n\tV trig = th.popZIn(\"ttrienv : trig\");\n\n\tth.push(new List(new TTriEnv(th, trig, dur, amp)));\n}\n\nstruct Tri2Env : public SymmetricEnv\n{\n\tTri2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Tri2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tri2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"tri2env : dur\");\n\n\tth.push(new List(new Tri2Env(th, dur)));\n}\n\nstruct TTri2Env : public TriggeredSymmetricEnv\n{\n\tTTri2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTri2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttri2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttri2env : amp\");\n\tV dur = th.popZIn(\"ttri2env : dur\");\n\tV trig = th.popZIn(\"ttri2env : trig\");\n\n\tth.push(new List(new TTri2Env(th, trig, dur, amp)));\n}\n\n\nstruct TrapezEnv : public SymmetricEnv\n{\n\tTrapezEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapezenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapezenv : dur\");\n\n\tth.push(new List(new TrapezEnv(th, dur)));\n}\n\n\nstruct TTrapezEnv : public TriggeredSymmetricEnv\n{\n\tTTrapezEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapezenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapezenv : amp\");\n\tV dur = th.popZIn(\"ttrapezenv : dur\");\n\tV trig = th.popZIn(\"ttrapezenv : trig\");\n\n\tth.push(new List(new TTrapezEnv(th, trig, dur, amp)));\n}\n\n\nstruct Trapez2Env : public SymmetricEnv\n{\n\tTrapez2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Trapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapez2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapez2env : dur\");\n\n\tth.push(new List(new Trapez2Env(th, dur)));\n}\n\nstruct TTrapez2Env : public TriggeredSymmetricEnv\n{\n\tTTrapez2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapez2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapez2env : amp\");\n\tV dur = th.popZIn(\"ttrapez2env : dur\");\n\tV trig = th.popZIn(\"ttrapez2env : trig\");\n\n\tth.push(new List(new TTrapez2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct CosEnv : public SymmetricEnv\n{\n\tCosEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"CosEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void cosenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"cosenv : dur\");\n\n\tth.push(new List(new CosEnv(th, dur)));\n}\n\n\nstruct TCosEnv : public TriggeredSymmetricEnv\n{\n\tTCosEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TCosEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tcosenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tcosenv : amp\");\n\tV dur = th.popZIn(\"tcosenv : dur\");\n\tV trig = th.popZIn(\"tcosenv : trig\");\n\n\tth.push(new List(new TCosEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct HanEnv : public SymmetricEnv\n{\n\tHanEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"HanEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void hanenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"hanenv : dur\");\n\n\tth.push(new List(new HanEnv(th, dur)));\n}\n\n\nstruct THanEnv : public TriggeredSymmetricEnv\n{\n\tTHanEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THanEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void thanenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"thanenv : amp\");\n\tV dur = th.popZIn(\"thanenv : dur\");\n\tV trig = th.popZIn(\"thanenv : trig\");\n\n\tth.push(new List(new THanEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct Han2Env : public SymmetricEnv\n{\n\tHan2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Han2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void han2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"han2env : dur\");\n\n\tth.push(new List(new Han2Env(th, dur)));\n}\n\n\nstruct THan2Env : public TriggeredSymmetricEnv\n{\n\tTHan2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THan2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = amp * y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void than2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"than2env : amp\");\n\tV dur = th.popZIn(\"than2env : dur\");\n\tV trig = th.popZIn(\"than2env : trig\");\n\n\tth.push(new List(new THan2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct GaussEnv : public SymmetricEnv\n{\n\tZ widthFactor;\n\tGaussEnv(Thread& th, Z dur, Z width) : SymmetricEnv(th, dur, 1.), widthFactor(-1. / (2. * width * width)) {}\n\t\n\tvirtual const char* TypeName() const override { return \"GaussEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = exp(x * x * widthFactor);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void gaussenv_(Thread& th, Prim* prim)\n{\n\tZ width = th.popFloat(\"gaussenv : width\");\n\tZ dur = th.popFloat(\"gaussenv : dur\");\n\n\tth.push(new List(new GaussEnv(th, dur, width)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Pause : public Gen\n{\n\tZIn _in;\n\tZIn _amp;\n\t\n\tPause(Thread& th, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, amp.isFinite()), _in(in), _amp(amp)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pause\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *amp;\n\t\t\tint n, ampStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_amp(th, n, ampStride, amp) ) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint framesThisTime = n;\n\t\t\twhile (framesThisTime) {\n\t\t\t\tint zerolen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp <= 0.; ++i) {\n\t\t\t\t\t*out++ = 0.;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t++zerolen;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= zerolen;\n\t\t\t\t\n\t\t\t\tint seglen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp > 0.; ++i) {\n\t\t\t\t\t++seglen;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tamp -= seglen * ampStride;\n\n\t\t\t\tint seglenRemain = seglen;\n\t\t\t\twhile (seglenRemain) {\n\t\t\t\t\tZ *in;\n\t\t\t\t\tint n2, inStride;\n\t\t\t\t\tn2 = seglenRemain;\n\t\t\t\t\tif (_in(th, n2, inStride, in) ) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0; i < n2; ++i) {\n\t\t\t\t\t\tout[i] = *amp * *in;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t}\n\t\t\t\t\tout += n2;\n\t\t\t\t\t_in.advance(n2);\n\t\t\t\t\tseglenRemain -= n2;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= seglen;\n\t\t\t\t\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\t_amp.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pause_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"pause : amp\");\n\tV in = th.popZIn(\"pause : in\");\n\n\tth.push(new List(new Pause(th, in, amp)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nP s_tempo;\nP s_dt;\nP s_out;\n\nclass OverlapAddInputSource;\nclass OverlapAddOutputChannel;\n\nclass OverlapAddBase : public Object\n{\nprotected:\n\tOverlapAddOutputChannel* mOutputs = nullptr;\n\tP mActiveSources;\n\tbool mFinished = false;\n\tbool mNoMoreSources = false;\n\tint mNumChannels;\npublic:\n OverlapAddBase(int numChannels);\n virtual ~OverlapAddBase();\n\n\tvirtual const char* TypeName() const override { return \"OverlapAddBase\"; }\n\n\tvirtual bool pull(Thread& th);\n\tvirtual void addNewSources(Thread& th, int blockSize) = 0;\n\n\tP createOutputs(Thread& th);\n void fulfillOutputs(int blockSize);\n void produceOutputs(int shrinkBy);\n int renderActiveSources(Thread& th, int blockSize, bool& anyDone);\n void removeInactiveSources();\n};\n\nclass OverlapAdd : public OverlapAddBase\n{\nprotected:\n\tVIn mSounds;\n\tBothIn mHops;\n\tZIn mRate;\n\tZ mBeatTime;\n\tZ mNextEventBeatTime;\n\tZ mEventCounter;\n\tZ mRateMul;\n\tint64_t mSampleTime;\n\tint64_t mPrevChaseTime;\n\t\n\tP mChasedSignals;\n\npublic:\n\tOverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels);\n\tvirtual ~OverlapAdd() {}\n\t\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n\t\t\n\tvirtual void addNewSources(Thread& th, int blockSize) override;\n\tvoid chaseToTime(Thread& th, int64_t inSampleTime);\n};\n\nclass OverlapAddInputSource : public Object\n{\npublic:\n\tP mNextSource;\n\tstd::vector mInputs;\n\tint mOffset;\n\tbool mSourceDone;\n\t\n\tOverlapAddInputSource(Thread& th, List* channels, int inOffset, P const& inNextSource) \n\t\t: mNextSource(inNextSource), mOffset(inOffset), mSourceDone(false)\n\t{\n\t\tif (channels->isVList()) {\n\t\t\tP packedChannels = channels->pack(th);\n\t\t\tArray* a = packedChannels->mArray();\n\t\t\t\n\t\t\t// put channels into mInputs\n\t\t\tmInputs.reserve(a->size());\n\t\t\tfor (int i = 0; i < a->size(); ++i) {\n\t\t\t\tZIn zin(a->v()[i]);\n\t\t\t\tmInputs.push_back(zin);\n\t\t\t}\n\t\t} else {\n\t\t\tZIn zin(channels);\n\t\t\tmInputs.push_back(zin);\n\t\t}\n\t}\n\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n};\n\nclass OverlapAddOutputChannel : public Gen\n{\n\tfriend class OverlapAddBase;\n\tP mOverlapAddBase;\n\tOverlapAddOutputChannel* mNextOutput;\n\t\npublic:\t\n\tOverlapAddOutputChannel(Thread& th, OverlapAddBase* inOverlapAdd)\n : Gen(th, itemTypeZ, false), mOverlapAddBase(inOverlapAdd), mNextOutput(nullptr)\n\t{\n\t}\n\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmOverlapAddBase = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"OverlapAddOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mOverlapAddBase->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nOverlapAddBase::OverlapAddBase(int numChannels)\n\t: mNumChannels(numChannels)\n{\n}\n\nOverlapAddBase::~OverlapAddBase()\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tOverlapAddOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nOverlapAdd::OverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels)\n\t: OverlapAddBase(numChannels),\n mSounds(sounds), mHops(hops), mRate(rate),\n\tmBeatTime(0.), mNextEventBeatTime(0.), mEventCounter(0.), mRateMul(th.rate.invSampleRate),\n\tmSampleTime(0), mPrevChaseTime(0),\n\tmChasedSignals(chasedSignals)\n{\n}\n\nP OverlapAddBase::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n OverlapAddOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n OverlapAddOutputChannel* c = new OverlapAddOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nvoid OverlapAdd::addNewSources(Thread& th, int blockSize)\n{\t\t\t\n\t// integrate tempo and add new sources.\n\tZ* rate;\n\tint rateStride;\n\tif (mRate(th, blockSize, rateStride, rate)) {\n\t\tmNoMoreSources = true;\n\t} else if (!mNoMoreSources) {\n\t\tZ beatTime = mBeatTime;\n\t\tZ nextEventBeatTime = mNextEventBeatTime;\n\t\tZ ratemul = mRateMul;\n\t\tfor (int i = 0; i < blockSize; ++i) {\n\t\t\twhile (beatTime >= nextEventBeatTime) {\n\t\t\t\n\t\t\t\tchaseToTime(th, mSampleTime + i);\n\t\t\t\n\t\t\t\tV newSource;\n\t\t\t\tif (mSounds.one(th, newSource)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\tif (newSource.isFun()) {\n\t\t\t\t\tSaveStack ss(th);\t\n\t\t\t\t\tth.push(mEventCounter);\n\t\t\t\t\tnewSource.apply(th);\n\t\t\t\t\tnewSource = th.pop();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tV out;\n\t\t\t\tZ deltaTime;\n\t\t\t\tif (mHops.onez(th, deltaTime)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (newSource.isForm()) {\n\t\t\t\t\tif (mChasedSignals()) {\n\t\t\t\t\t\tV parents[2];\n\t\t\t\t\t\tparents[0] = mChasedSignals;\n\t\t\t\t\t\tparents[1] = newSource;\n\t\t\t\t\t\tnewSource = linearizeInheritance(th, 2, parents);\n\t\t\t\t\t}\n\t\t\t\t\tnewSource.dot(th, s_out, out);\n\t\t\t\t\tV hop;\n\t\t\t\t\tif (newSource.dot(th, s_dt, hop) && hop.isReal()) {\n\t\t\t\t\t\tdeltaTime = hop.f;\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\t\t\t\t\tout = newSource;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// must be a finite array with fewer than mNumChannels\n\t\t\t\tif (out.isZList() || (out.isVList() && out.isFinite())) {\n\t\t\t\t\tList* s = (List*)out.o();\n\t\t\t\t\t// create an active source:\n\t\t\t\t\tP source = new OverlapAddInputSource(th, s, i, mActiveSources);\n\t\t\t\t\tmActiveSources = source;\n\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\tnextEventBeatTime += deltaTime;\n\t\t\t\tmEventCounter += 1.;\n\t\t\t}\n\t\t\tbeatTime += *rate * ratemul;\n\t\t\trate += rateStride;\n\t\t}\n\t\tmBeatTime = beatTime;\n\t\tmNextEventBeatTime = nextEventBeatTime;\n\t\tmSampleTime += blockSize;\n\t\t\n\t\tmRate.advance(blockSize);\n\n\t\tchaseToTime(th, mSampleTime);\n\t}\n}\n\nvoid OverlapAddBase::fulfillOutputs(int blockSize)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut) {\n\t\t\tZ* out = output->mOut->fulfillz(blockSize);\n\t\t\tmemset(out, 0, output->mBlockSize * sizeof(Z));\n\t\t}\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nint OverlapAddBase::renderActiveSources(Thread& th, int blockSize, bool& anyDone)\n{\n\tint maxProduced = 0;\n\tOverlapAddInputSource* source = mActiveSources();\n\twhile (source) {\n\t\tint offset = source->mOffset;\n\t\tint pullSize = blockSize - offset;\n\t\tstd::vector& sourceChannels = source->mInputs;\n\t\tbool allOutputsDone = true; // initial value for reduction on &&\n\t\tOverlapAddOutputChannel* output = mOutputs;\n\t\tfor (size_t j = 0; j < sourceChannels.size() && output; ++j, output = output->mNextOutput) {\n\t\t\tif (output->mOut) {\n\t\t\t\tZIn& zin = sourceChannels[j];\n\t\t\t\tif (zin.mIsConstant && zin.mConstant.f == 0.)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tint n = pullSize;\n\t\t\t\tZ* out = output->mOut->mArray->z() + offset;\n\t\t\t\tif (!zin.mix(th, n, out)) {\n\t\t\t\t\tallOutputsDone = false;\n\t\t\t\t}\n\t\t\t\tmaxProduced = std::max(maxProduced, n);\n\t\t\t}\n\t\t}\n\t\tsource->mOffset = 0;\n\t\tif (allOutputsDone) {\n\t\t\t// mark for removal from mActiveSources\n\t\t\tsource->mSourceDone = true;\n anyDone = true;\n\t\t}\n\t\tsource = source->mNextSource();\n\t}\n\treturn maxProduced;\n}\n\nvoid OverlapAddBase::removeInactiveSources()\n{\n\tP source = mActiveSources();\n\tP prevSource = nullptr;\n\tmActiveSources = nullptr;\n\t\n\twhile (source) {\n\t\tP nextSource = source->mNextSource;\n\t\tsource->mNextSource = nullptr;\n\t\tif (!source->mSourceDone) {\n\t\t\tif (prevSource()) prevSource->mNextSource = source;\n\t\t\telse mActiveSources = source;\n prevSource = source;\n\t\t}\n\t\tsource = nextSource;\n\t}\n}\n\nvoid OverlapAddBase::produceOutputs(int shrinkBy)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nbool OverlapAddBase::pull(Thread& th)\n{\n\tif (mFinished) {\n\t\treturn mFinished;\n }\n\t\n\tOverlapAddOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\taddNewSources(th, blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n bool anyDone = false;\n\tint maxProduced = renderActiveSources(th, blockSize, anyDone);\n\t\t\t\n\tmFinished = mNoMoreSources && mActiveSources() == nullptr;\n\tint shrinkBy = mFinished ? blockSize - maxProduced : 0;\n\t\n\tproduceOutputs(shrinkBy);\n\n\tif (anyDone)\n removeInactiveSources();\n\t\n\treturn mFinished; \n}\n\nvoid OverlapAdd::chaseToTime(Thread& th, int64_t inSampleTime)\n{\n\tint64_t n = inSampleTime - mPrevChaseTime;\n\tmPrevChaseTime = inSampleTime;\n\n\tif (mChasedSignals() && n > 0) {\n\t\tmChasedSignals = mChasedSignals->chaseForm(th, n);\n\t}\n}\n\n\nconst int64_t kMaxOverlapAddChannels = 10000;\n\nstatic void ola_(Thread& th, Prim* prim)\n{\n\tint64_t numChannels = th.popInt(\"ola : numChannels\");\n\tV rate = th.pop();\n\tV hops = th.popZInList(\"ola : hops\");\n\tV sounds = th.pop();\n\n\tif (numChannels > kMaxOverlapAddChannels) {\n\t\tpost(\"ola : too many channels\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tP chasedSignals;\n\tif (rate.isForm()) {\n\t\tchasedSignals = (Form*)rate.o();\n\t\trate = 1.;\n\t\tchasedSignals->dot(th, s_tempo, rate);\n\t}\n\n\tP ola = new OverlapAdd(th, sounds, hops, rate, chasedSignals, (int)numChannels);\n\t\n\tth.push(ola->createOutputs(th));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ITD;\n\nclass ITD_OutputChannel : public Gen\n{\n\tfriend class ITD;\n\tP mITD;\n\t\npublic:\t\n\tITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmITD = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ITD_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nstruct ITD : public Gen\n{\n\tZIn in_;\n\tZIn pan_;\n\tZ maxdelay_;\n\tZ half;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\n\tITD_OutputChannel* mLeft;\n\tITD_OutputChannel* mRight;\n\t\n\tITD(Thread& th, Arg in, Arg pan, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), pan_(pan), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\thalf = (int32_t)ceil(sr * maxdelay * .5 + .5);\n\t\tbufSize = NEXTPOWEROFTWO(2 * (int)half + 3);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~ITD() { delete mLeft; delete mRight; free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"ITD\"; }\n\t\n\tP createOutputs(Thread& th);\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, panStride;\n\t\t\tZ *in, *pan;\n\t\t\tif (in_(th, n, inStride, in) || pan_(th, n, panStride, pan)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., *pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Lout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., -*pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Rout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tRout += Routstride;\n\t\t\t\t\t}\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tpan += panStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tpan_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nITD_OutputChannel::ITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD) : Gen(th, itemTypeZ, inFinite), mITD(inITD)\n{\n}\n\nvoid ITD_OutputChannel::pull(Thread& th)\n{\n\tmITD->pull(th);\n}\n\nP ITD::createOutputs(Thread& th)\n{\n\tmLeft = new ITD_OutputChannel(th, finite, this);\n\tmRight = new ITD_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\nstatic void itd_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"itd : maxdelay\");\n\tV pan = th.popZIn(\"itd : pan\");\n\tV in = th.popZIn(\"itd : in\");\n \n\tP itd = new ITD(th, in, pan, maxdelay);\n\n\tP s = itd->createOutputs(th);\n\n\tth.push(s);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ninline Z fast_sin1(Z x)\n{\n\tx = x - floor(x + .5);\n\t\n Z y = x * (8. - 16. * fabs(x));\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\ninline Z fast_cos1(Z x)\n{\n\treturn fast_sin1(x + .25);\n}\n\ninline Z fast_pan(Z x)\n{\n\tZ y = .75 + x * (.5 - .25 * x);\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\nstruct Pan2Out;\n\nstruct Pan2 : public Object\n{\n\tZIn _in;\n\tZIn _pos;\n\t\n\tPan2Out* mLeft;\n\tPan2Out* mRight;\n\t\t\n\tPan2(Thread& th, Arg inIn, Arg inPos)\n\t\t: _in(inIn), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inIn, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Pan2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Pan2Out : public Gen\n{\n\tP mPan2;\n\t\n\tPan2Out(Thread& th, bool inFinite, P const& inPan2) : Gen(th, itemTypeZ, inFinite), mPan2(inPan2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmPan2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pan2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmPan2->pull(th);\n\t}\n\t\n};\n\nvoid Pan2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b;\n\t\tint n, aStride, bStride;\n\t\tn = framesToFill;\n\t\tif (_in(th, n, aStride, a) || _pos(th, n, bStride, b)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (bStride == 0) {\n\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * Lpan;\n\t\t\t\t*Rout = z * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * fast_pan(-x);\n\t\t\t\t*Rout = z * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_in.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Pan2::createOutputs(Thread& th)\n{\n\tmLeft = new Pan2Out(th, finite, this);\n\tmRight = new Pan2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void pan2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"pan2 : pos\");\n\tV in = th.popZIn(\"pan2 : in\");\n\n\tP pan = new Pan2(th, in, pos);\n\n\tP s = pan->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Balance2Out;\n\nstruct Balance2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tBalance2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Balance2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Balance2Out : public Gen\n{\n\tP mBalance2;\n\t\n\tBalance2Out(Thread& th, bool inFinite, P const& inBalance2) : Gen(th, itemTypeZ, inFinite), mBalance2(inBalance2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmBalance2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Balance2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmBalance2->pull(th);\n\t}\n\t\n};\n\nvoid Balance2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t*Lout = *a * Lpan;\n\t\t\t\t*Rout = *b * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t*Lout = *a * fast_pan(-x);\n\t\t\t\t*Rout = *b * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Balance2::createOutputs(Thread& th)\n{\n\tmLeft = new Balance2Out(th, finite, this);\n\tmRight = new Balance2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void bal2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"bal2 : pos\");\n\tV R = th.popZIn(\"bal2 : right\");\n\tV L = th.popZIn(\"bal2 : left\");\n\n\tP bal = new Balance2(th, L, R, pos);\n\n\tP s = bal->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Rot2Out;\n\nstruct Rot2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tRot2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Rot2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Rot2Out : public Gen\n{\n\tP mRot2;\n\t\n\tRot2Out(Thread& th, bool inFinite, P const& inRot2) : Gen(th, itemTypeZ, inFinite), mRot2(inRot2)\n\t{\n\t}\n\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmRot2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rot2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmRot2->pull(th);\n\t}\n\t\n};\n\nvoid Rot2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tif (_L.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = - R * sn;\n\t\t\t\t\t*Rout = R * cs;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else if (_R.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\t*Lout = L * cs;\n\t\t\t\t\t*Rout = L * sn;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ L = *a;\n\t\t\t\tZ R = *b;\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Rot2::createOutputs(Thread& th)\n{\n\tmLeft = new Rot2Out(th, finite, this);\n\tmRight = new Rot2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void rot2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"rot2 : pos\");\n\tV R = th.popZIn(\"rot2 : right\");\n\tV L = th.popZIn(\"rot2 : left\");\n\n\tP rot2 = new Rot2(th, L, R, pos);\n\n\tP s = rot2->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Fade2 : public Gen\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\t\n\tFade2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: Gen(th, itemTypeZ, mostFinite(inL, inR, inPos)), _L(inL), _R(inR), _pos(inPos)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fade2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *a, *b, *c;\n\t\t\tint n, aStride, bStride, cStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (cStride == 0) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\tZ Lpan = fast_pan(-x);\n\t\t\t\tZ Rpan = fast_pan(x);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a * Lpan + *b * Rpan;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t\tout[i] = *a * fast_pan(-x) + *b * fast_pan(x);\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tc += cStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_L.advance(n);\n\t\t\t_R.advance(n);\n\t\t\t_pos.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void fade2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"fade2 : pos\");\n\tV R = th.popZIn(\"fade2 : right\");\n\tV L = th.popZIn(\"fade2 : left\");\n\n\tth.push(new List(new Fade2(th, L, R, pos)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Trig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Trig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur > 0. && prev <= 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct NegTrig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tNegTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(-1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NegTrig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur >= 0. && prev < 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void tr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"tr : in\");\n\n\tth.push(new List(new Trig(th, in)));\n}\n\nstatic void ntr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"ntr : in\");\n\n\tth.push(new List(new NegTrig(th, in)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Gate : public TwoInputUGen\n{\n\tZ phase;\n\tZ freq;\n\tGate(Thread& th, Arg trig, Arg hold)\n\t\t: TwoInputUGen(th, trig, hold), phase(INFINITY), freq(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gate\"; }\n\t\n\tvoid calc(int n, Z* out, Z* trig, Z* hold, int trigStride, int holdStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ t = *trig;\n\t\t\tif (t > 0.) {\n\t\t\t\tphase = 0.;\n\t\t\t}\n\t\t\tout[i] = phase < *hold ? 1. : 0.;\n\t\t\tphase += freq;\n\t\t\ttrig += trigStride;\n\t\t\thold += holdStride;\n\t\t}\n\t}\n};\n\nstatic void gate_(Thread& th, Prim* prim)\n{\n\tV hold = th.popZIn(\"gate : hold\");\n\tV in = th.popZIn(\"gate : in\");\n\n\tth.push(new List(new Gate(th, in, hold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SampleAndHold : public Gen\n{\n\tZIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSampleAndHold(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SampleAndHold\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *tr;\n\t\t\tint n, inStride, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) val = *in;\n\t\t\t\tout[i] = val;\n\t\t\t\tin += inStride;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void sah_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"sah : trigger\");\n\tV in = th.popZIn(\"sah : in\");\n\n\tth.push(new List(new SampleAndHold(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Sequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Sequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tval = z;\n\t\t\t\t}\n\t\t\t\tout[i] = val;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void seq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"seq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new Sequencer(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct ImpulseSequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\t\n\tImpulseSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ImpulseSequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = z;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void iseq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"iseq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new ImpulseSequencer(th, in, trigger)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct PulseDivider : public Gen\n{\n\tZIn _tr;\n\tZIn _div;\n\tZ _count;\n\t\n\tPulseDivider(Thread& th, Arg tr, Arg div, Z start)\n\t\t: Gen(th, itemTypeZ, mostFinite(tr, div)), _tr(tr), _div(div), _count(start - 1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PulseDivider\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr, *div;\n\t\t\tint n, trStride, divStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr) || _div(th, n, divStride, div)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\t_count += 1.;\n\t\t\t\t\tZ idiv = floor(*div + .5);\n\t\t\t\t\tif (_count >= idiv) {\n\t\t\t\t\t\t_count -= idiv;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = _count == 0. ? *tr : 0.;\n\t\t\t\t} else out[i] = 0.;\n\t\t\t\ttr += trStride;\n\t\t\t\tdiv += divStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t\t_div.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pdiv_(Thread& th, Prim* prim)\n{\n\tZ start = th.popFloat(\"pdiv : istart\");\n\tV div = th.popZIn(\"pdiv : n\");\n\tV in = th.popZIn(\"pdiv : in\");\n\n\tth.push(new List(new PulseDivider(th, in, div, start)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Clip : public ThreeInputUGen\n{\n\t\n\tClip(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Clip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = std::clamp(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Wrap : public ThreeInputUGen\n{\n\t\n\tWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Wrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_wrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Fold : public ThreeInputUGen\n{\n\t\n\tFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_fold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\n\nstruct IWrap : public ThreeInputUGen\n{\n\t\n\tIWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IWrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_iwrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct IFold : public ThreeInputUGen\n{\n\t\n\tIFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IFold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_ifold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstatic void clip_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"clip : hi\");\n\tV lo = th.popZIn(\"clip : lo\");\n\tV in = th.popZIn(\"clip : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(std::clamp(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Clip(th, in, lo, hi)));\n\t}\n}\n\nstatic void wrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"wrap : hi\");\n\tV lo = th.popZIn(\"wrap : lo\");\n\tV in = th.popZIn(\"wrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_wrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Wrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void fold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"fold : hi\");\n\tV lo = th.popZIn(\"fold : lo\");\n\tV in = th.popZIn(\"fold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_fold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Fold(th, in, lo, hi)));\n\t}\n}\n\nstatic void iwrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"iwrap : hi\");\n\tV lo = th.popZIn(\"iwrap : lo\");\n\tV in = th.popZIn(\"iwrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_iwrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IWrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void ifold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"ifold : hi\");\n\tV lo = th.popZIn(\"ifold : lo\");\n\tV in = th.popZIn(\"ifold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_ifold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IFold(th, in, lo, hi)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \n\nstruct MouseUGenGlobalState {\n\tfloat mouseX, mouseY;\n\tbool mouseButton;\n} gMouseUGenGlobals;\n\nstatic void* gstate_update_func(void* arg)\n{\n\tMouseUGenGlobalState* gstate = &gMouseUGenGlobals;\n\n\tCGDirectDisplayID display = kCGDirectMainDisplay; // to grab the main display ID\n\tCGRect bounds = CGDisplayBounds(display);\n\tfloat rscreenWidth = 1. / bounds.size.width;\n\tfloat rscreenHeight = 1. / bounds.size.height;\n\tfor (;;) {\n\t\tHIPoint point;\n\t\tHICoordinateSpace space = 2;\n\t\tHIGetMousePosition(space, nullptr, &point);\n\n\t\tgstate->mouseX = point.x * rscreenWidth; //(float)p.h * rscreenWidth;\n\t\tgstate->mouseY = 1. - point.y * rscreenHeight; //(float)p.v * rscreenHeight;\n\t\tgstate->mouseButton = GetCurrentButtonState();\n\t\tusleep(17000);\n\t}\n\n\treturn 0;\n}\n\nZ gMouseLagTime = .1;\nZ gMouseLagMul = log001 / gMouseLagTime;\n\nstruct MouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct MouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void mousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousex : hi\");\n\tV lo = th.popZIn(\"mousex : lo\");\n\t\n\tth.push(new List(new MouseX(th, lo, hi)));\n}\n\nstatic void mousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousey : hi\");\n\tV lo = th.popZIn(\"mousey : lo\");\n\t\n\tth.push(new List(new MouseY(th, lo, hi)));\n}\n\nstatic void xmousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousex : hi\");\n\tV lo = th.popZIn(\"xmousex : lo\");\n\t\n\tth.push(new List(new ExpMouseX(th, lo, hi)));\n}\n\nstatic void xmousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousey : hi\");\n\tV lo = th.popZIn(\"xmousey : lo\");\n\t\n\tth.push(new List(new ExpMouseY(th, lo, hi)));\n}\n\nstatic void mousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousex1 : hi\");\n\tZ lo = th.popFloat(\"mousex1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseX * (hi - lo);\n\tth.push(z);\n}\n\nstatic void mousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousey1 : hi\");\n\tZ lo = th.popFloat(\"mousey1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseY * (hi - lo);\n\tth.push(z);\n}\n\nstatic void xmousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousex1 : hi\");\n\tZ lo = th.popFloat(\"xmousex1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseX);\n\tth.push(z);\n}\n\nstatic void xmousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousey1 : hi\");\n\tZ lo = th.popFloat(\"xmousey1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseY);\n\tth.push(z);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps();\nvoid AddOscilUGenOps();\nvoid AddDelayUGenOps();\n\nvoid AddUGenOps()\n{\n\ts_tempo = getsym(\"tempo\");\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\n\tpthread_t mouseListenThread;\n\tpthread_create (&mouseListenThread, nullptr, gstate_update_func, (void*)0);\n\n\tvm.addBifHelp(\"\\n*** unit generators ***\");\n\tvm.defmcx(\"*+\", 3, madd_, \"(a b c --> out) multiply add. a b * c +\");\n\n AddOscilUGenOps();\n AddFilterUGenOps();\n AddDelayUGenOps();\n\t\n\tvm.addBifHelp(\"\\n*** plugs ***\");\n\n\tvm.addBifHelp(\"\\n*** control rate subgraphs ***\");\n\tgK2A = automap(\"zk\", 2, new Prim(k2a_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tgK2AC = automap(\"zk\", 2, new Prim(k2ac_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tDEF(kr, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then linearly upsamples all returned signals by n.\")\n\tDEF(krc, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then cubically upsamples all returned signals by n.\")\n\t\n\tvm.addBifHelp(\"\\n*** control function unit generators ***\");\n\tDEFAM(imps, aaz, \"(values durs rate --> out) single sample impulses.\");\n\tDEFAM(steps, aaz, \"(values durs rate --> out) steps\");\n\tDEFAM(gates, aaaz, \"(values durs holds rate --> out) gates\");\n\tDEFAM(lines, aaz, \"(values durs rate --> out) lines\");\n\tDEFAM(xlines, aaz, \"(values durs rate --> out) exponential lines\");\n\tDEFAM(cubics, az, \"(values rate --> out) cubic splines\");\n\tDEFAM(curves, aaaz, \"(values curvatures durs rate --> out) curves.\");\n\t\n\n\tvm.addBifHelp(\"\\n*** random control unit generators ***\");\n\tDEFMCX(lfnoise0, 1, \"(freq --> out) step noise source.\");\n\tDEFMCX(lfnoise1, 1, \"(freq --> out) ramp noise source.\");\n\tDEFMCX(lfnoise3, 1, \"(freq --> out) cubic spline noise source.\");\n\t\n\tvm.addBifHelp(\"\\n*** tempo unit generators ***\");\n\tDEFAM(tempo, az, \"([bps dur bps dur ...] rate --> out) returns a signal of tempo vs time given a list of interleaved tempos (in beats per second) and durations (in beats).\");\n\tDEFAM(beats, z, \"(tempo --> beats) integrates a tempo signal to produce a signal of the time in beats.\");\n\n\tvm.addBifHelp(\"\\n*** envelope unit generators ***\");\n\tvm.addBifHelp(\"\\nFor asr, adsr, dadsr, dahdsr envelopes, the arguments are as follows:\");\n\tvm.addBifHelp(\" delay - a time in seconds. a period of time before the attack segment where the amplitude is zero.\");\n\tvm.addBifHelp(\" attack - a time in seconds to rise from zero to the level specified by the amp argument.\");\n\tvm.addBifHelp(\" hold - a time in seconds to hold at the level specified by the amp argument.\");\n\tvm.addBifHelp(\" delay - a time in seconds to fall from amp to the sustain level.\");\n\tvm.addBifHelp(\" sustain - a level from zero to one which is multiplied by the amp argument. The envelope holds at this level until released.\");\n\tvm.addBifHelp(\" release - a time in seconds to fall from the current level to zero. A release begins whenever the beat time (the integral of tempo), exceeds dur.\");\n\tvm.addBifHelp(\" amp - an amplitude that scales the peak and sustain levels of the envelope.\");\n\tvm.addBifHelp(\" dur - a time in beats to release the envelope.\");\n\tvm.addBifHelp(\" tempo - a signal giving the tempo in beats per second versus time.\");\n\tvm.addBifHelp(\"\");\n\n\tDEFAM(adsr, akkz, \"([attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dadsr, akkz, \"([delay attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dahdsr, akkz, \"([delay attack hold decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tvm.addBifHelp(\"\");\n \n\tDEFAM(endfade, zkkkk, \"(in startupTime holdTime fadeTime threshold --> out) after startupTime has elapsed, fade out the sound when peak amplitude has dropped below threshold for more than the holdTime.\");\n\tDEFAM(fadeout, zkk, \"(in sustainTime fadeTime --> out) fadeout after sustain.\");\n\tDEFAM(fadein, zk, \"(in fadeTime --> out) fade in.\");\n\tDEFAM(parenv, k, \"(dur --> out) parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(quadenv, k, \"(dur --> out) 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(octenv, k, \"(dur --> out) 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(trienv, k, \"(dur --> out) triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(tri2env, k, \"(dur --> out) triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(trapezenv, k, \"(dur --> out) trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(trapez2env, k, \"(dur --> out) trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(cosenv, k, \"(dur --> out) cosine envelope.\")\n\tDEFAM(hanenv, k, \"(dur --> out) hanning envelope.\")\n\tDEFAM(han2env, k, \"(dur --> out) hanning squared envelope.\")\n\tDEFAM(gaussenv, kk, \"(dur width --> out) gaussian envelope. exp(x^2/(-2*width^2)) for x from -1 to 1\")\n\n\tDEFAM(tsig, zza, \"(trig signal amp --> out) trigger a signal.\")\n\n\tDEFAM(tparenv, zaa, \"(trig dur amp --> out) triggered parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(tquadenv, zaa, \"(trig dur amp --> out) triggered 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(toctenv, zaa, \"(trig dur amp --> out) triggered 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(ttrienv, zaa, \"(trig dur amp --> out) triggered triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(ttri2env, zaa, \"(trig dur amp --> out) triggered triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(ttrapezenv, zaa, \"(trig dur amp --> out) triggered trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(ttrapez2env, zaa, \"(trig dur amp --> out) triggered trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(tcosenv, zaa, \"(trig dur amp --> out) triggered cosine envelope.\")\n\tDEFAM(thanenv, zaa, \"(trig dur amp --> out) triggered hanning envelope.\")\n\tDEFAM(than2env, zaa, \"(trig dur amp --> out) triggered hanning squared envelope.\")\n\t\n\tvm.addBifHelp(\"\\n*** spawn unit generators ***\");\n\tDEF(ola, 4, \"(sounds hops rate numChannels --> out) overlap add. This is the basic operator for polyphony. \")\n\n\tvm.addBifHelp(\"\\n*** pause unit generator ***\");\n\tDEFMCX(pause, 2, \"(in amp --> out) pauses the input when amp is <= 0, otherwise in is multiplied by amp.\")\n\n\tvm.addBifHelp(\"\\n*** panner unit generators ***\");\n\tDEFAM(itd, zzk, \"(in pan maxdelay --> out) interaural time delay.\");\n\tDEFMCX(pan2, 2, \"(in pos --> [left right]) stereo pan. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(rot2, 3, \"(left right pos --> [left right]) stereo rotation. pos 0 is no rotation, +/-1 is 180 degrees, -.5 is -90 degrees, +.5 is +90 degrees.\")\n\tDEFMCX(bal2, 3, \"(left right pos --> [left right]) stereo balance control. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(fade2, 3, \"(left right pos --> out) cross fade between two inputs. pos 0 is equal mix. pos -1 is all left, pos +1 is all right.\")\n\n\t\n\tvm.addBifHelp(\"\\n*** trigger unit generators ***\");\n\tDEFMCX(tr, 1, \"(in --> out) transitions from nonpositive to positive become single sample impulses.\")\n\tDEFMCX(ntr, 1, \"(in --> out) transitions from negative to nonnegative become single sample impulses.\")\n\tDEFMCX(gate, 1, \"(in hold --> out) outputs 1 for hold seconds after each trigger, else outputs zero.\")\n\tDEFMCX(sah, 2, \"(in trigger --> out) sample and hold\")\n\tDEFAM(seq, az, \"(in trigger --> out) pulls one value from the input for each trigger. output sustains at that level until the next trigger.\")\n\tDEFAM(iseq, az, \"(in trigger --> out) pulls one value from the input for each trigger. outputs that value for one sample. outputs zero when there is no trigger.\")\n\tDEFMCX(pdiv, 3, \"(in n istart --> out) pulse divider. outputs one impulse from the output for each n impulses in the input. istart is an offset. istart = 0 outputs a pulse on the first input pulse.\")\n\t\n\t\n\tvm.addBifHelp(\"\\n*** bounds unit generators ***\");\n\tDEFMCX(clip, 3, \"(in lo hi --> out) constrain the input to the bounds by clipping.\")\n\tDEFMCX(wrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping.\")\n\tDEFMCX(fold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges.\")\n\tDEFMCX(iwrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping. all inputs treated as integers.\")\n\tDEFMCX(ifold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges. all inputs treated as integers.\")\n\n\tvm.addBifHelp(\"\\n*** mouse control unit generators ***\");\n\tDEFMCX(mousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\n\n\tDEFMCX(mousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\t\n}\n"], ["/sapf/src/Midi.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Midi.hpp\"\n#include \"VM.hpp\"\n#include \"UGen.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n#include \n#include \n\n\nstruct MidiChanState\n{\n\tuint8_t control[128];\n\tuint8_t polytouch[128];\n\tuint8_t keyvel[128];\n\tuint32_t numKeysDown;\n\tuint16_t bend;\n\tuint8_t touch;\n\tuint8_t program;\n\tuint8_t lastkey;\n\tuint8_t lastvel;\n};\n\nconst int kMaxMidiPorts = 16;\nMidiChanState gMidiState[kMaxMidiPorts][16];\nbool gMidiDebug = false;\nMIDIClientRef gMIDIClient = 0;\nMIDIPortRef gMIDIInPort[kMaxMidiPorts], gMIDIOutPort[kMaxMidiPorts];\nint gNumMIDIInPorts = 0, gNumMIDIOutPorts = 0;\nbool gMIDIInitialized = false;\n\nstatic bool gSysexFlag = false;\nstatic Byte gRunningStatus = 0;\nstd::vector gSysexData;\n\nstatic void sysexBegin() {\n\tgRunningStatus = 0; // clear running status\n\t//gSysexData.clear();\n\tgSysexFlag = true;\n}\n\nstatic void sysexEnd(int lastUID) {\n\tgSysexFlag = false;\n}\n\nstatic void sysexEndInvalid() {\n\tgSysexFlag = false;\n}\n\nstatic int midiProcessSystemPacket(MIDIPacket *pkt, int chan) {\n\tint index, data;\n\tswitch (chan) {\n\tcase 7: // added cp: Sysex EOX must be taken into account if first on data packet\n\tcase 0:\n\t\t{\n\t\tint last_uid = 0;\n\t\tint m = pkt->length;\n\t\tByte* p_pkt = pkt->data;\n\t\tByte pktval;\n\n\t\twhile(m--) {\n\t\t\tpktval = *p_pkt++;\n\t\t\tif(pktval & 0x80) { // status byte\n\t\t\t\tif(pktval == 0xF7) { // end packet\n\t\t\t\t\tgSysexData.push_back(pktval); // add EOX\n\t\t\t\t\tif(gSysexFlag)\n\t\t\t\t\t\tsysexEnd(last_uid); // if last_uid != 0 rebuild the VM.\n\t\t\t\t\telse\n\t\t\t\t\t\tsysexEndInvalid(); // invalid 1 byte with only EOX can happen\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if(pktval == 0xF0) { // new packet\n\t\t\t\t\tif(gSysexFlag) {// invalid new one/should not happen -- but handle in case\n\t\t\t\t\t\t// store the last uid value previous to invalid data to rebuild VM after sysexEndInvalid call\n\t\t\t\t\t\t// since it may call sysexEnd() just after it !\n\t\t\t\t\t\tsysexEndInvalid();\n\t\t\t\t\t}\n\t\t\t\t\tsysexBegin(); // new sysex in\n\t\t\t\t\t//gSysexData.push_back(pktval); // add SOX\n\t\t\t\t}\n\t\t\t\telse {// abnormal data in middle of sysex packet\n\t\t\t\t\t//gSysexData.push_back(pktval); // add it as an abort message\n\t\t\t\t\tsysexEndInvalid(); // flush invalid\n\t\t\t\t\tm = 0; // discard all packet\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(gSysexFlag) {\n\t\t\t\t//gSysexData.push_back(pktval); // add Byte\n\t\t\t} else { // garbage - handle in case - discard it\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn (pkt->length-m);\n\t\t}\n\tbreak;\n\n\tcase 1 :\n\t\tindex = pkt->data[1] >> 4;\n\t\tdata = pkt->data[1] & 0xf;\n\t\tswitch (index) { case 1: case 3: case 5: case 7: { data = data << 4; } }\n\t\treturn 2;\n\n\tcase 2 : \t//songptr\n\t\treturn 3;\n\n\tcase 3 :\t// song select\n\t\treturn 2;\n\n\tcase 8 :\t//clock\n\tcase 10:\t//start\n\tcase 11:\t//continue\n\tcase 12: \t//stop\n\tcase 15:\t//reset\n\t\tgRunningStatus = 0; // clear running status\n\t\treturn 1;\n\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn (1);\n}\n\n\n\n\nstatic void midiProcessPacket(MIDIPacket *pkt, int srcIndex)\n{\n\tif(pkt) {\n\t\tint i = 0; \n\t\twhile (i < pkt->length) {\n\t\t\tuint8_t status = pkt->data[i] & 0xF0;\n\t\t\tuint8_t chan = pkt->data[i] & 0x0F;\n\t\t\tuint8_t a, b;\n\n\t\t\tif(status & 0x80) // set the running status for voice messages\n\t\t\t\tgRunningStatus = ((status >> 4) == 0xF) ? 0 : pkt->data[i]; // keep also additional info\n\t\tL:\n\t\t\tswitch (status) {\n\t\t\tcase 0x80 : //noteOff\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note off %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = 0;\n\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0x90 : //noteOn\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note on %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tif (b) {\n\t\t\t\t\tgMidiState[srcIndex][chan].lastkey = a;\n\t\t\t\t\tgMidiState[srcIndex][chan].lastvel = b;\n\t\t\t\t\t++gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t} else {\n\t\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t}\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xA0 : //polytouch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi poly %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].polytouch[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xB0 : //control\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi control %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].control[a] = b;\n\t\t\t\tif (a == 120 || (a >= 123 && a <= 127)) {\n\t\t\t\t\t// all notes off\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].keyvel, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].numKeysDown = 0;\n\t\t\t\t} else if (a == 121) {\n\t\t\t\t\t// reset ALL controls to zero, don't follow MMA recommended practices.\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].control, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].bend = 0x4000;\n\t\t\t\t}\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xC0 : //program\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tgMidiState[srcIndex][chan].program = a;\n\t\t\t\tif (gMidiDebug) printf(\"midi program %d %d %d\\n\", srcIndex, chan+1, a);\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xD0 : //touch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tprintf(\"midi touch %d %d\\n\", chan+1, a);\n\t\t\t\tgMidiState[srcIndex][chan].touch = a;\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xE0 : //bend\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi bend %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].bend = ((b << 7) | a) - 8192;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xF0 :\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\tdefault :\t// data byte => continuing sysex message\n\t\t\t\tif(gRunningStatus && !gSysexFlag) { // modified cp: handling running status. may be we should here\n\t\t\t\t\tstatus = gRunningStatus & 0xF0; // accept running status only inside a packet beginning\n\t\t\t\t\tchan = gRunningStatus & 0x0F;\t// with a valid status byte ?\n\t\t\t\t\t--i;\n\t\t\t\t\tgoto L; // parse again with running status set\n\t\t\t\t}\n\t\t\t\tchan = 0;\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nstatic void midiReadProc(const MIDIPacketList *pktlist, void* readProcRefCon, void* srcConnRefCon)\n{\n\tMIDIPacket *pkt = (MIDIPacket*)pktlist->packet;\n\tint srcIndex = (int)(size_t) srcConnRefCon;\n\tfor (uint32_t i=0; inumPackets; ++i) {\n\t\tmidiProcessPacket(pkt, srcIndex);\n\t\tpkt = MIDIPacketNext(pkt);\n\t}\n}\n\nstatic void midiNotifyProc(const MIDINotification *message, void *refCon)\n{\n\tprintf(\"midi notification %d %d\\n\", (int)message->messageID, (int)message->messageSize);\n}\n\nstatic struct mach_timebase_info machTimebaseInfo() {\n struct mach_timebase_info info;\n mach_timebase_info(&info);\n return info;\n}\n\nstatic MIDITimeStamp midiTime(float latencySeconds)\n{\n // add the latency expressed in seconds, to the current host time base.\n static struct mach_timebase_info info = machTimebaseInfo(); // cache the timebase info.\n Float64 latencyNanos = 1000000000 * latencySeconds;\n MIDITimeStamp latencyMIDI = (latencyNanos / (Float64)info.numer) * (Float64)info.denom;\n return (MIDITimeStamp)mach_absolute_time() + latencyMIDI;\n}\n\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late);\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late)\n{\n\tMIDIPacketList mpktlist;\n\tMIDIPacketList * pktlist = &mpktlist;\n\tMIDIPacket * pk = MIDIPacketListInit(pktlist);\n\tByteCount nData = (ByteCount) length;\n\tpk->data[0] = (Byte) (hiStatus & 0xF0) | (loStatus & 0x0F);\n\tpk->data[1] = (Byte) aval;\n\tpk->data[2] = (Byte) bval;\n\tpk = MIDIPacketListAdd(pktlist, sizeof(struct MIDIPacketList) , pk, midiTime(late), nData, pk->data);\n\t/*OSStatus error =*/ MIDISend(gMIDIOutPort[port], dest, pktlist );\n}\n\n\nstatic int midiCleanUp()\n{\n\t/*\n\t* do not catch errors when disposing ports\n\t* MIDIClientDispose should normally dispose the ports attached to it\n\t* but clean up the pointers in case\n\t*/\n\tint i = 0;\n\tfor (i=0; i= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\t//pass the uid to the midiReadProc to identify the src\n\tvoid* p = (void*)(uintptr_t)inputIndex;\n\tMIDIPortConnectSource(gMIDIInPort[inputIndex], src, p);\n\n\treturn errNone;\n}\n\n\nstatic int prDisconnectMIDIIn(int uid, int inputIndex)\n{\n\tif (inputIndex < 0 || inputIndex >= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\tMIDIPortDisconnectSource(gMIDIInPort[inputIndex], src);\n\n\treturn errNone;\n}\n\n\nstatic void midiStart_(Thread& th, Prim* prim)\n{\n\tmidiInit(16, 19);\n}\n\nstatic void midiRestart_(Thread& th, Prim* prim)\n{\n\tMIDIRestart();\n}\n\nstatic void midiStop_(Thread& th, Prim* prim)\n{\n\tmidiCleanUp();\n}\n\nstatic void midiList_(Thread& th, Prim* prim)\n{\n\tprListMIDIEndpoints();\n}\n\nstatic void midiConnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiConnectInput : port\");\n\tint uid = (int)th.popInt(\"midiConnectInput : sourceUID\");\n\tprConnectMIDIIn(uid, index);\n}\n\nstatic void midiDisconnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiDisconnectInput : port\");\n\tint uid = (int)th.popInt(\"midiDisconnectInput : sourceUID\");\n\tprDisconnectMIDIIn(uid, index);\n}\n\nstatic void midiDebug_(Thread& th, Prim* prim)\n{\n gMidiDebug = th.popFloat(\"midiDebug : onoff\") != 0.;\n}\n\nconst Z kOneOver127 = 1./127.;\nconst Z kOneOver8191 = 1./8191.;\n\nstatic void mctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl1 : hi\");\n\tZ lo = th.popFloat(\"mctl1 : lo\");\n\n\tint cnum = th.popInt(\"mctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl1 : hi\");\n\tZ lo = th.popFloat(\"xmctl1 : lo\");\n\n\tint cnum = th.popInt(\"xmctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly1 : hi\");\n\tZ lo = th.popFloat(\"mpoly1 : lo\");\n\n\tint key = th.popInt(\"mpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"mpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly1 : hi\");\n\tZ lo = th.popFloat(\"xmpoly1 : lo\");\n\n\tint key = th.popInt(\"xmpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mgate1_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate1 : key\") & 127;\n\tint chan = (th.popInt(\"mgate1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mgate1 : srcIndex\") & 15;\n\n\tth.pushBool(gMidiState[srcIndex][chan].keyvel[key] > 0);\n}\n\nstatic void mtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch1 : hi\");\n\tZ lo = th.popFloat(\"mtouch1 : lo\");\n\n\tint chan = (th.popInt(\"mtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch1 : hi\");\n\tZ lo = th.popFloat(\"xmtouch1 : lo\");\n\n\tint chan = (th.popInt(\"xmtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mprog1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mprog1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].touch);\n}\n\nstatic void mlastkey1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastkey1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].lastkey);\n}\n\nstatic void mlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel1 : hi\");\n\tZ lo = th.popFloat(\"mlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"mlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel1 : hi\");\n\tZ lo = th.popFloat(\"xmlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"xmlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nstatic void mbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend1 : hi\");\n\tZ lo = th.popFloat(\"mbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo + z * (hi - lo));\n}\nstatic void xmbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend1 : hi\");\n\tZ lo = th.popFloat(\"xmbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nZ gMidiLagTime = .1;\nZ gMidiLagMul = log001 / gMidiLagTime;\n\nstruct MCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct XMLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastKey : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMLastKey(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastKey\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastkey;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MProg : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMProg(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MProg\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].program;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MGate : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n int _key;\n\t\n\tMGate(Thread& th, int srcIndex, int chan, int key)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan), _key(key)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MGate\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].keyvel[_key];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl > 0 ? 1. : 0.;\n\t\t}\n\t}\n};\n\n\nstruct ZCtl : public ZeroInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n P zref;\n\t\n\tZCtl(Thread& th, P const& inZRef)\n : ZeroInputUGen(th, false), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n zref(inZRef)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ZCtl\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n Z& ctl = zref->z;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = ctl;\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void zctl_(Thread& th, Prim* prim)\n{\n\tP zref = th.popZRef(\"mctl : zref\");\n\n\tth.push(new List(new ZCtl(th, zref)));\n}\n\n\nstatic void mctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl : hi\");\n\tZ lo = th.popFloat(\"mctl : lo\");\n\n\tint cnum = th.popInt(\"mctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void xmctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl : hi\");\n\tZ lo = th.popFloat(\"xmctl : lo\");\n\n\tint cnum = th.popInt(\"xmctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void mpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly : hi\");\n\tZ lo = th.popFloat(\"mpoly : lo\");\n\n\tint key = th.popInt(\"mpoly : key\") & 127;\n\tint chan = (th.popInt(\"mpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void xmpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly : hi\");\n\tZ lo = th.popFloat(\"xmpoly : lo\");\n\n\tint key = th.popInt(\"xmpoly : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void mtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch : hi\");\n\tZ lo = th.popFloat(\"mtouch : lo\");\n\n\tint chan = (th.popInt(\"mtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch : hi\");\n\tZ lo = th.popFloat(\"xmtouch : lo\");\n\n\tint chan = (th.popInt(\"xmtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend : hi\");\n\tZ lo = th.popFloat(\"mbend : lo\");\n\n\tint chan = (th.popInt(\"mbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MBend(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend : hi\");\n\tZ lo = th.popFloat(\"xmbend : lo\");\n\n\tint chan = (th.popInt(\"xmbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMBend(th, srcIndex, chan, lo, hi)));\n}\n\n\nstatic void mprog_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MProg(th, srcIndex, chan)));\n}\n\nstatic void mgate_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate : key\") & 127;\n\tint chan = (th.popInt(\"mgate : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MGate(th, srcIndex, chan, key)));\n}\n\n\nstatic void mlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel : hi\");\n\tZ lo = th.popFloat(\"mlastvel : lo\");\n\n\tint chan = (th.popInt(\"mlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastVel(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mlastkey_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastKey(th, srcIndex, chan)));\n}\n\nstatic void xmlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel : hi\");\n\tZ lo = th.popFloat(\"xmlastvel : lo\");\n\n\tint chan = (th.popInt(\"xmlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMLastVel(th, srcIndex, chan, lo, hi)));\n}\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMidiOps()\n{\n\tvm.addBifHelp(\"\\n*** MIDI control ***\");\n\tDEF(midiStart, 0, 0, \"(-->) start up MIDI services\");\n\tDEF(midiRestart, 0, 0, \"(-->) rescan MIDI services\");\n\tDEF(midiStop, 0, 0, \"(-->) stop MIDI services\");\n\tDEF(midiList, 0, 0, \"(-->) list MIDI endpoints\");\n\tDEF(midiConnectInput, 2, 0, \"(sourceUID index -->) connect a MIDI source\");\n\tDEF(midiDisconnectInput, 2, 0, \"(sourceUID index -->) disconnect a MIDI source\");\n\tDEF(midiDebug, 1, 0, \"(onoff -->) turn on or off midi input monitoring\");\n\t\n\tvm.addBifHelp(\"\\n*** MIDI instantaneous value ***\");\n\tDEFMCX(mctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mprog1, 2, \"(srcIndex chan --> out) value of midi channel program 0-127.\");\n\tDEFMCX(mgate1, 3, \"(srcIndex chan key --> out) value of midi key state. 1 if key is down, 0 if key is up.\");\n\tDEFMCX(mlastkey1, 2, \"(srcIndex chan --> out) value of key of most recent midi note on.\");\n\tDEFMCX(mlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(xmctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** MIDI control signal ***\");\n\tDEFMCX(mctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mlastkey, 2, \"(srcIndex chan --> out) signal of key of most recent midi note on.\");\n\tDEFMCX(mlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(mprog, 2, \"(srcIndex chan --> out) signal of midi channel program 0-127.\");\n\tDEFMCX(mgate, 3, \"(srcIndex chan key --> out) signal of midi key state. 1 if key is down, 0 if key is up.\");\n\n\tDEFMCX(xmctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** ZRef control signal ***\");\n\tDEFMCX(zctl, 1, \"(zref --> out) makes a smoothed control signal from a zref.\");\n}\n\n\n"], ["/sapf/src/MultichannelExpansion.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n// multi channel mapping is a special case of auto mapping where the mask is all z's.\n\nclass MultichannelMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tVIn args[kMaxArgs];\npublic:\n\t\n\tMultichannelMapper(Thread& th, bool inFinite, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\targs[i].set(inArgs[i]);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"MultichannelMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nvoid mcx_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV& fun = prim->v;\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool hasVList = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tif (args[k].isVList()) {\n\t\t\thasVList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t}\n\t}\n\t\n\tif (hasVList) {\n\t\tList* s = new List(new MultichannelMapper(th, isFinite, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tfun.apply(th);\n\t}\n\n}\n\n\nconst char* kAaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";\nconst size_t kAaaLength = strlen(kAaa);\n\nconst char* kZzz = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\";\nconst size_t kZzzLength = strlen(kZzz);\n\nconst char* Prim::GetAutoMapMask() const\n{\n\t//return NoEachOps() || mNumArgs == 0 ? nullptr : kAaa + kAaaLength - mNumArgs;\n\treturn nullptr;\n}\n\nclass MultichannelMapPrim : public Prim\n{\npublic:\n\tMultichannelMapPrim(PrimFun _primFun, Arg _v, int n, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return kZzz + kZzzLength - mTakes; }\n\t\n};\n\nPrim* mcx(int n, Arg f, const char* name, const char* help)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = mcx_< 1>; break;\n\t\tcase 2 : pf = mcx_< 2>; break;\n\t\tcase 3 : pf = mcx_< 3>; break;\n\t\tcase 4 : pf = mcx_< 4>; break;\n\t\tcase 5 : pf = mcx_< 5>; break;\n\t\tcase 6 : pf = mcx_< 6>; break;\n\t\tcase 7 : pf = mcx_< 7>; break;\n\t\tcase 8 : pf = mcx_< 8>; break;\n\t\tcase 9 : pf = mcx_< 9>; break;\n\t\tcase 10 : pf = mcx_<10>; break;\n\t\tcase 11 : pf = mcx_<11>; break;\n\t\tcase 12 : pf = mcx_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new MultichannelMapPrim(pf, f, n, name, help);\n}\n\nclass AutoMapPrim : public Prim\n{\npublic:\n\tconst char* mask;\n\tAutoMapPrim(PrimFun _primFun, Arg _v, int n, const char* inMask, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp), mask(inMask)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return mask; }\n\t\n};\n\nclass AutoMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tBothIn args[kMaxArgs];\npublic:\n\t\n\tAutoMapper(Thread& th, bool inFinite, const char* inMask, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\tswitch (inMask[i]) {\n\t\t\t\tcase 'a' :\n\t\t\t\t\targs[i].setConstant(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'z' : // auto map over V lists, but not Z lists.\n\t\t\t\t\targs[i].setv(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", inMask[i]);\n\t\t\t\tcase 'k' :\n\t\t\t\t\targs[i].set(inArgs[i]);\n\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"AutoMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n/*\n\ta - as is. argument is not automapped.\n\tz - argument is expected to be a signal or scalar, streams are auto mapped.\n\tk - argument is expected to be a scalar, signals and streams are automapped.\n*/\n\ntemplate \nvoid automap_(Thread& th, Prim* prim)\n{\n\n\tconst char* mask = ((AutoMapPrim*)prim)->mask;\n\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool canMap = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tswitch (mask[k]) {\n\t\t\tcase 'a' :\n\t\t\t\tbreak;\n\t\t\tcase 'z' :\n\t\t\t\tif (args[k].isVList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", mask[k]);\n\t\t\t\tthrow errFailed;\n\t\t\t\tbreak;\n\t\t\tcase 'k' :\n\t\t\t\tif (args[k].isList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tif (canMap) {\n\t\tList* s = new List(new AutoMapper(th, isFinite, mask, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tprim->v.apply(th);\n\t}\n\n}\n\nPrim* automap(const char* mask, int n, Arg f, const char* inName, const char* inHelp)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = automap_< 1>; break;\n\t\tcase 2 : pf = automap_< 2>; break;\n\t\tcase 3 : pf = automap_< 3>; break;\n\t\tcase 4 : pf = automap_< 4>; break;\n\t\tcase 5 : pf = automap_< 5>; break;\n\t\tcase 6 : pf = automap_< 6>; break;\n\t\tcase 7 : pf = automap_< 7>; break;\n\t\tcase 8 : pf = automap_< 8>; break;\n\t\tcase 9 : pf = automap_< 9>; break;\n\t\tcase 10 : pf = automap_<10>; break;\n\t\tcase 11 : pf = automap_<11>; break;\n\t\tcase 12 : pf = automap_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new AutoMapPrim(pf, f, n, mask, inName, inHelp);\n}\n\n\n\n\n\nclass EachMapper : public Gen\n{\n\tconst int level;\n\tconst int numLevels;\n\tV fun;\n\tArgInfo args;\npublic:\n\t\n\tEachMapper(Thread& th, bool inFinite, int inLevel, int inNumLevels, const ArgInfo& inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), level(inLevel), numLevels(inNumLevels), args(inArgs), fun(inFun)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"EachMapper\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (level == 0) {\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, v)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tth.push(v);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tfun.apply(th);\n\t\t\t\t} catch (...) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tthrow;\n\t\t\t\t}\n\t\t\t\tout[i] = th.pop();\n\t\t\t\t\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t} else {\n\t\t\tArgInfo subargs;\n\t\t\tsubargs.numArgs = args.numArgs;\n\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\tsubargs.arg[j].mask = args.arg[j].mask;\n\t\t\t}\n\t\t\t\n\t\t\tint bit = 1 << (numLevels - level);\n\t\t\t\n\t\t\tbool mmIsFinite = true;\n\t\t\t\t\t\t\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tV argv[kMaxArgs];\n\t\t\t\tbool allConstant = true;\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, argv[j])) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (argv[j].isList() && (args.arg[j].mask & bit))\n\t\t\t\t\t\tallConstant = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (allConstant) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tth.push(argv[j]);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfun.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = th.pop();\n\t\t\t\t} else {\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tV v = argv[j];\n\t\t\t\t\t\tif (args.arg[j].mask & bit) {\n\t\t\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\t\t\tmmIsFinite = false;\n\t\t\t\t\t\t\tsubargs.arg[j].in.set(v);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tsubargs.arg[j].in.setConstant(v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\tout[i] = new List(new EachMapper(th, mmIsFinite, level - 1, numLevels, subargs, fun));\n\t\t\t\t}\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\n};\n\nList* handleEachOps(Thread& th, int numArgs, Arg fun)\n{\n\tArgInfo args;\n\tV argv[kMaxArgs];\n\t\n\targs.numArgs = numArgs;\n\tint32_t maxMask = 0;\n\n\tbool mmIsFinite = true;\n\n\tfor (int i = numArgs-1; i >= 0; --i) {\n\t\tV v = th.pop();\n\t\targv[i] = v;\n\t\tif (v.isEachOp()) {\n\t\t\t\n\t\t\tEachOp* adv = (EachOp*)v.o();\n\t\t\targs.arg[i].mask = adv->mask;\n\t\t\tmaxMask |= adv->mask;\n\t\t\tif (adv->mask & 1) {\n\t\t\t\tif (!adv->v.isFinite()) \n\t\t\t\t\tmmIsFinite = false;\n\t\t\t\targs.arg[i].in.set(adv->v);\n\t\t\t} else {\n\t\t\t\targs.arg[i].in.setConstant(adv->v);\n\t\t\t}\n\t\t} else {\n\t\t\targs.arg[i].in.setConstant(v);\n\t\t\targs.arg[i].mask = 0;\n\t\t}\n\t}\n\tif (maxMask > 1 && maxMask != NEXTPOWEROFTWO(maxMask) - 1) {\n\t\tpost(\"there are empty levels of iteration. mask: %x\\n\", maxMask);\n\t\tthrow errFailed;\n\t}\n\t\n\tint numLevels = maxMask <= 1 ? 1 : LOG2CEIL(maxMask);\n\treturn new List(new EachMapper(th, mmIsFinite, numLevels-1, numLevels, args, fun));\n}\n\n\nclass Flop : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlop(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flop\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nclass Flops : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlops(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tVIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flops\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flopz : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlopz(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flopz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeZ, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->addz(z);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopsNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopsNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopsNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isVList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid flop_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\nvoid flops_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flops : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flops : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flops : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flops : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopsNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nvoid flop1_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop1 : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tList* result = new List(itemTypeV, 1);\n\t\t\tresult->add(s);\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop1 : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop1 : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop1 : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nclass Lace : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLace(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), argPos(0)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lace\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (args[argPos].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Lacez : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLacez(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), argPos(0)\n\t{\n\t\tpost(\"Lacez\\n\");\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lacez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tZ z;\n\t\t\tif (args[argPos].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nvoid lace_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popList(\"lace : list\");\n\tif (!s->isVList())\n\t\twrongType(\"lace : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"lace : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Lacez(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Lace(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\nclass Sel : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSel(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sel\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = v;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Selz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSelz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Selz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = z;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sell : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSell(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sell\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tV v;\n\t\t\tif (args[k].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sellz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSellz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sellz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tZ z;\n\t\t\tif (args[k].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid sel_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sel : indices\");\n\n\tP s = th.popList(\"sel : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sel : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sel : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Selz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sel(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\nvoid sell_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sell : indices\");\n\n\tP s = th.popList(\"sell : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sell : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sell : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Sellz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sell(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\n\n\n\n\n\n"], ["/sapf/src/OscilUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n\n#include \"OscilUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"dsp.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst int kNumTables = 30; // third octave tables.\nconst int kWaveTableSize = 16384;\nconst int kWaveTableMask = kWaveTableSize - 1;\n//const int kWaveTableByteSize = kWaveTableSize * sizeof(Z);\nconst int kWaveTableTotalSize = kWaveTableSize * kNumTables;\n//const Z kPhaseInc = kTwoPi / kWaveTableSize;\nconst Z kWaveTableSizeF = kWaveTableSize;\n\n// the maximum number of harmonics is actually 1024, but 1290 is needed for extrapolation.\nconst int kMaxHarmonics = 1290;\nconst int gNumHarmonicsForTable[kNumTables+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 101, 128, 161, 203, 256, 322, 406, 512, 645, 812, 1024, 1290 };\n\nint gWaveTableSize[kNumTables];\n\nconst double kMaxHarmonicsF = kMaxHarmonics;\n\n\nZ gTableForNumHarmonics[kMaxHarmonics+1];\nZ gHertzToHarmonics[kMaxHarmonics+1];\n\nstatic void fillHarmonicsTable()\n{\t\n\tdouble maxval = kNumTables - 1.0000001;\n\t\n\tint t = 0;\n\tfor (int i = 1; i < kMaxHarmonics; ++i) {\n\t\tif (gNumHarmonicsForTable[t] < i && t < kNumTables) ++t;\n\t\t//int t1 = std::clamp(t-1, 0, kNumTables-1);\n\t\t\n\t\tdouble frac = (double)(i - gNumHarmonicsForTable[t]) / (double)(gNumHarmonicsForTable[t] - gNumHarmonicsForTable[t-1]);\n\t\tdouble ft = t - 1 + frac;\n\t\tgTableForNumHarmonics[i] = ft;\n\t}\n\t\t\n\tgTableForNumHarmonics[0] = 0.;\n\tgTableForNumHarmonics[kMaxHarmonics] = maxval;\n}\n\nstatic void zeroTable(size_t n, Z* table)\n{\n\tmemset(table, 0, n * sizeof(Z));\n}\n\nstatic void normalize(int n, Z* buf)\n{\n\tZ maxabs = 0.;\n\tfor (int i = 0; i < n; ++i) {\n\t\tmaxabs = std::max(maxabs, fabs(buf[i]));\n\t}\n\tif (maxabs > 0.) {\n\t\tZ scale = 1. / maxabs;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tbuf[i] *= scale;\n\t\t}\n\t}\n}\n\n\nstatic void fillWaveTable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* table)\n{\n\tconst size_t kWaveTableSize2 = kWaveTableSize / 2;\n\tconst Z two_pi = 2. * M_PI;\n\t\n\tZ real[kWaveTableSize2];\n\tZ imag[kWaveTableSize2];\n\tZ polar[kWaveTableSize];\n\tZ rect[kWaveTableSize];\n\t\n\tzeroTable(kWaveTableSize2, real);\n\tzeroTable(kWaveTableSize2, imag);\n\n\n\tZ w = M_PI_2 / n;\n\tfor (int i = 0; i < n; ++i) {\n\t\tZ smoothAmp = smooth == 0. ? 1. : pow(cos(w*i), smooth);\n\t\t//fillHarmonic(i+1, *amps * smoothAmp, *phases, table);\n\t\treal[i+1] = *amps * smoothAmp;\n\t\timag[i+1] = (*phases - .25) * two_pi;\n\t\tamps += ampStride;\n\t\tphases += phaseStride;\n\t}\n\t\n\tDSPDoubleSplitComplex in;\n\tin.realp = real;\n\tin.imagp = imag;\n\t\n\tvDSP_ztocD(&in, 1, (DSPDoubleComplex*)polar, 2, kWaveTableSize2);\n\tvDSP_rectD(polar, 2, rect, 2, kWaveTableSize2);\n\tvDSP_ctozD((DSPDoubleComplex*)rect, 2, &in, 1, kWaveTableSize2);\n\trifft(kWaveTableSize, real, imag, table);\n}\n\nstatic void fill3rdOctaveTables(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* tables)\n{\t\n\t// tables is assumed to be allocated to kNumTables * kWaveTableSize samples\n\tfor (int i = 0; i < kNumTables; ++i) {\n\t\tint numHarmonics = std::min(n, gNumHarmonicsForTable[i]);\n\t\tfillWaveTable(numHarmonics, amps, ampStride, phases, phaseStride, smooth, tables + i * kWaveTableSize);\n\t}\n\t\n\tnormalize(kWaveTableTotalSize, tables);\n}\n\nstatic P makeWavetable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth)\n{\n\tP list = new List(itemTypeZ, kWaveTableTotalSize);\n\tP array = list->mArray;\n\t\n\tZ* tables = array->z();\n\t\t\n\tfill3rdOctaveTables(n, amps, ampStride, phases, phaseStride, smooth, tables);\n\tarray->setSize(kWaveTableTotalSize);\n\t\n\treturn list;\n}\n\nstatic void wavefill_(Thread& th, Prim* prim)\n{\n\tZ smooth = th.popFloat(\"wavefill : smooth\");\n\tV phases = th.popZIn(\"wavefill : phases\");\n\tV amps = th.popZIn(\"wavefill : amps\");\n\t\t\n\tP ampl;\n\tP phasel;\n\tZ *phasez, *ampz;\n\tint phaseStride, ampStride; \n\tint64_t n = kMaxHarmonics;\n\tif (phases.isZList()) {\n\t\tphasel = ((List*)phases.o())->packSome(th, n);\n\t\tphasez = phasel->mArray->z();\n\t\tphaseStride = 1;\n\t} else {\n\t\tphasez = &phases.f;\n\t\tphaseStride = 0;\n\t}\n\t\n\tif (amps.isZList()) {\n\t\tampl = ((List*)amps.o())->packSome(th, n);\n\t\tampz = ampl->mArray->z();\n\t\tampStride = 1;\n\t} else {\n\t\tampz = &s.f;\n\t\tampStride = 0;\n\t}\n\t\n\tP list = makeWavetable((int)n, ampz, ampStride, phasez, phaseStride, smooth);\n\tth.push(list);\n}\n\nP gParabolicTable;\nP gTriangleTable;\nP gSquareTable;\nP gSawtoothTable;\n\nstatic void makeClassicWavetables()\n{\n\t//fprintf(stdout, \"computing wave tables\\n\");\n\tZ amps[kMaxHarmonics+1];\n\tZ phases[kMaxHarmonics+1];\n\tZ smooth = 0.;\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i;\n\t}\n\tphases[0] = .25;\n\tgParabolicTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = -1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i;\n\t}\n\n\tphases[0] = 0.;\n\tgTriangleTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t++i;\n\t}\n\tphases[0] = 0.;\n\tgSquareTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i;\n\t}\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tphases[i] = 0.;\t\t++i;\n\t\tphases[i] = .5;\t\t++i;\n\t}\n\tgSawtoothTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases+1, 1, smooth);\n\t\n\tvm.addBifHelp(\"\\n*** classic wave tables ***\");\n\tvm.def(\"parTbl\", gParabolicTable);\t\tvm.addBifHelp(\"parTbl - parabolic wave table.\");\n\tvm.def(\"triTbl\", gTriangleTable);\t\tvm.addBifHelp(\"triTbl - triangle wave table.\");\n\tvm.def(\"sqrTbl\", gSquareTable);\t\t\tvm.addBifHelp(\"sqrTbl - square wave table.\");\n\tvm.def(\"sawTbl\", gSawtoothTable);\t\tvm.addBifHelp(\"sawTbl - sawtooth wave table.\");\n\n\t//fprintf(stdout, \"done computing wave tables\\n\");\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Osc : public ZeroInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOsc(Thread& th, P const& inArray, Z ifreq, Z iphase) : ZeroInputUGen(th, false),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscPM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOscPM(Thread& th, P const& inArray, Z ifreq, Arg phasemod) : OneInputUGen(th, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* phasemod, int phasemodStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscFM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFM(Thread& th, P const& inArray, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\t\t\t\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstruct OscFMPM : public TwoInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFMPM(Thread& th, P const& inArray, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFMPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstatic void newOsc(Thread& th, Arg freq, Arg phase, P const& tables)\n{\n\tif (freq.isZList()) {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscFMPM(th, tables->mArray, freq, phase)));\n\t\t} else {\n\t\t\tth.push(new List(new OscFM(th, tables->mArray, freq, phase.asFloat())));\n\t\t}\n\t} else {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscPM(th, tables->mArray, freq.asFloat(), phase)));\n\t\t} else {\n\t\t\tth.push(new List(new Osc(th, tables->mArray, freq.asFloat(), phase.asFloat())));\n\t\t}\n\t}\n}\n\n\nstatic void osc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"osc : tables\");\n\tV phase = th.popZIn(\"osc : phase\");\n\tV freq = th.popZIn(\"osc : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"osc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tnewOsc(th, freq, phase, tables);\n}\n\nstatic void par_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"par : phase\");\n\tV freq = th.popZIn(\"par : freq\");\n\n\tnewOsc(th, freq, phase, gParabolicTable);\n}\n\nstatic void tri_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"tri : phase\");\n\tV freq = th.popZIn(\"tri : freq\");\n\n\tnewOsc(th, freq, phase, gTriangleTable);\n}\n\nstatic void saw_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"saw : phase\");\n\tV freq = th.popZIn(\"saw : freq\");\n\n\tnewOsc(th, freq, phase, gSawtoothTable);\n}\n\nstatic void square_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"square : phase\");\n\tV freq = th.popZIn(\"square : freq\");\n\n\tnewOsc(th, freq, phase, gSquareTable);\n}\n\nstruct OscPWM : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscPWM(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscPWM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\n\t\t\tZ pphase2 = pphase1 + *duty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\t\t\tout[i] = .5 * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct VarSaw : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tVarSaw(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"VarSaw\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\t\t\t\n\t\t\tZ zduty = std::clamp(*duty, .01, .99);\n\t\t\tZ pphase2 = pphase1 + zduty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\n\t\t\tZ amp = .25 / (zduty - zduty * zduty);\n\t\t\tout[i] = amp * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstatic void oscp_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"oscp : tables\");\n\tV duty = th.popZIn(\"oscp : phaseOffset\");\n\tV phase = th.popZIn(\"oscp : phase\");\n\tV freq = th.popZIn(\"oscp : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"oscp : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void pulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"pulse : phaseOffset\");\n\tV phase = th.popZIn(\"pulse : phase\");\n\tV freq = th.popZIn(\"pulse : freq\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void vsaw_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"vsaw : phaseOffset\");\n\tV phase = th.popZIn(\"vsaw : phase\");\n\tV freq = th.popZIn(\"vsaw : freq\");\n\n\tP tables = gParabolicTable;\n\n\tth.push(new List(new VarSaw(th, tables->mArray, freq, phase, duty)));\n}\n\n\n\nstruct SyncOsc : public TwoInputUGen\n{\n\tP const array;\n\tZ sinePhaseStart;\n\tZ sinePhaseReset;\n\tZ sinePhaseEnd;\n Z wavePhaseResetRatio;\n\tZ phase1;\n\tZ phase2a;\n\tZ phase2b;\n\tZ freqmul1;\n\tZ freqmul2;\n\tZ freqLimit;\n\tZ* tables;\n bool once = true;\n\t\n\tSyncOsc(Thread& th, P const& inArray, Arg freq1, Arg freq2) : TwoInputUGen(th, freq1, freq2),\n\t\tarray(inArray),\n sinePhaseStart(kSineTableSize/4),\n\t\tsinePhaseReset(kSineTableSize/2),\n\t\tsinePhaseEnd(sinePhaseStart + sinePhaseReset),\n wavePhaseResetRatio(kWaveTableSizeF / sinePhaseReset),\n\t\tphase1(sinePhaseStart), \n phase2a(0.), \n phase2b(0.),\n\t\tfreqmul1(.5 * th.rate.radiansPerSample * gInvSineTableOmega),\n\t\tfreqmul2(kWaveTableSizeF * th.rate.invSampleRate),\n\t\tfreqLimit(th.rate.freqLimit),\n\t\ttables(array->z())\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SyncOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq1, Z* freq2, int freq1Stride, int freq2Stride)\n\t{\n if (once) {\n once = false;\n phase2b = kWaveTableSizeF * (fabs(*freq2) / fabs(*freq1));\n }\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq1 = fabs(*freq1);\n\t\t\tZ ffreq2 = fabs(*freq2);\n\t\t\tfreq1 += freq1Stride;\n\t\t\tfreq2 += freq2Stride;\n\t\t\t\t\t\t\t\t\t\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq2), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase2a = floor(phase2a);\n\t\t\tint index2a = (int)iphase2a;\n\t\t\tZ fracphase2a = phase2a - iphase2a;\n\n\t\t\tZ iphase2b = floor(phase2b);\n\t\t\tint index2b = (int)iphase2b;\n\t\t\tZ fracphase2b = phase2b - iphase2b;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates an (extremely quiet) broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ sawA = oscilLUT2(tableA, tableB, index2a, mask, fracphase2a, fractable);\n\t\t\tZ sawB = oscilLUT2(tableA, tableB, index2b, mask, fracphase2b, fractable);\n\t\t\t\n\t\t\tZ window = .5 - .5 * tsinx(phase1);\n\t\t\tout[i] = sawB + window * (sawA - sawB);\n \n\t\t\tZ freq2inc = ffreq2 * freqmul2;\n\n\t\t\tphase2a += freq2inc;\n\t\t\tif (phase2a >= kWaveTableSizeF) phase2a -= kWaveTableSizeF;\n\n\t\t\tphase2b += freq2inc;\n\t\t\tif (phase2b >= kWaveTableSizeF) phase2b -= kWaveTableSizeF;\n\n\t\t\tphase1 += ffreq1 * freqmul1;\n\t\t\tif (phase1 >= sinePhaseEnd) {\n\t\t\t\tphase1 -= sinePhaseReset;\n \n // reset and swap phases\n phase2b = phase2a;\n phase2a = wavePhaseResetRatio * (phase1 - sinePhaseStart) * (ffreq2 / ffreq1); // reset to proper fractional position. \n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ssaw_(Thread& th, Prim* prim)\n{\n\tV freq2 = th.popZIn(\"ssaw : freq2\");\n\tV freq1 = th.popZIn(\"ssaw : freq1\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\nstatic void sosc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"sosc : tables\");\n\tV freq2 = th.popZIn(\"sosc : freq2\");\n\tV freq1 = th.popZIn(\"sosc : freq1\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"sosc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFSaw : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFSaw2 : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw2(Thread& th, Arg freq, Arg phasem) : TwoInputUGen(th, freq, phasem), phase(0.), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw2\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasem, int freqStride, int phasemStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ pphase = phase + 2. * *phasem - 1.;\n\t\t\tif (pphase >= 1.) do { pphase -= 2.; } while (pphase >= 1.);\n\t\t\telse if (pphase < -1.) do { pphase += 2.; } while (pphase < -1.);\n\t\t\tout[i] = pphase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFTri : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFTri(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(2. * th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFTri\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase <= 1. ? phase : 2. - phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 3.) phase -= 4.;\n\t\t\telse if (phase < -1.) phase += 4.;\n\t\t}\n\t}\n};\n\nstatic void lfsaw_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsaw : phase\");\n\tV freq = th.popZIn(\"lfsaw : freq\");\n\n\tth.push(new List(new LFSaw(th, freq, phase)));\n}\n\nstatic void lftri_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lftri : phase\");\n\tV freq = th.popZIn(\"lftri : freq\");\n\n\tth.push(new List(new LFTri(th, freq, phase)));\n}\n\nstruct LFPulse : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulse(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? 1. : 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? 1.f : 0.f;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFPulseBipolar : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulseBipolar(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulseBipolar\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? *duty : *duty - 1. ;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? *duty : *duty - 1.;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFSquare : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSquare(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSquare\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\tout[i] = phase < .5 ? 1. : -1.;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Vosim : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tVosim(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invSampleRate), freqLimit(.5*th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = (freqLimit / *freq);\n\t\t\tout[i] = sc_squared(std::sin(M_PI*std::min(maxnth, *nth)*phase)) * sc_squared(1.-phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\telse if (phase < 0.) phase += 1.;\n\t\t}\n\t}\n};\n\n\nstatic void vosim_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"vosim : n\");\n\tZ phase = th.popFloat(\"vosim : phase\");\n\tV freq = th.popZIn(\"vosim : freq\");\n\n\tth.push(new List(new Vosim(th, freq, phase, n)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SmoothSaw : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSaw(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tout[i] = phase-phase*std::pow(std::abs(phase),std::min(maxnth, *nth));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct SmoothSawPWM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSawPWM(Thread& th, Arg freq, Z iphase, Arg nth, Arg duty) : ThreeInputUGen(th, freq, nth, duty), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, Z* duty, int freqStride, int nthStride, int dutyStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tZ w = *duty;\n\t\t\tZ u = .5*phase - .5;\n\t\t\tZ wphase = (w+u)/(w*phase-u);\n\t\t\tout[i] = wphase*(1.-std::pow(std::abs(phase),std::min(maxnth, *nth)));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tduty += dutyStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\n\nstatic void smoothsawpwm_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"smoothsawpwm : duty\");\n\tV n = th.popZIn(\"smoothsawpwm : n\");\n\tZ phase = th.popFloat(\"smoothsawpwm : phase\");\n\tV freq = th.popZIn(\"smoothsawpwm : freq\");\n\n\tth.push(new List(new SmoothSawPWM(th, freq, phase, n, duty)));\n}\n\n\nstatic void smoothsaw_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"smoothsaw : n\");\n\tZ phase = th.popFloat(\"smoothsaw : phase\");\n\tV freq = th.popZIn(\"smoothsaw : freq\");\n\n\tth.push(new List(new SmoothSaw(th, freq, phase, n)));\n}\n\nstatic void lfpulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulse : duty\");\n\tZ phase = th.popFloat(\"lfpulse : phase\");\n\tV freq = th.popZIn(\"lfpulse : freq\");\n\n\tth.push(new List(new LFPulse(th, freq, phase, duty)));\n}\n\nstatic void lfpulseb_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulseb : duty\");\n\tZ phase = th.popFloat(\"lfpulseb : phase\");\n\tV freq = th.popZIn(\"lfpulseb : freq\");\n\n\tth.push(new List(new LFPulseBipolar(th, freq, phase, duty)));\n}\n\nstatic void lfsquare_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsquare : phase\");\n\tV freq = th.popZIn(\"lfsquare : freq\");\n\n\tth.push(new List(new LFSquare(th, freq, phase)));\n}\n\n\n\n\nstruct Impulse : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tImpulse(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t\tif (phase == 0.) phase = 1.; // force an initial impulse.\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Impulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\tout[i] = 1.;\n\t\t\t} else {\n\t\t\t\tout[i] = 0.;\n\t\t\t}\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstatic void impulse_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"impulse : phase\");\n\tV freq = th.popZIn(\"impulse : freq\");\n\n\tth.push(new List(new Impulse(th, freq, phase)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct SinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n#if 1\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n#else\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n#endif\n\t}\n};\n\nstruct SinOsc2 : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc2(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc2\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct TSinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tTSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"TSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\n\nstruct FSinOsc : public ZeroInputUGen\n{\n\tZ freq;\n\tZ b1, y1, y2;\n\t\n\tFSinOsc(Thread& th, Z ifreq, Z iphase) : ZeroInputUGen(th, false), \n\t\tfreq(ifreq * th.rate.radiansPerSample), \n\t\tb1(2. * cos(freq))\n\t{\n\t\tiphase = sc_wrap(iphase, 0., 1.) * kTwoPi;\n\t\ty1 = sin(iphase-freq);\n\t\ty2 = sin(iphase-2.*freq);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ zy1 = y1;\n\t\tZ zy2 = y2;\n\t\tZ zb1 = b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = zb1 * zy1 - zy2;\n\t\t\tout[i] = y0;\n\t\t\tzy2 = zy1;\n\t\t\tzy1 = y0;\n\t\t}\n\t\ty1 = zy1;\n\t\ty2 = zy2;\n\t}\n};\n\n\n\nstruct SinOscPMFB : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ y1;\n\t\n\tSinOscPMFB(Thread& th, Arg freq, Z iphase, Arg phasefb) : TwoInputUGen(th, freq, phasefb), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMFB\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasefb, int freqStride, int phasefbStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = sin(phase + *phasefb * y1);\n\t\t\tout[i] = y0;\n\t\t\ty1 = y0;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasefb += phasefbStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPM : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPM(Thread& th, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase + *phasemod * kTwoPi;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n\t}\n};\n\nstruct SinOscM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscM(Thread& th, Arg freq, Z iphase, Arg mul, Arg add) : ThreeInputUGen(th, freq, mul, add), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* mul, Z* add, int freqStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPMM : public FourInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPMM(Thread& th, Arg freq, Arg phasemod, Arg mul, Arg add)\n\t\t: FourInputUGen(th, freq, phasemod, mul, add), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* mul, Z* add, int freqStride, int phasemodStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase + *phasemod) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void tsinosc_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"tsinosc : iphase\");\n\tV freq = th.popZIn(\"tsinosc : freq\");\n\n th.push(new List(new SinOsc2(th, freq, phase)));\n}\n\nstatic void sinosc_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"sinosc : phase\");\n\tV freq = th.popZIn(\"sinosc : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPM(th, freq, phase)));\n\t} else if (freq.isZList()) {\n\t\tth.push(new List(new SinOsc(th, freq, phase.f)));\n\t} else {\n\t\tth.push(new List(new FSinOsc(th, freq.f, phase.f)));\n\t}\n}\n\nstatic void sinoscm_(Thread& th, Prim* prim)\n{\n\tV add = th.popZIn(\"sinoscm : mul\");\n\tV mul = th.popZIn(\"sinoscm : add\");\n\tV phase = th.popZIn(\"sinoscm : phase\");\n\tV freq = th.popZIn(\"sinoscm : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPMM(th, freq, phase, mul, add)));\n\t} else {\n\t\tth.push(new List(new SinOscM(th, freq, phase.f, mul, add)));\n\t}\n}\n\n\nstatic void sinoscfb_(Thread& th, Prim* prim)\n{\n\tV fb = th.popZIn(\"sinoscfb : fb\");\n\tZ iphase = th.popFloat(\"sinoscfb : phase\");\n\tV freq = th.popZIn(\"sinoscfb : freq\");\n\n\tth.push(new List(new SinOscPMFB(th, freq, iphase, fb)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Blip : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ nyq_;\n\tBlip(Thread& th, Arg freq, Z iphase, Arg numharms)\n\t\t: TwoInputUGen(th, freq, numharms), phase(sc_wrap(2. * iphase - 1., -1., 1.)), freqmul(th.rate.radiansPerSample),\n\t\tnyq_(th.rate.sampleRate * .5)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Blip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* numharms, int freqStride, int numharmsStride) \n\t{\n\t\tZ nyq = nyq_;\n\t\t\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\t\t\tZ ffreq = *freq * freqmul;\n\n\t\t\tZ maxN = floor(nyq / ffreq);\n\t\t\tZ N = *numharms;\n\t\t\t\n\t\t\tif (N > maxN) N = maxN;\n\t\t\telse if (N < 1.) N = 1.;\n\t\t\t\n\t\t\tZ Na = floor(N);\n\t\t\tZ Nb = Na + 1.;\n\t\t\t\n\t\t\tZ frac = N - Na;\n\t\t\tZ Na_scale = .5 / Na;\n\t\t\tZ Nb_scale = .5 / Nb;\n\n\t\t\tZ Na2 = 2. * Na + 1.;\n\t\t\tZ Nb2 = Na2 + 2.;\n\n\t\t\tZ d = 1. / sin(phase);\n\t\t\tZ a = Na_scale * (sin(Na2 * phase) * d - 1.);\n\t\t\tZ b = Nb_scale * (sin(Nb2 * phase) * d - 1.);\n\n\t\t\tfrac = sc_scurve0(frac); // this eliminates out a broadband tick in the spectrum.\n\n\t\t\tout[i] = a + frac * (b - a);\n\n\t\t\tphase += ffreq;\n\t\t\tfreq += freqStride;\n\t\t\tnumharms += numharmsStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < -kTwoPi) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void blip_(Thread& th, Prim* prim)\n{\n\tV numharms = th.popZIn(\"blip : numharms\");\n\tZ phase = th.popFloat(\"blip : phase\");\n\tV freq = th.popZIn(\"blip : freq\");\n\n\tth.push(new List(new Blip(th, freq, phase, numharms)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF1 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF1(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF1\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = *coef;\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scale = (a - 1.)/(an1 - 1.);\n\t\t\tout[i] = scale * (sin(p1) - a * sin(p1-p2) - an1 * (sin(p1 + N1*p2) - a * sin(p1 + N*p2)))/(1. + a2 - 2. * a * cos(p2));\nprintf(\"%d %f\\n\", i, out[i]);\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf1_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf1 : numharms\");\n\tV coef = th.popZIn(\"dsf1 : coef\");\n\tV modRatio = th.popZIn(\"dsf1 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf1 : carRatio\");\n\tV freq = th.popZIn(\"dsf1 : freq\");\n\n\tth.push(new List(new DSF1(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF3 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF3(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF3\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = std::clamp(*coef, -.9999, .9999);\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scalePeak = (a - 1.)/(2.*an1 - a - 1.);\n\t\t\tZ scale = scalePeak;\n\t\t\tZ denom = (1. + a2 - 2. * a * cos(p2));\n\t\t\tout[i] = scale * sin(p1) * (1. - a2 - 2. * an1 * (cos(N1*p2) - a * cos(N*p2)))/denom;\n\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf3_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf3 : numharms\");\n\tV coef = th.popZIn(\"dsf3 : coef\");\n\tV modRatio = th.popZIn(\"dsf3 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf3 : carRatio\");\n\tV freq = th.popZIn(\"dsf3 : freq\");\n\n\tth.push(new List(new DSF3(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct KlangOsc\n{\n\tKlangOsc(Arg f, Arg a, Z p) :\n\t\tfreq(f), amp(a), phase(p) {}\n\t\t\n\tZIn freq;\n\tZIn amp;\n\tZ phase;\n};\n\nstruct Klang : public Gen\n{\n\tstd::vector _oscs;\n\tZ _freqmul, _K;\n\tZ _nyq, _cutoff, _slope;\n\t\n\tKlang(Thread& th, V freqs, V amps, V phases)\n\t\t: Gen(th, itemTypeZ, false),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 / th.rate.sampleRate),\n\t\t\t_nyq(th.rate.sampleRate * .5),\n\t\t\t_cutoff(_nyq * .8),\n\t\t\t_slope(1. / (_nyq - _cutoff))\n\t{\n\t\tint64_t numOscs = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, freqs.length(th));\n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, amps.length(th));\n\t\t}\n\t\tif (phases.isList()) {\n\t\t\tphases = ((List*)phases.o())->pack(th);\n\t\t\tnumOscs = std::min(numOscs, phases.length(th));\n\t\t}\n\t\t\n\t\tif (numOscs == LONG_MAX) numOscs = 1;\n\t\t\n\t\tfor (int64_t i = 0; i < numOscs; ++i) {\n\t\t\tKlangOsc kf(freqs.at(i), amps.at(i), phases.atz(i));\n\t\t\t_oscs.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"Klang\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\tZ* out0 = mOut->fulfillz(mBlockSize);\n\t\tmemset(out0, 0, mBlockSize * sizeof(Z));\n\t\tint maxToFill = 0;\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ nyq = _nyq;\n\t\tZ cutoff = _cutoff;\n\t\tZ slope = _slope;\n\t\tfor (size_t osc = 0; osc < _oscs.size(); ++osc) {\n\t\t\tint framesToFill = mBlockSize;\n\t\t\tKlangOsc& ko = _oscs[osc];\n\t\t\tZ phase = ko.phase;\n\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp;\n\t\t\t\tint n, freqStride, ampStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (ko.freq(th, n, freqStride, freq) || ko.amp(th, n, ampStride, amp)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ ffreq = *freq;\n\t\t\t\t\tif (ffreq > cutoff) {\n\t\t\t\t\t\tif (ffreq < nyq) {\n\t\t\t\t\t\t\tout[i] += (cutoff - ffreq) * slope * *amp * tsin(phase);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] += *amp * tsin(phase);\n\t\t\t\t\t}\n\t\t\t\t\tphase += ffreq * freqmul;\n\t\t\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tko.freq.advance(n);\n\t\t\t\tko.amp.advance(n);\n\t\t\t}\n\t\t\tko.phase = phase;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\nstatic void klang_(Thread& th, Prim* prim)\n{\n\tV phases\t= th.popZInList(\"klang : phases\");\n\tV amps\t\t= th.popZInList(\"klang : amps\");\n\tV freqs = th.popZInList(\"klang : freqs\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (phases.isVList() && !phases.isFinite())\n\t\tindefiniteOp(\"klank : phases\", \"\");\n\n\tth.push(new List(new Klang(th, freqs, amps, phases)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddOscilUGenOps()\n{\n\tfillHarmonicsTable();\n\n\tvm.addBifHelp(\"\\n*** wavetable generation ***\");\n\tDEFAM(wavefill, aak, \"(amps phases smooth -> wavetable) generates a set 1/3 octave wavetables for table lookup oscillators. sin(i*theta + phases[i])*amps[i]*pow(cos(pi*i/n), smooth). smoothing reduces Gibb's phenomenon. zero is no smoothing\")\n\t\n\tmakeClassicWavetables();\n\n\tvm.addBifHelp(\"\\n*** oscillator unit generators ***\");\n\t\n\tDEFMCX(osc, 3, \"(freq phase wavetable --> out) band limited wave table oscillator. wavetable is a table created with wavefill.\")\n\tDEFMCX(oscp, 4, \"(freq phase phaseOffset wavetable --> out) band limited wave table oscillator pair with phase offset.\")\n\tDEFMCX(sosc, 2, \"(freq1 freq2 wavetable --> out) band limited hard sync wave table oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(par, 2, \"(freq phase --> out) band limited parabolic wave oscillator.\")\n\tDEFMCX(tri, 2, \"(freq phase --> out) band limited triangle wave oscillator.\")\n\tDEFMCX(square, 2, \"(freq phase --> out) band limited square wave oscillator.\")\n\tDEFMCX(saw, 2, \"(freq phase --> out) band limited sawtooth wave oscillator.\")\n\tDEFMCX(pulse, 3, \"(freq phase duty --> out) band limited pulse wave oscillator.\")\n\tDEFMCX(vsaw, 3, \"(freq phase duty --> out) band limited variable sawtooth oscillator.\")\n\tDEFMCX(ssaw, 2, \"(freq1 freq2 --> out) band limited hard sync sawtooth oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(blip, 3, \"(freq phase numharms --> out) band limited impulse oscillator.\")\n\tDEFMCX(dsf1, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 1\")\n\tDEFMCX(dsf3, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) two sided bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 3\")\n\t\n\tDEFMCX(lftri, 2, \"(freq phase --> out) non band limited triangle wave oscillator.\")\n\tDEFMCX(lfsaw, 2, \"(freq phase --> out) non band limited sawtooth wave oscillator.\")\n\tDEFMCX(lfpulse, 3, \"(freq phase duty --> out) non band limited unipolar pulse wave oscillator.\")\n\tDEFMCX(lfpulseb, 3, \"(freq phase duty --> out) non band limited bipolar pulse wave oscillator.\")\n\tDEFMCX(lfsquare, 2, \"(freq phase --> out) non band limited square wave oscillator.\")\n\tDEFMCX(impulse, 2, \"(freq phase --> out) non band limited single sample impulse train oscillator.\")\n\tDEFMCX(smoothsaw, 3, \"(freq phase nth --> out) smoothed sawtooth.\")\n\tDEFMCX(smoothsawpwm, 4, \"(freq phase nth duty --> out) smoothed sawtooth.\")\n\tDEFMCX(vosim, 3, \"(freq phase nth --> out) vosim sim.\")\n\tDEFMCX(sinosc, 2, \"(freq phase --> out) sine wave oscillator.\")\n\tDEFMCX(tsinosc, 2, \"(freq iphase --> out) sine wave oscillator.\")\n\tDEFMCX(sinoscfb, 3, \"(freq phase feedback --> out) sine wave oscillator with self feedback phase modulation\")\n\tDEFMCX(sinoscm, 4, \"(freq phase mul add --> out) sine wave oscillator with multiply and add.\")\n\n\tDEF(klang, 3, 1, \"(freqs amps iphases --> out) a sine oscillator bank. freqs amps and iphases are arrays.\")\n}\n\n\n\n"], ["/sapf/src/MathOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathOps.hpp\"\n#include \"clz.hpp\"\n#include \n#include \"primes.hpp\"\n#include \n\n\n\nV BinaryOp::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpGen(th, this, a, b));\n}\n\nV BinaryOp::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpZGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n}\n\nvoid UnaryOp::loop(Thread& th, int n, V *a, int astride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->unaryOp(th, this);\n\t\ta += astride;\n\t} \n}\n\nvoid BinaryOp::loop(Thread& th, int n, V *a, int astride, V *b, int bstride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, *b);\n\t\ta += astride;\n\t\tb += bstride;\n\t} \n}\n\nvoid BinaryOp::loopzv(Thread& th, int n, Z *aa, int astride, V *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa;\n\t\tArg b = *bb; \n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\nvoid BinaryOp::loopvz(Thread& th, int n, V *aa, int astride, Z *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa; \n\t\tArg b = *bb;\n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\n\nvoid BinaryOp::scan(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = x = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::pairs(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, x);\n\t\tx = *a;\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::reduce(Thread& th, int n, V& z, V *a, int astride)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tx = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\n\nvoid UnaryOpZGen::pull(Thread& th) {\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ *a;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, out);\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nvoid BinaryOpZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\nvoid BinaryOpLinkZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_b.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else if (_b(th, n,bstride, b)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nstatic void DoPairwise(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new PairsOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new PairsOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoScan(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new ScanOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new ScanOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIPairwise(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IPairsOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IPairsOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoIScan(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IScanOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IScanOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z, *x;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = kDefaultVBlockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = 0., *x;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = th.rate.blockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reducez(n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z = b, *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\twhile(1) {\n\t\t\tn = kDefaultVBlockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = b.asFloat(), *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\twhile(1) {\n\t\t\tn = th.rate.blockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reducez(n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n#define UNARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.unaryOp(th, &gUnaryOp_##NAME); \\\n\t\tth.push(c); \\\n\t} \\\n\n\n#define BINARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV b = th.pop(); \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.binaryOp(th, &gBinaryOp_##NAME, b); \\\n\t\tth.push(c); \\\n\t} \\\n\tstatic void NAME##_reduce_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoReduce(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_scan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_pairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_iscan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_ipairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\n#define DEFINE_UNOP_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV(NAME, CODE, VVNAME) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *x, int astride, Z *y) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVNAME(y, x, &n); \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *x; y[i] = CODE; x += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV2(NAME, CODE, VVCODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (Z)(CODE); aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_BOOL_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_BOOL_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (CODE) ? 1. : 0.; \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n\n\n\n\n\n#define DEFINE_BINOP_FLOAT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOAT_STRING(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE); \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOATVV(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tVVCODE; \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_FLOATVV1(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tif (astride == 1 && bstride == 1) { \\\n\t\t\t\t VVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t\t} \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_INT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa, double bb) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\tint64_t b = (int64_t)bb; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; int64_t b = (int64_t)*bb; out[i] = (Z)(CODE); aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t b = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = (Z)b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; Z x = CODE; out[i] = x; a = (int64_t)x; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; a = (int64_t)(CODE); aa += astride; } \\\n\t\t\tz = (Z)a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_BOOL_FLOAT(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = (CODE) ? 1. : 0.; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE) ? 1. : 0.; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\nDEFINE_UNOP_BOOL_INT(isalnum, isalnum((int)a))\nDEFINE_UNOP_BOOL_INT(isalpha, isalpha((int)a))\nDEFINE_UNOP_BOOL_INT(isblank, isblank((int)a))\nDEFINE_UNOP_BOOL_INT(iscntrl, iscntrl((int)a))\nDEFINE_UNOP_BOOL_INT(isdigit, isdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isgraph, isgraph((int)a))\nDEFINE_UNOP_BOOL_INT(islower, islower((int)a))\nDEFINE_UNOP_BOOL_INT(isprint, isprint((int)a))\nDEFINE_UNOP_BOOL_INT(ispunct, ispunct((int)a))\nDEFINE_UNOP_BOOL_INT(isspace, isspace((int)a))\nDEFINE_UNOP_BOOL_INT(isupper, isupper((int)a))\nDEFINE_UNOP_BOOL_INT(isxdigit, isxdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isascii, isascii((int)a))\n\nDEFINE_UNOP_BOOL_FLOAT(not, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonneg, a >= 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonpos, a <= 0.)\nDEFINE_UNOP_BOOL_FLOAT(isneg, a < 0.)\nDEFINE_UNOP_BOOL_FLOAT(ispos, a > 0.)\nDEFINE_UNOP_BOOL_FLOAT(iszero, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(isint, (a - floor(a)) == 0.)\nDEFINE_UNOP_BOOL_INT(iseven, !(a & 1))\nDEFINE_UNOP_BOOL_INT(isodd, (a & 1))\nDEFINE_UNOP_BOOL_INT(isprime, isprime(a))\n\nDEFINE_UNOP_BOOL_FLOAT(isfinite, std::isfinite(a))\nDEFINE_UNOP_BOOL_FLOAT(isinf, std::isinf(a))\nDEFINE_UNOP_BOOL_FLOAT(isnormal, std::isnormal(a))\nDEFINE_UNOP_BOOL_FLOAT(isnan, std::isnan(a))\nDEFINE_UNOP_BOOL_FLOAT(signbit, std::signbit(a))\n\nstruct UnaryOp_ToZero : public UnaryOp {\n\tvirtual const char *Name() { return \"ToZero\"; }\n\tvirtual double op(double a) { return 0.; }\n\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) {\n\t\tLOOP(i,n) { out[i] = 0.; }\n\t}\n};\nUnaryOp_ToZero gUnaryOp_ToZero; \n\nDEFINE_UNOP_FLOATVV2(neg, -a, vDSP_vnegD(const_cast(aa), astride, out, 1, n))\nDEFINE_UNOP_FLOAT(sgn, sc_sgn(a))\nDEFINE_UNOP_FLOATVV(abs, fabs(a), vvfabs)\n\nDEFINE_UNOP_INT(tolower, tolower((int)a))\nDEFINE_UNOP_INT(toupper, toupper((int)a))\nDEFINE_UNOP_INT(toascii, toascii((int)a))\n\nDEFINE_UNOP_FLOATVV2(frac, a - floor(a), vvfloor(out, aa, &n); vDSP_vsubD(out, 1, aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV(floor, floor(a), vvfloor)\nDEFINE_UNOP_FLOATVV(ceil, ceil(a), vvceil)\nDEFINE_UNOP_FLOATVV(rint, rint(a), vvnint)\n\nDEFINE_UNOP_FLOAT(erf, erf(a))\nDEFINE_UNOP_FLOAT(erfc, erfc(a))\n\nDEFINE_UNOP_FLOATVV(recip, 1./a, vvrec)\nDEFINE_UNOP_FLOATVV(sqrt, sc_sqrt(a), vvsqrt)\nDEFINE_UNOP_FLOATVV(rsqrt, 1./sc_sqrt(a), vvrsqrt)\nDEFINE_UNOP_FLOAT(cbrt, cbrt(a))\nDEFINE_UNOP_FLOATVV2(ssq, copysign(a*a, a), vDSP_vssqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV2(sq, a*a, vDSP_vsqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOAT(cb, a*a*a)\nDEFINE_UNOP_FLOAT(pow4, sc_fourth(a))\nDEFINE_UNOP_FLOAT(pow5, sc_fifth(a))\nDEFINE_UNOP_FLOAT(pow6, sc_sixth(a))\nDEFINE_UNOP_FLOAT(pow7, sc_seventh(a))\nDEFINE_UNOP_FLOAT(pow8, sc_eighth(a))\nDEFINE_UNOP_FLOAT(pow9, sc_ninth(a))\n\nDEFINE_UNOP_FLOATVV(exp, exp(a), vvexp)\nDEFINE_UNOP_FLOATVV(exp2, exp2(a), vvexp2)\nDEFINE_UNOP_FLOAT(exp10, pow(10., a))\nDEFINE_UNOP_FLOATVV(expm1, expm1(a), vvexpm1)\nDEFINE_UNOP_FLOATVV(log, sc_log(a), vvlog)\nDEFINE_UNOP_FLOATVV(log2, sc_log2(a), vvlog2)\nDEFINE_UNOP_FLOATVV(log10, sc_log10(a), vvlog10)\nDEFINE_UNOP_FLOATVV(log1p, log1p(a), vvlog1p)\nDEFINE_UNOP_FLOATVV(logb, logb(a), vvlogb)\n\nDEFINE_UNOP_FLOAT(sinc, sc_sinc(a))\n\nDEFINE_UNOP_FLOATVV(sin, sin(a), vvsin)\nDEFINE_UNOP_FLOATVV(cos, cos(a), vvcos)\nDEFINE_UNOP_FLOATVV2(sin1, sin(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvsin(out, out, &n))\nDEFINE_UNOP_FLOATVV2(cos1, cos(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvcos(out, out, &n))\nDEFINE_UNOP_FLOATVV(tan, tan(a), vvtan)\nDEFINE_UNOP_FLOATVV(asin, asin(a), vvasin)\nDEFINE_UNOP_FLOATVV(acos, acos(a), vvacos)\nDEFINE_UNOP_FLOATVV(atan, atan(a), vvatan)\nDEFINE_UNOP_FLOATVV(sinh, sinh(a), vvsinh)\nDEFINE_UNOP_FLOATVV(cosh, cosh(a), vvcosh)\nDEFINE_UNOP_FLOATVV(tanh, tanh(a), vvtanh)\nDEFINE_UNOP_FLOATVV(asinh, asinh(a), vvasinh)\nDEFINE_UNOP_FLOATVV(acosh, acosh(a), vvacosh)\nDEFINE_UNOP_FLOATVV(atanh, atanh(a), vvatanh)\n\nDEFINE_UNOP_FLOAT(J0, j0(a))\nDEFINE_UNOP_FLOAT(J1, j1(a))\nDEFINE_UNOP_FLOAT(Y0, y0(a))\nDEFINE_UNOP_FLOAT(Y1, y1(a))\n\nDEFINE_UNOP_FLOAT(tgamma, tgamma(a))\nDEFINE_UNOP_FLOAT(lgamma, lgamma(a))\n\nstatic void sc_clipv(int n, const Z* in, Z* out, Z a, Z b)\n{\n\tfor (int i = 0; i < n; ++i) {\n\t\tout[i] = std::clamp(in[i], a, b);\n\t}\n}\n\nDEFINE_UNOP_FLOATVV2(inc, a+1, Z b = 1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(dec, a-1, Z b = -1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(half, a*.5, Z b = .5; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(twice, a*2., Z b = 2.; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n))\n\n\nDEFINE_UNOP_FLOATVV2(biuni, a*.5+.5, Z b = .5; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibi, a*2.-1., Z b = 2.; Z c = -1.; vDSP_vsmulD(aa, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOATVV2(biunic, std::clamp(a,-1.,1.)*.5+.5, Z b = .5; sc_clipv(n, aa, out, -1., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibic, std::clamp(a,0.,1.)*2.-1., Z b = 2.; Z c = -1.; sc_clipv(n, aa, out, 0., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOAT(cmpl, 1.-a)\n\nDEFINE_UNOP_FLOATVV2(ampdb, sc_ampdb(a), Z b = 1.; vDSP_vdbconD(const_cast(aa), astride, &b, out, 1, n, 1))\nDEFINE_UNOP_FLOAT(dbamp, sc_dbamp(a))\n\nDEFINE_UNOP_FLOAT(hzo, sc_hzoct(a))\nDEFINE_UNOP_FLOAT(ohz, sc_octhz(a))\n\nDEFINE_UNOP_FLOAT(hzst, sc_hzkey(a))\nDEFINE_UNOP_FLOAT(sthz, sc_keyhz(a))\n\nDEFINE_UNOP_FLOAT(hznn, sc_hznn(a))\nDEFINE_UNOP_FLOAT(nnhz, sc_nnhz(a))\n\nDEFINE_UNOP_FLOAT(centsratio, sc_centsratio(a))\nDEFINE_UNOP_FLOAT(ratiocents, sc_ratiocents(a))\n\nDEFINE_UNOP_FLOAT(semiratio, sc_semiratio(a))\nDEFINE_UNOP_FLOAT(ratiosemi, sc_ratiosemi(a))\n\nDEFINE_UNOP_FLOATVV2(degrad, a*kDegToRad, Z b = kDegToRad; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(raddeg, a*kRadToDeg, Z b = kRadToDeg; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(minsec, a*kMinToSecs, Z b = kMinToSecs; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(secmin, a*kSecsToMin, Z b = kSecsToMin; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(bpmsec, kMinToSecs / a, Z b = kMinToSecs; vDSP_svdivD(&b, const_cast(aa), astride, out, 1, n))\n\nDEFINE_UNOP_FLOAT(distort, sc_distort(a))\nDEFINE_UNOP_FLOAT(softclip, sc_softclip(a))\n\nDEFINE_UNOP_FLOAT(rectWin, sc_rectWindow(a))\nDEFINE_UNOP_FLOAT(triWin, sc_triWindow(a))\nDEFINE_UNOP_FLOAT(bitriWin, sc_bitriWindow(a))\nDEFINE_UNOP_FLOAT(hanWin, sc_hanWindow(a))\nDEFINE_UNOP_FLOAT(sinWin, sc_sinWindow(a))\nDEFINE_UNOP_FLOAT(ramp, sc_ramp(a))\nDEFINE_UNOP_FLOAT(scurve, sc_scurve(a))\nDEFINE_UNOP_FLOAT(sigm,\t\ta/sqrt(1.+a*a))\n\nDEFINE_UNOP_FLOAT(zapgremlins, zapgremlins(a))\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nDEFINE_BINOP_BOOL_FLOAT(lt, a < b, strcmp(a, b) < 0)\nDEFINE_BINOP_BOOL_FLOAT(le, a <= b, strcmp(a, b) <= 0)\nDEFINE_BINOP_BOOL_FLOAT(gt, a > b, strcmp(a, b) > 0)\nDEFINE_BINOP_BOOL_FLOAT(ge, a >= b, strcmp(a, b) >= 0)\nDEFINE_BINOP_BOOL_FLOAT(eq, a == b, strcmp(a, b) == 0)\nDEFINE_BINOP_BOOL_FLOAT(ne, a != b, strcmp(a, b) != 0)\nDEFINE_BINOP_FLOAT_STRING(cmp, sc_cmp(a, b), sc_sgn(strcmp(a, b)))\n\nDEFINE_BINOP_FLOATVV1(copysign, copysign(a, b), vvcopysign(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\nDEFINE_BINOP_FLOATVV1(nextafter, nextafter(a, b), vvnextafter(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\n\n// identity optimizations of basic operators.\n\n\tstruct BinaryOp_plus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus gBinaryOp_plus;\n\tBinaryOp* gBinaryOpPtr_plus = &gBinaryOp_plus;\n\tBINARY_OP_PRIM(plus)\n\n\n\tstruct BinaryOp_plus_link : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus_link gBinaryOp_plus_link;\n\tBinaryOp* gBinaryOpPtr_plus_link = &gBinaryOp_plus_link;\n\tBINARY_OP_PRIM(plus_link)\n\n\n\tstruct BinaryOp_minus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"minus\"; }\n\t\tvirtual double op(double a, double b) { return a - b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\tif (*aa != 0.) {\n\t\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, const_cast(aa), out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\tif (*bb != 0.) {\n\t\t\t\t\tZ b = -*bb;\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, &b, out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vsubD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a - b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_minus gBinaryOp_minus;\n\tBinaryOp* gBinaryOpPtr_minus = &gBinaryOp_minus;\n\tBINARY_OP_PRIM(minus)\n\n\n\n\tstruct BinaryOp_mul : public BinaryOp {\n\t\tvirtual const char *Name() { return \"mul\"; }\n\t\tvirtual double op(double a, double b) { return a * b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else if (*aa == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(bb, bstride, aa, out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += astride; }\n\t\t\t\t} else if (*bb == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(aa, astride, bb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a * b; aa += astride; bb += bstride; }\n\t\t\t\tvDSP_vmulD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a * b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_mul gBinaryOp_mul;\n\tBinaryOp* gBinaryOpPtr_mul = &gBinaryOp_mul;\n\tBINARY_OP_PRIM(mul)\n\n\n\tstruct BinaryOp_div : public BinaryOp {\n\t\tvirtual const char *Name() { return \"div\"; }\n\t\tvirtual double op(double a, double b) { return a / b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0 && *aa == 0.) {\n\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tZ rb = 1. / *bb;\n\t\t\t\t\tvDSP_vsmulD(const_cast(aa), astride, &rb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vdivD(const_cast(bb), bstride, const_cast(aa), astride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a / b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a / b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_div gBinaryOp_div;\n\tBinaryOp* gBinaryOpPtr_div = &gBinaryOp_div;\n\tBINARY_OP_PRIM(div)\n\nDEFINE_BINOP_FLOAT(mod, sc_fmod(a, b))\nDEFINE_BINOP_FLOAT(remainder, remainder(a, b))\n\nDEFINE_BINOP_INT(idiv, sc_div(a, b))\nDEFINE_BINOP_INT(imod, sc_imod(a, b))\n\nDEFINE_BINOP_FLOATVV1(pow, sc_pow(a, b), vvpow(out, bb, aa, &n))\nDEFINE_BINOP_FLOATVV1(atan2, atan2(a, b), vvatan2(out, aa, bb, &n))\n\nDEFINE_BINOP_FLOAT(Jn, jn((int)b, a))\nDEFINE_BINOP_FLOAT(Yn, yn((int)b, a))\n\nDEFINE_BINOP_FLOATVV(min, fmin(a, b), vDSP_vminD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOATVV(max, fmax(a, b), vDSP_vmaxD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(dim, fdim(a, b))\nDEFINE_BINOP_FLOAT(xor, fdim(a, b))\n\nDEFINE_BINOP_FLOAT(avg2, (a + b) * .5)\nDEFINE_BINOP_FLOAT(absdif, fabs(a - b))\nDEFINE_BINOP_FLOATVV(hypot, hypot(a, b), vDSP_vdistD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(sumsq, a*a + b*b)\nDEFINE_BINOP_FLOAT(difsq, a*a - b*b)\nDEFINE_BINOP_FLOAT(sqsum, sc_squared(a + b))\nDEFINE_BINOP_FLOAT(sqdif, sc_squared(a - b))\n\nDEFINE_BINOP_FLOAT(thresh, a < b ? 0. : a)\nDEFINE_BINOP_FLOAT(absthresh, fabs(a) < b ? 0. : a)\nDEFINE_BINOP_FLOAT(amclip, b <= 0. ? 0. : a * b)\nDEFINE_BINOP_FLOAT(scaleneg, a < 0. ? a * b : a)\n\nDEFINE_BINOP_FLOAT(ring1, a * b + a)\nDEFINE_BINOP_FLOAT(ring2, a * b + a + b)\nDEFINE_BINOP_FLOAT(ring3, a*a*b)\nDEFINE_BINOP_FLOAT(ring4, a*b*(a - b))\n\nDEFINE_BINOP_INT(gcd, sc_gcd(a, b))\nDEFINE_BINOP_INT(lcm, sc_lcm(a, b))\n\nDEFINE_BINOP_FLOAT(clip2, std::clamp(a, -b, b))\nDEFINE_BINOP_FLOAT(wrap2, sc_wrap(a, -b, b))\nDEFINE_BINOP_FLOAT(fold2, sc_fold(a, -b, b))\nDEFINE_BINOP_INT(iwrap2, sc_iwrap(a, -b, b))\nDEFINE_BINOP_INT(ifold2, sc_ifold(a, -b, b))\nDEFINE_BINOP_FLOAT(excess, a - std::clamp(a, -b, b))\n\nDEFINE_BINOP_FLOAT(clip0, std::clamp(a, 0., b))\nDEFINE_BINOP_FLOAT(wrap0, sc_wrap(a, 0., b))\nDEFINE_BINOP_FLOAT(fold0, sc_fold(a, 0., b))\n\nDEFINE_BINOP_FLOAT(round, sc_round(a, b))\nDEFINE_BINOP_FLOAT(roundUp, sc_roundUp(a, b))\nDEFINE_BINOP_FLOAT(trunc, sc_trunc(a, b))\n\n\n#define DEFN(FUNNAME, OPNAME, HELP) \tvm.def(OPNAME, 1, 1, FUNNAME##_, \"(x --> z) \" HELP);\n#define DEFNa(FUNNAME, OPNAME, HELP) \tDEFN(FUNNAME, #OPNAME, HELP)\n#define DEF(NAME, HELP) \tDEFNa(NAME, NAME, HELP); \n\n#define DEFNa2(FUNNAME, OPNAME, HELP) \t\\\n\t(vm.def(#OPNAME, 2, 1, FUNNAME##_, \"(x y --> z) \" HELP), \\\n\tvm.def(#OPNAME \"/\", 1, 1, FUNNAME##_reduce_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\\", 1, 1, FUNNAME##_scan_, nullptr), \\\n\tvm.def(#OPNAME \"^\", 1, 1, FUNNAME##_pairs_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\i\", 2, 1, FUNNAME##_iscan_, nullptr), \\\n\tvm.def(#OPNAME \"^i\", 1, 1, FUNNAME##_ipairs_, nullptr));\n\n#define DEF2(NAME, HELP) \tDEFNa2(NAME, NAME, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMathOps();\nvoid AddMathOps()\n{\t\n\tfillSineTable();\n\tfillDBAmpTable();\n\tfillDecayTable();\n fillFirstOrderCoeffTable();\n\n\tvm.addBifHelp(\"\\n*** unary math ops ***\");\n\tDEF(isalnum, \"return whether an ASCII value is alphanumeric.\")\n\tDEF(isalpha, \"return whether an ASCII value is alphabetic.\")\n\tDEF(isblank, \"return whether an ASCII value is a space or tab character.\")\n\tDEF(iscntrl, \"return whether an ASCII value is a control character.\")\n\tDEF(isdigit, \"return whether an ASCII value is a digit.\")\n\tDEF(isgraph, \"return whether an ASCII value is a graphic character.\");\n\tDEF(islower, \"return whether an ASCII value is lower case.\")\n\tDEF(isprint, \"return whether an ASCII value is a printable character.\")\n\tDEF(ispunct, \"return whether an ASCII value is a punctuation character.\")\n\tDEF(isspace, \"return whether an ASCII value is a graphic character.\")\n\tDEF(isupper, \"return whether an ASCII value is upper case.\")\n\tDEF(isxdigit, \"return whether an ASCII value is a hexadecimal digit.\")\n\tDEF(isascii, \"return whether a value is ASCII\")\n\n\tDEF(tolower, \"convert an ASCII character value to lower case.\")\n\tDEF(toupper, \"convert an ASCII character value to upper case.\")\n\tDEF(toascii, \"convert a value to ASCII by stripping the upper bits.\")\n\n\tDEFN(nonpos, \"0<=\", \"less than or equal to zero.\")\n\tDEFN(nonneg, \"0>=\", \"greater than or equal to zero.\")\n\tDEFN(isneg, \"0<\", \"less than zero.\")\n\tDEFN(ispos, \"0>\", \"greater than zero.\")\n\tDEFN(iszero, \"0=\", \"equal to zero.\")\n\tDEFN(iseven, \"even?\", \"is even.\")\n\tDEFN(isodd, \"odd?\", \"is odd.\")\n\tDEFN(isprime, \"prime?\", \"is prime.\")\n\tDEFN(isint, \"int?\", \"is integer.\")\n\t\n\tDEF(isfinite, \"is x a finite number.\")\n\tDEF(isinf, \"is x an infinity.\")\n\tDEF(isnan, \"is x not a number.\")\n\tDEF(isnormal, \"is x a normalized number (as opposed to denormals).\")\n\tDEF(signbit, \"sign bit of x.\")\n\t\t\n\tDEF(abs, \"absolute value.\")\n\tDEF(sgn, \"signum function. returns -1 when x < 0, 0 when x == 0, 1 when x > 0.\")\n\tDEFN(not, \"~\", \"logical negation. returns 1 when x == 0, else returns 0.\")\n\tDEF(neg, \"negative. -x\")\n\tDEF(sqrt, \"square root.\")\n\tDEF(cbrt, \"cube root.\")\n\tDEF(rsqrt, \"reciprocal square root.\")\n\tDEF(sq, \"square. x x *\")\n\tDEF(ssq, \"signed square. x x abs *\")\n\tDEF(cb, \"x cubed. x 3 ^\")\n\tDEFN(sq, \"^2\", \"x squared. x x *\")\n\tDEFN(cb, \"^3\", \"x cubed. x 3 ^\")\n\tDEFN(pow4, \"^4\", \"x to the fourth power. x 4 ^\")\n\tDEFN(pow5, \"^5\", \"x to the fifth power. x 5 ^\")\n\tDEFN(pow6, \"^6\", \"x to the sixth power. x 6 ^\")\n\tDEFN(pow7, \"^7\", \"x to the seventh power. x 7 ^\")\n\tDEFN(pow8, \"^8\", \"x to the eighth power. x 8 ^\")\n\tDEFN(pow9, \"^9\", \"x to the ninth power. x 9 ^\")\n\n\tDEF(recip, \"reciprocal.\")\n\tDEFN(recip, \"1/\", \"reciprocal. 1 x /\")\n\tDEF(exp, \"e to the x.\")\n\tDEF(exp2, \"2 to the x.\")\n\tDEF(exp10, \"10 to the x.\")\n\tDEFN(exp, \"e^\", \"e to the x.\")\n\tDEFN(exp2, \"2^\", \"2 to the x.\")\n\tDEFN(exp10, \"10^\", \"10 to the x.\")\n\tDEF(expm1, \"computes exp(x-1) accurately even for very small values of x.\")\n\tDEF(log, \"base e log of x.\")\n\tDEF(log2, \"base 2 log of x.\")\n\tDEF(log10, \"base 10 log of x.\")\n\tDEF(log1p, \"computes the value of log(1+x) accurately even for very small values of x.\")\n\tDEF(logb, \"x log2 floor\")\n\n\tDEF(frac, \"fractional part.\")\n\tDEF(floor, \"nearest integer <= x.\")\n\tDEF(ceil, \"nearest integer >= x.\")\n\tDEF(rint, \"nearest integer.\")\n\tDEF(erf, \"the error function.\")\n\tDEF(erfc, \"the complement of the error function.\")\n\n\tDEF(sinc, \"sinc. x sin x /\")\n\tDEF(sin, \"sine.\")\n\tDEF(cos, \"cosine.\")\n\tDEF(sin1, \"sine(x * 2pi).\")\n\tDEF(cos1, \"cosine(x * 2pi).\")\n\tDEF(tan, \"tangent.\")\n\tDEF(asin, \"arcsine.\")\n\tDEF(acos, \"arccosine.\")\n\tDEF(atan, \"arctangent.\")\n\tDEF(sinh, \"hyperbolic sine.\")\n\tDEF(cosh, \"hyperbolic cosine.\")\n\tDEF(tanh, \"hyperbolic tangent.\")\n\tDEF(asinh, \"hyperbolic arcsine.\")\n\tDEF(acosh, \"hyperbolic arccosine.\")\n\tDEF(atanh, \"hyperbolic arctangent.\")\n\t\n\tDEF(J0, \"zeroth Bessel function of the first kind evaluated at x.\")\n\tDEF(J1, \"first Bessel function of the first kind evaluated at x.\")\n\tDEF(Y0, \"zeroth Bessel function of the second kind evaluated at x.\")\n\tDEF(Y1, \"first Bessel function of the second kind evaluated at x.\")\n\n\tDEF(tgamma, \"the gamma function.\")\n\tDEF(lgamma, \"natural logarithm of the absolute value of the gamma function.\")\n\n\tDEF(inc, \"increment. x 1 +\")\n\tDEF(dec, \"decrement. x 1 -\")\n\tDEF(half, \"x .5 *\")\n\tDEF(twice, \"x 2 *\")\n\tDEFN(inc, \"++\", \"increment. x 1 +\")\n\tDEFN(dec, \"--\", \"decrement. x 1 -\")\n\tDEFN(half, \"/2\", \"half.\")\n\tDEFN(twice, \"*2\", \"twice.\")\n\tDEF(biuni, \"convert bipolar to unipolar. .5 * .5 +\")\n\tDEF(unibi, \"convert unipolar to bipolar. 2 * 1 -\")\n\tDEF(biunic, \"convert bipolar to unipolar with clipping to range. -1 1 clip .5 * .5 +\")\n\tDEF(unibic, \"convert unipolar to bipolar with clipping to range. 0 1 clip 2 * 1 -\")\n\tDEF(cmpl, \"unipolar complement. 1 x -\")\n\n\tDEF(ampdb, \"convert linear amplitude to decibels.\")\n\tDEF(dbamp, \"convert decibels to linear amplitude.\")\n\t\n\tDEF(ohz, \"convert octaves to Hertz. Octave 0.0 is middle C.\")\n\tDEF(hzo, \"convert Hertz to octaves. Octave 0.0 is middle C.\")\n\tDEF(nnhz, \"convert MIDI note numbers to Hertz. 60 is middle C.\")\n\tDEF(hznn, \"convert Hertz to MIDI note numbers. 60 is middle C.\")\n\n\tDEF(centsratio, \"convert an interval in cents to a ratio.\")\n\tDEF(ratiocents, \"convert a ratio to an interval in cents.\")\n\n\tDEF(semiratio, \"convert an interval in semitones to a ratio.\")\n\tDEF(ratiosemi, \"a ratio to an interval in semitones.\")\n\n\tDEF(minsec, \"convert from minutes to seconds. also for converting from bps to bpm\")\n\tDEF(secmin, \"convert from seconds to minutes. also for converting from bpm to bps.\")\n\tDEF(bpmsec, \"convert from beats per minute to a period in seconds(e.g. for delay times)\")\n\tDEF(degrad, \"convert from degrees to radians.\")\n\tDEF(raddeg, \"convert from radians to degrees.\")\n\n\tDEF(distort, \"sigmoid wave distortion function. x/sqrt(1 + x^2)\")\n\tDEF(softclip, \"sigmoid wave distortion function. returns x when abs(x) < .5, else returns (abs(x) - .25) / x\")\n\tDEF(sigm, \"sigmoid wave distortion function. x/sqrt(1+x*x).\")\n\n\tDEF(rectWin, \"rectangular window for x in the interval [0,1].\")\n\tDEF(triWin, \"triangular window for x in the interval [0,1].\")\n\tDEF(bitriWin, \"triangular window for x in the interval [-1,1]\")\n\tDEF(hanWin, \"hanning window for x in the interval [0,1]\")\n\tDEF(sinWin, \"sine window for x in the interval [0,1]\")\n\tDEF(ramp, \"return 0 when x <= 0, return x when 0 < x < 1, return 1 when x > 1.\")\n\tDEF(scurve, \"return 0 when x <= 0, return 3*x*x - 2*x*x*x when 0 < x < 1, return 1 when x > 1.\")\n\n\tDEF(zapgremlins, \"\")\n\n\t/////////////////////////////////////////////////////\n\n\tvm.addBifHelp(\"\\n*** binary math ops ***\");\n\tvm.addBifHelp(\"\\n All built-in binary math operators have the following variations defined:\");\n\tvm.addBifHelp(\" op/ (list --> z) reducing math operator.\");\n\tvm.addBifHelp(\" op\\\\ (list --> z) scanning math operator.\");\n\tvm.addBifHelp(\" op^ (list --> z) pairwise math operator.\");\n\tvm.addBifHelp(\" op/i (list init --> z) reducing math operator with initial value.\");\n\tvm.addBifHelp(\" op\\\\i (list init --> z) scanning math operator with initial value.\");\n\tvm.addBifHelp(\" op^i (list init --> z) pairwise math operator with initial value.\");\n\tvm.addBifHelp(\" For example, + has the following variations: +/ +\\\\ +^ +/i +\\\\i +^i\");\n\tvm.addBifHelp(\"\");\n\t\n\n\tvm.plusFun = DEFNa2(plus, +, \"addition.\")\n\tDEFNa2(plus_link, +>, \"addition. For lists, acts as if shorter list were extended with zeroes.\")\n\tDEFNa2(minus, -, \"subtraction.\")\n\tvm.mulFun = DEFNa2(mul, *, \"multiplication.\")\n\tDEFNa2(div, /, \"real division.\")\n\tDEFNa2(mod, %, \"modulo.\")\n\tDEF2(idiv, \"integer division.\")\n\tDEF2(imod, \"integer modulo.\")\n\tDEF2(remainder, \"remainder.\")\n\n\tDEFNa2(lt, <, \"less than.\")\n\tDEFNa2(le, <=, \"less than or equal.\")\n\tDEFNa2(gt, >, \"greater than.\")\n\tDEFNa2(ge, >=, \"greater than or equal.\")\n\tDEFNa2(eq, ==, \"equal.\")\n\tDEFNa2(ne, !=, \"not equal.\")\n\n\tDEF2(cmp, \"returns -1 when x < y, returns 1 when x > y, returns 0 when x == y.\")\n\n\tDEF2(copysign, \"copy the sign of y to the value of x.\")\n\tDEF2(nextafter, \"return the next machine representable number from x in direction y.\")\n\n\tDEF2(pow, \"x to the power y.\")\n\tDEFNa2(pow, ^, \"x to the power y.\")\n\tDEF2(atan2, \"arctangent of y/x.\")\n\t\n\tDEF2(Jn, \"yth Bessel function of the first kind evaluated at x.\")\n\tDEF2(Yn, \"yth Bessel function of the second kind evaluated at x.\")\n\n\tvm.minFun = DEFNa2(min, &, \"return the minimum of x and y. functions as logical AND.\")\n\tvm.maxFun = DEFNa2(max, |, \"return the maximum of x and y. functions as logical OR.\")\n\n\tDEF2(avg2, \"x y + .5 *\")\n\tDEF2(dim, \"positive difference of x and y. x y - 0 |\")\n\tDEF2(absdif, \"x y - abs\")\n\tDEF2(hypot, \"x sq y sq + sqrt\")\n\tDEF2(sumsq, \"x sq y sq +\")\n\tDEF2(difsq, \"x sq y sq -\")\n\tDEF2(sqsum, \"x y + sq\")\n\tDEF2(sqdif, \"x y - sq\")\n\n\tDEF2(thresh, \"returns 0 when x < y, else returns x.\")\n\tDEF2(absthresh, \"returns 0 when |x| < y, else returns x.\")\n\tDEF2(amclip, \"returns 0 when y <= 0, else returns x*y.\")\n\tDEF2(scaleneg, \"returns x*y when x < 0, else returns x.\")\n\n\tDEF2(ring1, \"x y * x +\")\n\tDEF2(ring2, \"x y * x + y +\")\n\tDEF2(ring3, \"x sq y *\")\n\tDEF2(ring4, \"x y * x y - *\")\n\n\tDEF2(gcd, \"greatest common divisor.\")\n\tDEF2(lcm, \"least common multiple.\")\n\n\tDEF2(clip0, \"clip x between 0 and y.\")\n\tDEF2(wrap0, \"wrap x between 0 and y.\")\n\tDEF2(fold0, \"fold x between 0 and y.\")\n\n\tDEF2(clip2, \"clip x between -y and y.\")\n\tDEF2(wrap2, \"wrap x between -y and y.\")\n\tDEF2(fold2, \"fold x between -y and y.\")\n\tDEF2(iwrap2, \"wrap integer x between -y and y.\")\n\tDEF2(ifold2, \"fold integer x between -y and y.\")\n\tDEF2(excess, \"return the excess after clipping. x x y clip2 -\")\n\n\tDEF2(round, \"round x to nearest multiple of y.\")\n\tDEF2(roundUp, \"round x to nearest multiple of y >= x.\")\n\tDEF2(trunc, \"round x to nearest multiple of y <= x\")\n\n}\n\n"], ["/sapf/src/SetOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n\nstruct SetPair\n{\n\tV mValue;\n\tint mIndex;\n};\n\nclass Set : public Object\n{\n\tint mSize;\n\tint mCap;\n\tint* mIndices;\n\tSetPair* mPairs;\n\t\n\tvoid grow(Thread& th);\n\tvoid alloc(int cap);\n \n\tSet(const Set& that) {}\npublic:\n\t\n\tSet(int capacity) { alloc(capacity); }\n Set(Thread& th, P list) { alloc(32); putAll(th, list); }\n \n\tvirtual ~Set();\n\t\n\tvirtual const char* TypeName() const override { return \"Set\"; }\n \n\tvirtual bool isSet() const override { return true; }\n\tvirtual bool Equals(Thread& th, Arg v) override;\n\t\n\tint size() { return mSize; }\n\t\n\tbool has(Thread& th, V& value);\n int indexOf(Thread& th, V& value);\n\t\n\tvoid put(Thread& th, V& inValue, int inIndex);\n \n void putAll(Thread& th, P& list);\n\t\n\tvirtual V at(int64_t i) override { return mPairs[i].mValue; }\n \n P asVList(Thread& th);\n P asZList(Thread& th);\n};\n\n\nbool Set::Equals(Thread& th, Arg v) \n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isSet()) return false;\n\tif (this == v.o()) return true;\n\tSet* that = (Set*)v.o();\n\tif (mSize != that->size()) return false;\n \n\tfor (int64_t i = 0; i < mSize; ++i) {\n\t\tV& value = mPairs[i].mValue;\n\t\tV u;\n\t\tif (!that->has(th, value)) return false;\n\t}\n \n\treturn true;\n}\n\nbool Set::has(Thread& th, V& value) \n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn false;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn true;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn false;\n}\n\nint Set::indexOf(Thread& th, V& value)\n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn -1;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn pairs[index2].mIndex;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn -1;\n}\n\n\nSet::~Set()\n{\n\tdelete [] mPairs;\n\tfree(mIndices);\n}\n\nvoid Set::alloc(int cap)\n{\n\tcap = NEXTPOWEROFTWO(cap);\n\tmPairs = new SetPair[cap];\n\tmIndices = (int*)calloc(2 * cap, sizeof(int));\n\tmCap = cap;\n\tmSize = 0;\n}\n\nvoid Set::grow(Thread& th)\n{\n\tfree(mIndices);\n \n\tSetPair* oldPairs = mPairs;\n\tint oldSize = mSize;\n \n\talloc(mCap * 2);\n\t\n\tfor (int i = 0; i < oldSize; ++i) {\n\t\tSetPair& pair = oldPairs[i];\n\t\tput(th, pair.mValue, pair.mIndex);\n\t}\n\t\n\tdelete [] oldPairs;\n}\n\nvoid Set::put(Thread& th, V& inValue, int inIndex)\n{\n\tif (mSize == mCap) {\n\t\tgrow(th);\n\t}\n \n\tint hash = inValue.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n \n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\tindex2 = mSize++;\n\t\t\tindices[index] = index2+1;\n\t\t\tpairs[index2].mValue = inValue;\n\t\t\tpairs[index2].mIndex = inIndex;\n\t\t\treturn;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (inValue.Equals(th, testVal)) {\n\t\t\treturn;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\n}\n\nvoid Set::putAll(Thread& th, P& in)\n{\n // caller must ensure that in is finite.\n int64_t insize = in->length(th);\n in = in->pack(th);\n for (int i = 0; i < insize; ++i) {\n V val = in->at(i);\n put(th, val, i);\n }\n}\n\n\nP Set::asVList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeV, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nP Set::asZList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeZ, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nstatic P nub(Thread& th, P in)\n{\n P set = new Set(th, in);\n \n return set->asVList(th);\n}\n\n\nstatic P set_or(Thread& th, P a, P b)\n{\n P set = new Set(32);\n\n set->putAll(th, a);\n set->putAll(th, b);\n return a->isZ() && b->isZ() ? set->asZList(th) : set->asVList(th);\n}\n\nstatic P set_and(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_minus(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_xor(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n for (int64_t i = 0; i < setB->size(); ++i) {\n V v = setB->at(i);\n if (!setA->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic bool subset(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) return false;\n }\n\t\n\treturn true;\n}\n\nstatic bool set_equals(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n\treturn setA->Equals(th, setB);\n}\n\n/* \n \n list minus values from set.\n \n \n \n\n \n \n \n*/\n\n\nstatic void nub_(Thread& th, Prim* prim)\n{\n P a = th.popList(\"nub : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"nub : a\", \"\");\n \n th.push(nub(th, a));\n}\n\nstatic void set_or_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"|| : b\");\n if (!b->isFinite())\n indefiniteOp(\"|| : b\", \"\");\n \n P a = th.popList(\"|| : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"|| : a\", \"\");\n \n th.push(set_or(th, a, b));\n}\n\nstatic void set_and_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"&& : b\");\n if (!b->isFinite())\n indefiniteOp(\"&& : b\", \"\");\n \n P a = th.popList(\"&& : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"&& : a\", \"\");\n \n th.push(set_and(th, a, b));\n}\n\n\nstatic void set_xor_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_xor : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_xor : b\", \"\");\n \n P a = th.popList(\"set_xor : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_xor : a\", \"\");\n \n th.push(set_xor(th, a, b));\n}\n\nstatic void set_minus_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_minus : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_minus : b\", \"\");\n \n P a = th.popList(\"set_minus : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_minus : a\", \"\");\n \n th.push(set_minus(th, a, b));\n}\n\nstatic void subset_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"subset : b\");\n if (!b->isFinite())\n indefiniteOp(\"subset : b\", \"\");\n \n P a = th.popList(\"subset : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"subset : a\", \"\");\n \n th.pushBool(subset(th, a, b));\n}\n\n\nstatic void set_equals_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_equals : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_equals : b\", \"\");\n \n P a = th.popList(\"set_equals : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_equals : a\", \"\");\n \n th.push(set_equals(th, a, b));\n}\n\nstruct FindV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tFindV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->indexOf(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct FindZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tFindZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeZ, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->indexOf(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct SetHasV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tSetHasV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->has(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct SetHasZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tSetHasZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->has(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic V findBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new FindZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new FindV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->indexOf(th, a);\n\t}\n\treturn result;\n}\n\nstatic void find_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"find : list\");\n if (!b->isFinite())\n indefiniteOp(\"find : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(findBase(th, a, setB));\n}\n\nstatic V hasBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new SetHasZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new SetHasV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->has(th, a);\n\t}\n\treturn result;\n}\n\nstatic void sethas_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"Shas : list\");\n if (!b->isFinite())\n indefiniteOp(\"Shas : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(hasBase(th, a, setB));\n}\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddSetOps();\nvoid AddSetOps()\n{\n\tvm.addBifHelp(\"\\n*** set operations ***\");\n vm.def(\"S\", 1, 1, nub_, \"(list --> set) removes all duplicates from a finite list.\");\n vm.def(\"S|\", 2, 1, set_or_, \"(listA listB --> set) returns the set union of the elements of lists A and B.\");\n vm.def(\"S&\", 2, 1, set_and_, \"(listA listB --> set) returns the set intersection of the elements of lists A and B.\");\n vm.def(\"Sx\", 2, 1, set_xor_, \"(listA listB --> set) returns the set of the elements which occur in list A or B, but not both.\");\n vm.def(\"S-\", 2, 1, set_minus_, \"(listA listB --> set) returns the set of the elements of listA which do not occur in listB.\");\n vm.def(\"S=\", 2, 1, set_equals_, \"(listA listB --> set) returns 1 if the set of elements in listA is equal to the set of elements in listB.\");\n vm.def(\"subset?\", 2, 1, subset_, \"(listA listB --> set) returns 1 if the set of elements of listA is a subset of the set of elements of listB. else 0.\");\n vm.def(\"find\", 2, 1, find_, \"(item(s) list --> set) returns index of item in finite list, or -1 if not in list.\");\n vm.def(\"Shas\", 2, 1, sethas_, \"(item(s) list --> set) returns 1 if finite list contains item(s), else 0.\");\n}\n\n\n\n\n\n\n"], ["/sapf/src/Play.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Play.hpp\"\n#include \n#include \n#include \n\n#include \"SoundFiles.hpp\"\n\npthread_mutex_t gPlayerMutex = PTHREAD_MUTEX_INITIALIZER;\n\nconst int kMaxChannels = 32;\n\nstruct AUPlayer* gAllPlayers = nullptr;\n\n\n\nstruct AUPlayer\n{\n\tAUPlayer(Thread& inThread, int inNumChannels, ExtAudioFileRef inXAFRef = nullptr)\n\t\t: th(inThread), count(0), done(false), prev(nullptr), next(gAllPlayers), outputUnit(nullptr), numChannels(inNumChannels), xaf(inXAFRef)\n\t{ \n\t\tgAllPlayers = this; \n\t\tif (next) next->prev = this; \n\t}\n\t\n\t~AUPlayer() {\n\t\tif (next) next->prev = prev;\n\n\t\tif (prev) prev->next = next;\n\t\telse gAllPlayers = next;\n\t\t\n\t\tif (xaf) {\n\t\t\tExtAudioFileDispose(xaf);\n\t\t\tchar cmd[1100];\n\t\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path.c_str());\n\t\t\tsystem(cmd);\n\t\t}\n\t}\n\t\n\tThread th;\n\tint count;\n\tbool done;\n\tAUPlayer* prev;\n\tAUPlayer* next;\n\tAudioComponentInstance outputUnit;\n\tint numChannels;\n\tZIn in[kMaxChannels];\n\tExtAudioFileRef xaf = nullptr;\n\tstd::string path;\n\t\n};\n\nstatic void stopPlayer(AUPlayer* player)\n{\n\tAudioComponentInstance outputUnit = player->outputUnit;\n\tplayer->outputUnit = nullptr;\n\tif (outputUnit) {\n\t\n\t\tOSStatus err = AudioOutputUnitStop(outputUnit);\n\t\tif (err) post(\"AudioOutputUnitStop err %d\\n\", (int)err);\n\t\terr = AudioComponentInstanceDispose(outputUnit);\n\t\tif (err) post(\"AudioComponentInstanceDispose outputUnit err %d\\n\", (int)err);\n\t\t\n\t}\n\tdelete player;\n}\n\nvoid stopPlaying()\n{\n\tLocker lock(&gPlayerMutex);\n\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nvoid stopPlayingIfDone()\n{\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tif (player->done)\n\t\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nstatic void* stopDonePlayers(void* x)\n{\n\twhile(1) {\n\t\tsleep(1);\n\t\tstopPlayingIfDone();\n\t}\n\treturn nullptr;\n}\n\nbool gWatchdogRunning = false;\npthread_t watchdog;\n\nstatic bool fillBufferList(AUPlayer* player, int inNumberFrames, AudioBufferList* ioData)\n{\n\tif (player->done) {\nzeroAll:\n\t\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\t\tmemset((float*)ioData->mBuffers[i].mData, 0, inNumberFrames * sizeof(float));\n\t\t}\n\t\treturn true;\n\t}\n\tZIn* in = player->in;\n\tbool done = true;\n\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\tint n = inNumberFrames;\n\t\tif (i >= player->numChannels) {\n\t\t\tmemset(ioData->mBuffers[i].mData, 0, ioData->mBuffers[i].mDataByteSize);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfloat* buf = (float*)ioData->mBuffers[i].mData;\n\t\t\t\tbool imdone = in[i].fill(player->th, n, buf, 1);\n\t\t\t\tif (n < inNumberFrames) {\n\t\t\t\t\tmemset((float*)ioData->mBuffers[i].mData + n, 0, (inNumberFrames - n) * sizeof(float));\n\t\t\t\t}\n\t\t\t\tdone = done && imdone;\n\t\t\t} catch (int err) {\n\t\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t\t} else {\n\t\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t\t}\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (std::bad_alloc& xerr) {\n\t\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (...) {\n\t\t\t\tpost(\"\\nunknown error\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn done;\n}\n\nstatic void recordPlayer(AUPlayer* player, int inNumberFrames, AudioBufferList const* inData)\n{\n\tif (!player->xaf) return;\n\t\t\n\tOSStatus err = ExtAudioFileWriteAsync(player->xaf, inNumberFrames, inData); // initialize async.\n\tif (err) printf(\"ExtAudioFileWriteAsync err %d\\n\", (int)err);\n}\n\nstatic OSStatus inputCallback(\tvoid *\t\t\t\t\t\t\tinRefCon,\n\t\t\t\t\t\tAudioUnitRenderActionFlags *\tioActionFlags,\n\t\t\t\t\t\tconst AudioTimeStamp *\t\t\tinTimeStamp,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinBusNumber,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinNumberFrames,\n\t\t\t\t\t\tAudioBufferList *\t\t\t\tioData)\n{\n\t\n\tAUPlayer* player = (AUPlayer*)inRefCon;\n\t\t\n\tbool done = fillBufferList(player, inNumberFrames, ioData);\n\trecordPlayer(player, inNumberFrames, ioData);\n\n\tif (done) {\n\t\tplayer->done = true;\n\t}\n\treturn noErr;\n}\n\n\nstatic AudioComponentInstance openAU(UInt32 inType, UInt32 inSubtype, UInt32 inManuf)\n{\n AudioComponentDescription desc;\n desc.componentType = inType;\n desc.componentSubType = inSubtype;\n desc.componentManufacturer = inManuf;\n desc.componentFlags = 0;\n desc.componentFlagsMask = 0;\n\n AudioComponent comp = AudioComponentFindNext(nullptr, &desc);\n\tif (!comp) {\n\t\treturn nullptr;\n\t}\n\n AudioComponentInstance au = nullptr;\n AudioComponentInstanceNew(comp, &au);\n\t\n\treturn au;\n}\n\nstatic OSStatus createGraph(AUPlayer* player)\n{\n OSStatus err = noErr;\n\tAudioComponentInstance outputUnit = openAU('auou', 'def ', 'appl');\n\tif (!outputUnit) {\n\t\tpost(\"open output unit failed\\n\");\n\t\treturn 'fail';\n\t}\n\t\n\tplayer->outputUnit = outputUnit;\n\t\n\tUInt32 flags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;\n\tAudioStreamBasicDescription fmt = { vm.ar.sampleRate, kAudioFormatLinearPCM, flags, 4, 1, 4, (UInt32)player->numChannels, 32, 0 };\n\t\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &fmt, sizeof(fmt));\n\tif (err) {\n\t\tpost(\"set outputUnit client format failed\\n\");\n\t\treturn err;\n\t}\n\t\n\tAURenderCallbackStruct cbs;\n\t\t\n\tcbs.inputProc = inputCallback;\n\tcbs.inputProcRefCon = player;\n\t\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &cbs, sizeof(cbs));\n\tif (err) {\n\t\tpost(\"set render callback failed\\n\");\n\t\treturn err;\n\t}\n\t\n\terr = AudioUnitInitialize(outputUnit);\n\tif (err) {\n\t\tpost(\"initialize output unit failed\\n\");\n\t\treturn err;\n\t}\n\t\n\terr = AudioOutputUnitStart(outputUnit);\n\tif (err) {\n\t\tpost(\"start output unit failed\\n\");\n\t\treturn err;\n\t}\n\t\n\tpost(\"start output unit OK\\n\");\n\t\n\treturn noErr;\n}\n\nvoid playWithAudioUnit(Thread& th, V& v)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\t\n\tif (v.isZList()) {\n\t\tplayer = new AUPlayer(th, 1);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint asize = (int)a->size();\n\t\t\n\t\tplayer = new AUPlayer(th, asize);\n\t\tfor (int i = 0; i < asize; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n \n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n\nvoid recordWithAudioUnit(Thread& th, V& v, Arg filename)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\n\tchar path[1024];\n\tExtAudioFileRef xaf = nullptr;\n\t\n\tif (v.isZList()) {\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, 1, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\n\t\tplayer = new AUPlayer(th, 1, xaf);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint numChannels = (int)a->size();\n\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, numChannels, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tplayer = new AUPlayer(th, numChannels, xaf);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n\n\tplayer->path = path;\n\n\t{\n\t\tOSStatus err = ExtAudioFileWriteAsync(xaf, 0, nullptr); // initialize async.\n\t\tif (err) printf(\"init ExtAudioFileWriteAsync err %d\\n\", (int)err);\n }\n\t\n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n"], ["/sapf/src/SoundFiles.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"SoundFiles.hpp\"\n#include \n\nextern char gSessionTime[256];\n\n\nclass SFReaderOutputChannel;\n\nclass SFReader : public Object\n{\n\tExtAudioFileRef mXAF;\n\tint64_t mFramesRemaining;\n\tSFReaderOutputChannel* mOutputs;\n\tint mNumChannels;\n\tAudioBufferList* mABL;\n\tbool mFinished = false;\n\t\npublic:\n\t\n\tSFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration);\n\t\n\t~SFReader();\n\n\tvirtual const char* TypeName() const override { return \"SFReader\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tbool pull(Thread& th);\n\tvoid fulfillOutputs(int blockSize);\n\tvoid produceOutputs(int shrinkBy);\n};\n\nclass SFReaderOutputChannel : public Gen\n{\n\tfriend class SFReader;\n\tP mSFReader;\n\tSFReaderOutputChannel* mNextOutput = nullptr;\n\tZ* mDummy = nullptr;\n\t\npublic:\t\n\tSFReaderOutputChannel(Thread& th, SFReader* inSFReader)\n : Gen(th, itemTypeZ, true), mSFReader(inSFReader)\n\t{\n\t}\n\t\n\t~SFReaderOutputChannel()\n\t{\n\t\tif (mDummy) free(mDummy);\n\t}\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr; \n\t\tmSFReader = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"SFReaderOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mSFReader->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nSFReader::SFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration)\n\t: mXAF(inXAF), mNumChannels(inNumChannels), mFramesRemaining(inDuration), mABL(nullptr)\n{\n\tmABL = (AudioBufferList*)calloc(1, sizeof(AudioBufferList) + (mNumChannels - 1) * sizeof(AudioBuffer));\n}\n\nSFReader::~SFReader()\n{\n\tExtAudioFileDispose(mXAF); free(mABL);\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tSFReaderOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nvoid SFReader::fulfillOutputs(int blockSize)\n{\n\tmABL->mNumberBuffers = mNumChannels;\n\tSFReaderOutputChannel* output = mOutputs;\n\tsize_t bufSize = blockSize * sizeof(Z);\n\tfor (int i = 0; output; ++i, output = output->mNextOutput){\n\t\tZ* out;\n\t\tif (output->mOut)\n\t\t\tout = output->mOut->fulfillz(blockSize);\n\t\telse {\n\t\t\tif (!output->mDummy)\n\t\t\t\toutput->mDummy = (Z*)calloc(output->mBlockSize, sizeof(Z));\n\n\t\t\tout = output->mDummy;\n\t\t}\n\t\t\t\n\t\tmABL->mBuffers[i].mNumberChannels = 1;\n\t\tmABL->mBuffers[i].mData = out;\n\t\tmABL->mBuffers[i].mDataByteSize = (UInt32)bufSize;\n\t\tmemset(out, 0, bufSize);\n\t};\n}\n\nvoid SFReader::produceOutputs(int shrinkBy)\n{\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nP SFReader::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n SFReaderOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n SFReaderOutputChannel* c = new SFReaderOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nbool SFReader::pull(Thread& th)\n{\n\tif (mFramesRemaining == 0) \n\t\tmFinished = true;\n\n\tif (mFinished) \n\t\treturn true;\n\t\n\tSFReaderOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\tif (mFramesRemaining > 0)\n\t\tblockSize = (int)std::min(mFramesRemaining, (int64_t)blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n\t// read file here.\n\tUInt32 framesRead = blockSize;\n\tOSStatus err = ExtAudioFileRead(mXAF, &framesRead, mABL);\n\t\n\tif (err || framesRead == 0) {\n\t\tmFinished = true;\n\t}\n\t\n\tproduceOutputs(blockSize - framesRead);\n\tif (mFramesRemaining > 0) mFramesRemaining -= blockSize;\n\t\n\treturn mFinished; \n}\n\nvoid sfread(Thread& th, Arg filename, int64_t offset, int64_t frames)\n{\n\tconst char* path = ((String*)filename.o())->s;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path\\n\");\n\t\treturn;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileOpenURL(url, &xaf);\n\n\tcfpathReleaser.release();\n\turlReleaser.release();\n\t\n\tif (err) {\n\t\tpost(\"failed to open file %d\\n\", (int)err);\n\t\treturn;\n\t}\n\n\tAudioStreamBasicDescription fileFormat;\n\t\n\tUInt32 propSize = sizeof(fileFormat);\n\terr = ExtAudioFileGetProperty(xaf, kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);\n\t\n\tint numChannels = fileFormat.mChannelsPerFrame;\n\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved,\n\t\tstatic_cast(sizeof(double)),\n\t\t1,\n\t\tstatic_cast(sizeof(double)),\n\t\tstatic_cast(numChannels),\n\t\t64,\n\t\t0\n\t};\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\terr = ExtAudioFileSeek(xaf, offset);\n\tif (err) {\n\t\tpost(\"seek failed %d\\n\", (int)err);\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\tSFReader* sfr = new SFReader(xaf, numChannels, -1);\n\t\n\tth.push(sfr->createOutputs(th));\n}\n\nExtAudioFileRef sfcreate(Thread& th, const char* path, int numChannels, double fileSampleRate, bool interleaved)\n{\n\tif (fileSampleRate == 0.)\n\t\tfileSampleRate = th.rate.sampleRate;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path '%s'\\n\", path);\n\t\treturn nullptr;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn nullptr;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tAudioStreamBasicDescription fileFormat = {\n\t\tfileSampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\n\tint interleavedChannels = interleaved ? numChannels : 1;\n\tUInt32 interleavedBit = interleaved ? 0 : kAudioFormatFlagIsNonInterleaved;\n\t\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | interleavedBit,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileCreateWithURL(url, kAudioFileWAVEType, &fileFormat, nullptr, kAudioFileFlags_EraseFile, &xaf);\n\t\n\tif (err) {\n\t\tpost(\"failed to create file '%s'. err: %d\\n\", path, (int)err);\n\t\treturn nullptr;\n\t}\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn nullptr;\n\t}\n\t\n\treturn xaf;\n}\n\nstd::atomic gFileCount = 0;\n\nvoid makeRecordingPath(Arg filename, char* path, int len)\n{\n\tif (filename.isString()) {\n\t\tconst char* recDir = getenv(\"SAPF_RECORDINGS\");\n\t\tif (!recDir || strlen(recDir)==0) recDir = \"/tmp\";\n\t\tsnprintf(path, len, \"%s/%s.wav\", recDir, ((String*)filename.o())->s);\n\t} else {\n\t\tint32_t count = ++gFileCount;\n\t\tsnprintf(path, len, \"/tmp/sapf-%s-%04d.wav\", gSessionTime, count);\n\t}\n}\n\nvoid sfwrite(Thread& th, V& v, Arg filename, bool openIt)\n{\n\tstd::vector in;\n\t\n\tint numChannels = 0;\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin.push_back(ZIn(v));\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin.push_back(ZIn(va));\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tchar path[1024];\n\t\n\tmakeRecordingPath(filename, path, 1024);\n\t\n\tExtAudioFileRef xaf = sfcreate(th, path, numChannels, 0., true);\n\tif (!xaf) return;\n\t\n\tstd::valarray buf(0., numChannels * kBufSize);\n\tAudioBufferList abl;\n\tabl.mNumberBuffers = 1;\n\tabl.mBuffers[0].mNumberChannels = numChannels;\n\tabl.mBuffers[0].mData = &buf[0];\n\tabl.mBuffers[0].mDataByteSize = kBufSize * sizeof(float);\n\t\n\tint64_t framesPulled = 0;\n\tint64_t framesWritten = 0;\n\tbool done = false;\n\twhile (!done) {\n\t\tint minn = kBufSize;\n\t\tmemset(&buf[0], 0, kBufSize * numChannels);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].fill(th, n, &buf[0]+i, numChannels);\n\t\t\tframesPulled += n;\n\t\t\tif (imdone) done = true;\n\t\t\tminn = std::min(n, minn);\n\t\t}\n\n\t\tabl.mBuffers[0].mDataByteSize = minn * sizeof(float);\n\t\tOSStatus err = ExtAudioFileWrite(xaf, minn, &abl);\n\t\tif (err) {\n\t\t\tpost(\"ExtAudioFileWrite failed %d\\n\", (int)err);\n\t\t\tbreak;\n\t\t}\n\n\t\tframesWritten += minn;\n\t}\n\t\n\tpost(\"wrote file '%s' %d channels %g secs\\n\", path, numChannels, framesWritten * th.rate.invSampleRate);\n\t\n\tExtAudioFileDispose(xaf);\n\t\n\tif (openIt) {\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n}\n"], ["/sapf/src/RandomOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark RANDOM STREAMS\n\n\ntemplate \nvoid swapifgt(T& a, T& b) { \n\tif (a > b) {\n\t\tT t = a;\n\t\ta = b;\n\t\tb = t;\n\t}\n}\n\n\nstruct URand : ZeroInputGen\n{\t\n RGen r;\n \n\tURand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct URandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tURandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\n\nstruct NURand : NZeroInputGen\n{\t\n RGen r;\n \n\tNURand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct NURandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNURandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct BRand : ZeroInputGen\n{\t\n RGen r;\n \n\tBRand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct BRandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tBRandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct NBRand : NZeroInputGen\n{\t\n RGen r;\n \n\tNBRand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct NBRandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNBRandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct Rand : TwoInputGen\n{\t\n RGen r;\n \n\tRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Randz : TwoInputUGen\n{\t\n RGen r;\n \n\tRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Randz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void urands_(Thread& th, Prim* prim)\n{\n\tGen* g = new URand(th);\n\tth.push(new List(g));\n}\n\nstatic void urandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new URandz(th);\n\tth.push(new List(g));\n}\n\nstatic void brands_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRand(th);\n\tth.push(new List(g));\n}\n\nstatic void brandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRandz(th);\n\tth.push(new List(g));\n}\n\nstatic void nurands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurands : n\");\n\tGen* g = new NURand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nurandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurandz : n\");\n\tGen* g = new NURandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrands : n\");\n\tGen* g = new NBRand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrandz : n\");\n\tGen* g = new NBRandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void rands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Rand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void randz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"randz : hi\");\n\tV a = th.popZIn(\"randz : lo\");\n\t\n\tGen* g = new Randz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrands : n\");\n\t\n\tGen* g = new NRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nrandz : hi\");\n\tV a = th.popZIn(\"nrandz : lo\");\n\tint64_t n = th.popInt(\"nrandz : n\");\n\t\n\tGen* g = new NRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void urand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand();\n\tth.push(z);\n}\n\nstatic void brand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand2();\n\tth.push(z);\n}\n\n\nstatic void newseed_(Thread& th, Prim* prim)\n{\n\tV v;\n\tv.i = timeseed();\n\tth.push(v);\n}\n\nstatic void setseed_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isReal()) wrongType(\"setseed : seed\", \"Float\", v);\n\tth.rgen.init(v.i);\n}\n\nstatic void rand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"rand : hi\");\n\tZ a = th.popFloat(\"rand : lo\");\n\t\n\tswapifgt(a, b);\n\tZ z = th.rgen.rand(a, b);\n\tth.push(z);\n}\n\nstruct Coin : OneInputGen\n{\t\n RGen r;\n \n\tCoin(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Coinz : OneInputUGen\n{\t\n RGen r;\n \n\tCoinz(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoin : NOneInputGen\n{\t\n RGen r;\n \n\tNCoin(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoinz : NOneInputUGen\n{\t\n RGen r;\n \n\tNCoinz(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void coin_(Thread& th, Prim* prim)\n{\n\tZ p = th.popFloat(\"coin : p\");\n\t\n\tZ z = th.rgen.coin(p);\n\tth.push(z);\n}\n\nstatic void coins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coin(th, a);\n\tth.push(new List(g));\n}\n\nstatic void coinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coinz(th, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoins : n\");\n\t\n\tGen* g = new NCoin(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoinz : n\");\n\t\n\tGen* g = new NCoinz(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstruct IRand : TwoInputGen\n{\t\n RGen r;\n \n\tIRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tIRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NIRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNIRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNIRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new IRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"irandz : hi\");\n\tV a = th.popZIn(\"irandz : lo\");\n\t\n\tGen* g = new IRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirands : n\");\n\t\n\tGen* g = new NIRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nirandz : hi\");\n\tV a = th.popZIn(\"nirandz : lo\");\n\tint64_t n = th.popInt(\"nirandz : n\");\n\t\n\tGen* g = new NIRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"irand : hi\");\n\tint64_t a = th.popInt(\"irand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tswapifgt(a, b);\n\tZ z = (Z)r.irand(a, b);\n\tth.push(z);\n}\n\n\nstruct ExcRand : TwoInputGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExcRandz : TwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\t\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExcRand : NTwoInputGen\n{\t\n RGen r;\n \tint64_t prev;\n \n\tNExcRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExcRandz : NTwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tNExcRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void eprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExcRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void eprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprandz : hi\");\n\tV a = th.popZIn(\"eprandz : lo\");\n\t\n\tGen* g = new ExcRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"neprands : n\");\n\t\n\tGen* g = new NExcRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprands : hi\");\n\tV a = th.popZIn(\"eprands : lo\");\n\tint64_t n = th.popInt(\"neprandz : n\");\n\t\n\tGen* g = new NExcRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstruct ExpRand : TwoInputGen\n{\t\n RGen r;\n \n\tExpRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExpRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tExpRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExpRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNExpRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExpRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNExpRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void xrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExpRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"xrandz : hi\");\n\tV a = th.popZIn(\"xrandz : lo\");\n\t\n\tGen* g = new ExpRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nxrands : n\");\n\t\n\tGen* g = new NExpRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nxrandz : hi\");\n\tV a = th.popZIn(\"nxrandz : lo\");\n\tint64_t n = th.popInt(\"xrandz : n\");\n\t\n\tGen* g = new NExpRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"xrand : hi\");\n\tZ a = th.popFloat(\"xrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.xrand(a, b);\n\tth.push(z);\n}\n\nstruct ILinRand : TwoInputGen\n{\t\n RGen r;\n \n\tILinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ILinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tILinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NILinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNILinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NILinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNILinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ILinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"ilinrandz : hi\");\n\tV a = th.popZIn(\"ilinrandz : lo\");\n\t\n\tGen* g = new ILinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nilinrands : n\");\n\t\n\tGen* g = new NILinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nilinrandz : hi\");\n\tV a = th.popZIn(\"nilinrandz : lo\");\n\tint64_t n = th.popInt(\"nilinrandz : n\");\n\t\n\tGen* g = new NILinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"ilinrand : hi\");\n\tint64_t a = th.popInt(\"ilinrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tint64_t x;\n\tif (b < a) { x = a; a = b; b = x; }\n\tZ z = (Z)r.ilinrand(a, b);\n\tth.push(z);\n}\n\n\n\nstruct LinRand : TwoInputGen\n{\t\n RGen r;\n \n\tLinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct LinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tLinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NLinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNLinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NLinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNLinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void linrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new LinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\t\n\tGen* g = new LinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"linrandz : n\");\n\t\n\tGen* g = new NLinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\tint64_t n = th.popInt(\"randz : n\");\n\t\n\tGen* g = new NLinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"linrand : hi\");\n\tZ a = th.popFloat(\"linrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.linrand(a, b);\n\tth.push(z);\n}\n\n\nstruct Rand2 : OneInputGen\n{\t\n RGen r;\n \n\tRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Rand2z : OneInputUGen\n{\t\n RGen r;\n \n\tRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct XorNoise1 : OneInputUGen\n{\t\n uint64_t x = 0xA40203C12F2AD936LL;\n\t\n\tXorNoise1(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise1\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct XorNoise2 : OneInputUGen\n{\t\n uint64_t s[2] = { 0xA40203C12F2AD936LL, 0x9E390BD16B74D6D3LL };\n\t\n\tXorNoise2(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise2\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint32_t raprng(uint64_t i, uint64_t seed)\n{\n// http://cessu.blogspot.com/2008/11/random-access-pseudo-random-numbers.html\n uint64_t r = (2857720171ULL * ((uint32_t) i)) ^ 0x1EF57D8A7B344E7BULL;\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n r += r >> 32;\n r = (2857720171ULL * ((uint32_t) (i ^ r))) ^ (0xD9EA571C8AF880B6ULL + seed);\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n return uint32_t(r + (r >> 32));\n}\n\n\nstruct RandomAccessNoise : OneInputUGen\n{\n uint64_t seed = 0xA40203C12F2AD936LL;\n\tuint64_t k = 0;\n\t\n\tRandomAccessNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RandomAccessNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t hash64shift(uint64_t key)\n{\n key = (~key) + (key << 21); // key = (key << 21) - key - 1;\n key = key ^ (key >> 24);\n key = (key + (key << 3)) + (key << 8); // key * 265\n key = key ^ (key >> 14);\n key = (key + (key << 2)) + (key << 4); // key * 21\n key = key ^ (key >> 28);\n key = key + (key << 31);\n return key;\n}\n\nstruct WangNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tWangNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WangNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t Hash128to64(uint64_t x, uint64_t y) {\n\tconst uint64_t kMul = 0x9ddfea08eb382d69ULL;\n\tuint64_t a = (x ^ y) * kMul;\n\ta ^= (a >> 47);\n\tuint64_t b = (y ^ a) * kMul;\n\tb ^= (b >> 47);\n\tb *= kMul;\n\treturn b;\n}\n\n\nstruct CityNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tCityNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"CityNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Violet : OneInputUGen\n{\t\n RGen r;\n\tZ prev;\n \n\tViolet(Thread& th, Arg a) : OneInputUGen(th, a), prev(0.)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Violet\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = .5 * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = a * r.drand() - a2;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ x = a * r.drand() - .5 * a;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void rand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2s : n\");\n\t\n\tGen* g = new NRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2z : n\");\n\t\n\tGen* g = new NRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstatic void white_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void wangwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"wangwhite : a\");\n\tGen* g = new WangNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void citywhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"citywhite : a\");\n\tGen* g = new CityNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rawhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"rawhite : a\");\n\tGen* g = new RandomAccessNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite : a\");\n\tGen* g = new XorNoise1(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite2_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite2 : a\");\n\tGen* g = new XorNoise2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void violet_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Violet(th, a);\n\tth.push(new List(g));\n}\n\n\nstatic void rand2_(Thread& th, Prim* prim)\n{\n\tZ a = th.popFloat(\"rand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = 2. * a * r.drand() - a;\n\tth.push(z);\n}\n\nstruct IRand2 : OneInputGen\n{\t\n RGen r;\n \n\tIRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRand2z : OneInputUGen\n{\t\n RGen r;\n \n\tIRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNIRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNIRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2s : n\");\n\t\n\tGen* g = new NIRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2z : n\");\n\t\n\tGen* g = new NIRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2_(Thread& th, Prim* prim)\n{\n\tint64_t a = th.popInt(\"irand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = floor((2. * a + 1.) * r.drand() - a);\n\tth.push(z);\n}\n\n\nstruct Pick : ZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPick(Thread& th, P const& array) : ZeroInputGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Pickz : ZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPickz(Thread& th, P const& array) : ZeroInputUGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstruct NPick : NZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPick(Thread& th, int64_t n, P const& array) : NZeroInputGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NPickz : NZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPickz(Thread& th, int64_t n, P const& array) : NZeroInputUGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstatic void picks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"picks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"picks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pick(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pickz(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npicks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npicks : list\");\n\tint64_t n = th.popInt(\"npicks : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npicks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPick(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npickz : list\");\n\tint64_t n = th.popInt(\"npickz : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPickz(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pick_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pick : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\tint64_t n = a->mArray->size();\n\tth.push(a->at(th.rgen.irand0(n)));\n}\n\nstatic int64_t weightIndex(int64_t n, Z* z, Z r)\n{\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += z[i];\n\t\tif (r < sum) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn n-1;\n}\n\nstruct WPick : ZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPick(Thread& th, P const& array, P const& weights) : ZeroInputGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct WPickz : ZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPickz(Thread& th, P const& array, P const& weights) : ZeroInputUGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstruct NWPick : NZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPick(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NWPickz : NZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPickz(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputUGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstatic P sumWeights(P& weights)\n{\n\tconst int64_t n = weights->size();\n\n\tP summedWeights = new Array(itemTypeZ, n);\n\tsummedWeights->setSize(n);\n\t\n\tZ sum = 0.;\n\tZ* z = summedWeights->z();\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += weights->atz(i);\n\t\tz[i] = sum;\n\t}\n\tZ scale = 1. / sum;\n\t\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tz[i] *= scale;\n\t}\n\t\n\treturn summedWeights;\n}\n\nstatic void wpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpicks : weights\");\n\tP a = th.popList(\"wpicks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new WPick(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void wpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpickz : weights\");\n\tP a = th.popList(\"wpickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n \n\tGen* g = new WPickz(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpicks : weights\");\n\tP a = th.popList(\"nwpicks : list\");\n\tint64_t n = th.popInt(\"nwpicks : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPick(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpickz : weights\");\n\tP a = th.popList(\"nwpickz : list\");\n\tint64_t n = th.popInt(\"nwpickz : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPickz(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wpick_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpick : weights\");\n\tP a = th.popList(\"wpick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpick : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpick : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->pack(th);\n\t\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\tconst int64_t n = aa->size();\n\tconst int64_t wn = wa->size();\n\n\tif (n != wn) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push(aa->at(i));\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push(aa->at(n-1));\n}\n\n\nstruct WRand : ZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRand(Thread& th, P const& weights) : ZeroInputGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct WRandz : ZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRandz(Thread& th, P const& weights) : ZeroInputUGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRand : NZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRand(Thread& th, int64_t n, P const& weights) : NZeroInputGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRandz : NZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRandz(Thread& th, int64_t n, P const& weights) : NZeroInputUGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\n\nstatic void wrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrands : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRand(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void wrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrandz : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRandz(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrands : weights\");\n\tint64_t n = th.popInt(\"nwrands : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRand(th, n, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrandz : weights\");\n\tint64_t n = th.popInt(\"nwrandz : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRandz(th, n, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wrand_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrand : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrand : weights must be finite\",\"\");\n\t\n\tw = w->pack(th);\n\t\n\tP wa = w->mArray;\n\tconst int64_t n = wa->size();\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push((Z)i);\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push((Z)(n-1));\n}\n\n\nstruct GrayNoise : OneInputUGen\n{\t\n RGen r;\n\tint32_t counter_;\n \n\tGrayNoise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"GrayNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 4.65661287308e-10f;\n\t\tint32_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstruct Gray64Noise : OneInputUGen\n{\t\n RGen r;\n\tint64_t counter_;\n \n\tGray64Noise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gray64Noise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 1.084202172485504434e-19;\n\t\tint64_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstatic void gray_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray : a\");\n\t\n\tth.push(new List(new GrayNoise(th, a)));\n}\n\nstatic void gray64_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray64 : a\");\n\t\n\tth.push(new List(new Gray64Noise(th, a)));\n}\n\nstruct PinkNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tout[i] = *aa * (u.f - 3.);\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct PinkNoise0 : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise0(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tdice[i] = 0;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise0\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\tconst double scale = pow(2.,-47.)/17.;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tout[i] = *aa * (scale * double(total + newrand)) - 1;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct BlueNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\tZ prev;\n\t\n\tBlueNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a), prev(0.)\n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"BlueNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tZ x = 4. * *aa * (u.f - 3.);\n\t\t\t\t\tout[i] = x - prev;\n\t\t\t\t\tprev = x;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void pink_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink : a\");\n\t\n\tth.push(new List(new PinkNoise(th, a)));\n}\n\nstatic void pink0_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink0 : a\");\n\t\n\tth.push(new List(new PinkNoise0(th, a)));\n}\n\nstatic void blue_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"blue : a\");\n\t\n\tth.push(new List(new BlueNoise(th, a)));\n}\n\n\nstruct BrownNoise : Gen\n{\n\tZIn _a;\n\tZ total_;\n\t\n\tBrownNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\ttotal_ = r.drand2();\n \n\t}\n \n\tvirtual const char* TypeName() const override { return \"BrownNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ z = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tz += r.drand16();\n\t\t\t\t\tif (z > 1.) z = 2. - z;\n\t\t\t\t\telse if (z < -1.) z = -2. - z;\n\t\t\t\t\tout[i] = *aa * z;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = z;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void brown_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"brown : a\");\n\t\n\tth.push(new List(new BrownNoise(th, a)));\n}\n\nstruct Dust : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * z / thresh : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Dust2 : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust2(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust2\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * (2. * z / thresh - 1.) : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Velvet : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tVelvet(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Velvet\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ thresh2 = .5 * thresh;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? (zfulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct TooshPlus : Gen\n{\n\tZIn _delay;\n\tZIn _amp;\n\tint64_t _counter;\n\tZ sampleRate;\n\t\n\tTooshPlus(Thread& th, Arg delay, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(delay, amp)), _delay(delay), _amp(amp), sampleRate(th.rate.sampleRate)\n\t{\n\t\t_counter = th.rgen.trand();\n\t}\n \n\tvirtual const char* TypeName() const override { return \"TooshPlus\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void toosh_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toosh : amp\");\n\tV delay = th.popZIn(\"toosh : delay\");\n \n\tth.push(new List(new Toosh(th, delay, amp)));\n}\n\nstatic void tooshp_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tooshp : amp\");\n\tV delay = th.popZIn(\"tooshp : delay\");\n \n\tth.push(new List(new TooshPlus(th, delay, amp)));\n}\n\nstruct Crackle : Gen\n{\n\tZIn _param;\n\tZ _y1, _y2;\n\t\n\tCrackle(Thread& th, Arg param) \n : Gen(th, itemTypeZ, param.isFinite()), _param(param), _y1(th.rgen.drand()), _y2(0.)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Crackle\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint paramStride;\n\t\t\tZ *param;\n\t\t\tif (_param(th, n, paramStride, param)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n Z y1 = _y1;\n Z y2 = _y2;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n Z y0 = fabs(y1 * *param - y2 - 0.05);\n y2 = y1; y1 = y0;\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\tparam += paramStride;\n\t\t\t\t}\n _y1 = y1;\n _y2 = y2;\n\t\t\t\t_param.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void crackle_(Thread& th, Prim* prim)\n{\n\tV param = th.popZIn(\"cracke : param\");\n \n\tth.push(new List(new Crackle(th, param)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD RANDOM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n\nvoid AddRandomOps();\nvoid AddRandomOps()\n{\n\tvm.addBifHelp(\"\\n*** random number generation ***\");\n\n\tDEFnoeach(newseed, 0, 1, \"(--> seed) make a new random seed.\");\n\tDEFnoeach(setseed, 1, 0, \"(seed -->) set the random seed.\");\n\n\t\n\tvm.addBifHelp(\"\\n*** single random numbers ***\");\n\tDEFAM(rand, kk, \"(a b --> r) return a uniformly distributed random real value from a to b.\")\n\tDEFAM(coin, k, \"(p --> r) return 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(rand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(irand, kk, \"(a b --> r) return a uniformly distributed random integer value from a to b.\")\n\tDEFAM(irand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(xrand, kk, \"(a b --> r) return a exponentially distributed random real value from a to b.\") \n\tDEFAM(linrand, kk, \"(a b --> r) return a linearly distributed random real value from a to b.\")\t \n\tDEFAM(ilinrand, kk, \"(a b --> r) return a linearly distributed random integer value from a to b.\") \n\tDEF(wrand, 1, 1, \"(w --> r) return a randomly chosen index from a list of probability weights. w should sum to one.\") \n\tDEF(pick, 1, 1, \"(a --> r) return a randomly chosen element from the finite list a.\") \n\tDEF(wpick, 2, 1, \"(a w --> r) return a randomly chosen element from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random streams ***\");\n\tDEFAM(rands, kk, \"(a b --> r) return a stream of uniformly distributed random real values from a to b.\")\n\tDEFAM(coins, k, \"(p --> r) return a stream of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(eprands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b, excluding the previously returned value.\")\t\n\tDEFAM(rand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(irands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b.\")\n\tDEFAM(irand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(xrands, kk, \"(a b --> r) return a stream of exponentially distributed random real values from a to b.\")\n\tDEFAM(linrands, kk, \"(a b --> r) return a stream of linearly distributed random real values from a to b.\")\n\tDEFAM(ilinrands, kk, \"(a b --> r) return a stream of linearly distributed random integer values from a to b.\")\n\tDEF(wrands, 1, 1, \"(w --> r) return a stream of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEF(picks, 1, 1, \"(a --> r) return a stream of randomly chosen elements from the finite list a.\") \n\tDEF(wpicks, 2, 1, \"(a w --> r) return a stream of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random signals ***\");\n\tDEFMCX(randz, 2, \"(a b --> r) return a signal of uniformly distributed random real values from a to b.\")\n\tDEFMCX(coinz, 1, \"(p --> r) return a signal of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(eprandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(rand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(irandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b.\")\n\tDEFMCX(irand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(xrandz, 2, \"(a b --> r) return a signal of exponentially distributed random real values from a to b.\")\n\tDEFMCX(linrandz, 2, \"(a b --> r) return a signal of linearly distributed random real values from a to b.\")\n\tDEFMCX(ilinrandz, 2, \"(a b --> r) return a signal of linearly distributed random integer values from a to b.\")\n\tDEFMCX(wrandz, 1, \"(w --> r) return a signal of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(pickz, 1, \"(a --> r) return a signal of randomly chosen elements from the finite list a.\") \n\tDEFMCX(wpickz, 2, \"(a w --> r) return a signal of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** finite random streams ***\");\n\tDEFAM(nrands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random real values from a to b.\")\n\tDEFAM(ncoins, kk, \"(n p --> r) return a stream of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(neprands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b, excluding the previously returned value.\")\n\tDEFAM(nrand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nirands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b.\")\n\tDEFAM(nirand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nxrands, kkk, \"(n a b --> r) return a stream of n exponentially distributed random real values from a to b.\")\n\tDEFAM(nlinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random real values from a to b.\")\n\tDEFAM(nilinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random integer values from a to b.\")\n\tDEFAM(nwrands, ka, \"(n w --> r) return a stream of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFAM(npicks, ka, \"(n a --> r) return a stream of n randomly chosen elements from the finite list a.\") \n\tDEFAM(nwpicks, kaa, \"(n a w --> r) return a stream of n randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** finite random signals ***\");\n\tDEFMCX(nrandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random real values from a to b.\")\n\tDEFMCX(ncoinz, 2, \"(n p --> r) return a signal of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(neprandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(nrand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nirandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b.\")\n\tDEFMCX(nirand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nxrandz, 3, \"(n a b --> r) return a signal of n exponentially distributed random real values from a to b.\")\n\tDEFMCX(nlinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random real values from a to b.\")\n\tDEFMCX(nilinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random integer values from a to b.\")\t\n\tDEFMCX(nwrandz, 2, \"(n w --> r) return a signal of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(npickz, 2, \"(n a --> r) return a signal of n randomly chosen elements from the finite signal a.\") \n\tDEFMCX(nwpickz, 3, \"(n a w --> r) return a signal of n randomly chosen elements from the finite signal a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** noise unit generators ***\");\n\tDEFMCX(violet, 1, \"(amp --> z) violet noise\")\n\tDEFMCX(blue, 1, \"(amp --> z) blue noise\")\n\tDEFMCX(xorwhite, 1, \"(amp --> z) white noise\")\n\tDEFMCX(xorwhite2, 1, \"(amp --> z) white noise\")\n\tDEFMCX(rawhite, 1, \"(amp --> z) white noise based on Cessu's random access random numbers\")\n\tDEFMCX(wangwhite, 1, \"(amp --> z) white noise based on Thomas Wang's integer hash\")\n\tDEFMCX(citywhite, 1, \"(amp --> z) white noise based on a function from CityHash\")\n\tDEFMCX(white, 1, \"(amp --> z) white noise\")\n\tDEFMCX(pink, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(pink0, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(brown, 1, \"(amp --> z) brown noise\")\n\tDEFMCX(gray, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(gray64, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(dust, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from 0 to a and whose average density is in impulses per second.\")\t\n\tDEFMCX(dust2, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from -a to +a and whose average density is in impulses per second.\")\n\tDEFMCX(velvet, 2, \"(density amp --> z) a stream of impulses whose amplitude is randomly either -a or +a and whose average density is in impulses per second.\")\n\tDEFMCX(toosh, 2, \"(delay amp --> z) flanged noise. difference of two white noise sources with a delay.\")\n\tDEFMCX(tooshp, 2, \"(delay amp--> z) flanged noise. sum of two white noise sources with a delay. no null at delay == 0. \")\n\tDEFMCX(crackle, 1, \"(param --> z) a chaotic generator.\")\t\n}\n\n\n"], ["/sapf/src/DelayUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"DelayUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass DelayN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\n\tDelayN(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n int32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n out[i] = buf[(bufPos-offset) & bufMask];\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayn_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayn : maxdelay\");\n\tV delay = th.popZIn(\"delayn : delay\");\n\tV in = th.popZIn(\"delayn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayN(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayL(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayl_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayl : maxdelay\");\n\tV delay = th.popZIn(\"delayl : delay\");\n\tV in = th.popZIn(\"delayl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayL(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayC(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayc_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayc : maxdelay\");\n\tV delay = th.popZIn(\"delayc : delay\");\n\tV in = th.popZIn(\"delayc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayC(th, in, delay, maxdelay)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass Flange : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlange(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flange() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flange\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) - zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flangep : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlangep(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flangep() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flangep\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) + zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void flange_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flange : maxdelay\");\n\tV delay = th.popZIn(\"flange : delay\");\n\tV in = th.popZIn(\"flange : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flange : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flange(th, in, delay, maxdelay)));\n}\n\nstatic void flangep_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flangep : maxdelay\");\n\tV delay = th.popZIn(\"flangep : delay\");\n\tV in = th.popZIn(\"flangep : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flangep : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flangep(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass CombN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay + 1.));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(std::abs(zdelay) * sr + .5));\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(std::abs(zdelay) * sr + .5);\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combn : decay\");\n\tZ maxdelay = th.popFloat(\"combn : maxdelay\");\n\tV delay = th.popZIn(\"combn : delay\");\n\tV in = th.popZIn(\"combn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ z = fb * (a + frac * (b - a));\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combl : decay\");\n\tZ maxdelay = th.popFloat(\"combl : maxdelay\");\n\tV delay = th.popZIn(\"combl : delay\");\n\tV in = th.popZIn(\"combl : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combc : decay\");\n\tZ maxdelay = th.popFloat(\"combc : maxdelay\");\n\tV delay = th.popZIn(\"combc : delay\");\n\tV in = th.popZIn(\"combc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass LPCombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZIn lpfreq_;\n\tZ maxdelay_;\n\tZ y1_;\n\tZ freqmul_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tLPCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay, Arg lpfreq) : Gen(th, itemTypeZ, false),\n\t\t\tin_(in), delay_(delay), decay_(decay), lpfreq_(lpfreq), maxdelay_(maxdelay), y1_(0.), freqmul_(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~LPCombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"LPCombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tZ y1 = y1_;\n\t\tZ freqmul = freqmul_;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride, lpfreqStride;\n\t\t\tZ *in, *delay, *decay, *lpfreq;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay) || lpfreq_(th, n, lpfreqStride, lpfreq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (lpfreqStride == 0) {\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n }\n\t\t\t\ty1_ = y1;\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tlpfreq_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void lpcombc_(Thread& th, Prim* prim)\n{\n\tV lpfreq = th.popZIn(\"lpcombc : lpfreq\");\n\tV decay = th.popZIn(\"lpcombc : decay\");\n\tZ maxdelay = th.popFloat(\"lpcombc : maxdelay\");\n\tV delay = th.popZIn(\"lpcombc : delay\");\n\tV in = th.popZIn(\"lpcombc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"lpcombc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new LPCombC(th, in, delay, maxdelay, decay, lpfreq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass AllpassN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(zdelay * sr + .5);\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasn : decay\");\n\tZ maxdelay = th.popFloat(\"alpasn : maxdelay\");\n\tV delay = th.popZIn(\"alpasn : delay\");\n\tV in = th.popZIn(\"alpasn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasl : decay\");\n\tZ maxdelay = th.popFloat(\"alpasl : maxdelay\");\n\tV delay = th.popZIn(\"alpasl : delay\");\n\tV in = th.popZIn(\"alpasl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasc : decay\");\n\tZ maxdelay = th.popFloat(\"alpasc : maxdelay\");\n\tV delay = th.popZIn(\"alpasc : delay\");\n\tV in = th.popZIn(\"alpasc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\nclass FDN;\n\nclass FDN_OutputChannel : public Gen\n{\n\tfriend class FDN;\n\tP mFDN;\n\t\npublic:\t\n\tFDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmFDN = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FDN_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nclass FDN : public Object\n{\n\tZIn in_;\n\tZIn wet_;\n\tZ decayLo_;\n\tZ decayMid_;\n\tZ decayHi_;\n\tZ mindelay_;\n\tZ maxdelay_;\n\tZ sr_;\n\t\n\tZ a1Lo, a1Hi;\n\tZ scaleLoLPF, scaleLoHPF, scaleHiLPF, scaleHiHPF;\n\tFDN_OutputChannel* mLeft;\n\tFDN_OutputChannel* mRight;\n\t\n\tstatic const int kNumDelays = 16;\n\t\n\tstruct FDNDelay\n\t{\n\t\tZ* buf;\n\t\tint size, mask, rpos, wpos, offset;\n\t\tZ delay, gain;\n\t\tZ fbLo, fbMid, fbHi;\n\t\tZ x1A, x1B, x1C, x1D;\n\t\tZ y1A, y1B, y1C, y1D;\n\t\t\n\t\tFDNDelay()\n\t\t{\n\t\t}\n\t\t~FDNDelay() { free(buf); }\n\t\t\n\t\tvoid set(Thread& th, const FDN& fdn, Z inDelay, int& ioSampleDelay)\n\t\t{\n\t\t\tint sampleDelay = (int)(th.rate.sampleRate * inDelay);\n\t\t\tif (sampleDelay <= ioSampleDelay) sampleDelay = ioSampleDelay + 2;\n\t\t\tsampleDelay = (int)nextPrime(sampleDelay);\n\t\t\tioSampleDelay = sampleDelay;\n\t\t\tZ actualDelay = (Z)sampleDelay * th.rate.invSampleRate;\n\t\t\tsize = NEXTPOWEROFTWO(sampleDelay);\n\t\t\tmask = size - 1;\n\t\t\tprintf(\"delay %6d %6d %6d %f\\n\", sampleDelay, size, mask, actualDelay);\n\t\t\trpos = 0;\n\t\t\twpos = sampleDelay;\n\t\t\tbuf = (Z*)calloc(size, sizeof(Z));\n\t\t\tconst Z n1 = 1. / sqrt(kNumDelays);\n\t\t\t//const Z n1 = 1. / kNumDelays;\n\t\t\tfbLo = n1 * calcDecay(actualDelay / fdn.decayLo_);\n\t\t\tfbMid = n1 * calcDecay(actualDelay / fdn.decayMid_);\n\t\t\tfbHi = n1 * calcDecay(actualDelay / fdn.decayHi_);\n\t\t\ty1A = 0.;\n\t\t\ty1B = 0.;\n\t\t\ty1C = 0.;\n\t\t\ty1D = 0.;\n\t\t\tx1A = 0.;\n\t\t\tx1B = 0.;\n\t\t\tx1C = 0.;\n\t\t\tx1D = 0.;\n\t\t}\n\t};\n\npublic:\n\n\tFDNDelay mDelay[kNumDelays];\n\t\n\tFDN(Thread& th, Arg in, Arg wet, Z mindelay, Z maxdelay, Z decayLo, Z decayMid, Z decayHi, Z seed)\n\t\t: in_(in), wet_(wet),\n\t\tdecayLo_(decayLo), decayMid_(decayMid), decayHi_(decayHi),\n\t\tmindelay_(mindelay), maxdelay_(maxdelay)\n\t{\n\t\tsr_ = th.rate.sampleRate;\n\t\tZ freqmul = th.rate.invNyquistRate * kFirstOrderCoeffScale;\n\t\ta1Lo = t_firstOrderCoeff(freqmul * 200.);\n\t\ta1Hi = t_firstOrderCoeff(freqmul * 2000.);\n\t\tscaleLoLPF = .5 * (1. - a1Lo);\n\t\tscaleLoHPF = .5 * (1. + a1Lo);\n\t\tscaleHiLPF = .5 * (1. - a1Hi);\n\t\tscaleHiHPF = .5 * (1. + a1Hi);\n\t\t\n\t\tZ delay = mindelay;\n\t\tZ ratio = maxdelay / mindelay;\n\t\tZ interval = pow(ratio, 1. / (kNumDelays - 1.));\n\t\tint prevSampleDelay = 0;\n\t\tfor (int i = 0; i < kNumDelays; ++i) {\n\t\t\tdouble expon = (random() / 2147483647. - .5) * 0.8;\n\t\t\tdouble deviation = pow(interval, expon);\n\t\t\tmDelay[i].set(th, *this, delay * deviation, prevSampleDelay);\n\t\t\tdelay *= interval;\n\t\t}\n\t\t\n\t}\n\t\n\t~FDN() { delete mLeft; delete mRight; }\n\t\n\tvirtual const char* TypeName() const override { return \"FDN\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tvoid matrix(Z x[kNumDelays])\n\t{\n\t\tZ a0 = x[ 0];\n\t\tZ a1 = x[ 1];\n\t\tZ a2 = x[ 2];\n\t\tZ a3 = x[ 3];\n\t\tZ a4 = x[ 4];\n\t\tZ a5 = x[ 5];\n\t\tZ a6 = x[ 6];\n\t\tZ a7 = x[ 7];\n\t\tZ a8 = x[ 8];\n\t\tZ a9 = x[ 9];\n\t\tZ a10 = x[10];\n\t\tZ a11 = x[11];\n\t\tZ a12 = x[12];\n\t\tZ a13 = x[13];\n\t\tZ a14 = x[14];\n\t\tZ a15 = x[15];\n\n\t\tZ b0 = a0 + a1;\n\t\tZ b1 = a0 - a1;\n\t\tZ b2 = a2 + a3;\n\t\tZ b3 = a2 - a3;\n\t\tZ b4 = a4 + a5;\n\t\tZ b5 = a4 - a5;\n\t\tZ b6 = a6 + a7;\n\t\tZ b7 = a6 - a7;\n\t\tZ b8 = a8 + a9;\n\t\tZ b9 = a8 - a9;\n\t\tZ b10 = a10 + a11;\n\t\tZ b11 = a10 - a11;\n\t\tZ b12 = a12 + a13;\n\t\tZ b13 = a12 - a13;\n\t\tZ b14 = a14 + a15;\n\t\tZ b15 = a14 - a15;\n\n\t\tZ c0 = b0 + b2;\n\t\tZ c1 = b1 + b3;\n\t\tZ c2 = b0 - b2;\n\t\tZ c3 = b1 - b3;\n\t\tZ c4 = b4 + b6;\n\t\tZ c5 = b5 + b7;\n\t\tZ c6 = b4 - b6;\n\t\tZ c7 = b5 - b7;\n\t\tZ c8 = b8 + b10;\n\t\tZ c9 = b9 + b11;\n\t\tZ c10 = b8 - b10;\n\t\tZ c11 = b9 - b11;\n\t\tZ c12 = b12 + b14;\n\t\tZ c13 = b13 + b15;\n\t\tZ c14 = b12 - b14;\n\t\tZ c15 = b13 - b15;\n\n\t\tZ d0 = c0 + c4;\n\t\tZ d1 = c1 + c5;\n\t\tZ d2 = c2 + c6;\n\t\tZ d3 = c3 + c7;\n\t\tZ d4 = c0 - c4;\n\t\tZ d5 = c1 - c5;\n\t\tZ d6 = c2 - c6;\n\t\tZ d7 = c3 - c7;\n\t\tZ d8 = c8 + c12;\n\t\tZ d9 = c9 + c13;\n\t\tZ d10 = c10 + c14;\n\t\tZ d11 = c11 + c15;\n\t\tZ d12 = c8 - c12;\n\t\tZ d13 = c9 - c13;\n\t\tZ d14 = c10 - c14;\n\t\tZ d15 = c11 - c15;\n\n\t\tx[ 0] = d0 + d8;\n\t\tx[ 1] = d1 + d9;\n\t\tx[ 2] = d2 + d10;\n\t\tx[ 3] = d3 + d11;\n\t\tx[ 4] = d4 + d12;\n\t\tx[ 5] = d5 + d13;\n\t\tx[ 6] = d6 + d14;\n\t\tx[ 7] = d7 + d15;\n\t\tx[ 8] = d0 - d8;\n\t\tx[ 9] = d1 - d9;\n\t\tx[10] = d2 - d10;\n\t\tx[11] = d3 - d11;\n\t\tx[12] = d4 - d12;\n\t\tx[13] = d5 - d13;\n\t\tx[14] = d6 - d14;\n\t\tx[15] = d7 - d15;\n\t}\n \n\tvirtual void pull(Thread& th) \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, wetStride;\n\t\t\tZ *in;\n\t\t\tZ *wet;\n\t\t\tif (in_(th, n, inStride, in) || wet_(th, n, wetStride, wet)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x[kNumDelays];\n\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\n\t\t\t\t\t\t// read from delay line\n\t\t\t\t\t\tZ x0 = d.buf[d.rpos & d.mask];\n\n\t\t\t\t\t\t// attenuate and filter the output of the delay line.\n\t\t\t\t\t\t\n\t\t\t\t\t\t// high crossover\n\t\t\t\t\t\tZ x0A = scaleHiHPF * x0;\n\t\t\t\t\t\tZ x0B = scaleHiLPF * x0 ;\n\t\t\t\t\t\tZ y0A = x0A - d.x1A + a1Hi * d.y1A;\t// hpf -> high band\n\t\t\t\t\t\tZ y0B = x0B + d.x1B + a1Hi * d.y1B;\t// lpf -> low + mid\n\t\t\t\t\t\td.y1A = y0A;\n\t\t\t\t\t\td.y1B = y0B;\n\t\t\t\t\t\td.x1A = x0A;\n\t\t\t\t\t\td.x1B = x0B;\n\t\t\t\t\t\t\n\t\t\t\t\t\t// low crossover\n\t\t\t\t\t\tZ x0C = scaleLoHPF * y0B;\n\t\t\t\t\t\tZ x0D = scaleLoLPF * y0B;\n\t\t\t\t\t\tZ y0C = x0C - d.x1C + a1Lo * d.y1C;\t// hpf -> mid band\n\t\t\t\t\t\tZ y0D = x0D + d.x1D + a1Lo * d.y1D;\t// lpf -> low band\n\t\t\t\t\t\td.y1C = y0C;\n\t\t\t\t\t\td.y1D = y0D;\n\t\t\t\t\t\td.x1C = x0C;\n\t\t\t\t\t\td.x1D = x0D;\n\t\t\t\t\t\t\n\t\t\t\t\t\tx[j] = d.fbLo * y0D + d.fbMid * y0C + d.fbHi * y0A;\n\n\t\t\t\t\t\t++d.rpos;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tmatrix(x);\n\t\t\t\t\t\n\t\t\t\t\tZ ini = *in;\n\t\t\t\t\tZ w = *wet;\n\t\t\t\t\t*Lout = ini + w * (x[1] - ini);\n\t\t\t\t\t*Rout = ini + w * (x[2] - ini);\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\n\t\t\t\t\t// write back to delay line\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j) \n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\td.buf[d.wpos & d.mask] = x[j] + ini;\n\t\t\t\t\t\t++d.wpos;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tin += inStride;\n\t\t\t\t\twet += wetStride;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nFDN_OutputChannel::FDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN)\n : Gen(th, itemTypeZ, inFinite), mFDN(inFDN)\n{\n}\n\nvoid FDN_OutputChannel::pull(Thread& th)\n{\n\tmFDN->pull(th);\n}\n\nP FDN::createOutputs(Thread& th)\n{\n\tmLeft = new FDN_OutputChannel(th, finite, this);\n\tmRight = new FDN_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void fdn_(Thread& th, Prim* prim)\n{\n\tZ seed = th.popFloat(\"fdn : seed\");\n\tZ maxdelay = th.popFloat(\"fdn : maxdelay\");\n\tZ mindelay = th.popFloat(\"fdn : mindelay\");\n\tZ decayHi = th.popFloat(\"fdn : decayHi\");\n\tZ decayMid = th.popFloat(\"fdn : decayMid\");\n\tZ decayLo = th.popFloat(\"fdn : decayLo\");\n\tV wet = th.popZIn(\"fdn : wet\");\n\tV in = th.popZIn(\"fdn : in\");\n \n\tP fdn = new FDN(th, in, wet, mindelay, maxdelay, decayLo, decayMid, decayHi, seed);\n\t\n\tP s = fdn->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddDelayUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** delay unit generators ***\");\n\tDEFAM(delayn, zzk, \"(in delay maxdelay --> out) delay line with no interpolation.\");\n\tDEFAM(delayl, zzk, \"(in delay maxdelay --> out) delay line with linear interpolation.\");\n\tDEFAM(delayc, zzk, \"(in delay maxdelay --> out) delay line with cubic interpolation.\");\n\tDEFAM(flange, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. delay can be negative. latency is maxdelay.\");\n\tDEFAM(flangep, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. adds delayed signal instead of subtracts.\");\n\t\n\tDEFAM(combn, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with no interpolation.\");\n\tDEFAM(combl, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with linear interpolation.\");\n\tDEFAM(combc, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with cubic interpolation.\");\n\tDEFAM(lpcombc, zzkzz, \"(in delay maxdelay decayTime lpfreq --> out) low pass comb delay filter with cubic interpolation.\");\n\t\n\tDEFAM(alpasn, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with no interpolation.\");\n\tDEFAM(alpasl, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with linear interpolation.\");\n\tDEFAM(alpasc, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with cubic interpolation.\");\n\t//DEFAM(fdn, zzkkkkkk, \"(in wet decayLo decayMid decayHi mindelay maxdelay rseed --> out) feedback delay network reverb.\");\n}\n\n\n"], ["/sapf/src/FilterUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"FilterUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// classes for specializing feedback\n\nstruct NormalFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return x; }\n};\n\nstruct TanhApproximationFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return sc_tanh_approx(x); }\n};\n\nstruct UnityHardClipFeedback : public Gen\n{\n\tstatic inline double feedback(double x)\n\t{\n\t\tif (x <= -1.) return -1.;\n\t\tif (x >= 1.) return 1.;\n\t\treturn x;\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag : lagTime\");\n\tV in = th.popZIn(\"lag : in\");\n\n\tth.push(new List(new Lag(th, in, lagTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag2 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag2(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag2_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag2 : lagTime\");\n\tV in = th.popZIn(\"lag2 : in\");\n\n\tth.push(new List(new Lag2(th, in, lagTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag3 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag3(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag3_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag3 : lagTime\");\n\tV in = th.popZIn(\"lag3 : in\");\n\n\tth.push(new List(new Lag3(th, in, lagTime)));\n}\n\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstruct LagUD : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ b1 = y0 > y1 ? b1r : b1f;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ lagTime = y0 > y1 ? *riseTime : *fallTime;\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud : fallTime\");\n\tV riseTime = th.popZIn(\"lagud : riseTime\");\n\tV in = th.popZIn(\"lagud : in\");\n\n\tth.push(new List(new LagUD(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD2 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD2(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud2_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud2 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud2 : riseTime\");\n\tV in = th.popZIn(\"lagud2 : in\");\n\n\tth.push(new List(new LagUD2(th, in, riseTime, fallTime)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD3 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD3(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud3_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud3 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud3 : riseTime\");\n\tV in = th.popZIn(\"lagud3 : in\");\n\n\tth.push(new List(new LagUD3(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct FirstOrderLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct FirstOrderHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void lpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf1 : freq\");\n\tV in = th.popZIn(\"lpf1 : in\");\n\n\tth.push(new List(new FirstOrderLPF(th, in, freq)));\n}\n\nstatic void hpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf1 : freq\");\n\tV in = th.popZIn(\"hpf1 : in\");\n\n\tth.push(new List(new FirstOrderHPF(th, in, freq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0inv = 1. / a0;\n\t\t\t\tZ a1 = a0inv * (-2. * cs);\n\t\t\t\tZ a2 = a0inv * (1. - alpha);\n\t\t\t\tZ b1 = a0inv * (1. - cs);\n\t\t\t\tZ b0 = a0inv * (.5 * b1);\n\t\t\t\tZ b2 = a0inv * b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct LPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\t\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\nstruct HPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct HPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ntemplate \nstruct RLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RLPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRLPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\ntemplate \nstruct RHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRHPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RHPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRHPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct BPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b0 = alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * (x0 - x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstruct BSF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBSF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BSF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (x0 + x2 + a1 * (x1 - y1) - a2 * y2) * a0r;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\n\nstruct APF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tAPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"APF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2; \n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (a2 * (x0 - y2) + a1 * (x1 - y1)) * a0r + x2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct PEQ : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tPEQ(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PEQ\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alphaA = alpha * A;\n\t\t\t\tZ alphaOverA = alpha / A;\n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alphaOverA;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alphaOverA;\n\t\t\t\n\t\t\t\tZ b0 = 1. + alphaA;\n\t\t\t\tZ b2 = 1. - alphaA;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + a1 * (x1 - y1) + b2 * x2 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLowShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct HighShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHighShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HighShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 + Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 + Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 - Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ a2 = Ap1 - Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf1 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tLowShelf1(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf1\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ sqrt_g = t_dbamp(.25 * *gain);\n\t\t\t\tZ d = *freq * freqmul;\n\t\t\t\t\n\t\t\t\tZ p = 1. - d*sqrt_g;\n\t\t\t\tZ q = 1. - d/sqrt_g;\n\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = x0 + q * x1 - p * y1;\n\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct RLowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLowShelf(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = A*( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*A*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = A*( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void lpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf : freq\");\n\tV in = th.popZIn(\"lpf : in\");\n\n\tth.push(new List(new LPF(th, in, freq)));\n}\n\nstatic void lpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf2 : freq\");\n\tV in = th.popZIn(\"lpf2 : in\");\n\n\tth.push(new List(new LPF2(th, in, freq)));\n}\n\nstatic void hpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf : freq\");\n\tV in = th.popZIn(\"hpf : in\");\n\n\tth.push(new List(new HPF(th, in, freq)));\n}\n\nstatic void hpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf2 : freq\");\n\tV in = th.popZIn(\"hpf2 : in\");\n\n\tth.push(new List(new HPF2(th, in, freq)));\n}\n\n\n\nstatic void rlpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf : rq\");\n\tV freq = th.popZIn(\"rlpf : freq\");\n\tV in = th.popZIn(\"rlpf : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2 : rq\");\n\tV freq = th.popZIn(\"rlpf2 : freq\");\n\tV in = th.popZIn(\"rlpf2 : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf : rq\");\n\tV freq = th.popZIn(\"rhpf : freq\");\n\tV in = th.popZIn(\"rhpf : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2 : rq\");\n\tV freq = th.popZIn(\"rhpf2 : freq\");\n\tV in = th.popZIn(\"rhpf2 : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\nstatic void rlpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpfc : rq\");\n\tV freq = th.popZIn(\"rlpfc : freq\");\n\tV in = th.popZIn(\"rlpfc : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2c : rq\");\n\tV freq = th.popZIn(\"rlpf2c : freq\");\n\tV in = th.popZIn(\"rlpf2c : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpfc : rq\");\n\tV freq = th.popZIn(\"rhpfc : freq\");\n\tV in = th.popZIn(\"rhpfc : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2c : rq\");\n\tV freq = th.popZIn(\"rhpf2c : freq\");\n\tV in = th.popZIn(\"rhpf2c : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\n\nstatic void bpf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bpf : bw\");\n\tV freq = th.popZIn(\"bpf : freq\");\n\tV in = th.popZIn(\"bpf : in\");\n\n\tth.push(new List(new BPF(th, in, freq, bw)));\n}\n\nstatic void bsf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bsf : bw\");\n\tV freq = th.popZIn(\"bsf : freq\");\n\tV in = th.popZIn(\"bsf : in\");\n\n\tth.push(new List(new BSF(th, in, freq, bw)));\n}\n\nstatic void apf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"apf : bw\");\n\tV freq = th.popZIn(\"apf : freq\");\n\tV in = th.popZIn(\"apf : in\");\n\n\tth.push(new List(new APF(th, in, freq, bw)));\n}\n\nstatic void peq_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"peq : gain\");\n\tV bw = th.popZIn(\"peq : bw\");\n\tV freq = th.popZIn(\"peq : freq\");\n\tV in = th.popZIn(\"peq : in\");\n\n\tth.push(new List(new PEQ(th, in, freq, bw, gain)));\n}\n\nstatic void lsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf(th, in, freq, gain)));\n}\n\nstatic void hsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"hsf : gain\");\n\tV freq = th.popZIn(\"hsf : freq\");\n\tV in = th.popZIn(\"hsf : in\");\n\n\tth.push(new List(new HighShelf(th, in, freq, gain)));\n}\n\n\nstatic void lsf1_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf1(th, in, freq, gain)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Resonz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tResonz(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Resonz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. - .5 * w0 * *rq;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Ringz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _ringTime;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul, _K;\n\t\n\tRingz(Thread& th, Arg in, Arg freq, Arg ringTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, ringTime)), _in(in), _freq(freq), _ringTime(ringTime),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Ringz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *ringTime;\n\t\t\tint n, inStride, freqStride, ringTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tringTime += ringTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_ringTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Formlet : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _atkTime;\n\tZIn _dcyTime;\n\tZ _x1a, _x2a, _y1a, _y2a;\n\tZ _x1b, _x2b, _y1b, _y2b;\n\tZ _freqmul, _K;\n\t\n\tFormlet(Thread& th, Arg in, Arg freq, Arg atkTime, Arg dcyTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, atkTime, dcyTime)),\n\t\t\t_in(in), _freq(freq), _atkTime(atkTime), _dcyTime(dcyTime),\n\t\t\t_x1a(0.), _x2a(0.), _y1a(0.), _y2a(0.),\n\t\t\t_x1b(0.), _x2b(0.), _y1b(0.), _y2b(0.),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Formlet\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1a = _x1a;\n\t\tZ x2a = _x2a;\n\t\tZ y1a = _y1a;\n\t\tZ y2a = _y2a;\n\t\tZ x1b = _x1b;\n\t\tZ x2b = _x2b;\n\t\tZ y1b = _y1b;\n\t\tZ y2b = _y2b;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *atkTime, *dcyTime;\n\t\t\tint n, inStride, freqStride, atkTimeStride, dcyTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _atkTime(th, n, atkTimeStride, atkTime) || _dcyTime(th, n, dcyTimeStride, dcyTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ Ra = 1. + K / *atkTime;\n\t\t\t\tZ Rb = 1. + K / *dcyTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1a = 2. * Ra * cs;\n\t\t\t\tZ a2a = -(Ra * Ra);\n\t\t\t\tZ a1b = 2. * Rb * cs;\n\t\t\t\tZ a2b = -(Rb * Rb);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0a = *in;\n\t\t\t\tZ y0a = b0 * (x0a - x2a) + a1a * y1a + a2a * y2a;\n\t\t\t\n\t\t\t\tZ x0b = *in;\n\t\t\t\tZ y0b = b0 * (x0b - x2b) + a1b * y1b + a2b * y2b;\n\t\t\t\t\n\t\t\t\tout[i] = y0b - y0a;\n\t\t\t\ty2a = y1a;\n\t\t\t\ty1a = y0a;\n\t\t\t\tx2a = x1a;\n\t\t\t\tx1a = x0a;\n\n\t\t\t\ty2b = y1b;\n\t\t\t\ty1b = y0b;\n\t\t\t\tx2b = x1b;\n\t\t\t\tx1b = x0b;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tatkTime += atkTimeStride;\n\t\t\t\tdcyTime += dcyTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_atkTime.advance(n);\n\t\t\t_dcyTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1a = x1a;\n\t\t_x2a = x2a;\n\t\t_y1a = y1a;\n\t\t_y2a = y2a;\n\t\t\n\t\t_x1b = x1b;\n\t\t_x2b = x2b;\n\t\t_y1b = y1b;\n\t\t_y2b = y2b;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct KlankFilter\n{\n\tKlankFilter(V f, V a, V r) : \n\t\tfreq(f), amp(a), ringTime(r),\n\t\tx1(0.), x2(0.), y1(0.), y2(0.) {}\n\t\n\tZIn freq, amp, ringTime;\n\tZ x1, x2, y1, y2;\n\t\n};\n\nstruct Klank : public Gen\n{\n\tZIn _in;\n\tstd::vector _filters;\n\tZ _freqmul, _K;\n\tZ* inputBuffer;\n\t\n\tKlank(Thread& th, Arg in, V freqs, V amps, V ringTimes)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t\tinputBuffer = new Z[mBlockSize];\n\t\n\t\tint64_t numFilters = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, freqs.length(th)); \n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, amps.length(th)); \n\t\t}\n\t\tif (ringTimes.isVList()) { \n\t\t\tringTimes = ((List*)ringTimes.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, ringTimes.length(th)); \n\t\t}\n\t\t\n\t\tif (numFilters == LONG_MAX) numFilters = 1;\n\t\t\n\t\tfor (ssize_t i = 0; i < numFilters; ++i) {\n\t\t\tKlankFilter kf(freqs.at(i), amps.at(i), ringTimes.at(i));\n\t\t\t_filters.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\n\tvirtual ~Klank()\n\t{\n\t\tdelete [] inputBuffer;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Klank\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\t\n\t\t// copy input\n\t\tint numInputFrames = mBlockSize;\n\t\tif (_in.fill(th, numInputFrames, inputBuffer, 1))\n\t\t{\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tint maxToFill = 0;\n\n\t\tZ* out0 = mOut->fulfillz(numInputFrames);\n\t\tmemset(out0, 0, numInputFrames * sizeof(Z));\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ K = log001 * th.rate.invSampleRate;\n\t\t\n\t\tfor (size_t filter = 0; filter < _filters.size(); ++filter) {\n\t\t\tint framesToFill = numInputFrames;\n\t\t\tKlankFilter& kf = _filters[filter];\n\t\t\t\t\n\t\t\tZ x1 = kf.x1;\n\t\t\tZ x2 = kf.x2;\n\t\t\tZ y1 = kf.y1;\n\t\t\tZ y2 = kf.y2;\n\n\t\t\tZ* in = inputBuffer;\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp, *ringTime;\n\t\t\t\tint n, freqStride, ampStride, ringTimeStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (kf.freq(th, n, freqStride, freq) || kf.amp(th, n, ampStride, amp) || kf.ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\n\t\t\t\tif (freqStride == 0) {\n\t\t\t\t\tif (ringTimeStride == 0) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\n\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\n\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\n\t\t\t\t\t\t++in;\n\t\t\t\t\t\t++out;\n\t\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\tringTime += ringTimeStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tkf.freq.advance(n);\n\t\t\t\tkf.amp.advance(n);\n\t\t\t\tkf.ringTime.advance(n);\n\t\t\t}\n\t\t\tkf.x1 = x1;\n\t\t\tkf.x2 = x2;\n\t\t\tkf.y1 = y1;\n\t\t\tkf.y2 = y2;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\n\nstatic void resonz_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"resonz : rq\");\n\tV freq = th.popZIn(\"resonz : freq\");\n\tV in = th.popZIn(\"resonz : in\");\n\n\tth.push(new List(new Resonz(th, in, freq, rq)));\n}\n\nstatic void ringz_(Thread& th, Prim* prim)\n{\n\tV ringTime = th.popZIn(\"ringz : ringTime\");\n\tV freq = th.popZIn(\"ringz : freq\");\n\tV in = th.popZIn(\"ringz : in\");\n\n\tth.push(new List(new Ringz(th, in, freq, ringTime)));\n}\n\nstatic void formlet_(Thread& th, Prim* prim)\n{\n\tV dcyTime = th.popZIn(\"formlet : dcyTime\");\n\tV atkTime = th.popZIn(\"formlet : atkTime\");\n\tV freq = th.popZIn(\"formlet : freq\");\n\tV in = th.popZIn(\"formlet : in\");\n\n\tth.push(new List(new Formlet(th, in, freq, atkTime, dcyTime)));\n}\n\n\nstatic void klank_(Thread& th, Prim* prim)\n{\n\tV ringTimes = th.popZInList(\"klank : ringTimes\");\n\tV amps\t\t= th.popZInList(\"klank : amps\");\n\tV freqs = th.popZInList(\"klank : freqs\");\n\tV in\t\t= th.popZIn(\"klank : in\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (ringTimes.isVList() && !ringTimes.isFinite())\n\t\tindefiniteOp(\"klank : ringTimes\", \"\");\n\n\tth.push(new List(new Klank(th, in, freqs, amps, ringTimes)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakDC : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _x1, _y1;\n\t\n\tLeakDC(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_x1(0.), _y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakDC\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 - x1 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tx1 = x0;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leakdc_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leakdc : leak\");\n\tV in = th.popZIn(\"leakdc : in\");\n\n\tth.push(new List(new LeakDC(th, in, leak)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakyIntegrator : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _y1;\n\t\n\tLeakyIntegrator(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakyIntegrator\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leaky_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leaky : leak\");\n\tV in = th.popZIn(\"leaky : in\");\n\n\tth.push(new List(new LeakyIntegrator(th, in, leak)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay : public Gen\n{\n\tZIn _in;\n\tZIn _decayTime;\n\tZ _y1;\n\tZ _lagmul;\n\t\n\t\n\tDecay(Thread& th, Arg in, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, decayTime)), _in(in), _decayTime(decayTime), \n\t\t\t_y1(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *decayTime;\n\t\t\tint n, inStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (decayTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay : decayTime\");\n\tV in = th.popZIn(\"decay : in\");\n\n\tth.push(new List(new Decay(th, in, decayTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay2 : public Gen\n{\n\tZIn _in;\n\tZIn _attackTime;\n\tZIn _decayTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\t\n\t\n\tDecay2(Thread& th, Arg in, Arg attackTime, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, attackTime, decayTime)), _in(in), _attackTime(attackTime), _decayTime(decayTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *attackTime, *decayTime;\n\t\t\tint n, inStride, attackTimeStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _attackTime(th, n, attackTimeStride, attackTime) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (attackTimeStride == 0 && decayTimeStride == 0) {\n\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tattackTime += attackTimeStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_attackTime.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay2_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay2 : decayTime\");\n\tV attackTime = th.popZIn(\"decay2 : attackTime\");\n\tV in = th.popZIn(\"decay2 : in\");\n\n\tth.push(new List(new Decay2(th, in, attackTime, decayTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Phase90A : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90A(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90A\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z1;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct Phase90B : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90B(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90B\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z0;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct AmpFollow : public OneInputUGen\n{\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1a_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2a_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3a_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4a_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1a_ = 0.;\n\tZ v2a_ = 0.;\n\tZ w1a_ = 0.;\n\tZ w2a_ = 0.;\n\tZ x1a_ = 0.;\n\tZ x2a_ = 0.;\n\tZ y1a_ = 0.;\n\tZ y2a_ = 0.;\n\tZ z1a_ = 0.;\n\tZ z2a_ = 0.;\n\n\tconstexpr static Z c1b_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2b_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3b_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4b_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1b_ = 0.;\n\tZ v2b_ = 0.;\n\tZ w1b_ = 0.;\n\tZ w2b_ = 0.;\n\tZ x1b_ = 0.;\n\tZ x2b_ = 0.;\n\tZ y1b_ = 0.;\n\tZ y2b_ = 0.;\n\tZ z1b_ = 0.;\n\tZ z2b_ = 0.;\n\n\tZ b1r_;\n\tZ b1f_;\n\t\n\tZ l1a_ = 0.;\n\tZ l1b_ = 0.;\n\n\tAmpFollow(Thread& th, Arg in, Z atk, Z dcy)\n\t\t: OneInputUGen(th, in),\n\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t\tb1r_ = atk == 0. ? 0. : std::max(0., 1. + _lagmul / atk); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime)\n\t\tb1f_ = dcy == 0. ? 0. : std::max(0., 1. + _lagmul / dcy);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"AmpFollow\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1a = c1a_;\n\t\tZ c2a = c2a_;\n\t\tZ c3a = c3a_;\n\t\tZ c4a = c4a_;\n\t\t\n\t\tZ v1a = v1a_;\n\t\tZ v2a = v2a_;\n\t\tZ w1a = w1a_;\n\t\tZ w2a = w2a_;\n\t\tZ x1a = x1a_;\n\t\tZ x2a = x2a_;\n\t\tZ y1a = y1a_;\n\t\tZ y2a = y2a_;\n\t\tZ z1a = z1a_;\n\t\tZ z2a = z2a_;\n\n\t\tZ c1b = c1b_;\n\t\tZ c2b = c2b_;\n\t\tZ c3b = c3b_;\n\t\tZ c4b = c4b_;\n\t\t\n\t\tZ v1b = v1b_;\n\t\tZ v2b = v2b_;\n\t\tZ w1b = w1b_;\n\t\tZ w2b = w2b_;\n\t\tZ x1b = x1b_;\n\t\tZ x2b = x2b_;\n\t\tZ y1b = y1b_;\n\t\tZ y2b = y2b_;\n\t\tZ z1b = z1b_;\n\t\tZ z2b = z2b_;\n\t\t\n\t\tZ l1a = l1a_;\n\t\tZ l1b = l1b_;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\t{\n\t\t\t\tZ w0 = c1a * (v0 + w2a) - v2a;\n\t\t\t\tZ x0 = c2a * (w0 + x2a) - w2a;\n\t\t\t\tZ y0 = c3a * (x0 + y2a) - x2a;\n\t\t\t\tZ z0 = c4a * (y0 + z2a) - y2a;\n\t\t\t\tv2a = v1a;\n\t\t\t\tw2a = w1a;\n\t\t\t\tx2a = x1a;\n\t\t\t\ty2a = y1a;\n\t\t\t\tz2a = z1a;\n\t\t\t\tv1a = v0;\n\t\t\t\tw1a = w0;\n\t\t\t\tx1a = x0;\n\t\t\t\ty1a = y0;\n\t\t\t\tz1a = z0;\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tZ w0 = c1b * (v0 + w2b) - v2b;\n\t\t\t\tZ x0 = c2b * (w0 + x2b) - w2b;\n\t\t\t\tZ y0 = c3b * (x0 + y2b) - x2b;\n\t\t\t\tZ z0 = c4b * (y0 + z2b) - y2b;\n\t\t\t\tv2b = v1b;\n\t\t\t\tw2b = w1b;\n\t\t\t\tx2b = x1b;\n\t\t\t\ty2b = y1b;\n\t\t\t\tz2b = z1b;\n\t\t\t\tv1b = v0;\n\t\t\t\tw1b = w0;\n\t\t\t\tx1b = x0;\n\t\t\t\ty1b = y0;\n\t\t\t\tz1b = z0;\n\t\t\t}\n\t\t\t\n\t\t\tZ l0a = hypot(z1a, z1b); // vectorize this\n\n\t\t\tl1a = l0a + (l0a > l1a ? b1r_ : b1f_) * (l1a - l0a);\n\t\t\tl1b = l1a + (l1a > l1b ? b1r_ : b1f_) * (l1b - l1a);\n\t\t\tout[i] = l1b;\n\t\t}\n\t\tv1a_ = v1a;\n\t\tv2a_ = v2a;\n\t\tw1a_ = w1a;\n\t\tw2a_ = w2a;\n\t\tx1a_ = x1a;\n\t\tx2a_ = x2a;\n\t\ty1a_ = y1a;\n\t\ty2a_ = y2a;\n\t\tz1a_ = z1a;\n\t\tz2a_ = z2a;\n\n\t\tv1b_ = v1b;\n\t\tv2b_ = v2b;\n\t\tw1b_ = w1b;\n\t\tw2b_ = w2b;\n\t\tx1b_ = x1b;\n\t\tx2b_ = x2b;\n\t\ty1b_ = y1b;\n\t\ty2b_ = y2b;\n\t\tz1b_ = z1b;\n\t\tz2b_ = z2b;\n\t\t\n\t\tl1a_ = l1a;\n\t\tl1b_ = l1b;\n\t}\n};\n\nstatic void hilbert_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"hilbert : in\");\n\t\n\tth.push(new List(new Phase90A(th, in)));\n\tth.push(new List(new Phase90B(th, in)));\n}\n\nstatic void ampf_(Thread& th, Prim* prim)\n{\n\tZ dcy = th.popFloat(\"ampf : dcyTime\");\n\tZ atk = th.popFloat(\"ampf : atkTime\");\n\tV in = th.popZIn(\"ampf : in\");\n\t\n\tth.push(new List(new AmpFollow(th, in, atk, dcy)));\n}\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** filter unit generators ***\");\n\tDEFMCX(lag, 2, \"(in decayTime --> out) one pole lag filter. decayTime determines rate of convergence.\")\n\tDEFMCX(lag2, 2, \"(in decayTime --> out) cascade of two one pole lag filters. decayTime determines rate of convergence.\")\n\tDEFMCX(lag3, 2, \"(in decayTime --> out) cascade of three one pole lag filters. decayTime determines rate of convergence.\")\n\n\tDEFMCX(lagud, 3, \"(in upDecayTime, downDecayTime --> out) one pole lag filter. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud2, 3, \"(in upDecayTime, downDecayTime --> out) cascade of two one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud3, 3, \"(in upDecayTime, downDecayTime --> out) cascade of three one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\t\n\tDEFMCX(lpf1, 2, \"(in freq --> out) low pass filter. 6 dB/oct.\")\n\tDEFMCX(hpf1, 2, \"(in freq --> out) high pass filter. 6 dB/oct.\")\n\tDEFMCX(lpf, 2, \"(in freq --> out) low pass filter. 12 dB/oct.\")\n\tDEFMCX(hpf, 2, \"(in freq --> out) high pass filter. 12 dB/oct.\")\n\tDEFMCX(lpf2, 2, \"(in freq --> out) low pass filter. 24 dB/oct.\")\n\tDEFMCX(hpf2, 2, \"(in freq --> out) high pass filter. 24 dB/oct.\")\n\t\n\tDEFMCX(rlpf, 3, \"(in freq rq --> out) resonant low pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf, 3, \"(in freq rq --> out) resonant high pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2, 3, \"(in freq rq --> out) resonant low pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2, 3, \"(in freq rq --> out) resonant high pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\t\n\tDEFMCX(rlpfc, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpfc, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2c, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2c, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\n\tDEFMCX(bpf, 3, \"(in freq bw --> out) band pass filter. bw is bandwidth in octaves.\")\n\tDEFMCX(bsf, 3, \"(in freq bw --> out) band stop filter. bw is bandwidth in octaves.\")\n\tDEFMCX(apf, 3, \"(in freq bw --> out) all pass filter. bw is bandwidth in octaves.\")\n\t\n\tDEFMCX(peq, 4, \"(in freq bw gain --> out) parametric equalization filter. bw is bandwidth in octaves.\")\n\tDEFMCX(lsf, 3, \"(in freq gain --> out) low shelf filter.\")\n\tDEFMCX(hsf, 3, \"(in freq gain --> out) high shelf filter.\")\n\tDEFMCX(lsf1, 3, \"(in freq gain --> out) low shelf filter.\")\n\n\tDEFMCX(resonz, 3, \"(in freq rq --> out) resonant filter.\")\n\tDEFMCX(ringz, 3, \"(in freq ringTime --> out) resonant filter specified by a ring time in seconds.\")\n\tDEFMCX(formlet, 4, \"(in freq atkTime dcyTime --> out) a formant filter whose impulse response is a sine grain.\")\n\tDEFAM(klank, zaaa, \"(in freqs amps ringTimes --> out) a bank of ringz filters. freqs amps and ringTimes are arrays.\")\n\n\tDEFMCX(leakdc, 2, \"(in coef --> out) leaks away energy at 0 Hz.\")\n\tDEFMCX(leaky, 2, \"(in coef --> out) leaky integrator.\")\n\tDEFMCX(decay, 2, \"(in decayTime --> out) outputs an exponential decay for impulses at the input.\")\n\tDEFMCX(decay2, 3, \"(in atkTime dcyTime --> out) outputs an exponential attack and decay for impulses at the input.\")\n\n\tDEFMCX(hilbert, 1, \"(in --> outA outB) returns two signals that are 90 degrees phase shifted from each other.\")\n\tDEFMCX(ampf, 3, \"(in atkTime dcyTime --> out) amplitude follower.\")\n}\n\n\n\n"], ["/sapf/src/main.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \n#include \n#include \n#include \n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \"Manta.h\"\n\nclass MyManta : public Manta\n{\n\tvirtual void PadEvent(int row, int column, int id, int value) {\n\t\tprintf(\"pad %d %d %d %d\\n\", row, column, id, value);\n\t}\n\tvirtual void SliderEvent(int id, int value) {\n\t\tprintf(\"slider %d %d\\n\", id, value);\n\t}\n\tvirtual void ButtonEvent(int id, int value) {\n\t\tprintf(\"button %d %d\\n\", id, value);\n\t}\n\tvirtual void PadVelocityEvent(int row, int column, int id, int velocity) {\n\t\tprintf(\"pad vel %d %d %d %d\\n\", row, column, id, velocity);\n\n\t}\n\tvirtual void ButtonVelocityEvent(int id, int velocity) {\n\t\tprintf(\"button vel %d %d\\n\", id, velocity);\n\t}\n\tvirtual void FrameEvent(uint8_t *frame) {}\n\tvirtual void DebugPrint(const char *fmt, ...) {}\n};\n\nManta* manta();\nManta* manta()\n{\n\tstatic MyManta* sManta = new MyManta();\n\treturn sManta;\n}\n\n/* issue:\n\n[These comments are very old and I have not checked if they are still relevant.]\n\nTableData alloc should use new\n\nbugs:\n\nitd should have a tail time. currently the ugen stops as soon as its input, cutting off the delayed signal.\n\n+ should not stop until both inputs stop?\nother additive binops: - avg2 sumsq\n\nno, use a operator \n\n---\n\nadsrg (gate a d s r --> out) envelope generator with gate. \nadsr (dur a d s r --> out) envelope generator with duration. \nevgg - (gate levels times curves suspt --> out) envelope generator with gate. suspt is the index of the sustain level. \nevg - (dur levels times curves suspt --> out) envelope generator with duration. suspt is the index of the sustain level.\n\nblip (freq phase nharm --> out) band limited impulse oscillator.\ndsf1 (freq phase nharm lharm hmul --> out) sum of sines oscillator.\n\nformant (freq formfreq bwfreq --> out) formant oscillator\n\nsvf (in freq rq --> [lp hp bp bs]) state variable filter.\nmoogf (in freq rq --> out) moog ladder low pass filter.\n\n*/\n\nextern void AddCoreOps();\nextern void AddMathOps();\nextern void AddStreamOps();\nextern void AddLFOps();\nextern void AddUGenOps();\nextern void AddSetOps();\nextern void AddRandomOps();\nextern void AddMidiOps();\n\nconst char* gVersionString = \"0.1.21\";\n\nstatic void usage()\n{\n\tfprintf(stdout, \"sapf [-r sample-rate][-p prelude-file]\\n\");\n\tfprintf(stdout, \"\\n\");\n\tfprintf(stdout, \"sapf [-h]\\n\");\n\tfprintf(stdout, \" print this help\\n\");\n\tfprintf(stdout, \"\\n\");\t\n}\n\nint main (int argc, const char * argv[]) \n{\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"A tool for the expression of sound as pure form.\\n\");\t\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"--- version %s\\n\", gVersionString);\n\t\n\tfor (int i = 1; i < argc;) {\n\t\tint c = argv[i][0];\n\t\tif (c == '-') {\n\t\t\tc = argv[i][1];\n\t\t\tswitch (c) {\n\t\t\t\tcase 'r' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected sample rate after -r\\n\"); return 1; }\n\t\t\t\t\t\t\n\t\t\t\t\tdouble sr = atof(argv[i+1]);\n\t\t\t\t\tif (sr < 1000. || sr > 768000.) { post(\"sample rate out of range.\\n\"); return 1; }\n\t\t\t\t\tvm.setSampleRate(sr);\n\t\t\t\t\tpost(\"sample rate set to %g\\n\", vm.ar.sampleRate);\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'p' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected prelude file name after -p\\n\"); return 1; }\n\t\t\t\t\tvm.prelude_file = argv[i+1];\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'h' : {\n\t\t\t\t\tusage();\n\t\t\t\t\texit(0);\n\t\t\t\t} break;\n\t\t\t\tdefault: \n\t\t\t\t\tpost(\"unrecognized option -%c\\n\", c);\n\t\t\t}\n\t\t} else {\n\t\t\tpost(\"expected option, got \\\"%s\\\"\\n\", argv[i]);\n\t\t\t++i;\n\t\t}\n\t}\n\t\n\t\n\tvm.addBifHelp(\"Argument Automapping legend:\");\n\tvm.addBifHelp(\" a - as is. argument is not automapped.\");\n\tvm.addBifHelp(\" z - argument is expected to be a signal or scalar, streams are auto mapped.\");\n\tvm.addBifHelp(\" k - argument is expected to be a scalar, signals and streams are automapped.\");\n\tvm.addBifHelp(\"\");\n\t\n\tAddCoreOps();\n\tAddMathOps();\n\tAddStreamOps();\n AddRandomOps();\n\tAddUGenOps();\n\tAddMidiOps();\n AddSetOps();\n\t\n\t\n\tvm.log_file = getenv(\"SAPF_LOG\");\n\tif (!vm.log_file) {\n\t\tconst char* home_dir = getenv(\"HOME\");\n\t\tchar logfilename[PATH_MAX];\n\t\tsnprintf(logfilename, PATH_MAX, \"%s/sapf-log.txt\", home_dir);\n\t\tvm.log_file = strdup(logfilename);\n\t}\n\t\n\t__block Thread th;\n\n\tauto m = manta();\n\ttry {\n\t\tm->Connect();\n\t} catch(...) {\n\t}\n\tprintf(\"Manta %s connected.\\n\", m->IsConnected() ? \"is\" : \"IS NOT\");\n\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\t/*** see at bottom for better way ***/\n\t\twhile(true) {\n\t\t\ttry {\n\t\t\t\tMantaUSB::HandleEvents();\n\t\t\t\tusleep(5000);\n\t\t\t} catch(...) {\n\t\t\t\tsleep(1);\n\t\t\t}\n\t\t}\n\t});\n\t\n\tif (!vm.prelude_file) {\n\t\tvm.prelude_file = getenv(\"SAPF_PRELUDE\");\n\t}\n\tif (vm.prelude_file) {\n\t\tloadFile(th, vm.prelude_file);\n\t}\n\t\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\tth.repl(stdin, vm.log_file);\n\t\texit(0);\n\t});\n\t\n\tCFRunLoopRun();\n\t\n\treturn 0;\n}\n\n"], ["/sapf/src/Spectrogram.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Spectrogram.hpp\"\n#include \"makeImage.hpp\"\n#include \n#include \n#include \n#include \n\nstatic void makeColorTable(unsigned char* table);\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double i0(double x)\n{\n\tconst double epsilon = 1e-18;\n\tint n = 1;\n\tdouble S = 1., D = 1., T;\n\n\twhile (D > epsilon * S) {\n\t\tT = x / (2 * n++);\n\t\tD *= T * T;\n\t\tS += D;\n\t}\n\treturn S;\n}\n\nstatic void calcKaiserWindowD(size_t size, double* window, double stopBandAttenuation)\n{\n\tsize_t M = size - 1;\n\tsize_t N = M-1;\n#if VERBOSE\n\tprintf(\"FillKaiser %d %g\\n\", M, stopBandAttenuation);\n#endif\n\n\tdouble alpha = 0.;\n\tif (stopBandAttenuation <= -50.)\n\t\talpha = 0.1102 * (-stopBandAttenuation - 8.7);\n else if (stopBandAttenuation < -21.)\n\t\talpha = 0.5842 * pow(-stopBandAttenuation - 21., 0.4) + 0.07886 * (-stopBandAttenuation - 21.);\n\n\tdouble p = N / 2;\n\tdouble kk = 1.0 / i0(alpha);\n\n\tfor(unsigned int k = 0; k < M; k++ )\n\t{\n\t\tdouble x = (k-p) / p;\n\t\t\n\t\t// Kaiser window\n\t\twindow[k+1] *= kk * bessi0(alpha * sqrt(1.0 - x*x) );\n\t}\n\twindow[0] = 0.;\n\twindow[size-1] = 0.;\n#if VERBOSE\n\tprintf(\"done\\n\");\n#endif\n}\n\nconst int border = 8;\n\nvoid spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor)\n{\n\tint numRealFreqs = 1 << log2bins;\n\n\tint log2n = log2bins + 1;\n\tint n = 1 << log2n;\n\tint nOver2 = n / 2;\n\t\n\n\tdouble scale = 1./nOver2;\n\t\n\tint64_t paddedSize = size + n;\n\tdouble* paddedData = (double*)calloc(paddedSize, sizeof(double));\n\tmemcpy(paddedData + nOver2, data, size * sizeof(double));\n\n\t\n\tdouble* dBMags = (double*)calloc(numRealFreqs + 1, sizeof(double));\n\n\tdouble hopSize = size <= n ? 0 : (double)(size - n) / (double)(width - 1);\n\n\tdouble* window = (double*)calloc(n, sizeof(double));\n\tfor (int i = 0; i < n; ++i) window[i] = 1.;\n\tcalcKaiserWindowD(n, window, -180.);\n\n\tunsigned char table[1028];\n\tmakeColorTable(table);\n\n\tint heightOfAmplitudeView = 128;\n\tint heightOfFFT = numRealFreqs+1;\n\tint totalHeight = heightOfAmplitudeView+heightOfFFT+3*border;\n\tint topOfSpectrum = heightOfAmplitudeView + 2*border;\n\tint totalWidth = width+2*border;\n\tBitmap* b = createBitmap(totalWidth, totalHeight);\n\tfillRect(b, 0, 0, totalWidth, totalHeight, 160, 160, 160, 255);\n\tfillRect(b, border, border, width, heightOfAmplitudeView, 0, 0, 0, 255);\n\t\n\tFFTSetupD fftSetup = vDSP_create_fftsetupD(log2n, kFFTRadix2);\n\n\tdouble* windowedData = (double*)calloc(n, sizeof(double));\n\tdouble* interleavedData = (double*)calloc(n, sizeof(double));\n\tdouble* resultData = (double*)calloc(n, sizeof(double));\n\tDSPDoubleSplitComplex interleaved;\n\tinterleaved.realp = interleavedData;\n\tinterleaved.imagp = interleavedData + nOver2;\n\tDSPDoubleSplitComplex result;\n\tresult.realp = resultData;\n\tresult.imagp = resultData + nOver2;\n\tdouble maxmag = 0.;\n\t\n\tdouble hpos = nOver2;\n\tfor (int i = 0; i < width; ++i) {\n\t\tsize_t ihpos = (size_t)hpos;\n\t\t\n\t\t// do analysis\n\t\t// find peak\n\t\tdouble peak = 1e-20;\n\t\tfor (int w = 0; w < n; ++w) {\n\t\t\tdouble x = paddedData[w+ihpos];\n\t\t\tx = fabs(x);\n\t\t\tif (x > peak) peak = x;\n\t\t}\n\t\t\n\t\tfor (int64_t w = 0; w < n; ++w) windowedData[w] = window[w] * paddedData[w+ihpos];\n\t\t\n\t\tvDSP_ctozD((DSPDoubleComplex*)windowedData, 2, &interleaved, 1, nOver2);\n\t\t\n\t\tvDSP_fft_zropD(fftSetup, &interleaved, 1, &result, 1, log2n, kFFTDirection_Forward);\n\t\t\n\t\tdBMags[0] = result.realp[0] * scale;\n\t\tdBMags[numRealFreqs] = result.imagp[0] * scale;\n\t\tif (dBMags[0] > maxmag) maxmag = dBMags[0];\n\t\tif (dBMags[numRealFreqs] > maxmag) maxmag = dBMags[numRealFreqs];\n\t\tfor (int64_t j = 1; j < numRealFreqs-1; ++j) {\n\t\t\tdouble x = result.realp[j] * scale;\n\t\t\tdouble y = result.imagp[j] * scale;\n\t\t\tdBMags[j] = sqrt(x*x + y*y);\n\t\t\tif (dBMags[j] > maxmag) maxmag = dBMags[j];\n\t\t}\n\n\t\tdouble invmag = 1.;\n\t\tdBMags[0] = 20.*log2(dBMags[0]*invmag);\n\t\tdBMags[numRealFreqs] = 20.*log10(dBMags[numRealFreqs]*invmag);\n\t\tfor (int64_t j = 0; j <= numRealFreqs-1; ++j) {\n\t\t\tdBMags[j] = 20.*log10(dBMags[j]*invmag);\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t// set pixels\n\t\t{\n\t\t\tdouble peakdB = 20.*log10(peak);\n\t\t\tint peakColorIndex = 256. - peakdB * (256. / dBfloor);\n\t\t\tint peakIndex = heightOfAmplitudeView - peakdB * (heightOfAmplitudeView / dBfloor);\n\t\t\tif (peakIndex < 0) peakIndex = 0;\n\t\t\tif (peakIndex > heightOfAmplitudeView) peakIndex = heightOfAmplitudeView;\n\t\t\tif (peakColorIndex < 0) peakColorIndex = 0;\n\t\t\tif (peakColorIndex > 255) peakColorIndex = 255;\n\n\t\t\tunsigned char* t = table + 4*peakColorIndex;\n\t\t\tfillRect(b, i+border, border+128-peakIndex, 1, peakIndex, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\t\n\t\tfor (int j = 0; j < numRealFreqs; ++j) {\n\t\t\tint colorIndex = 256. - dBMags[j] * (256. / dBfloor); \n\t\t\tif (colorIndex < 0) colorIndex = 0;\n\t\t\tif (colorIndex > 255) colorIndex = 255;\n\t\t\t\n\t\t\tunsigned char* t = table + 4*colorIndex;\n\t\t\t\n\t\t\tsetPixel(b, i+border, numRealFreqs-j+topOfSpectrum, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\t\n\t\thpos += hopSize;\n\t}\n\n\tvDSP_destroy_fftsetupD(fftSetup);\n\t\n\twriteBitmap(b, path);\n\tfreeBitmap(b);\n\tfree(dBMags);\n\tfree(paddedData);\n\tfree(window);\n\tfree(windowedData);\n\tfree(interleavedData);\n\tfree(resultData);\n}\n\n\nstatic void makeColorTable(unsigned char* table)\n{\n\t// white >> red >> yellow >> green >> cyan >> blue >> magenta >> pink >> black\n\t// 0 -20 -40 -60 -80 -100 -120 -140 -160\n\t// 255 224 192 160 128 96 64 32 0\n\t\n\tint colors[9][4] = {\n\t\t{ 0, 0, 64, 255},\t// dk blue\n\t\t{ 0, 0, 255, 255},\t// blue\n\t\t{255, 0, 0, 255},\t// red\n\t\t{255, 255, 0, 255},\t// yellow\n\t\t{255, 255, 255, 255}\t// white\n\t};\n\t\n\tfor (int j = 0; j < 4; ++j) {\n\t\tfor (int i = 0; i < 64; ++i) {\n\t\t\tfor (int k = 0; k < 4; ++k) {\n\t\t\t\tint x = (colors[j][k] * (64 - i) + colors[j+1][k] * i) / 64;\n\t\t\t\tif (x > 255) x = 255;\n\t\t\t\ttable[j*64*4 + i*4 + k + 4] = x;\n\t\t\t}\n\t\t}\n\t}\n\t\n\ttable[0] = 0;\n\ttable[1] = 0;\n\ttable[2] = 0;\n\ttable[3] = 255;\n}\n\n"], ["/sapf/src/symbol.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"symbol.hpp\"\n#include \"VM.hpp\"\n#include \"Hash.hpp\"\n#include \n#include \n\nconst int kSymbolTableSize = 4096;\nconst int kSymbolTableMask = kSymbolTableSize - 1;\n\t\n// global atomic symbol table\nvolatile std::atomic sSymbolTable[kSymbolTableSize];\n\n\n\nstatic String* SymbolTable_lookup(String* list, const char* name, int32_t hash)\n{\n\twhile (list) {\n\t\tif (list->hash == hash && strcmp(list->s, name) == 0)\n\t\t\treturn list;\n\t\tlist = list->nextSymbol;\n\t}\n\treturn nullptr;\n}\n\nstatic String* SymbolTable_lookup(const char* name, int hash)\n{\n\treturn SymbolTable_lookup(sSymbolTable[hash & kSymbolTableMask].load(), name, hash);\n}\n\nstatic String* SymbolTable_lookup(const char* name)\n{\n\tuintptr_t hash = Hash(name);\n\treturn SymbolTable_lookup(name, (int)hash);\n}\n\nP getsym(const char* name)\n{\n\t// thread safe\n\n\tint32_t hash = Hash(name);\n int32_t binIndex = hash & kSymbolTableMask;\n\tvolatile std::atomic* bin = &sSymbolTable[binIndex];\n\twhile (1) {\n // get the head of the list.\n\t\tString* head = bin->load();\n // search the list for the symbol\n\t\tString* existingSymbol = head;\n\t\twhile (existingSymbol) {\n\t\t\tif (existingSymbol->hash == hash && strcmp(existingSymbol->s, name) == 0) {\n\t\t\t\treturn existingSymbol;\n\t\t\t}\n\t\t\texistingSymbol = existingSymbol->nextSymbol;\n\t\t}\n\t\tString* newSymbol = new String(name, hash, head);\n\t\tif (bin->compare_exchange_weak(head, newSymbol)) {\n\t\t\tnewSymbol->retain(); \n\t\t\treturn newSymbol;\n\t\t}\n delete newSymbol;\n\t}\t\n}\n"], ["/sapf/libmanta/Manta.h", "class Manta {\n public:\n Manta(void) {\n for(int i = 0; i < 53; ++i)\n {\n LastInReport[i] = 0;\n MaxSensorValues[i] = AverageMaxSensorValues[i];\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = 0xFF;\n }\n for(unsigned int i = 0; i < sizeof(CurrentOutReport); ++i)\n {\n CurrentOutReport[i] = 0;\n }\n for(unsigned int i = 0; i < sizeof(VelocityWaiting) / sizeof(VelocityWaiting[0]); ++i)\n {\n VelocityWaiting[i] = false;\n }\n}\n virtual void SetPadLED(LEDState state, int ledID) {\n int row = ledID / 8;\n int column = ledID % 8;\n\n if(ledID < 0 || ledID > 47)\n {\n throw std::invalid_argument(\"Invalid Pad Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= (1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= (1 << column);\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n break;\n case Off:\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) {\n if(row < 0 || row > 5)\n {\n throw std::invalid_argument(\"Invalid Row Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDRow(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", row, mask);\n MantaClient::DebugPrint(\"ByteReverse(0x%X) = 0x%X\", 0xA0, byteReverse(0xA0));\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= byteReverse(mask);\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n case Off:\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) {\n if(column < 0 || column > 7)\n {\n throw std::invalid_argument(\"Invalid Column Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDColumn(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", column, mask);\n switch(state)\n {\n case Amber:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[AmberIndex + i] |= (0x01 << column);\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Red:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] |= (0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Off:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) {\n switch(state)\n {\n case Amber:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Red:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Off:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case All:\n // when setting both colors we use two frames at once\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n uint8_t amberMask = mask[i];\n uint8_t redMask = mask[i+sizeof(LEDFrame)];\n // turn off any amber LEDs if there's a red LED in that position\n amberMask &= ~redMask;\n CurrentOutReport[RedIndex + i] = byteReverse(redMask);\n CurrentOutReport[AmberIndex + i] = byteReverse(amberMask);\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) {\n if(id < 0 || id > 1)\n {\n throw std::invalid_argument(\"Invalid Slider Index\");\n }\n switch(state)\n {\n case Amber:\n CurrentOutReport[SliderIndex + id] |= byteReverse(mask);\n break;\n case Red:\n /* no Red slider LEDs, do nothing */\n break;\n case Off:\n CurrentOutReport[SliderIndex + id] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetButtonLED(LEDState state, int id) {\n if(id < 0 || id > 3)\n {\n throw std::invalid_argument(\"Invalid Button Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n break;\n case Red:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n case Off:\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ResendLEDState(void) {\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearPadAndButtonLEDs(void) {\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] = 0;\n CurrentOutReport[RedIndex + i] = 0;\n }\n\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearButtonLEDs(void) {\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void Recalibrate(void) {\n if(! IsConnected())\n {\n throw MantaNotConnectedException(this);\n }\n\n /* make sure these messages get queued so that they\n * don't just cancel each other out */\n CurrentOutReport[ConfigIndex] |= 0x40;\n WriteFrame(CurrentOutReport, true);\n CurrentOutReport[ConfigIndex] &= ~0x40;\n WriteFrame(CurrentOutReport, true);\n}\n virtual void SetLEDControl(LEDControlType control, bool state) {\n uint8_t flag;\n\n switch(control)\n {\n case PadAndButton:\n flag = 0x01;\n break;\n case Slider:\n flag = 0x02;\n break;\n case Button:\n flag = 0x20;\n break;\n default:\n throw std::invalid_argument(\"Invalid Control Type\");\n }\n\n if(state)\n CurrentOutReport[ConfigIndex] |= flag;\n else\n CurrentOutReport[ConfigIndex] &= ~flag;\n if(IsConnected())\n {\n /* if we're disabling LEDControl, we want to make sure that this\n * message gets queued so that any pending LED messages get sent\n * down before we disable LEDs */\n WriteFrame(CurrentOutReport, !state);\n }\n}\n virtual void SetTurboMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x04;\n else\n CurrentOutReport[ConfigIndex] &= ~0x04;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetRawMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x08;\n else\n CurrentOutReport[ConfigIndex] &= ~0x08;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetMaxSensorValues(int *values) {\n for(int i = 0; i < 53; ++i)\n {\n MaxSensorValues[i] = values[i];\n }\n}\n private:\n virtual void FrameReceived(int8_t *frame) {\nbool hadEvent = false;\n uint8_t *uframe = (uint8_t *)frame;\n for(int i = 1; i < 53; ++i)\n {\n uframe[i] = ScaleSensorValue(frame[i] + 128, i);\n }\n /* apply the offset to the slider bytes without scaling them */\n for(int i = 53; i < 57; ++i)\n {\n uframe[i] = frame[i] + 128;\n }\n //printf(\"\\n\");\n FrameEvent(uframe);\n /* input frames have one reportID byte at the beginning */\n for(int i = 1; i < 53; ++i)\n {\n /*\n * overall pad logic:\n * if there's a velocity waiting to be calculated, send a note-on\n * if this is the first zero value, send a note-off\n * if the pad changed, send a padValue\n */\n int padIndex = i - 1;\n /* track whether this pad just went high for a single sample,\n * so we don't trigger a simultaneous note-on and note-off */\n bool singleSample = false;\n\n /* check to see if there's a previous sample waiting to have\n * the velocity algorithm run */\n if(VelocityWaiting[i])\n {\n if(uframe[i] == 0)\n {\n // we were waiting for a 2nd sample for velocity but we got zero.\n singleSample = true;\n }\n else\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n VelocityWaiting[i] = false;\n }\n\n\n if(uframe[i] != LastInReport[i])\n {\n if(padIndex < 48) {\n PadEvent(padIndex / 8, padIndex % 8, padIndex, uframe[i]);\n\t\t\t hadEvent = true;\n } else {\n ButtonEvent(padIndex - 48, uframe[i]);\n\t\t\t hadEvent = true;\n\t\t}\n\n /* check to see if this is a release */\n if(0 == uframe[i] && !singleSample)\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex, 0);\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48, 0);\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n /* check to see if this is the first nonzero sample */\n else if(0 == LastInReport[i])\n {\n VelocityWaiting[i] = true;\n }\n }\n LastInReport[i] = uframe[i];\n }\n if(uframe[53] != LastInReport[53] || uframe[54] != LastInReport[54])\n {\n\t //printf(\"slider 0 %3d %3d\\n\", (int)uframe[53], uframe[54]);\n\t int value = (uframe[53]) | ((uframe[54]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n if(uframe[55] != LastInReport[55] || uframe[56] != LastInReport[56])\n {\n\t //printf(\"slider 1 %3d %3d\\n\", (int)uframe[55], uframe[56]);\n\t int value = (uframe[55]) | ((uframe[56]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = uframe[i];\n }\n\t\n if (hadEvent) printf(\"---\\n\");\n}\n int ScaleSensorValue(int rawValue, int index) {\n float div = (float)rawValue / MaxSensorValues[index];\n return (int)((div * 210) + 0.5);\n}\n static uint8_t byteReverse(uint8_t inByte) {\n // Algorithm from Bit Twiddling Hacks\n uint8_t outByte = inByte; // first get LSB of inByte\n int s = 7; // extra shift needed at end\n\n for (inByte >>= 1; inByte; inByte >>= 1)\n {\n outByte <<= 1;\n outByte |= inByte & 1;\n s--;\n }\n outByte <<= s; // shift when inByte's highest bits are zero\n return outByte;\n}\n static int CalculateVelocity(int firstValue, int secondValue) {\n float LOG1, LOG2;\n float MAX;\n float MIN;\n float RELATIVE1, RELATIVE2;\n float LOG_RELATIVE1, LOG_RELATIVE2;\n float SUM_RAW;\n float LOG_SUM_RAW;\n float LOG_SUM_RELATIVE;\n float UP1;\n float VELOCITY = 0;\n int VELint = 0;\n\n\n // now do the velocity calculation\n LOG1 = log(1.0 + (float)LastValue);\n LOG2 = log(1.0 + (float)CurrentValue);\n\n MIN = LastValue;\n if (CurrentValue < MIN)\n {\n MIN = CurrentValue;\n }\n MAX = LastValue;\n if (CurrentValue > MAX)\n {\n MAX = CurrentValue;\n }\n RELATIVE1 = LastValue/MAX;\n RELATIVE2 = CurrentValue/MAX;\n LOG_RELATIVE1 = log(1.0 + RELATIVE1);\n LOG_RELATIVE2 = log(1.0 + RELATIVE2);\n SUM_RAW = LastValue+CurrentValue;\n LOG_SUM_RAW = log(1.0 + SUM_RAW);\n LOG_SUM_RELATIVE = log(1.0 + SUM_RAW/MAX);\n UP1 = 0;\n if (CurrentValue>LastValue) { UP1 = 1; }\n VELOCITY =\n -14.997037 +\n LastValue * 0.009361 +\n MIN * -0.014234 +\n LOG1 * 1.099763 +\n RELATIVE2 * -9.588311 +\n LOG_RELATIVE1 *-27.595303 +\n LOG_RELATIVE2 * -8.803761 +\n LOG_SUM_RELATIVE * 44.013138 +\n UP1 * 0.221622;\n //Then trim value to [0.4] range:\n if (VELOCITY < 0.)\n {\n VELOCITY = 0.;\n }\n if (VELOCITY > 4.)\n {\n VELOCITY = 4.;\n }\n //get it to 0. to 1. range\n VELOCITY = VELOCITY / 4.;\n // curve it exponentially\n VELOCITY = VELOCITY * VELOCITY;\n //get it to 0-126 range\n VELOCITY = VELOCITY * 126;\n //get it to 1-127 range\n VELOCITY = VELOCITY+ 1;\n //round to ints\n VELint = (int)VELOCITY;\n return VELint;\n}\n static const int AmberIndex = 0;\n static const int RedIndex = 10;\n static const int SliderIndex = 7;\n static const int ButtonIndex = 6;\n static const int ConfigIndex = 9;\n static const int AverageMaxSensorValues[53];\n int MaxSensorValues[53];\n uint8_t LastInReport[InPacketLen];\n uint8_t CurrentOutReport[OutPacketLen];\n bool VelocityWaiting[53];\n bool CentroidEnabled;\n bool MaximumEnabled;\n bool PadFrameEnabled;\n};"], ["/sapf/libmanta/extern/hidapi/hidapi/hidapi.h", "/*******************************************************\n HIDAPI - Multi-Platform library for\n communication with HID devices.\n\n Alan Ott\n Signal 11 Software\n\n 8/22/2009\n\n Copyright 2009, All Rights Reserved.\n\n At the discretion of the user of this library,\n this software may be licensed under the terms of the\n GNU Public License v3, a BSD-Style license, or the\n original HIDAPI license as outlined in the LICENSE.txt,\n LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt\n files located at the root of the source distribution.\n These files may also be found in the public source\n code repository located at:\n http://github.com/signal11/hidapi .\n********************************************************/\n\n/** @file\n * @defgroup API hidapi API\n */\n\n#ifndef HIDAPI_H__\n#define HIDAPI_H__\n\n#include \n\n#ifdef _WIN32\n #define HID_API_EXPORT __declspec(dllexport)\n #define HID_API_CALL\n#else\n #define HID_API_EXPORT /**< API export macro */\n #define HID_API_CALL /**< API call macro */\n#endif\n\n#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\t\tstruct hid_device_;\n\t\ttypedef struct hid_device_ hid_device; /**< opaque hidapi structure */\n\n\t\t/** hidapi info structure */\n\t\tstruct hid_device_info {\n\t\t\t/** Platform-specific device path */\n\t\t\tchar *path;\n\t\t\t/** Device Vendor ID */\n\t\t\tunsigned short vendor_id;\n\t\t\t/** Device Product ID */\n\t\t\tunsigned short product_id;\n\t\t\t/** Serial Number */\n\t\t\twchar_t *serial_number;\n\t\t\t/** Device Release Number in binary-coded decimal,\n\t\t\t also known as Device Version Number */\n\t\t\tunsigned short release_number;\n\t\t\t/** Manufacturer String */\n\t\t\twchar_t *manufacturer_string;\n\t\t\t/** Product string */\n\t\t\twchar_t *product_string;\n\t\t\t/** Usage Page for this Device/Interface\n\t\t\t (Windows/Mac only). */\n\t\t\tunsigned short usage_page;\n\t\t\t/** Usage for this Device/Interface\n\t\t\t (Windows/Mac only).*/\n\t\t\tunsigned short usage;\n\t\t\t/** The USB interface which this logical device\n\t\t\t represents. Valid on both Linux implementations\n\t\t\t in all cases, and valid on the Windows implementation\n\t\t\t only if the device contains more than one interface. */\n\t\t\tint interface_number;\n\n\t\t\t/** Pointer to the next device */\n\t\t\tstruct hid_device_info *next;\n\t\t};\n\n\n\t\t/** @brief Initialize the HIDAPI library.\n\n\t\t\tThis function initializes the HIDAPI library. Calling it is not\n\t\t\tstrictly necessary, as it will be called automatically by\n\t\t\thid_enumerate() and any of the hid_open_*() functions if it is\n\t\t\tneeded. This function should be called at the beginning of\n\t\t\texecution however, if there is a chance of HIDAPI handles\n\t\t\tbeing opened by different threads simultaneously.\n\t\t\t\n\t\t\t@ingroup API\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_init(void);\n\n\t\t/** @brief Finalize the HIDAPI library.\n\n\t\t\tThis function frees all of the static data associated with\n\t\t\tHIDAPI. It should be called at the end of execution to avoid\n\t\t\tmemory leaks.\n\n\t\t\t@ingroup API\n\n\t\t @returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_exit(void);\n\n\t\t/** @brief Enumerate the HID Devices.\n\n\t\t\tThis function returns a linked list of all the HID devices\n\t\t\tattached to the system which match vendor_id and product_id.\n\t\t\tIf @p vendor_id and @p product_id are both set to 0, then\n\t\t\tall HID devices will be returned.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the types of device\n\t\t\t\tto open.\n\t\t\t@param product_id The Product ID (PID) of the types of\n\t\t\t\tdevice to open.\n\n\t\t @returns\n\t\t \tThis function returns a pointer to a linked list of type\n\t\t \tstruct #hid_device, containing information about the HID devices\n\t\t \tattached to the system, or NULL in the case of failure. Free\n\t\t \tthis linked list by calling hid_free_enumeration().\n\t\t*/\n\t\tstruct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);\n\n\t\t/** @brief Free an enumeration Linked List\n\n\t\t This function frees a linked list created by hid_enumerate().\n\n\t\t\t@ingroup API\n\t\t @param devs Pointer to a list of struct_device returned from\n\t\t \t hid_enumerate().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);\n\n\t\t/** @brief Open a HID device using a Vendor ID (VID), Product ID\n\t\t\t(PID) and optionally a serial number.\n\n\t\t\tIf @p serial_number is NULL, the first device with the\n\t\t\tspecified VID and PID is opened.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the device to open.\n\t\t\t@param product_id The Product ID (PID) of the device to open.\n\t\t\t@param serial_number The Serial Number of the device to open\n\t\t\t\t (Optionally NULL).\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);\n\n\t\t/** @brief Open a HID device by its path name.\n\n\t\t\tThe path name be determined by calling hid_enumerate(), or a\n\t\t\tplatform-specific path name can be used (eg: /dev/hidraw0 on\n\t\t\tLinux).\n\n\t\t\t@ingroup API\n\t\t @param path The path name of the device to open\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);\n\n\t\t/** @brief Write an Output report to a HID device.\n\n\t\t\tThe first byte of @p data[] must contain the Report ID. For\n\t\t\tdevices which only support a single report, this must be set\n\t\t\tto 0x0. The remaining bytes contain the report data. Since\n\t\t\tthe Report ID is mandatory, calls to hid_write() will always\n\t\t\tcontain one more byte than the report contains. For example,\n\t\t\tif a hid report is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_write(), the Report ID (or 0x0, for devices with a\n\t\t\tsingle report), followed by the report data (16 bytes). In\n\t\t\tthis example, the length passed in would be 17.\n\n\t\t\thid_write() will send the data on the first OUT endpoint, if\n\t\t\tone exists. If it does not, it will send the data through\n\t\t\tthe Control Endpoint (Endpoint 0).\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Read an Input report from a HID device with timeout.\n\n\t\t\tInput reports are returned\n\t\t\tto the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\t\t\t@param milliseconds timeout in milliseconds or -1 for blocking wait.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);\n\n\t\t/** @brief Read an Input report from a HID device.\n\n\t\t\tInput reports are returned\n\t\t to the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Set the device handle to be non-blocking.\n\n\t\t\tIn non-blocking mode calls to hid_read() will return\n\t\t\timmediately with a value of 0 if there is no data to be\n\t\t\tread. In blocking mode, hid_read() will wait (block) until\n\t\t\tthere is data to read before returning.\n\n\t\t\tNonblocking can be turned on and off at any time.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param nonblock enable or not the nonblocking reads\n\t\t\t - 1 to enable nonblocking\n\t\t\t - 0 to disable nonblocking.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);\n\n\t\t/** @brief Send a Feature report to the device.\n\n\t\t\tFeature reports are sent over the Control endpoint as a\n\t\t\tSet_Report transfer. The first byte of @p data[] must\n\t\t\tcontain the Report ID. For devices which only support a\n\t\t\tsingle report, this must be set to 0x0. The remaining bytes\n\t\t\tcontain the report data. Since the Report ID is mandatory,\n\t\t\tcalls to hid_send_feature_report() will always contain one\n\t\t\tmore byte than the report contains. For example, if a hid\n\t\t\treport is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_send_feature_report(): the Report ID (or 0x0, for\n\t\t\tdevices which do not use numbered reports), followed by the\n\t\t\treport data (16 bytes). In this example, the length passed\n\t\t\tin would be 17.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send, including\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Get a feature report from a HID device.\n\n\t\t\tMake sure to set the first byte of @p data[] to the Report\n\t\t\tID of the report to be read. Make sure to allow space for\n\t\t\tthis extra byte in @p data[].\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into, including\n\t\t\t\tthe Report ID. Set the first byte of @p data[] to the\n\t\t\t\tReport ID of the report to be read.\n\t\t\t@param length The number of bytes to read, including an\n\t\t\t\textra byte for the report ID. The buffer can be longer\n\t\t\t\tthan the actual report.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Close a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);\n\n\t\t/** @brief Get The Manufacturer String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Product String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Serial Number String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string from a HID device, based on its string index.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string_index The index of the string to get.\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string describing the last error which occurred.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\n\t\t\t@returns\n\t\t\t\tThis function returns a string containing the last error\n\t\t\t\twhich occurred or NULL if none has occurred.\n\t\t*/\n\t\tHID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"], ["/sapf/libmanta/MantaUSB.h", "class MantaUSB {\n public:\n MantaUSB(void) {\n mantaList.push_back(this);\n MantaIndex = int(mantaList.size());\n\n DebugPrint(\"%s-%d: Manta %d initialized\", __FILE__, __LINE__, MantaIndex);\n}\n virtual ~MantaUSB(void) {\n Disconnect();\n mantaList.remove(this);\n if(mantaList.empty())\n {\n hid_exit();\n }\n}\n void WriteFrame(uint8_t *frame, bool forceQueued) {\n if(NULL == DeviceHandle)\n {\n throw(MantaNotConnectedException(this));\n }\n MantaTxQueueEntry *queuedMessage = GetQueuedTxMessage();\n if(queuedMessage && !forceQueued)\n {\n /* replace the queued packet payload with the new one */\n for(int i = 0; i < OutPacketLen; ++i)\n {\n /* the first byte of the report is the report ID (0x00) */\n queuedMessage->OutFrame[i+1] = frame[i];\n }\n DebugPrint(\"%s-%d: (WriteFrame) Queued Transfer overwritten on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n else\n {\n /* no transfer in progress, queue up a new one */\n MantaTxQueueEntry *newMessage = new MantaTxQueueEntry;\n newMessage->OutFrame[0] = 0;\n newMessage->TargetManta = this;\n /* the first byte of the report is the report ID (0x00) */\n memcpy(newMessage->OutFrame + 1, frame, OutPacketLen);\n txQueue.push_back(newMessage);\n DebugPrint(\"%s-%d: (WriteFrame) Transfer Queued on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n}\n bool IsConnected(void) {\n return DeviceHandle != NULL;\n}\n void Connect(int connectionSerial = 0) {\n#define SERIAL_STRING_SIZE 32\n wchar_t serialString[SERIAL_STRING_SIZE];\n\n if(IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Attempting to Connect to Manta %d...\",\n __FILE__, __LINE__, connectionSerial);\n if(connectionSerial)\n {\n swprintf(serialString, SERIAL_STRING_SIZE, L\"%d\", connectionSerial);\n DeviceHandle = hid_open(VendorID, ProductID, serialString);\n }\n else\n {\n DeviceHandle = hid_open(VendorID, ProductID, NULL);\n }\n if(NULL == DeviceHandle)\n throw(MantaNotFoundException());\n hid_get_serial_number_string(DeviceHandle, serialString, SERIAL_STRING_SIZE);\n SerialNumber = int(wcstol(serialString, NULL, 10));\n int rc = hid_set_nonblocking(DeviceHandle, 1);\n printf(\"hid_set_nonblocking %d\\n\", rc);\n printf(\"SerialNumber %d\\n\", SerialNumber);\n}\n void Disconnect() {\n if(! IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Manta %d Disconnecting...\", __FILE__, __LINE__, GetSerialNumber());\n hid_close(DeviceHandle);\n DeviceHandle = NULL;\n}\n int GetSerialNumber(void) {\n return SerialNumber;\n}\n int GetHardwareVersion(void) {\n return (SerialNumber < 70) ? 1 : 2;\n}\n bool MessageQueued(void) {\n return GetQueuedTxMessage() != NULL;\n}\n static void HandleEvents(void) {\n list::iterator i = mantaList.begin();\n /* read from each manta and trigger any events */\n while(mantaList.end() != i)\n {\n MantaUSB *current = *i;\n if(current->IsConnected())\n {\n int bytesRead;\n int8_t inFrame[InPacketLen];\n\n bytesRead = hid_read(current->DeviceHandle,\n reinterpret_cast(inFrame), InPacketLen);\n if(bytesRead < 0)\n {\n current->DebugPrint(\"%s-%d: Read error on Manta %d\",\n __FILE__, __LINE__, current->GetSerialNumber());\n throw(MantaCommunicationException(current));\n }\n else if(bytesRead)\n {\n current->FrameReceived(inFrame);\n }\n }\n ++i;\n }\n\n /* pop one item off the transmit queue and send down to its target */\n if(! txQueue.empty())\n {\n int bytesWritten;\n MantaTxQueueEntry *txMessage = txQueue.front();\n txQueue.pop_front();\n bytesWritten = hid_write(txMessage->TargetManta->DeviceHandle,\n txMessage->OutFrame, OutPacketLen + 1);\n txMessage->TargetManta->DebugPrint(\"%s-%d: Frame Written to Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n for(int j = 0; j < 16; j += 8)\n {\n uint8_t *frame = txMessage->OutFrame + 1;\n txMessage->TargetManta->DebugPrint(\"\\t\\t%x %x %x %x %x %x %x %x\",\n frame[j], frame[j+1], frame[j+2], frame[j+3], frame[j+4],\n frame[j+5], frame[j+6], frame[j+7]);\n }\n delete txMessage;\n if(bytesWritten < 0)\n {\n txMessage->TargetManta->DebugPrint(\"%s-%d: Write error on Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n throw(MantaCommunicationException(txMessage->TargetManta));\n }\n }\n}\n protected:\n virtual void FrameReceived(int8_t *frame) = 0;\n static const int OutPacketLen = 16;\n static const int InPacketLen = 64;\n int SerialNumber;\n int MantaIndex;\n private:\n struct MantaTxQueueEntry\n {\n MantaUSB *TargetManta;\n uint8_t OutFrame[17];\n };\n MantaTxQueueEntry *GetQueuedTxMessage();\n static const int Interface = 0;\n static const int EndpointIn = 0x81;\n static const int EndpointOut = 0x02;\n static const int Timeout = 5000;\n static const int VendorID = 0x2424;\n static const int ProductID = 0x2424;\n hid_device *DeviceHandle;\n static list mantaList;\n static list txQueue;\n};"], ["/sapf/src/dsp.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"dsp.hpp\"\n#include \n#include \n#include \n\n\nFFTSetupD fftSetups[kMaxFFTLogSize+1];\n\nvoid initFFT()\n{\n\tfor (int i = kMinFFTLogSize; i <= kMaxFFTLogSize; ++i) {\n\t\tfftSetups[i] = vDSP_create_fftsetupD(i, kFFTRadix2);\n\t}\n}\n\nvoid fft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid ifft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid fft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\nvoid ifft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\n\nvoid rfft(int n, double* inReal, double* outReal, double* outImag)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\n vDSP_ctozD((DSPDoubleComplex*)inReal, 1, &in, 1, n2);\n\t\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zropD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n2);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n2);\n \n out.realp[n2] = out.imagp[0];\n out.imagp[0] = 0.;\n out.imagp[n2] = 0.;\n}\n\n\nvoid rifft(int n, double* inReal, double* inImag, double* outReal)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\t\n //in.imagp[0] = in.realp[n2];\n in.imagp[0] = 0.;\n\n\tvDSP_fft_zripD(fftSetups[log2n], &in, 1, log2n, FFT_INVERSE);\n\n vDSP_ztocD(&in, 1, (DSPDoubleComplex*)outReal, 2, n2);\n\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n); \n}\n\n\n#define USE_VFORCE 1\n\ninline void complex_expD_conj(double& re, double& im)\n{\n\tdouble rho = expf(re);\n\tre = rho * cosf(im);\n\tim = rho * sinf(im);\n}\n\n"], ["/sapf/src/MathFuns.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathFuns.hpp\"\n#include \"VM.hpp\"\n\ndouble gSineTable[kSineTableSize+1];\ndouble gDBAmpTable[kDBAmpTableSize+2];\ndouble gDecayTable[kDecayTableSize+1];\ndouble gFirstOrderCoeffTable[kFirstOrderCoeffTableSize+1];\n\n\ninline double freqToTableF(double freq)\n{\n\treturn std::clamp(3. * log2(freq * .05), 0., 28.999);\n}\n\nZ gFreqToTable[20001];\n\nstatic void initFreqToTable()\n{\n\tfor (int freq = 0; freq < 20001; ++freq) {\n\t\tgFreqToTable[freq] = freqToTableF(freq);\n\t}\n}\n\ninline double freqToTable(double freq)\n{\n\tdouble findex = std::clamp(freq, 0., 20000.);\n\tdouble iindex = floor(findex);\n\treturn lut(gFreqToTable, (int)iindex, findex - iindex);\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\nvoid fillSineTable()\n{\n\tfor (int i = 0; i < kSineTableSize; ++i) {\n\t\tgSineTable[i] = sin(gSineTableOmega * i);\n\t}\n\tgSineTable[kSineTableSize] = gSineTable[0];\n}\n\nvoid fillDBAmpTable()\n{\n\tfor (int i = 0; i < kDBAmpTableSize+2; ++i) {\n\t\tdouble dbgain = i * kInvDBAmpScale - kDBAmpOffset;\n\t\tdouble amp = pow(10., .05 * dbgain);\n\t\tgDBAmpTable[i] = amp;\n\t}\n}\n\nvoid fillDecayTable()\n{\n\tfor (int i = 0; i < kDecayTableSize+1; ++i) {\n\t\tgDecayTable[i] = exp(log001 * i * .001);\n\t}\t\n}\n\nvoid fillFirstOrderCoeffTable()\n{\n\tdouble k = M_PI * kInvFirstOrderCoeffTableSize;\n\tfor (int i = 0; i < kFirstOrderCoeffTableSize+1; ++i) {\n\t\tdouble x = k * i;\n\t\tZ b = 2. - cos(x);\n\t\tgFirstOrderCoeffTable[i] = b - sqrt(b*b - 1.);\n\t}\t\n}\n\n\n"], ["/sapf/src/primes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"primes.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n\n// Within a cycle of 30, there are only 8 numbers that are not multiples of 2, 3 or 5.\n// We pack these 8 into a one byte bit map.\n\nconst int gLowPrimes[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimeOffsets[8] = {1, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimesShift[30] = \n{\n\t-1, 0, -1, -1, -1, -1, -1, 1, -1, -1, \n\t-1, 2, -1, 3, -1, -1, -1, 4, -1, 5, \n\t-1, -1, -1, 6, -1, -1, -1, -1, -1, 7 \n};\n\t\nconst uint32_t gLowPrimesMask = 0x208a28ac;\n\n//const int kPrimeUpperLimit = kPrimesMaskSize * 30;\nuint8_t gPrimesMask[kPrimesMaskSize] = {\n\t0xdf, 0xef, 0x7e, 0xb6, 0xdb, 0x3d, 0xf9, 0xd5, 0x4f, 0x1e, 0xf3, 0xea, 0xa6, 0xed, 0x9e, 0xe6, \n\t0x0c, 0xd3, 0xd3, 0x3b, 0xdd, 0x59, 0xa5, 0x6a, 0x67, 0x92, 0xbd, 0x78, 0x1e, 0xa6, 0x56, 0x56, \n\t0xe3, 0xad, 0x2d, 0xde, 0x2a, 0x4c, 0x55, 0xd9, 0xa3, 0xf0, 0x9f, 0x03, 0x54, 0xa1, 0xf8, 0x2e, \n\t0xfd, 0x44, 0xe9, 0x66, 0xf6, 0x13, 0x3a, 0xb8, 0x4c, 0x2b, 0x3a, 0x45, 0x11, 0xbf, 0x54, 0x8c, \n\t0xc1, 0x7a, 0xb3, 0xc8, 0xbc, 0x8c, 0x4f, 0x21, 0x58, 0x71, 0x71, 0x9b, 0xc1, 0x17, 0xef, 0x54, \n\t0x96, 0x1a, 0x08, 0xe5, 0x83, 0x8c, 0x46, 0x72, 0xfb, 0xae, 0x65, 0x92, 0x8f, 0x58, 0x87, 0xd2, \n\t0x92, 0xd8, 0x81, 0x65, 0x26, 0xe3, 0xa0, 0x11, 0x38, 0xc7, 0x26, 0x3c, 0x81, 0xeb, 0x99, 0x8d, \n\t0x51, 0x88, 0x3e, 0x24, 0xf3, 0x33, 0x4d, 0x5a, 0x8b, 0x1c, 0xa7, 0x2a, 0xb4, 0x58, 0x4c, 0x4e, \n\t0x26, 0xf6, 0x19, 0x82, 0xdc, 0x83, 0xc3, 0x2c, 0xf1, 0x38, 0x02, 0xb5, 0xcd, 0xcd, 0x02, 0xb2, \n\t0x4a, 0x94, 0x0c, 0x57, 0x4c, 0x7a, 0x30, 0x43, 0x0b, 0xf1, 0xcb, 0x44, 0x6c, 0x24, 0xf8, 0x19, \n\t0x01, 0x95, 0xa8, 0x5c, 0x73, 0xea, 0x8d, 0x24, 0x96, 0x2b, 0x50, 0xa6, 0x22, 0x1e, 0xc4, 0xd1, \n\t0x48, 0x06, 0xd4, 0x3a, 0x2f, 0x74, 0x9c, 0x07, 0x6a, 0x05, 0x88, 0xbf, 0x68, 0x15, 0x2e, 0x60, \n\t0x55, 0xe3, 0xb7, 0x51, 0x98, 0x08, 0x14, 0x86, 0x5a, 0xaa, 0x45, 0x4d, 0x49, 0x70, 0x27, 0xd2, \n\t0x93, 0xd5, 0xca, 0xab, 0x02, 0x83, 0x61, 0x05, 0x24, 0xce, 0x87, 0x22, 0xc2, 0xa9, 0xad, 0x18, \n\t0x8c, 0x4d, 0x78, 0xd1, 0x89, 0x16, 0xb0, 0x57, 0xc7, 0x62, 0xa2, 0xc0, 0x34, 0x24, 0x52, 0xae, \n\t0x5a, 0x40, 0x32, 0x8d, 0x21, 0x08, 0x43, 0x34, 0xb6, 0xd2, 0xb6, 0xd9, 0x19, 0xe1, 0x60, 0x67, \n\t0x1a, 0x39, 0x60, 0xd0, 0x44, 0x7a, 0x94, 0x9a, 0x09, 0x88, 0x83, 0xa8, 0x74, 0x55, 0x10, 0x27, \n\t0xa1, 0x5d, 0x68, 0x1e, 0x23, 0xc8, 0x32, 0xe0, 0x19, 0x03, 0x44, 0x73, 0x48, 0xb1, 0x38, 0xc3, \n\t0xe6, 0x2a, 0x57, 0x61, 0x98, 0xb5, 0x1c, 0x0a, 0x68, 0xc5, 0x81, 0x8f, 0xac, 0x02, 0x29, 0x1a, \n\t0x47, 0xe3, 0x94, 0x11, 0x4e, 0x64, 0x2e, 0x14, 0xcb, 0x3d, 0xdc, 0x14, 0xc5, 0x06, 0x10, 0xe9, \n\t0x29, 0xb1, 0x82, 0xe9, 0x30, 0x47, 0xe3, 0x34, 0x19, 0xc3, 0x25, 0x0a, 0x30, 0x30, 0xb4, 0x6c, \n\t0xc1, 0xe5, 0x46, 0x44, 0xd8, 0x8e, 0x4c, 0x5d, 0x22, 0x24, 0x70, 0x78, 0x92, 0x89, 0x81, 0x82, \n\t0x56, 0x26, 0x1b, 0x86, 0xe9, 0x08, 0xa5, 0x00, 0xd3, 0xc3, 0x29, 0xb0, 0xc2, 0x4a, 0x10, 0xb2, \n\t0x59, 0x38, 0xa1, 0x1d, 0x42, 0x60, 0xc7, 0x22, 0x27, 0x8c, 0xc8, 0x44, 0x1a, 0xc6, 0x8b, 0x82, \n\t0x81, 0x1a, 0x46, 0x10, 0xa6, 0x31, 0x09, 0xf0, 0x54, 0x2f, 0x18, 0xd2, 0xd8, 0xa9, 0x15, 0x06, \n\t0x2e, 0x0c, 0xf6, 0xc0, 0x0e, 0x50, 0x91, 0xcd, 0x26, 0xc1, 0x18, 0x38, 0x65, 0x19, 0xc3, 0x56, \n\t0x93, 0x8b, 0x2a, 0x2d, 0xd6, 0x84, 0x4a, 0x61, 0x0a, 0xa5, 0x2c, 0x09, 0xe0, 0x76, 0xc4, 0x6a, \n\t0x3c, 0xd8, 0x08, 0xe8, 0x14, 0x66, 0x1b, 0xb0, 0xa4, 0x02, 0x63, 0x36, 0x10, 0x31, 0x07, 0xd5, \n\t0x92, 0x48, 0x42, 0x12, 0xc3, 0x8a, 0xa0, 0x9f, 0x2d, 0x74, 0xa4, 0x82, 0x85, 0x78, 0x5c, 0x0d, \n\t0x18, 0xb0, 0x61, 0x14, 0x1d, 0x02, 0xe8, 0x18, 0x12, 0xc1, 0x01, 0x49, 0x1c, 0x83, 0x30, 0x67, \n\t0x33, 0xa1, 0x88, 0xd8, 0x0f, 0x0c, 0xf4, 0x98, 0x88, 0x58, 0xd7, 0x66, 0x42, 0x47, 0xb1, 0x16, \n\t0xa8, 0x96, 0x08, 0x18, 0x41, 0x59, 0x15, 0xb5, 0x44, 0x2a, 0x52, 0xe1, 0xb3, 0xaa, 0xa1, 0x59, \n\t0x45, 0x62, 0x55, 0x18, 0x11, 0xa5, 0x0c, 0xa3, 0x3c, 0x67, 0x00, 0xbe, 0x54, 0xd6, 0x0a, 0x20, \n\t0x36, 0x6b, 0x82, 0x0c, 0x15, 0x08, 0x7e, 0x56, 0x91, 0x01, 0x78, 0xd0, 0x61, 0x0a, 0x84, 0xa8, \n\t0x2c, 0x01, 0x57, 0x0e, 0x56, 0xa0, 0x50, 0x0b, 0x98, 0x8c, 0x47, 0x6c, 0x20, 0x63, 0x10, 0xc4, \n\t0x09, 0xe4, 0x0c, 0x57, 0x88, 0x0b, 0x75, 0x0b, 0xc2, 0x52, 0x82, 0xc2, 0x39, 0x24, 0x02, 0x2c, \n\t0x56, 0x25, 0x7a, 0x31, 0x29, 0xd6, 0xa3, 0x20, 0xe1, 0xb1, 0x18, 0xb0, 0x0c, 0x8a, 0x32, 0xc1, \n\t0x11, 0x32, 0x09, 0xc5, 0xad, 0x30, 0x37, 0x08, 0xbc, 0x91, 0x82, 0xcf, 0x20, 0x25, 0x6b, 0x9c, \n\t0x30, 0x8f, 0x44, 0x26, 0x46, 0x6a, 0x07, 0x49, 0x8e, 0x09, 0x58, 0x10, 0x02, 0x25, 0xc5, 0xc4, \n\t0x42, 0x5a, 0x80, 0xa0, 0x80, 0x3c, 0x90, 0x28, 0x64, 0x14, 0xe1, 0x03, 0x84, 0x51, 0x0c, 0x2e, \n\t0xa3, 0x8a, 0xa4, 0x08, 0xc0, 0x47, 0x7e, 0xd3, 0x2b, 0x03, 0xcd, 0x54, 0x2a, 0x00, 0x04, 0xb3, \n\t0x92, 0x6c, 0x42, 0x29, 0x4c, 0x83, 0xc1, 0x92, 0xcc, 0x1c, 0x2d, 0x46, 0x21, 0xdb, 0x38, 0x59, \n\t0x84, 0x8c, 0x24, 0x12, 0x58, 0xbb, 0xe0, 0x06, 0x0d, 0x70, 0x30, 0xc9, 0x09, 0x28, 0x91, 0x41, \n\t0x44, 0x32, 0xf9, 0x8c, 0x30, 0x80, 0xc2, 0x72, 0xa4, 0x62, 0x0c, 0x7d, 0x81, 0x83, 0x14, 0xe1, \n\t0xaa, 0x0e, 0x15, 0x82, 0x0a, 0x78, 0x14, 0x70, 0x97, 0x08, 0x10, 0x6f, 0x2e, 0xf0, 0xb2, 0x1d, \n\t0x30, 0x49, 0x44, 0x32, 0x53, 0x62, 0x86, 0x65, 0x45, 0x84, 0x0a, 0x11, 0x4b, 0x36, 0xd9, 0x8c, \n\t0x69, 0x3a, 0x61, 0x80, 0x90, 0x7c, 0x19, 0xc0, 0x30, 0x95, 0x40, 0x8b, 0x0c, 0x05, 0x2d, 0x0e, \n\t0xc0, 0x71, 0xa1, 0xb4, 0x96, 0x85, 0x1a, 0x16, 0xc0, 0x15, 0x14, 0x51, 0x4c, 0x48, 0xb7, 0x79, \n\t0x95, 0x10, 0x89, 0x8a, 0x2e, 0x02, 0xa1, 0x1c, 0xd5, 0x90, 0x81, 0x10, 0x91, 0x08, 0x22, 0xb4, \n\t0x1e, 0xe9, 0x78, 0xc0, 0x33, 0x20, 0x5c, 0x8b, 0xc4, 0x0e, 0xe2, 0xaa, 0x23, 0x10, 0x47, 0xe3, \n\t0x28, 0x55, 0x7b, 0x19, 0xa1, 0x51, 0xa8, 0x06, 0x04, 0x90, 0x82, 0x2c, 0xd1, 0x61, 0x60, 0xa1, \n\t0x52, 0x06, 0x41, 0x44, 0x81, 0x54, 0x23, 0x88, 0x18, 0xa9, 0x04, 0x27, 0x22, 0x72, 0x48, 0xb6, \n\t0x40, 0x1c, 0x42, 0x12, 0x17, 0xca, 0x29, 0xa0, 0x5a, 0x01, 0x3c, 0xe1, 0x52, 0x84, 0x89, 0xda, \n\t0x01, 0x40, 0x06, 0xf1, 0x2c, 0x69, 0xd2, 0x48, 0x42, 0x63, 0xc1, 0x21, 0x34, 0x8a, 0xc8, 0x6c, \n\t0x21, 0x71, 0x26, 0x09, 0x88, 0x2e, 0x44, 0xd5, 0x28, 0x92, 0x1d, 0x98, 0x86, 0x12, 0xd1, 0x52, \n\t0xa3, 0xa0, 0x46, 0x20, 0x46, 0x14, 0x50, 0x83, 0xdc, 0xdd, 0x83, 0x50, 0x44, 0xa9, 0x8c, 0x4d, \n\t0x14, 0x2e, 0x54, 0x14, 0x89, 0x1b, 0x39, 0x42, 0x80, 0x14, 0x81, 0x29, 0x8f, 0x80, 0x02, 0x03, \n\t0x32, 0x96, 0x82, 0x83, 0xb0, 0x05, 0x0c, 0x14, 0x51, 0x88, 0x07, 0xf8, 0xd9, 0xec, 0x1a, 0x06, \n\t0x48, 0x31, 0x5c, 0x43, 0x86, 0x06, 0x23, 0xb3, 0x09, 0x44, 0x0c, 0xa5, 0x00, 0xf0, 0xb2, 0x80, \n\t0x01, 0xca, 0xe1, 0x42, 0xc2, 0x18, 0xb6, 0x2c, 0x9b, 0xc7, 0x2e, 0x52, 0x29, 0x2c, 0x61, 0x1a, \n\t0x8a, 0x26, 0x24, 0x8b, 0x84, 0x80, 0x5e, 0x60, 0x02, 0xc1, 0x53, 0x2a, 0x35, 0x45, 0x21, 0x52, \n\t0xd1, 0x42, 0xb8, 0xc5, 0x4a, 0x48, 0x04, 0x16, 0x70, 0x23, 0x61, 0xc1, 0x09, 0x50, 0xc4, 0x81, \n\t0x88, 0x18, 0xd9, 0x01, 0x16, 0x22, 0x28, 0x8c, 0x90, 0x84, 0xeb, 0x38, 0x24, 0x53, 0x09, 0xa9, \n\t0x41, 0x6a, 0x14, 0x82, 0x09, 0x86, 0x30, 0x9c, 0xa2, 0x38, 0x42, 0x00, 0x2b, 0x95, 0x5a, 0x02, \n\t0x4a, 0xc1, 0xa2, 0xad, 0x45, 0x04, 0x27, 0x54, 0xc0, 0x28, 0xa9, 0x05, 0x8c, 0x2e, 0x6e, 0x60, \n\t0xf3, 0x16, 0x90, 0x1b, 0x82, 0x1e, 0x00, 0x80, 0x26, 0x1c, 0x1d, 0x4a, 0x14, 0xc2, 0x1a, 0x22, \n\t0x3c, 0x85, 0xc1, 0x10, 0xb0, 0x48, 0x11, 0x00, 0x4a, 0xc5, 0x30, 0xf4, 0xaa, 0x30, 0x8c, 0xc8, \n\t0x49, 0x18, 0x07, 0xf0, 0x1c, 0xe9, 0x07, 0xcd, 0x0c, 0x22, 0x1b, 0x1c, 0xec, 0xc2, 0x45, 0x0a, \n\t0x50, 0x3a, 0x20, 0xe4, 0x0e, 0x6c, 0x20, 0x82, 0xc3, 0x91, 0xd9, 0xc8, 0x62, 0x4c, 0xd1, 0x80, \n\t0x85, 0x65, 0x09, 0x02, 0x30, 0x95, 0xf9, 0x10, 0x69, 0x02, 0xa6, 0x4a, 0x64, 0xc2, 0xb6, 0xf9, \n\t0x16, 0x20, 0x48, 0xa1, 0x73, 0x94, 0x31, 0x54, 0x61, 0x44, 0x07, 0x03, 0x82, 0x2c, 0x06, 0x00, \n\t0x38, 0x33, 0x09, 0x1c, 0xc1, 0x4b, 0xce, 0x12, 0x35, 0x41, 0xa4, 0x90, 0x99, 0x2d, 0x2a, 0xc0, \n\t0x59, 0x84, 0xd1, 0x4a, 0xa4, 0x72, 0x04, 0x22, 0x3c, 0x54, 0xc2, 0xa0, 0x0c, 0x01, 0x18, 0xac, \n\t0xac, 0x96, 0xe4, 0x04, 0x04, 0x03, 0x93, 0x05, 0x9b, 0x48, 0x44, 0x63, 0x32, 0x01, 0x31, 0x5f, \n\t0x60, 0x5c, 0x02, 0x00, 0x03, 0x80, 0xd1, 0x04, 0x2e, 0x34, 0xa9, 0x30, 0x49, 0xc4, 0xca, 0x1e, \n\t0x02, 0x4b, 0x32, 0x14, 0x05, 0x86, 0x22, 0xc5, 0xc2, 0x2a, 0x4c, 0xc8, 0x00, 0x08, 0xf3, 0x18, \n\t0x38, 0x65, 0x99, 0x82, 0x4a, 0x54, 0x63, 0xa1, 0x94, 0x8f, 0x44, 0x12, 0x93, 0xe9, 0x19, 0x28, \n\t0xca, 0xa1, 0x06, 0x12, 0x8a, 0x20, 0xa5, 0x51, 0x48, 0x18, 0x70, 0x31, 0xae, 0x90, 0x08, 0x43, \n\t0x68, 0x97, 0x32, 0xaf, 0x91, 0xc8, 0x0a, 0x2c, 0x02, 0x02, 0x8c, 0x0c, 0x51, 0xa5, 0x12, 0x00, \n\t0x1b, 0x1e, 0x81, 0x8a, 0x08, 0x28, 0x60, 0xd2, 0x86, 0x34, 0x44, 0x63, 0x76, 0x04, 0x43, 0x00, \n\t0xf1, 0x01, 0x04, 0x40, 0x36, 0xc8, 0xa1, 0x8c, 0xc3, 0xce, 0x32, 0x42, 0x09, 0x29, 0x55, 0x44, \n\t0x4e, 0x28, 0x43, 0x60, 0x1c, 0xa0, 0xda, 0x28, 0x0e, 0xa5, 0xf2, 0x05, 0x40, 0x59, 0x8c, 0x4e, \n\t0xa2, 0x60, 0x05, 0xe0, 0x05, 0xc5, 0x04, 0x62, 0x81, 0x26, 0xa8, 0x8a, 0xa4, 0x24, 0xb4, 0xd3, \n\t0x1a, 0x81, 0x42, 0xe4, 0x60, 0x34, 0x08, 0x2a, 0x39, 0xcc, 0x62, 0x08, 0x47, 0xd0, 0x00, 0x40, \n\t0x07, 0x02, 0x78, 0x20, 0xd9, 0xa2, 0x89, 0x50, 0x23, 0x32, 0x00, 0xb8, 0x80, 0x64, 0x11, 0xe9, \n\t0x74, 0x62, 0x0a, 0xaa, 0x44, 0x08, 0x8b, 0x16, 0x06, 0x18, 0x2d, 0xf1, 0x4c, 0x4f, 0x2a, 0x21, \n\t0x40, 0x15, 0xb4, 0x0c, 0x48, 0x22, 0xd1, 0xe1, 0x80, 0xd8, 0x17, 0xa7, 0x14, 0xa0, 0x82, 0x15, \n\t0x64, 0xc0, 0x89, 0x5a, 0x11, 0xbb, 0x8c, 0x78, 0x08, 0xcd, 0x04, 0x24, 0xa2, 0x9b, 0x9c, 0x10, \n\t0xcc, 0x42, 0xa3, 0x28, 0x3b, 0x58, 0x5f, 0xa6, 0x40, 0x90, 0x23, 0x04, 0x2c, 0xd2, 0xae, 0x52, \n\t0x51, 0x1a, 0xa4, 0x69, 0x80, 0xc1, 0x4a, 0xa3, 0xc8, 0x90, 0x19, 0x48, 0x42, 0x24, 0x22, 0x43, \n\t0x02, 0x45, 0xc1, 0x05, 0x00, 0x74, 0x11, 0x15, 0x94, 0x10, 0x0c, 0x38, 0x73, 0x8a, 0x25, 0x04, \n\t0x07, 0x28, 0x7e, 0x01, 0x40, 0x82, 0x41, 0x48, 0x6d, 0x16, 0x36, 0x29, 0x31, 0xe5, 0x81, 0xa4, \n\t0x1c, 0x81, 0xfa, 0x09, 0x00, 0x14, 0x2d, 0x10, 0x60, 0x40, 0x97, 0xdc, 0x88, 0x02, 0x4e, 0x17, \n\t0x98, 0x85, 0x44, 0x9c, 0xa2, 0x60, 0x91, 0x8a, 0x92, 0x68, 0x19, 0x0a, 0x40, 0x51, 0x80, 0x37, \n\t0x84, 0x15, 0x40, 0x62, 0x64, 0xb2, 0x0e, 0x91, 0x48, 0x2a, 0x00, 0x55, 0x48, 0x99, 0xb0, 0x08, \n\t0x85, 0x1a, 0x13, 0x10, 0x9b, 0x00, 0x5e, 0xc9, 0x50, 0x00, 0xe8, 0xa4, 0x00, 0x83, 0x45, 0x6c, \n\t0x40, 0x0b, 0x9d, 0xa0, 0x02, 0x2d, 0x34, 0x92, 0x01, 0x21, 0x81, 0x17, 0xa3, 0x46, 0xa0, 0x8a, \n\t0x85, 0xe8, 0x88, 0x47, 0x18, 0x96, 0x01, 0xb6, 0x41, 0x93, 0x84, 0x08, 0x02, 0x18, 0x02, 0x35, \n\t0x50, 0xe4, 0x3a, 0x81, 0x10, 0x11, 0xa1, 0xda, 0x82, 0x4c, 0x34, 0x32, 0x85, 0x00, 0x57, 0x4b, \n\t0x28, 0xa5, 0xa8, 0x38, 0x84, 0x1d, 0x0e, 0x30, 0xb3, 0x50, 0x22, 0x41, 0xc3, 0xc6, 0x06, 0xd0, \n\t0x20, 0x28, 0xa1, 0x05, 0x8a, 0x1a, 0x84, 0x22, 0x85, 0x0c, 0x46, 0x44, 0x72, 0x90, 0xc8, 0x17, \n\t0xd8, 0x41, 0x61, 0x64, 0x30, 0x39, 0x00, 0x0c, 0x97, 0xa3, 0x0e, 0xb2, 0x29, 0x02, 0x50, 0x88, \n\t0xa9, 0x5c, 0x22, 0xc1, 0x8e, 0x90, 0xc3, 0x47, 0x40, 0x31, 0x12, 0x2c, 0x38, 0x8c, 0x63, 0x64, \n\t0x86, 0xc0, 0xb3, 0x00, 0x4a, 0x2a, 0x38, 0x11, 0x91, 0x13, 0x38, 0x47, 0x49, 0x14, 0x81, 0x73, \n\t0x02, 0x2c, 0x4c, 0x8e, 0x52, 0xe5, 0xd1, 0x10, 0x10, 0x07, 0x4c, 0x06, 0x65, 0x61, 0x1a, 0x54, \n\t0x84, 0x01, 0x4a, 0xe2, 0x01, 0x2f, 0x10, 0x06, 0x09, 0x42, 0x44, 0x9a, 0x00, 0xa9, 0x52, 0x8c, \n\t0x28, 0x94, 0x61, 0x01, 0x99, 0x05, 0x20, 0x1c, 0x23, 0x78, 0xa2, 0x51, 0x18, 0x82, 0x3c, 0x41, \n\t0xd0, 0xb7, 0xc4, 0x43, 0x87, 0x44, 0xc6, 0x0a, 0x93, 0x68, 0xc1, 0x81, 0x30, 0x52, 0xb2, 0xa8, \n\t0xc1, 0x8a, 0x24, 0x1c, 0x21, 0x03, 0x33, 0x41, 0x14, 0x4a, 0x2e, 0x41, 0xe2, 0x82, 0x45, 0x01, \n\t0xac, 0x06, 0x40, 0x18, 0x20, 0x95, 0x4c, 0x67, 0x20, 0x26, 0x50, 0x94, 0x55, 0x92, 0x08, 0x1a, \n\t0x82, 0xe1, 0x8c, 0x10, 0x5b, 0x61, 0x02, 0x86, 0x72, 0x99, 0x30, 0x8d, 0x06, 0x2c, 0xb0, 0xa1, \n\t0x18, 0x28, 0x06, 0x27, 0x46, 0x20, 0x18, 0x82, 0x21, 0x9c, 0xeb, 0x18, 0xc4, 0x30, 0x81, 0x58, \n\t0xc1, 0x84, 0x06, 0x37, 0x9a, 0x24, 0x50, 0x0d, 0xa2, 0x40, 0x05, 0x29, 0x19, 0x09, 0x02, 0x84, \n\t0x52, 0x64, 0x11, 0x17, 0xec, 0xd1, 0x20, 0x78, 0x86, 0x63, 0x0e, 0xd1, 0x11, 0x2a, 0x60, 0x03, \n\t0xd1, 0x22, 0x60, 0x84, 0x06, 0x32, 0xa4, 0x68, 0x24, 0x81, 0xc7, 0xc0, 0x12, 0x42, 0x01, 0xbb, \n\t0xa8, 0x00, 0x41, 0x7c, 0x41, 0x21, 0x81, 0x91, 0x10, 0x85, 0x14, 0xa0, 0xa8, 0x2d, 0x5c, 0x15, \n\t0x47, 0x40, 0xd0, 0xfa, 0x2a, 0x84, 0x0e, 0x8f, 0x10, 0xd2, 0x80, 0x09, 0xd4, 0x49, 0x21, 0x26, \n\t0x32, 0xb0, 0x38, 0x20, 0x41, 0xa0, 0x4a, 0x11, 0x4b, 0xba, 0xac, 0x4e, 0x20, 0x34, 0x61, 0x60, \n\t0x15, 0x0d, 0x13, 0x6a, 0x70, 0x43, 0x42, 0x9c, 0x2d, 0x55, 0xe8, 0x00, 0x96, 0x98, 0x92, 0xe4, \n\t0xc8, 0x4c, 0x0c, 0xa5, 0x19, 0x81, 0x31, 0xca, 0x42, 0x02, 0x12, 0x4a, 0x30, 0x30, 0x51, 0x01, \n\t0x66, 0xa2, 0xe2, 0x16, 0x41, 0xcf, 0xa0, 0x2a, 0x84, 0x51, 0x18, 0x18, 0x41, 0xc6, 0x56, 0xa0, \n\t0x21, 0x8e, 0xe1, 0x96, 0x0b, 0x04, 0x60, 0x11, 0xb8, 0x4c, 0x93, 0x0d, 0x06, 0x04, 0x2a, 0x2a, \n\t0x4c, 0x04, 0x86, 0x2a, 0x51, 0x51, 0x31, 0x00, 0x01, 0x80, 0x76, 0x51, 0x98, 0x94, 0x2d, 0xcc, \n\t0x4a, 0x6a, 0xa4, 0x42, 0xb2, 0x69, 0x48, 0x01, 0x40, 0xb5, 0xd2, 0x32, 0x5c, 0x0e, 0x62, 0x20, \n\t0x16, 0x01, 0x37, 0xe4, 0xc1, 0xc2, 0x58, 0x24, 0x23, 0x08, 0x88, 0x02, 0x24, 0x14, 0x85, 0x98, \n\t0x06, 0xd0, 0x1d, 0xaa, 0x34, 0x80, 0x0a, 0x34, 0x61, 0x10, 0x4b, 0x48, 0x42, 0xc2, 0x02, 0x98, \n\t0x94, 0x00, 0x20, 0x57, 0xb3, 0xa1, 0x88, 0x1a, 0xce, 0x08, 0x05, 0xa0, 0xb0, 0x79, 0x4a, 0x01, \n\t0x14, 0x46, 0x03, 0x24, 0x24, 0x8d, 0x00, 0x44, 0x41, 0x41, 0x03, 0x6c, 0x8a, 0xc1, 0x02, 0xc1, \n\t0x59, 0x26, 0xd8, 0x41, 0x68, 0x56, 0x53, 0x43, 0x2a, 0x14, 0x04, 0x28, 0x0a, 0x25, 0x20, 0x8a, \n\t0x94, 0x47, 0x83, 0x1a, 0x85, 0xa0, 0x0f, 0x84, 0xd5, 0x08, 0x40, 0x70, 0x19, 0x06, 0x08, 0x51, \n\t0x80, 0x5a, 0x16, 0xa8, 0x08, 0x55, 0xd2, 0x28, 0x18, 0x41, 0x49, 0x09, 0x85, 0x02, 0x65, 0x50, \n\t0xb4, 0x80, 0x3d, 0x80, 0x81, 0x2a, 0x4a, 0x86, 0x80, 0x30, 0x01, 0x03, 0x86, 0x1c, 0x53, 0x93, \n\t0xa3, 0x61, 0x58, 0x2a, 0x54, 0x21, 0xb2, 0x97, 0xb0, 0x86, 0xab, 0x52, 0x44, 0xe9, 0x88, 0x59, \n\t0x00, 0x8b, 0x20, 0x10, 0xd2, 0x18, 0x18, 0x85, 0x08, 0x1c, 0x31, 0x50, 0x03, 0x64, 0x8c, 0x0a, \n\t0x40, 0x61, 0xc0, 0x0c, 0xa8, 0x08, 0x40, 0x32, 0x65, 0x0b, 0x9c, 0x88, 0x02, 0x42, 0x4c, 0x14, \n\t0x60, 0x34, 0x85, 0x13, 0x21, 0x50, 0x71, 0x48, 0xa1, 0xe5, 0x14, 0x6e, 0x48, 0x20, 0x32, 0x8a, \n\t0x18, 0x18, 0x45, 0x6a, 0x32, 0x20, 0x82, 0x71, 0x8b, 0xa3, 0x62, 0x16, 0x92, 0xbb, 0x01, 0x91, \n\t0x20, 0x76, 0x11, 0x21, 0x34, 0x54, 0x4c, 0x80, 0x16, 0xc6, 0x38, 0x10, 0xe4, 0x04, 0x84, 0x00, \n\t0x41, 0x01, 0x9a, 0x59, 0x48, 0x84, 0x1a, 0xa4, 0x68, 0x89, 0x51, 0x91, 0x48, 0x40, 0x46, 0xa9, \n\t0x09, 0x94, 0x04, 0x4d, 0x2a, 0x60, 0xb9, 0x18, 0x08, 0xc9, 0xc6, 0x40, 0xa4, 0x99, 0x34, 0x3c, \n\t0x11, 0x8d, 0x10, 0xe0, 0x20, 0xa4, 0x75, 0x0a, 0xe6, 0x44, 0x93, 0xb2, 0x94, 0x04, 0x81, 0xa0, \n\t0x48, 0x75, 0x2a, 0xa3, 0x48, 0x42, 0x05, 0x6e, 0x96, 0x0a, 0x08, 0x29, 0x91, 0x0c, 0x14, 0x05, \n\t0xf0, 0x22, 0x84, 0x01, 0x21, 0x04, 0xa1, 0x00, 0x3a, 0xd8, 0x15, 0x65, 0x10, 0x11, 0xc1, 0xa0, \n\t0x98, 0x8c, 0x2a, 0x16, 0xc1, 0x01, 0x88, 0xf5, 0x12, 0x42, 0x40, 0xa5, 0x01, 0x0b, 0xa0, 0xc2, \n\t0x09, 0x5c, 0xc4, 0x72, 0x00, 0x18, 0x06, 0xe4, 0x0c, 0x26, 0x5a, 0x3d, 0x80, 0x10, 0x40, 0x40, \n\t0x40, 0x11, 0x23, 0x30, 0x9c, 0x80, 0x74, 0x32, 0x82, 0x84, 0x85, 0x00, 0xaf, 0x20, 0x95, 0x20, \n\t0x8f, 0x51, 0x8e, 0xc3, 0x26, 0x84, 0x62, 0x03, 0xc1, 0x09, 0xa8, 0x34, 0x34, 0x83, 0x22, 0xcc, \n\t0x90, 0x23, 0x1a, 0x82, 0x22, 0x88, 0x48, 0x40, 0x6c, 0x32, 0xc5, 0x91, 0xa3, 0x35, 0x89, 0xa0, \n\t0x24, 0xa0, 0x58, 0x07, 0x21, 0x98, 0x0e, 0x0a, 0xf2, 0x6b, 0xb0, 0xac, 0x4a, 0x6c, 0x08, 0x92, \n\t0x29, 0x18, 0x40, 0x42, 0xc1, 0x2e, 0x04, 0x91, 0x30, 0xd1, 0x94, 0xa3, 0x42, 0x43, 0xd9, 0x20, \n\t0x59, 0x98, 0x2d, 0x20, 0x74, 0x00, 0x3d, 0x8c, 0x13, 0x0a, 0x46, 0x62, 0x00, 0x05, 0x34, 0x59, \n\t0x40, 0x26, 0x02, 0x58, 0x38, 0xad, 0x94, 0x2a, 0x18, 0x10, 0x0a, 0xa0, 0x69, 0x47, 0xe3, 0x18, \n\t0xe2, 0x70, 0x8c, 0x04, 0x54, 0x01, 0x24, 0x00, 0x8a, 0x10, 0x29, 0x06, 0xad, 0x02, 0x46, 0x28, \n\t0x0b, 0xd0, 0x50, 0xc5, 0x72, 0x50, 0xc1, 0xa9, 0x14, 0x14, 0x09, 0x60, 0xb0, 0x52, 0x12, 0x60, \n\t0x45, 0x20, 0x16, 0x06, 0xc3, 0x01, 0xa9, 0x93, 0xae, 0x04, 0x82, 0x1a, 0x0b, 0x58, 0x0e, 0x2c, \n\t0x64, 0x84, 0x30, 0x07, 0x55, 0x92, 0x09, 0x08, 0x90, 0xba, 0x91, 0x25, 0x02, 0x47, 0x66, 0x56, \n\t0x68, 0x21, 0x00, 0x9c, 0x06, 0x60, 0x20, 0x88, 0x34, 0x89, 0x9b, 0x88, 0x22, 0xc2, 0x52, 0x92, \n\t0x1d, 0x14, 0x80, 0x40, 0xd5, 0x19, 0x0b, 0xb4, 0xc4, 0xe0, 0x38, 0x45, 0x50, 0x1b, 0x44, 0x88, \n\t0x08, 0x08, 0x07, 0xe2, 0x0f, 0x24, 0x80, 0x65, 0x28, 0x72, 0x00, 0x0a, 0xe9, 0xc1, 0x08, 0x48, \n\t0xb0, 0x42, 0x0c, 0x41, 0x55, 0x26, 0x0e, 0x21, 0x1a, 0x84, 0xd1, 0x10, 0x42, 0x18, 0x07, 0xa1, \n\t0x13, 0x4c, 0xd0, 0xc0, 0x0c, 0x44, 0x2a, 0x83, 0x44, 0x01, 0x46, 0x06, 0x45, 0xf0, 0xbc, 0x04, \n\t0x8a, 0xa6, 0x0a, 0x30, 0x11, 0xb4, 0x61, 0xc3, 0x6b, 0x06, 0x07, 0x23, 0xb4, 0x6c, 0x19, 0x49, \n\t0x46, 0xa0, 0x18, 0x28, 0x60, 0x84, 0x8a, 0x12, 0xa5, 0x20, 0x04, 0x31, 0xda, 0x4c, 0x60, 0x21, \n\t0x0a, 0x17, 0x14, 0x02, 0x04, 0x32, 0x90, 0x92, 0x83, 0x89, 0x4b, 0x42, 0x68, 0x00, 0x53, 0x11, \n\t0x80, 0xd7, 0x88, 0x18, 0x72, 0xa1, 0x04, 0xb0, 0x00, 0x64, 0x08, 0x42, 0xc1, 0x2e, 0x54, 0x81, \n\t0x85, 0x68, 0xa4, 0x98, 0x92, 0x38, 0x59, 0x04, 0x44, 0x00, 0xa3, 0xa1, 0x64, 0x0f, 0x22, 0x3e, \n\t0x00, 0x90, 0x02, 0xdd, 0x1c, 0x8b, 0x1c, 0x60, 0xd0, 0x32, 0x84, 0x04, 0x03, 0x06, 0x74, 0x1a, \n\t0x31, 0x2d, 0xc9, 0x82, 0x22, 0xc3, 0x10, 0x82, 0x30, 0x8c, 0x41, 0x12, 0x12, 0x60, 0x35, 0x94, \n\t0x1f, 0x09, 0x32, 0xf1, 0xa8, 0x8c, 0x08, 0x90, 0x6b, 0x48, 0x20, 0x79, 0x3d, 0x54, 0x86, 0x04, \n\t0x4a, 0x71, 0xc8, 0x00, 0xcc, 0x02, 0xe9, 0x0c, 0x24, 0x21, 0x0a, 0x80, 0x52, 0xee, 0x00, 0xa4, \n\t0x32, 0x96, 0x1c, 0x92, 0x64, 0x20, 0x82, 0x8a, 0x88, 0xa1, 0x4b, 0x0e, 0x78, 0x35, 0x51, 0x00, \n\t0xa0, 0x49, 0x69, 0x72, 0x07, 0x23, 0x14, 0xa0, 0x45, 0x0a, 0x04, 0xd0, 0xd9, 0x82, 0xa1, 0x07, \n\t0xe5, 0x08, 0x03, 0x20, 0x3c, 0x70, 0xd4, 0x0c, 0x12, 0xc0, 0x49, 0x20, 0x08, 0xd1, 0x08, 0x62, \n\t0x63, 0x11, 0x02, 0x10, 0x98, 0x4f, 0x72, 0x20, 0x81, 0x11, 0xa8, 0x53, 0xab, 0x14, 0x02, 0x10, \n\t0x8e, 0x94, 0x86, 0x49, 0x20, 0x31, 0x02, 0x19, 0x41, 0x48, 0x62, 0x44, 0xc5, 0x80, 0x18, 0x14, \n\t0xd0, 0x83, 0x00, 0x57, 0x88, 0x25, 0xad, 0x42, 0x80, 0x3a, 0x30, 0x90, 0x15, 0xd5, 0x1a, 0xe1, \n\t0x4c, 0x24, 0x20, 0x80, 0xe1, 0x08, 0xc7, 0x14, 0x05, 0x8a, 0x11, 0xb0, 0x01, 0x28, 0x10, 0x33, \n\t0x21, 0x93, 0x04, 0xcf, 0x44, 0x22, 0xc0, 0xc9, 0x9a, 0x00, 0x4a, 0x0c, 0x2c, 0x01, 0xb1, 0x8e, \n\t0x10, 0x58, 0x21, 0x14, 0x96, 0x63, 0x34, 0x44, 0x43, 0x04, 0x44, 0xb0, 0x5b, 0x80, 0x28, 0x0c, \n\t0x00, 0x24, 0x33, 0x80, 0x0a, 0x1c, 0x0b, 0x65, 0x26, 0xe0, 0x2a, 0x1e, 0x09, 0x9d, 0xa5, 0x48, \n\t0x44, 0x13, 0x25, 0x2c, 0xc4, 0x22, 0x30, 0x00, 0x62, 0xa4, 0x48, 0x46, 0x40, 0x50, 0x27, 0x00, \n\t0xb8, 0xa4, 0x44, 0x0c, 0x26, 0x44, 0x98, 0x89, 0x81, 0x03, 0x0d, 0x1c, 0xc6, 0x58, 0x82, 0x40, \n\t0x18, 0x4b, 0x40, 0x85, 0x8b, 0x3b, 0x38, 0xc8, 0x2d, 0x64, 0x87, 0x61, 0x11, 0x58, 0x41, 0x88, \n\t0x16, 0x14, 0x89, 0x19, 0x9d, 0x10, 0xa0, 0x08, 0x22, 0x80, 0x02, 0x44, 0x86, 0x81, 0x04, 0x33, \n\t0x80, 0x10, 0x19, 0xc0, 0xc1, 0x48, 0x10, 0x80, 0x31, 0x40, 0x1f, 0x01, 0x24, 0x03, 0xe1, 0x3f, \n\t0x48, 0x4b, 0x8a, 0x10, 0x21, 0xd8, 0x06, 0x95, 0x19, 0x6b, 0x42, 0x80, 0x68, 0x16, 0x64, 0x48, \n\t0x22, 0x40, 0xd5, 0x18, 0xa9, 0x10, 0xc5, 0x0b, 0x1c, 0x74, 0x51, 0xb8, 0x25, 0x00, 0xc0, 0x62, \n\t0xa2, 0xa9, 0x10, 0xb4, 0x8a, 0x60, 0x2a, 0x77, 0xc1, 0x8e, 0x10, 0x83, 0x48, 0x76, 0x92, 0x42, \n\t0x25, 0x08, 0xc0, 0x2c, 0x1e, 0x30, 0x60, 0x21, 0x79, 0x02, 0x88, 0x30, 0x95, 0x30, 0x2a, 0x84, \n\t0x00, 0x4a, 0x4c, 0x43, 0x10, 0x17, 0x11, 0x94, 0xa2, 0x08, 0x80, 0x31, 0xb4, 0x6d, 0xc8, 0x80, \n\t0x6a, 0x40, 0x2b, 0x04, 0x70, 0x1b, 0x49, 0x78, 0xc0, 0x88, 0x04, 0x5c, 0x01, 0x25, 0x40, 0x44, \n\t0x41, 0x18, 0x05, 0x4f, 0x06, 0x0a, 0x20, 0x61, 0x37, 0xd0, 0x40, 0x05, 0x0a, 0x26, 0x48, 0xb8, \n\t0x88, 0x5b, 0x21, 0x10, 0x43, 0xda, 0x9e, 0x29, 0x81, 0xa3, 0x18, 0x00, 0x33, 0x09, 0x98, 0x93, \n\t0xcd, 0x52, 0x42, 0xa3, 0x25, 0x85, 0x1e, 0x28, 0x14, 0x35, 0x50, 0x01, 0xd0, 0xd0, 0x4a, 0x2c, \n\t0xa1, 0x22, 0xa0, 0x5d, 0x1c, 0xe2, 0x02, 0x54, 0x90, 0x02, 0x88, 0x5f, 0x28, 0x78, 0x04, 0x83, \n\t0x02, 0x40, 0x8c, 0x20, 0x0c, 0x82, 0x11, 0x04, 0x71, 0x4d, 0x26, 0x66, 0x32, 0x88, 0x8a, 0xa0, \n\t0x07, 0x8c, 0x00, 0xa3, 0x40, 0x09, 0x31, 0xc7, 0x81, 0x30, 0xd4, 0x43, 0x0a, 0x88, 0x9d, 0x49, \n\t0x4a, 0x81, 0x01, 0x8a, 0x18, 0x02, 0x67, 0x64, 0x36, 0x88, 0x18, 0x88, 0x05, 0xe8, 0x14, 0x40, \n\t0x79, 0x07, 0x49, 0x90, 0xc9, 0x2c, 0xd6, 0x02, 0x93, 0x80, 0x48, 0xa9, 0x0c, 0x67, 0x10, 0xa6, \n\t0x24, 0x51, 0x66, 0x04, 0x00, 0x5b, 0x13, 0xc8, 0xcd, 0x00, 0x62, 0x05, 0x2b, 0x32, 0x31, 0x19, \n\t0xc8, 0x20, 0x02, 0x90, 0x92, 0x21, 0x4d, 0xe0, 0x64, 0xc0, 0x43, 0x10, 0x84, 0x44, 0xa7, 0x1a, \n\t0x12, 0x18, 0x34, 0x01, 0x08, 0x07, 0x0a, 0xb4, 0xaa, 0x32, 0x1c, 0x16, 0x40, 0x06, 0xc1, 0xa8, \n\t0x1e, 0x21, 0x40, 0x41, 0x12, 0xb4, 0x13, 0x08, 0x85, 0x40, 0x0c, 0x02, 0xf0, 0x13, 0x28, 0x69, \n\t0x80, 0x45, 0x70, 0x75, 0x70, 0x80, 0x41, 0x02, 0x21, 0x00, 0x33, 0x88, 0xbc, 0x65, 0x80, 0x46, \n\t0x54, 0x82, 0x03, 0x13, 0x04, 0xc1, 0x08, 0x20, 0x50, 0x03, 0x23, 0x30, 0x1e, 0x82, 0x32, 0xa6, \n\t0xc8, 0x2a, 0x91, 0x48, 0x4c, 0x10, 0x94, 0xc1, 0x20, 0x9c, 0x03, 0x28, 0x34, 0x90, 0x70, 0xba, \n\t0xb1, 0x4a, 0xc4, 0x58, 0x44, 0xe0, 0xa8, 0xbc, 0x40, 0x05, 0x48, 0x35, 0x22, 0x10, 0x30, 0x16, \n\t0x27, 0x24, 0x20, 0x12, 0x38, 0x64, 0x07, 0x46, 0x08, 0xa3, 0xf0, 0x09, 0x14, 0x8a, 0xea, 0x20, \n\t0x07, 0xc3, 0x00, 0x85, 0x89, 0xc0, 0x22, 0xc0, 0x20, 0x8c, 0x68, 0x0a, 0x02, 0x26, 0x43, 0x48, \n\t0x8e, 0x4c, 0x03, 0xa2, 0x48, 0x75, 0xb2, 0x00, 0x61, 0x81, 0x60, 0x68, 0x40, 0x83, 0x90, 0xc5, \n\t0x50, 0x00, 0x50, 0x56, 0x02, 0xa3, 0x14, 0x44, 0x24, 0x3e, 0xa4, 0x49, 0x3a, 0x01, 0xd0, 0x0b, \n\t0x48, 0x63, 0x8a, 0xa4, 0x20, 0xd2, 0x4c, 0x1e, 0x44, 0x61, 0x11, 0x49, 0x44, 0x61, 0x36, 0x84, \n\t0x12, 0x38, 0xe8, 0x04, 0xa6, 0x50, 0x92, 0x69, 0x89, 0x35, 0x1c, 0xa1, 0x04, 0x75, 0x62, 0x2d, \n\t0xc0, 0x91, 0x82, 0x02, 0x32, 0x18, 0x05, 0x71, 0xc8, 0x66, 0x50, 0x06, 0x58, 0x3a, 0x04, 0x00, \n\t0x2c, 0x18, 0x21, 0x21, 0x07, 0x8c, 0x41, 0x42, 0x14, 0xc0, 0xb0, 0x2e, 0x08, 0x01, 0x0b, 0x10, \n\t0x03, 0x80, 0x91, 0x88, 0x02, 0xae, 0x0c, 0x14, 0x09, 0x84, 0x60, 0x5b, 0xc1, 0x40, 0x23, 0x63, \n\t0x08, 0x80, 0x10, 0x0d, 0x0e, 0x82, 0xc8, 0x00, 0xb9, 0xdd, 0x44, 0x2a, 0x30, 0x6a, 0x30, 0x69, \n\t0x10, 0x6c, 0x00, 0x93, 0x19, 0x82, 0xcc, 0x10, 0x80, 0x2c, 0x41, 0xd2, 0x85, 0x18, 0x88, 0x24, \n\t0x4e, 0xd7, 0x88, 0xa9, 0x0c, 0x86, 0xa1, 0x04, 0x43, 0x2a, 0x91, 0x60, 0x03, 0x04, 0x12, 0x50, \n\t0x50, 0x20, 0xb1, 0xcc, 0x02, 0x60, 0x87, 0xab, 0x16, 0x90, 0x10, 0xe4, 0x72, 0x51, 0x00, 0x2b, \n\t0x60, 0x4a, 0x05, 0x0a, 0x35, 0x00, 0x22, 0x40, 0x89, 0x8a, 0x48, 0x56, 0xc2, 0x0c, 0x00, 0xc2, \n\t0x2c, 0x40, 0x34, 0x3a, 0x08, 0x39, 0x9b, 0x85, 0x5a, 0x14, 0x53, 0x0d, 0x10, 0x01, 0x0f, 0x00, \n\t0x81, 0x93, 0x2e, 0x69, 0x94, 0x2e, 0x1c, 0x41, 0xc0, 0x17, 0x18, 0x91, 0x8e, 0x08, 0x44, 0x98, \n\t0xa3, 0x61, 0x02, 0x44, 0x26, 0x42, 0xe1, 0x80, 0x88, 0x16, 0x02, 0x00, 0x64, 0x0a, 0x30, 0x00, \n\t0x08, 0xe1, 0x04, 0x03, 0xd1, 0x38, 0x14, 0x19, 0x01, 0x72, 0x52, 0x51, 0x18, 0x05, 0x85, 0x4e, \n\t0x06, 0xa1, 0x30, 0x26, 0x84, 0x4e, 0x4b, 0x42, 0x71, 0x01, 0x98, 0x30, 0x44, 0x21, 0x0e, 0x70, \n\t0x62, 0x19, 0x11, 0x00, 0x2b, 0x10, 0x30, 0x22, 0x25, 0x6c, 0x14, 0xc0, 0x5e, 0xd2, 0xb8, 0x07, \n\t0x45, 0x90, 0x48, 0x50, 0xc5, 0xa3, 0x81, 0x85, 0x40, 0x22, 0x4a, 0x05, 0x9a, 0x16, 0x48, 0x8d, \n\t0x05, 0x32, 0x16, 0xe2, 0xa2, 0x21, 0x4c, 0x00, 0x06, 0x05, 0x60, 0xa2, 0xbd, 0x48, 0xcb, 0x50, \n\t0x04, 0x02, 0x8a, 0xe4, 0x08, 0xa0, 0x00, 0x41, 0x00, 0x19, 0x65, 0x05, 0x8d, 0x20, 0x00, 0x20, \n\t0x87, 0x30, 0x0d, 0x4a, 0x7a, 0xd3, 0x28, 0x07, 0x04, 0x84, 0x61, 0x14, 0xd0, 0x81, 0x88, 0xa1, \n\t0xde, 0x86, 0x22, 0x80, 0x69, 0x00, 0xa9, 0xc3, 0x00, 0x06, 0x33, 0xc8, 0x01, 0x51, 0x16, 0x08, \n\t0x20, 0x66, 0x10, 0x9e, 0xc4, 0x00, 0xc6, 0x44, 0xc6, 0x02, 0x02, 0x0d, 0xd1, 0x25, 0x74, 0xd2, \n\t0x41, 0x28, 0xe0, 0x18, 0x82, 0x04, 0x34, 0x52, 0xa5, 0x48, 0x84, 0x4a, 0x76, 0xa1, 0x0b, 0xb6, \n\t0x0c, 0x50, 0x20, 0x20, 0x04, 0x03, 0x88, 0xdc, 0x0c, 0x41, 0x0a, 0x06, 0x00, 0x31, 0x91, 0x02, \n\t0x89, 0x10, 0xe4, 0x23, 0x91, 0x10, 0x9f, 0x45, 0x6c, 0x54, 0xf9, 0x9f, 0x60, 0x0a, 0x80, 0x02, \n\t0x30, 0x71, 0x0d, 0x10, 0x42, 0x82, 0x46, 0x30, 0x12, 0x04, 0x0c, 0x12, 0x08, 0x70, 0xa1, 0x71, \n\t0xa2, 0x50, 0x00, 0xe4, 0x44, 0xd2, 0x28, 0x09, 0x0d, 0xda, 0x40, 0x40, 0x16, 0x78, 0x26, 0xa0, \n\t0x86, 0xa4, 0x08, 0x14, 0x90, 0x00, 0xd1, 0x0a, 0x00, 0x0a, 0xc3, 0x19, 0xac, 0xa5, 0x41, 0xc0, \n\t0x66, 0xb1, 0x50, 0x22, 0x28, 0x09, 0x04, 0x0a, 0xc6, 0x01, 0x96, 0x20, 0x5a, 0x4c, 0x08, 0x45, \n\t0xa2, 0x20, 0xac, 0x57, 0x0c, 0x20, 0x24, 0xa0, 0x81, 0x48, 0x50, 0x85, 0x4e, 0x14, 0x8a, 0x08, \n\t0x50, 0xd5, 0x4f, 0x46, 0xe3, 0x79, 0x0d, 0x0c, 0x88, 0x83, 0x10, 0x03, 0xa0, 0x0b, 0x85, 0x92, \n\t0x05, 0x60, 0xe2, 0x08, 0x20, 0x25, 0x15, 0x44, 0x1a, 0x45, 0x11, 0xbc, 0x80, 0x08, 0x80, 0x50, \n\t0x34, 0x22, 0x15, 0x80, 0x8b, 0x8a, 0x10, 0x41, 0x79, 0xa8, 0x64, 0x50, 0x4e, 0x04, 0xa4, 0x0a, \n\t0x18, 0xcc, 0x88, 0xa5, 0x04, 0xa2, 0x41, 0x8d, 0x40, 0x56, 0x00, 0x70, 0xa3, 0x41, 0x03, 0x30, \n\t0x88, 0x2c, 0x2c, 0x07, 0xcb, 0x92, 0xc1, 0x05, 0xae, 0x14, 0x82, 0xb8, 0x01, 0x58, 0x07, 0x09, \n\t0x10, 0xc2, 0x21, 0x2c, 0xf0, 0x18, 0x02, 0x40, 0x64, 0xa2, 0x29, 0x58, 0x41, 0x80, 0x28, 0xc4, \n\t0x88, 0x09, 0x64, 0x87, 0x82, 0x16, 0x90, 0x21, 0x09, 0x09, 0x5f, 0x06, 0x50, 0x00, 0xd0, 0x92, \n\t0xb8, 0x83, 0x81, 0x68, 0x01, 0x5a, 0x10, 0x3c, 0x05, 0x60, 0x20, 0xb0, 0x10, 0x80, 0x48, 0x88, \n\t0x2b, 0x04, 0x53, 0x38, 0xb3, 0x41, 0x92, 0x4c, 0x62, 0xa6, 0x21, 0x05, 0x2c, 0x48, 0x4d, 0x14, \n\t0x34, 0x32, 0x0b, 0x01, 0x1a, 0xa9, 0x48, 0x02, 0xca, 0x20, 0x21, 0x44, 0x47, 0x06, 0x40, 0x40, \n\t0x81, 0xd4, 0x12, 0x62, 0x14, 0x95, 0x61, 0xb1, 0x98, 0x00, 0x6b, 0x46, 0xa3, 0xb2, 0x1e, 0x10, \n\t0xd6, 0x21, 0x1c, 0x01, 0x88, 0x94, 0x25, 0x80, 0x80, 0x46, 0x61, 0xcb, 0xb3, 0x40, 0x84, 0x8b, \n\t0x50, 0x43, 0xd1, 0x34, 0x31, 0x1d, 0x04, 0x12, 0x15, 0x40, 0x30, 0x00, 0x48, 0xc2, 0x20, 0x95, \n\t0x19, 0x18, 0xf5, 0x8d, 0x84, 0x10, 0x31, 0x0a, 0xbc, 0x04, 0xd9, 0x20, 0x1c, 0x42, 0xf0, 0x01, \n\t0x68, 0x94, 0x2e, 0x0a, 0x86, 0xb0, 0x01, 0x4c, 0x40, 0x21, 0x4c, 0x91, 0x80, 0xaa, 0x34, 0x06, \n\t0xa4, 0x58, 0x01, 0x13, 0xa1, 0x50, 0x41, 0x43, 0x20, 0xc4, 0xa2, 0xa0, 0x20, 0x46, 0x04, 0x38, \n\t0x96, 0xaa, 0x82, 0x6c, 0x12, 0x0e, 0x4c, 0x21, 0x43, 0x13, 0x94, 0x1e, 0x02, 0x46, 0x66, 0x48, \n\t0x10, 0x44, 0x45, 0xe8, 0x06, 0x01, 0x10, 0x12, 0xcc, 0x0a, 0xcd, 0x08, 0x31, 0x10, 0x2f, 0xf0, \n\t0x19, 0x00, 0x70, 0x22, 0x63, 0x88, 0x0c, 0x13, 0x04, 0x48, 0xe0, 0x68, 0x86, 0xa8, 0xcf, 0x60, \n\t0x50, 0x00, 0xb2, 0x00, 0x81, 0x47, 0x22, 0x48, 0x40, 0x3b, 0x25, 0x40, 0x96, 0x45, 0x24, 0x62, \n\t0xa1, 0x08, 0x99, 0xc2, 0x44, 0x04, 0x32, 0x22, 0x01, 0x14, 0x96, 0xa5, 0x58, 0x16, 0x4b, 0x90, \n\t0x49, 0x01, 0x08, 0x32, 0x74, 0x61, 0x00, 0x6d, 0x17, 0x22, 0x12, 0x46, 0x41, 0x20, 0x79, 0x11, \n\t0x01, 0x56, 0xa6, 0x00, 0x02, 0x49, 0x46, 0x2f, 0x02, 0x07, 0x08, 0x0d, 0x45, 0x40, 0xc9, 0x68, \n\t0x07, 0x01, 0x98, 0x34, 0x00, 0x48, 0x28, 0x83, 0x00, 0x1c, 0x81, 0x41, 0xc8, 0x50, 0x20, 0x32, \n\t0x34, 0x95, 0x07, 0x45, 0x48, 0x60, 0x08, 0x0a, 0x54, 0x82, 0x24, 0x60, 0x37, 0xd0, 0xaa, 0xc5, \n\t0xd3, 0x42, 0x04, 0x32, 0xaa, 0x1a, 0x40, 0x05, 0xc1, 0x10, 0x44, 0x0a, 0x80, 0x2c, 0xd0, 0x88, \n\t0x4c, 0x31, 0x42, 0x06, 0x95, 0x07, 0xe2, 0x0c, 0x23, 0xdb, 0xa0, 0x81, 0x09, 0x64, 0x24, 0xf0, \n\t0x4a, 0x10, 0x30, 0x03, 0xc0, 0x1c, 0xc6, 0x40, 0x88, 0xa5, 0x5d, 0x45, 0x22, 0xc1, 0xc2, 0x03, \n\t0x20, 0x9a, 0x2c, 0x40, 0x76, 0x08, 0x14, 0x21, 0x8c, 0xe0, 0x26, 0xb4, 0xf2, 0x08, 0x74, 0x82, \n\t0x0d, 0x04, 0x90, 0x98, 0x2a, 0x48, 0x00, 0x09, 0x50, 0x31, 0xc2, 0x06, 0x08, 0x43, 0xe3, 0x22, \n\t0x14, 0x02, 0x89, 0x45, 0xc4, 0x23, 0x18, 0xd0, 0xb8, 0xa0, 0x89, 0x92, 0x2a, 0x58, 0x51, 0xa0, \n\t0x80, 0xed, 0x03, 0x2b, 0x20, 0x80, 0x18, 0x96, 0x8c, 0x08, 0x00, 0x02, 0x62, 0x83, 0x09, 0x61, \n\t0x01, 0x8d, 0x28, 0x04, 0x48, 0x85, 0x11, 0x58, 0x07, 0x50, 0x05, 0x08, 0x37, 0xb0, 0x96, 0x40, \n\t0x04, 0x05, 0x93, 0x01, 0x11, 0x0f, 0xa9, 0x74, 0x02, 0xb0, 0x04, 0xac, 0xd0, 0xa3, 0x00, 0x21, \n\t0xb0, 0x04, 0x68, 0x10, 0x63, 0x20, 0x60, 0x53, 0x98, 0x88, 0x11, 0x47, 0x28, 0x31, 0x20, 0x24, \n\t0x79, 0x03, 0x20, 0x66, 0x13, 0xa3, 0x36, 0xa1, 0x0f, 0x00, 0x42, 0x74, 0x50, 0x84, 0x70, 0x87, \n\t0x40, 0x28, 0x61, 0xd2, 0x06, 0x98, 0x18, 0x09, 0x44, 0x75, 0x88, 0x93, 0x81, 0x46, 0x82, 0x06, \n\t0xc4, 0x20, 0x8c, 0x44, 0x02, 0x8c, 0x62, 0x94, 0x4b, 0x80, 0x04, 0x0d, 0x49, 0x18, 0x80, 0x80, \n\t0x98, 0x29, 0xc0, 0x2a, 0x76, 0x80, 0x40, 0x15, 0xd1, 0x42, 0x2a, 0x0e, 0xd0, 0xe9, 0x81, 0x11, \n\t0x0a, 0x84, 0x58, 0x00, 0x00, 0x9f, 0x80, 0x80, 0x8e, 0x02, 0x45, 0x90, 0x10, 0x30, 0x53, 0x82, \n\t0x0e, 0x06, 0xa0, 0xb2, 0xa8, 0x90, 0x84, 0x04, 0x41, 0x99, 0x05, 0x11, 0x0f, 0xa1, 0x70, 0x82, \n\t0x29, 0x8e, 0xbc, 0x10, 0x41, 0x20, 0xe5, 0x5b, 0x32, 0x05, 0x86, 0x47, 0x02, 0x23, 0x20, 0x25, \n\t0xd0, 0x8c, 0x02, 0x30, 0x40, 0x4a, 0x32, 0x28, 0xc1, 0x40, 0x62, 0x52, 0x12, 0x19, 0xa8, 0x5a, \n\t0xc5, 0x78, 0x26, 0x4a, 0x0d, 0x65, 0x97, 0x08, 0x1c, 0x81, 0x03, 0x8c, 0xd1, 0x8c, 0x02, 0x0c, \n\t0xa4, 0xe1, 0x02, 0xc0, 0xc9, 0x2e, 0x20, 0x00, 0x32, 0x30, 0x59, 0x50, 0xa7, 0x20, 0xc1, 0x40, \n\t0x84, 0xe9, 0xd8, 0x08, 0x5a, 0x50, 0x91, 0x10, 0x50, 0x1a, 0xc8, 0x28, 0x80, 0x4a, 0x0a, 0x14, \n\t0x09, 0x86, 0x70, 0x80, 0x51, 0x13, 0xc8, 0x02, 0xc4, 0x34, 0x54, 0x60, 0x8a, 0x95, 0x80, 0x07, \n\t0x28, 0x64, 0x22, 0x8c, 0x1c, 0x8a, 0x25, 0x18, 0x03, 0xe2, 0x97, 0x90, 0x16, 0x61, 0x00, 0x26, \n\t0x08, 0x38, 0x24, 0xc1, 0xe8, 0x50, 0x82, 0x12, 0x00, 0x09, 0x90, 0x84, 0x4c, 0x80, 0x92, 0x01, \n\t0x04, 0x0a, 0x6f, 0x68, 0x34, 0x9a, 0xa8, 0x30, 0x58, 0x05, 0x12, 0x84, 0xa3, 0x02, 0x0c, 0xd1, \n\t0xa4, 0x2a, 0x10, 0x09, 0x03, 0x45, 0x15, 0x61, 0x30, 0xa7, 0x00, 0x98, 0x01, 0x44, 0x88, 0x16, \n\t0x13, 0x93, 0x28, 0x11, 0xc6, 0x44, 0x04, 0x77, 0x68, 0x18, 0x00, 0x8b, 0x03, 0x4a, 0xb3, 0x60, \n\t0x2e, 0x90, 0x85, 0x29, 0x42, 0x36, 0x38, 0x9c, 0xa0, 0x00, 0x2a, 0x40, 0x04, 0x2b, 0x14, 0x05, \n\t0x86, 0xa1, 0x4c, 0xd1, 0x0a, 0x27, 0xc0, 0x04, 0x4a, 0x60, 0x04, 0xb1, 0xa1, 0x04, 0x10, 0xe9, \n\t0x62, 0xb6, 0xb2, 0x04, 0x74, 0x48, 0x61, 0x4c, 0x01, 0x12, 0x87, 0x05, 0x91, 0xa4, 0x16, 0x30, \n\t0x09, 0xb4, 0x68, 0x54, 0x03, 0x04, 0x82, 0x02, 0x22, 0x45, 0x54, 0x88, 0x00, 0x81, 0xda, 0x8a, \n\t0xb5, 0x00, 0x42, 0x30, 0x41, 0x30, 0xb1, 0x04, 0x06, 0x0e, 0x1a, 0xa0, 0xe8, 0x09, 0x00, 0x48, \n\t0x40, 0x0e, 0x86, 0x10, 0x02, 0xe0, 0x0e, 0x07, 0x60, 0x10, 0x10, 0x29, 0x08, 0xd3, 0xec, 0x12, \n\t0x71, 0x88, 0x22, 0x8c, 0x92, 0xa4, 0x08, 0x20, 0x53, 0x0f, 0xc0, 0x81, 0x00, 0x0a, 0x87, 0x08, \n\t0x03, 0x0d, 0x08, 0x20, 0x7c, 0x40, 0x08, 0x2b, 0xa1, 0x46, 0x24, 0x60, 0x70, 0x22, 0x85, 0x11, \n\t0x81, 0xc1, 0x6a, 0x84, 0x80, 0x06, 0xa4, 0x14, 0xcb, 0x04, 0xa2, 0x02, 0xb8, 0x10, 0x05, 0x4b, \n\t0x30, 0x55, 0x28, 0x84, 0xc4, 0x00, 0x42, 0x2a, 0xc0, 0xc2, 0x18, 0x80, 0x04, 0x25, 0x4a, 0x65, \n\t0x13, 0x1d, 0x39, 0x90, 0x0c, 0x58, 0x84, 0xc3, 0x0c, 0x38, 0x83, 0xe2, 0x00, 0x21, 0x0a, 0x8c, \n\t0x38, 0x86, 0x4d, 0x74, 0xc2, 0x10, 0x04, 0x09, 0x4b, 0xa1, 0x40, 0xb4, 0x0a, 0xa2, 0x2c, 0x52, \n\t0x22, 0x10, 0xc0, 0x63, 0x08, 0xc1, 0x82, 0x82, 0x0e, 0x21, 0x28, 0x12, 0x94, 0xd8, 0x02, 0x0c, \n\t0x46, 0x09, 0x3a, 0x84, 0x11, 0xc8, 0x12, 0x30, 0x89, 0x90, 0x35, 0x48, 0xe8, 0x24, 0x55, 0x10, \n\t0xa7, 0x80, 0x03, 0x43, 0x02, 0x17, 0x09, 0x9a, 0x10, 0x8d, 0x28, 0x62, 0xe4, 0x2a, 0x11, 0x68, \n\t0x04, 0x20, 0x22, 0x10, 0x42, 0x01, 0xcc, 0x04, 0x88, 0x1e, 0xc1, 0x83, 0x28, 0x20, 0x0c, 0x24, \n\t0x14, 0x63, 0xa1, 0x90, 0x09, 0x19, 0x23, 0x28, 0x20, 0x2a, 0x38, 0x0c, 0x1d, 0x42, 0x4c, 0x90, \n\t0xc0, 0x0b, 0x41, 0x8f, 0x06, 0x14, 0x55, 0xb8, 0x92, 0x2d, 0xc8, 0x49, 0x42, 0xa0, 0x23, 0x92, \n\t0x48, 0x05, 0xc7, 0x74, 0x84, 0x80, 0x8b, 0x4d, 0x8d, 0x40, 0x38, 0x00, 0x20, 0x9c, 0xa1, 0x06, \n\t0x09, 0x32, 0x54, 0xa8, 0x85, 0x88, 0x41, 0x05, 0x44, 0xd3, 0x13, 0x04, 0x21, 0xd8, 0x8f, 0x02, \n\t0x90, 0xc1, 0x08, 0x78, 0x54, 0x26, 0x40, 0x50, 0x4a, 0x24, 0x39, 0x16, 0xa0, 0x00, 0x12, 0x41, \n\t0xb0, 0x14, 0x50, 0x82, 0x6c, 0xa3, 0x80, 0xa3, 0x71, 0x82, 0x03, 0x04, 0x04, 0xd9, 0x21, 0x09, \n\t0x5e, 0xa8, 0x08, 0x70, 0x82, 0x15, 0x68, 0x04, 0x8b, 0x52, 0x63, 0x29, 0x3a, 0x54, 0x51, 0x4b, \n\t0x62, 0x80, 0x99, 0x18, 0x34, 0x44, 0x2e, 0x30, 0x30, 0x40, 0xb2, 0x41, 0x4e, 0x44, 0x10, 0xc0, \n\t0xca, 0xa4, 0x10, 0x1a, 0x01, 0x40, 0x66, 0xf2, 0x8c, 0x01, 0x84, 0x2c, 0x18, 0x30, 0xaa, 0x11, \n\t0x05, 0xd0, 0x40, 0x52, 0xa1, 0x79, 0x83, 0xb0, 0x80, 0x2b, 0x64, 0x01, 0x80, 0x9e, 0x50, 0x18, \n\t0x01, 0x04, 0x00, 0xa2, 0x17, 0x28, 0xca, 0x24, 0x30, 0xd3, 0x22, 0xa2, 0x6d, 0x50, 0x20, 0x46, \n\t0x24, 0x80, 0x84, 0xe8, 0x0a, 0x00, 0x02, 0x01, 0x33, 0x8c, 0x74, 0x00, 0x07, 0x42, 0xd6, 0x13, \n\t0x11, 0x38, 0x0c, 0x8c, 0x18, 0x32, 0x49, 0x29, 0x61, 0x82, 0x8a, 0x20, 0x50, 0x41, 0x08, 0xac, \n\t0xc1, 0x41, 0x30, 0x25, 0x58, 0x8a, 0xb0, 0x42, 0x24, 0x5c, 0x02, 0x5a, 0x00, 0xc5, 0x12, 0x82, \n\t0x1c, 0x20, 0x42, 0x07, 0xad, 0x04, 0x21, 0x64, 0x52, 0x00, 0x9f, 0x48, 0x48, 0x09, 0x24, 0x31, \n\t0xa2, 0xa9, 0x14, 0x58, 0xe1, 0x72, 0x15, 0x58, 0x26, 0x89, 0x0d, 0x0e, 0x04, 0x00, 0x00, 0x26, \n\t0x84, 0x85, 0xa0, 0x26, 0x03, 0x00, 0x32, 0xb9, 0x00, 0xa2, 0x50, 0x05, 0x80, 0x11, 0x10, 0x0e, \n\t0x85, 0x00, 0x62, 0x61, 0x85, 0x74, 0x99, 0x8a, 0x00, 0x31, 0x4a, 0x01, 0x90, 0x09, 0x0c, 0x26, \n\t0xd0, 0x90, 0x07, 0xc1, 0x50, 0x41, 0x26, 0xb6, 0xd9, 0x3c, 0x19, 0x83, 0x09, 0x08, 0x71, 0x10, \n\t0x2a, 0x68, 0x88, 0x25, 0x00, 0xb2, 0xb0, 0x00, 0xc4, 0x82, 0xc1, 0x48, 0x07, 0x92, 0x16, 0x0c, \n\t0x01, 0xe4, 0x22, 0x02, 0x03, 0x88, 0x0c, 0x81, 0x24, 0x4e, 0x24, 0x48, 0x20, 0x75, 0x41, 0xa2, \n\t0x28, 0x80, 0x90, 0x12, 0x59, 0x15, 0x47, 0x52, 0x80, 0x00, 0xb1, 0x15, 0x09, 0xc0, 0x18, 0x81, \n\t0x18, 0x21, 0x44, 0x58, 0x80, 0x28, 0xc2, 0x00, 0xb6, 0xac, 0x58, 0x00, 0x50, 0x24, 0x32, 0x81, \n\t0x18, 0x15, 0x6a, 0x64, 0x84, 0xc9, 0x21, 0xd0, 0x01, 0x4e, 0x16, 0x31, 0xe8, 0x2e, 0xc1, 0x98, \n\t0x81, 0x04, 0x03, 0x30, 0xa4, 0x8c, 0xc0, 0x0f, 0x02, 0xe1, 0x08, 0x13, 0x49, 0x00, 0xe0, 0x40, \n\t0x52, 0xd2, 0x08, 0x09, 0x8c, 0x02, 0x44, 0x60, 0x89, 0xb3, 0x29, 0x93, 0x89, 0x1c, 0x24, 0x9a, \n\t0x04, 0x71, 0x18, 0x08, 0x30, 0x91, 0xc2, 0x2a, 0x51, 0x40, 0xa6, 0x02, 0x04, 0x19, 0x18, 0xc1, \n\t0xc8, 0x41, 0x12, 0x06, 0xc0, 0x05, 0x18, 0x47, 0x6c, 0x24, 0x91, 0x21, 0x08, 0x90, 0x4d, 0x6d, \n\t0x10, 0x24, 0xe0, 0x01, 0x0d, 0x92, 0x8b, 0x16, 0xc0, 0x20, 0xa1, 0x40, 0x00, 0x80, 0x24, 0xd4, \n\t0x72, 0x00, 0x88, 0x80, 0xc1, 0x20, 0x43, 0x28, 0x3a, 0x58, 0x42, 0xc5, 0x24, 0x54, 0x69, 0xa6, \n\t0x81, 0x06, 0xac, 0x2a, 0x24, 0x13, 0x12, 0x8c, 0x8a, 0x03, 0x0c, 0x80, 0x32, 0x86, 0xc5, 0x44, \n\t0xa8, 0x00, 0x30, 0x13, 0x19, 0xc8, 0x43, 0x80, 0x1e, 0x10, 0x08, 0x0b, 0x44, 0x5b, 0xc4, 0x10, \n\t0x60, 0x09, 0x25, 0x24, 0xd4, 0x45, 0x24, 0x02, 0xc0, 0x1f, 0x89, 0x14, 0x61, 0x18, 0x30, 0x48, \n\t0x25, 0xac, 0x91, 0xa4, 0x04, 0x51, 0x13, 0xa8, 0x39, 0x14, 0x48, 0x04, 0x20, 0x23, 0x1e, 0x48, \n\t0x0a, 0x83, 0x08, 0x86, 0x20, 0x35, 0x00, 0x09, 0x01, 0x48, 0x90, 0x01, 0xb6, 0xe0, 0x08, 0x08, \n\t0x44, 0x41, 0x61, 0x02, 0x50, 0x1c, 0x29, 0x62, 0x03, 0xd0, 0xaa, 0x00, 0x59, 0xad, 0x30, 0x15, \n\t0x40, 0x0a, 0xfc, 0x81, 0x80, 0x20, 0x63, 0x10, 0x1a, 0x01, 0x15, 0x41, 0x40, 0x47, 0x08, 0x21, \n\t0x00, 0x96, 0x28, 0x22, 0x92, 0x88, 0x8e, 0x80, 0x0b, 0xe8, 0x22, 0x10, 0x11, 0x00, 0x04, 0x07, \n\t0xee, 0x46, 0xb2, 0x48, 0x88, 0x01, 0x8c, 0x42, 0x7c, 0x07, 0xa0, 0x84, 0xd0, 0x82, 0xce, 0x06, \n\t0x97, 0x3a, 0xa0, 0x18, 0x43, 0x81, 0x34, 0x80, 0xa3, 0x01, 0x44, 0xca, 0x2e, 0x44, 0x01, 0x51, \n\t0x00, 0x18, 0x5d, 0x41, 0x0a, 0x84, 0x90, 0x34, 0x24, 0x00, 0xcc, 0x26, 0x03, 0x08, 0x11, 0xc8, \n\t0x0a, 0xc6, 0x20, 0x42, 0x01, 0x18, 0x11, 0xca, 0x46, 0x40, 0x51, 0x00, 0x21, 0x88, 0x0b, 0x25, \n\t0x58, 0x21, 0x80, 0x91, 0x09, 0x18, 0xc2, 0x54, 0x24, 0x41, 0x00, 0xc4, 0xd0, 0x09, 0x0a, 0x10, \n\t0xb9, 0x80, 0xb8, 0x18, 0x21, 0x24, 0x86, 0x30, 0xac, 0x40, 0xd0, 0x63, 0x64, 0xa0, 0x10, 0x10, \n\t0x69, 0x41, 0x41, 0x42, 0x11, 0xaa, 0x16, 0x8d, 0x40, 0x8c, 0x2a, 0x50, 0x8b, 0x80, 0xe1, 0x58, \n\t0x03, 0x46, 0x24, 0x52, 0x84, 0x45, 0x04, 0xa2, 0x52, 0xe6, 0x98, 0x28, 0x10, 0xcf, 0x69, 0x08, \n\t0x14, 0x48, 0x2a, 0x30, 0x83, 0xc0, 0x50, 0x83, 0x20, 0x07, 0xa4, 0x1b, 0x64, 0x52, 0x43, 0x23, \n\t0x14, 0x18, 0x01, 0xc2, 0x78, 0x30, 0x09, 0x04, 0xbc, 0x40, 0x40, 0x4c, 0xc1, 0x90, 0x04, 0x40, \n\t0x0c, 0xa2, 0x70, 0x05, 0xa2, 0x29, 0x09, 0x90, 0xc6, 0x2c, 0xd2, 0x08, 0x0e, 0x68, 0x19, 0xc4, \n\t0x26, 0xd0, 0x12, 0x00, 0x24, 0x87, 0xa0, 0x18, 0x10, 0x9a, 0x85, 0x78, 0x88, 0x60, 0x52, 0x45, \n\t0x43, 0x20, 0xdd, 0x01, 0x20, 0x32, 0x44, 0xc9, 0x9a, 0xc8, 0x4a, 0x83, 0x06, 0x25, 0x10, 0x83, \n\t0xe0, 0x56, 0x00, 0x08, 0x60, 0x2b, 0x8c, 0x28, 0x94, 0x00, 0x26, 0xd0, 0xb1, 0x80, 0x58, 0x9c, \n\t0x00, 0x32, 0x00, 0x80, 0x01, 0x48, 0x07, 0xe4, 0x44, 0x20, 0x22, 0xa6, 0x99, 0x8a, 0x0c, 0x78, \n\t0x90, 0x22, 0x15, 0x94, 0x4a, 0x80, 0x46, 0x32, 0x30, 0x37, 0x05, 0xd1, 0x22, 0x10, 0x04, 0x71, \n\t0xa4, 0x84, 0x13, 0x82, 0x50, 0x44, 0x32, 0x07, 0x50, 0x80, 0x89, 0x18, 0xe3, 0x28, 0x08, 0x91, \n\t0x5c, 0x20, 0x24, 0x24, 0x42, 0x93, 0x89, 0x80, 0x49, 0x20, 0xb4, 0x41, 0x20, 0x01, 0x00, 0x84, \n\t0x00, 0x13, 0x29, 0x8a, 0x04, 0x4c, 0x41, 0x4a, 0xc4, 0x60, 0x08, 0x08, 0x04, 0x8d, 0x48, 0xa6, \n\t0x18, 0x38, 0x0c, 0x84, 0xca, 0x08, 0xa3, 0xb0, 0x8c, 0x0c, 0x0e, 0x4f, 0x34, 0xc0, 0xc0, 0x21, \n\t0x55, 0x53, 0x04, 0x60, 0x76, 0x9a, 0x28, 0x39, 0x81, 0x83, 0x3a, 0x95, 0x43, 0xb4, 0x21, 0x05, \n\t0x82, 0x0c, 0x54, 0xb0, 0xb3, 0x80, 0x02, 0x62, 0x5c, 0x04, 0x2a, 0x2e, 0x08, 0x00, 0x65, 0x06, \n\t0x50, 0x80, 0x8b, 0x90, 0x08, 0x61, 0x12, 0x60, 0x20, 0x0f, 0x50, 0x0b, 0xc1, 0x08, 0x20, 0x41, \n\t0x10, 0x30, 0x01, 0x60, 0x0c, 0x16, 0x89, 0x01, 0x78, 0x9a, 0x68, 0x22, 0x04, 0x31, 0x30, 0x4c, \n\t0x12, 0x85, 0x18, 0x42, 0xb1, 0x81, 0x14, 0x8a, 0x05, 0x58, 0x82, 0x83, 0x34, 0x09, 0x83, 0x07, \n\t0x6e, 0x63, 0x00, 0x1d, 0x00, 0x18, 0xc4, 0x3a, 0xc1, 0x98, 0x3a, 0x2d, 0x41, 0x02, 0x64, 0x15, \n\t0xa8, 0x26, 0x08, 0x0b, 0x68, 0x48, 0x24, 0x03, 0x16, 0x94, 0x4c, 0x86, 0x46, 0x65, 0x82, 0x8a, \n\t0xc8, 0x4d, 0x48, 0x34, 0x71, 0x30, 0x2a, 0x20, 0xd4, 0x8b, 0x00, 0xf0, 0x8a, 0x9e, 0xa4, 0x43, \n\t0x48, 0x1c, 0x02, 0x10, 0x84, 0x01, 0xc5, 0x63, 0x34, 0x16, 0x13, 0x25, 0xc1, 0x10, 0x48, 0x54, \n\t0xc1, 0xc3, 0x00, 0xd0, 0x10, 0x22, 0x04, 0x84, 0xc1, 0x38, 0x01, 0x02, 0x09, 0x02, 0xa0, 0x00, \n\t0x8c, 0x24, 0x0c, 0x03, 0x08, 0x11, 0xc8, 0x2d, 0x48, 0x58, 0x0e, 0x00, 0x04, 0xb2, 0x84, 0x30, \n\t0x80, 0x49, 0x62, 0x00, 0xb8, 0x20, 0x30, 0x08, 0xa7, 0x74, 0x32, 0x08, 0x02, 0x8c, 0xc9, 0x46, \n\t0x12, 0x91, 0x31, 0x33, 0xa0, 0xc7, 0x85, 0x32, 0x24, 0x68, 0x84, 0x90, 0xc0, 0x09, 0x30, 0x50, \n\t0x49, 0x8e, 0xa8, 0x90, 0x84, 0x6a, 0x92, 0x39, 0x14, 0x0d, 0x10, 0xa8, 0x48, 0x21, 0x13, 0x2a, \n\t0x74, 0x98, 0x84, 0x40, 0x96, 0x82, 0x81, 0x00, 0x11, 0x44, 0x00, 0x62, 0xa8, 0xb3, 0x28, 0xd9, \n\t0x02, 0x30, 0xc5, 0xf2, 0x19, 0x80, 0x57, 0x04, 0x02, 0x41, 0x73, 0x00, 0x0c, 0x90, 0x28, 0x00, \n\t0x07, 0x32, 0xa8, 0x2c, 0x58, 0x64, 0x42, 0x03, 0x43, 0x18, 0xb4, 0x04, 0x85, 0x2c, 0x21, 0x19, \n\t0x21, 0x80, 0x02, 0x43, 0x32, 0x54, 0xc0, 0x16, 0x30, 0x8e, 0x21, 0x4a, 0x55, 0x08, 0x02, 0xc0, \n\t0x8b, 0x20, 0x4c, 0x80, 0x32, 0x38, 0x14, 0xd4, 0xa3, 0x40, 0x63, 0xd3, 0x00, 0x49, 0x10, 0xe4, \n\t0x18, 0xe0, 0x01, 0x81, 0x04, 0x52, 0x81, 0x6e, 0x33, 0x28, 0x04, 0x05, 0xce, 0x46, 0x72, 0x82, \n\t0xc2, 0x8d, 0x60, 0x58, 0x0a, 0x36, 0x51, 0x6a, 0x26, 0x04, 0xda, 0x80, 0x0e, 0x06, 0xb1, 0x2a, \n\t0x89, 0x15, 0x08, 0x30, 0x83, 0x10, 0xa1, 0x01, 0x00, 0x84, 0x1c, 0xa1, 0x70, 0xa4, 0x34, 0x4a, \n\t0x4e, 0x28, 0x00, 0xa1, 0x2b, 0x10, 0x90, 0x00, 0x28, 0xc2, 0x70, 0x05, 0xf9, 0x41, 0x67, 0x74, \n\t0x02, 0x18, 0x08, 0xb0, 0xd4, 0x8a, 0x4a, 0xc1, 0x03, 0x0a, 0x91, 0x08, 0x02, 0x3c, 0x25, 0x22, \n\t0x05, 0x44, 0x50, 0x40, 0x08, 0x55, 0x32, 0x07, 0x49, 0x02, 0x27, 0x00, 0x00, 0x02, 0x9a, 0xa4, \n\t0x02, 0x80, 0x44, 0x65, 0x4b, 0xa4, 0x20, 0x13, 0x8b, 0x48, 0x81, 0x0a, 0x88, 0xc0, 0x44, 0x08, \n\t0x56, 0xa7, 0x40, 0x22, 0x05, 0x4e, 0x2e, 0x04, 0xd1, 0x19, 0x88, 0x34, 0x0c, 0x03, 0x00, 0xa2, \n\t0x21, 0x22, 0xa8, 0x1c, 0x01, 0x06, 0x72, 0x91, 0x15, 0x39, 0xd8, 0x8c, 0x2a, 0x22, 0xc8, 0x38, \n\t0x48, 0x05, 0x47, 0x48, 0x12, 0x30, 0x0a, 0x2c, 0x16, 0x89, 0x30, 0xd3, 0x02, 0x06, 0x09, 0x18, \n\t0x24, 0x22, 0x04, 0x02, 0x28, 0x45, 0x46, 0x25, 0x32, 0xc6, 0x00, 0x00, 0x01, 0xc2, 0x0a, 0x78, \n\t0x51, 0xa8, 0x32, 0xa0, 0x03, 0xe8, 0x58, 0xc6, 0x0a, 0x84, 0x65, 0x01, 0x80, 0x10, 0xd4, 0x12, \n\t0xa1, 0x60, 0x0e, 0x89, 0x00, 0x96, 0x01, 0x31, 0x80, 0x09, 0x00, 0x08, 0xf4, 0x0b, 0xb3, 0x1c, \n\t0x8d, 0x20, 0x14, 0x90, 0xe3, 0x12, 0x30, 0x48, 0x0d, 0x1e, 0x04, 0x60, 0x21, 0x88, 0x82, 0x8a, \n\t0x5a, 0x00, 0x4b, 0x89, 0x44, 0x0e, 0xe0, 0x64, 0x01, 0x72, 0x1c, 0x58, 0x11, 0x04, 0x0c, 0x30, \n\t0xa0, 0x1a, 0x1d, 0x9d, 0x03, 0x12, 0x02, 0xd0, 0x12, 0x25, 0x43, 0x2a, 0x3a, 0x50, 0x21, 0x35, \n\t0x69, 0x44, 0x43, 0x08, 0xc0, 0x4a, 0x2c, 0x01, 0x18, 0x41, 0x04, 0x12, 0xd2, 0x0b, 0x48, 0xc7, \n\t0x40, 0x0a, 0xa4, 0x18, 0x9e, 0x80, 0x88, 0x40, 0x18, 0x55, 0xe1, 0x0c, 0x94, 0x5d, 0x01, 0x70, \n\t0x83, 0x48, 0x12, 0x90, 0x59, 0x29, 0x24, 0x22, 0x0a, 0x20, 0x38, 0x80, 0x08, 0x08, 0x03, 0x08, \n\t0x09, 0x64, 0x10, 0x43, 0x20, 0x85, 0x00, 0x2a, 0x1d, 0xda, 0x20, 0x06, 0xe0, 0x22, 0x3c, 0x24, \n\t0x43, 0x40, 0x26, 0xc0, 0x78, 0x94, 0x08, 0x17, 0x0e, 0x58, 0x20, 0x29, 0x07, 0xa4, 0xcc, 0x80, \n\t0x54, 0x42, 0xa2, 0x18, 0x91, 0x01, 0xc4, 0x00, 0x80, 0x10, 0x23, 0x7c, 0x05, 0x87, 0x02, 0xc0, \n\t0x58, 0xaa, 0x01, 0x1e, 0x0b, 0x68, 0x41, 0x03, 0x83, 0xa0, 0x57, 0x01, 0x10, 0x34, 0x19, 0x14, \n\t0x80, 0x02, 0xa0, 0x28, 0x82, 0x61, 0x2c, 0x61, 0x42, 0x40, 0x0e, 0xa3, 0x92, 0x84, 0x81, 0x10, \n\t0x43, 0x2c, 0x94, 0x02, 0x04, 0xcc, 0x48, 0x60, 0x2a, 0x51, 0x92, 0x01, 0x18, 0x49, 0xe6, 0x38, \n\t0x81, 0xa3, 0x2d, 0x60, 0x44, 0x20, 0x10, 0x21, 0x71, 0xb0, 0x04, 0x07, 0xaa, 0x0c, 0xc4, 0x2a, \n\t0x18, 0x14, 0x00, 0x8e, 0x54, 0xf2, 0x01, 0x18, 0x19, 0x48, 0x23, 0x22, 0xc0, 0x18, 0x0c, 0x35, \n\t0x06, 0x49, 0x32, 0x10, 0x63, 0x32, 0xac, 0x44, 0x60, 0x08, 0xe1, 0x48, 0x96, 0x88, 0x84, 0x08, \n\t0x24, 0x00, 0xfb, 0x25, 0x80, 0x81, 0xce, 0x16, 0x02, 0xb9, 0x00, 0xc1, 0x00, 0x0c, 0x44, 0x06, \n\t0x10, 0x83, 0x40, 0x51, 0xc2, 0x60, 0x23, 0x1a, 0xb8, 0x41, 0x80, 0x42, 0x0c, 0x11, 0xe2, 0x12, \n\t0xa4, 0x0d, 0x8a, 0x2e, 0x41, 0x98, 0x20, 0x0d, 0x14, 0xe0, 0x6a, 0x41, 0x10, 0x10, 0xc1, 0x54, \n\t0x05, 0x16, 0x42, 0x18, 0x28, 0x55, 0x0d, 0x03, 0x0a, 0x43, 0x40, 0x00, 0xe0, 0x96, 0x80, 0x10, \n\t0xa1, 0x48, 0x01, 0xa4, 0x12, 0x40, 0x34, 0xe5, 0x30, 0x00, 0x39, 0x06, 0x23, 0x08, 0x94, 0x21, \n\t0x19, 0xc8, 0x41, 0x06, 0x14, 0x82, 0x82, 0x80, 0x4c, 0x90, 0x41, 0x3c, 0x03, 0x12, 0xa6, 0xc4, \n\t0x40, 0x4b, 0x24, 0x44, 0x32, 0x97, 0x7c, 0x02, 0x64, 0x66, 0x52, 0x29, 0x06, 0x85, 0x1c, 0xa2, \n\t0x34, 0x00, 0x18, 0x21, 0x09, 0x90, 0x21, 0x62, 0x06, 0xcb, 0x00, 0x01, 0x45, 0xa0, 0x20, 0x12, \n\t0x41, 0x33, 0x94, 0x08, 0x62, 0x1e, 0x82, 0x50, 0x84, 0xb0, 0x10, 0x8d, 0x50, 0x23, 0x8b, 0x14, \n\t0x00, 0x10, 0x04, 0x48, 0x70, 0x8b, 0x80, 0x88, 0x8f, 0x4d, 0x5c, 0xb0, 0xa1, 0x01, 0x00, 0x84, \n\t0xa8, 0x04, 0x12, 0xf9, 0x00, 0x08, 0x00, 0x8f, 0x30, 0x41, 0x62, 0x90, 0x05, 0x8a, 0xa3, 0x6a, \n\t0x90, 0x02, 0x14, 0x58, 0x4d, 0x00, 0x40, 0x04, 0x80, 0xa5, 0xc1, 0x17, 0x02, 0x76, 0x04, 0x83, \n\t0x07, 0x50, 0x98, 0x49, 0x04, 0x22, 0x90, 0x88, 0x01, 0x5d, 0x04, 0x30, 0x11, 0x58, 0x11, 0x68, \n\t0x80, 0x4c, 0x28, 0x51, 0x61, 0x15, 0x11, 0x4d, 0x42, 0x02, 0x92, 0x22, 0x02, 0x34, 0x5e, 0x49, \n\t0x5a, 0xa2, 0xe2, 0x80, 0x98, 0x0a, 0x0f, 0x40, 0x04, 0x60, 0x08, 0x50, 0x12, 0x60, 0x40, 0x90, \n\t0x1b, 0x8d, 0xd4, 0x86, 0x0e, 0x40, 0x40, 0x70, 0x2b, 0x99, 0xc9, 0x65, 0x00, 0x87, 0x88, 0x2e, \n\t0x10, 0xd3, 0x84, 0x42, 0x01, 0x58, 0x98, 0x05, 0x80, 0x00, 0x20, 0x60, 0xd8, 0x03, 0x80, 0x92, \n\t0xcb, 0x0c, 0x40, 0x98, 0x06, 0x29, 0x40, 0x23, 0x20, 0x36, 0x90, 0x91, 0x50, 0x83, 0x0d, 0x16, \n\t0x24, 0x48, 0xaa, 0x95, 0x0f, 0xc7, 0x60, 0xa0, 0x48, 0x2d, 0xa0, 0x41, 0x28, 0x30, 0x45, 0x82, \n\t0x02, 0x40, 0x55, 0x0e, 0x2e, 0x90, 0x52, 0x20, 0xa5, 0x03, 0x20, 0x5a, 0x41, 0x71, 0xa1, 0x18, \n\t0x90, 0x8e, 0x40, 0xf1, 0xe0, 0xad, 0x40, 0x90, 0x21, 0x06, 0x52, 0x32, 0xa4, 0x20, 0x90, 0x02, \n\t0x0a, 0x90, 0x11, 0x0e, 0x0c, 0x1c, 0xa4, 0x40, 0x21, 0x40, 0x90, 0xa8, 0x4c, 0x8b, 0x3a, 0x20, \n\t0x53, 0x3a, 0x45, 0x01, 0xa5, 0x14, 0x82, 0xc8, 0xb8, 0x11, 0x8c, 0xa2, 0x10, 0x33, 0x08, 0x86, \n\t0xe4, 0x11, 0x07, 0x02, 0xb2, 0x28, 0x1b, 0x24, 0x43, 0x04, 0x66, 0x66, 0x62, 0x8e, 0x60, 0x53, \n\t0x8a, 0x70, 0x90, 0x01, 0x1d, 0x11, 0x14, 0x27, 0x58, 0x10, 0x80, 0x21, 0x89, 0x04, 0xe0, 0x24, \n\t0x44, 0xc0, 0x99, 0x98, 0x00, 0xcf, 0x08, 0x03, 0x10, 0xa0, 0x5d, 0x18, 0x20, 0x0c, 0xd2, 0xb8, \n\t0x15, 0x44, 0xc3, 0xa8, 0x60, 0x40, 0x50, 0x91, 0xc0, 0x03, 0x88, 0x4c, 0x82, 0x60, 0x0e, 0x0d, \n\t0x19, 0x03, 0x26, 0x15, 0x80, 0xba, 0x01, 0xce, 0xa0, 0x10, 0xa0, 0x10, 0x84, 0x50, 0x05, 0x43, \n\t0x38, 0x62, 0x00, 0x19, 0x00, 0x88, 0x08, 0x64, 0x52, 0x23, 0x14, 0x00, 0xc6, 0x0a, 0x50, 0x84, \n\t0x0b, 0x01, 0x00, 0x10, 0x05, 0x52, 0x71, 0xd1, 0x0a, 0x80, 0x94, 0xe0, 0x08, 0x22, 0x83, 0xac, \n\t0x40, 0xc9, 0x2a, 0x4a, 0x34, 0xa2, 0xa2, 0x41, 0x13, 0x80, 0x14, 0x05, 0xc8, 0x18, 0xa0, 0x4c, \n\t0xa6, 0x00, 0x40, 0x13, 0x01, 0x24, 0x54, 0x22, 0x14, 0xa1, 0x78, 0x98, 0x38, 0x4d, 0x29, 0x06, \n\t0x60, 0x43, 0x22, 0x2c, 0x8a, 0x40, 0x22, 0x00, 0x49, 0x25, 0xc0, 0xd4, 0x8c, 0x32, 0x85, 0x81, \n\t0x18, 0x24, 0x5b, 0x04, 0x68, 0x61, 0x39, 0x16, 0x61, 0x42, 0x41, 0x60, 0x10, 0x0a, 0x00, 0x44, \n\t0x12, 0x40, 0x4c, 0x61, 0x03, 0xa0, 0xc4, 0x90, 0x22, 0x2c, 0xe4, 0x10, 0x98, 0x45, 0x1a, 0x05, \n\t0x48, 0x02, 0x02, 0x28, 0x74, 0x40, 0x42, 0x06, 0x06, 0x4a, 0x0b, 0xa8, 0x94, 0x28, 0x0c, 0x40, \n\t0x02, 0x05, 0xd9, 0x8a, 0xc2, 0x00, 0x43, 0x60, 0x20, 0xb0, 0x10, 0x2c, 0x06, 0x05, 0x01, 0x89, \n\t0x08, 0x8c, 0x03, 0x12, 0x74, 0x21, 0x88, 0x44, 0x87, 0x47, 0x20, 0x25, 0x82, 0x35, 0x10, 0x0a, \n\t0x0d, 0x0a, 0x22, 0x01, 0x07, 0xd0, 0x80, 0xe3, 0x44, 0x04, 0xf0, 0x38, 0x3d, 0x92, 0xa5, 0x50, \n\t0xa0, 0x30, 0x80, 0x39, 0x80, 0x40, 0x14, 0x17, 0xd2, 0x02, 0x45, 0xc0, 0xa0, 0x00, 0x34, 0x18, \n\t0xa0, 0x41, 0x04, 0x82, 0x1e, 0x16, 0x2b, 0x04, 0x41, 0x8a, 0x80, 0x02, 0x00, 0x50, 0x25, 0x71, \n\t0xd2, 0x21, 0x60, 0x87, 0x81, 0x24, 0x39, 0x15, 0x06, 0x74, 0x22, 0x41, 0xa2, 0xe8, 0x42, 0x02, \n\t0x08, 0xc3, 0x71, 0x31, 0xc5, 0x44, 0x8b, 0x48, 0x20, 0x02, 0x0a, 0x04, 0x46, 0x0d, 0x40, 0x95, \n\t0x30, 0x18, 0x19, 0x44, 0x6a, 0x02, 0x92, 0xaa, 0x30, 0xf0, 0x10, 0x87, 0x1e, 0xb2, 0xa8, 0x06, \n\t0x25, 0x14, 0xcf, 0x74, 0xe0, 0x01, 0x0a, 0x00, 0x08, 0xc7, 0x22, 0x10, 0x08, 0x20, 0x15, 0x0a, \n\t0x67, 0x64, 0x05, 0x82, 0x01, 0x8c, 0xca, 0xa8, 0x40, 0x00, 0x58, 0xa3, 0x04, 0x12, 0x69, 0x06, \n\t0x84, 0xb9, 0x9e, 0x2c, 0x40, 0x00, 0x04, 0xa2, 0x5b, 0x01, 0x80, 0x0c, 0xae, 0x2a, 0x05, 0x41, \n\t0x13, 0x00, 0xc0, 0x0d, 0x50, 0x95, 0x22, 0xb0, 0x10, 0x43, 0x0c, 0x38, 0x03, 0xfa, 0x12, 0x08, \n\t0x52, 0x86, 0x40, 0x84, 0x00, 0x1d, 0xb0, 0xc6, 0x8c, 0x0a, 0x70, 0x92, 0x0d, 0x38, 0x00, 0x82, \n\t0x60, 0xd4, 0x32, 0xa3, 0x88, 0x10, 0x04, 0x28, 0x51, 0x18, 0x10, 0x29, 0x98, 0x20, 0x50, 0x04, \n\t0xc0, 0x2e, 0x88, 0x51, 0x0a, 0x28, 0x55, 0x32, 0xb1, 0x90, 0x0d, 0x62, 0x60, 0x04, 0x00, 0xb6, \n\t0xdc, 0x58, 0xc9, 0x34, 0x14, 0x41, 0xa8, 0xc1, 0x44, 0x82, 0x38, 0x90, 0x00, 0x19, 0x90, 0x11, \n\t0x01, 0x3a, 0x04, 0xc0, 0x2f, 0x00, 0x88, 0x21, 0x28, 0x20, 0x51, 0x93, 0x01, 0x89, 0x61, 0x14, \n\t0x26, 0x29, 0x15, 0xe4, 0x12, 0x64, 0x00, 0xc1, 0x28, 0x0b, 0x45, 0x02, 0xa8, 0x44, 0x63, 0x80, \n\t0x8a, 0x94, 0x8a, 0x04, 0x42, 0x04, 0x28, 0x95, 0x25, 0x86, 0x42, 0x40, 0x02, 0xb3, 0xa0, 0xc8, \n\t0x1e, 0x00, 0x1e, 0x51, 0xb0, 0x02, 0x7c, 0x4c, 0x00, 0x06, 0x86, 0xe8, 0x38, 0x80, 0x0c, 0xad, \n\t0x02, 0xc4, 0x02, 0x89, 0xb1, 0x81, 0xa4, 0x20, 0x21, 0x20, 0x2d, 0xd1, 0x54, 0x02, 0x08, 0x62, \n\t0x68, 0x81, 0xa8, 0x11, 0x05, 0x42, 0x50, 0x10, 0x92, 0x91, 0x50, 0x4c, 0x18, 0x04, 0x71, 0x04, \n\t0x24, 0xd5, 0x2a, 0x14, 0x00, 0x89, 0xaa, 0x78, 0x08, 0x04, 0x5c, 0x50, 0x00, 0x04, 0x11, 0x08, \n\t0x64, 0x0c, 0xd1, 0x92, 0x91, 0x0c, 0x13, 0x61, 0x00, 0x40, 0xd3, 0x22, 0xc1, 0x8e, 0x86, 0x1c, \n\t0x34, 0xd9, 0x31, 0x4c, 0xc1, 0xa2, 0x08, 0x80, 0x02, 0x82, 0x60, 0x08, 0x00, 0x06, 0x62, 0x48, \n\t0x20, 0x11, 0x4a, 0x26, 0x00, 0x71, 0x49, 0x14, 0x84, 0x07, 0xc7, 0x40, 0xa0, 0x43, 0xa7, 0x80, \n\t0x8f, 0x20, 0x56, 0x35, 0x12, 0x10, 0x50, 0x1c, 0x43, 0x38, 0x20, 0xab, 0x1c, 0xcd, 0xc0, 0xc1, \n\t0x08, 0x12, 0x00, 0x09, 0xd8, 0x18, 0xa5, 0x58, 0x72, 0x43, 0x20, 0x41, 0x41, 0xe8, 0x48, 0xa0, \n\t0x90, 0xa2, 0x70, 0xc1, 0x45, 0x36, 0x00, 0x69, 0x93, 0xec, 0x87, 0x28, 0x36, 0x00, 0x0a, 0xb0, \n\t0x8c, 0x41, 0x02, 0x62, 0x26, 0x53, 0x2a, 0x80, 0x48, 0x2b, 0x42, 0xc5, 0x91, 0x99, 0x78, 0x00, \n\t0x61, 0x26, 0x14, 0x20, 0x1d, 0x10, 0x01, 0x4a, 0x48, 0xa0, 0x08, 0x2f, 0x90, 0x8a, 0x4c, 0x04, \n\t0xe0, 0xa1, 0x82, 0x31, 0x45, 0x22, 0x30, 0x04, 0x20, 0x10, 0x08, 0x81, 0xe3, 0x50, 0xb1, 0x22, \n\t0xa0, 0x4c, 0x8c, 0x49, 0x60, 0x66, 0xa1, 0x0e, 0x09, 0x11, 0xa4, 0x00, 0x80, 0xa0, 0x9c, 0x21, \n\t0x43, 0x61, 0x18, 0x03, 0x58, 0x80, 0xc1, 0xc5, 0x22, 0x08, 0x31, 0x12, 0x80, 0x00, 0x18, 0x08, \n\t0x1a, 0x85, 0xc3, 0x34, 0x90, 0x48, 0x20, 0x06, 0x13, 0x49, 0x28, 0xa1, 0x01, 0x0d, 0x02, 0x65, \n\t0x50, 0x15, 0x95, 0x10, 0x0c, 0x02, 0x04, 0x80, 0x09, 0x18, 0x8c, 0x49, 0x04, 0x25, 0x91, 0x18, \n\t0x38, 0x1b, 0x01, 0x72, 0x02, 0x90, 0x20, 0x80, 0x03, 0xa4, 0x06, 0xc1, 0x78, 0x08, 0x98, 0x10, \n\t0x00, 0x10, 0x85, 0x01, 0x8f, 0x81, 0x48, 0x82, 0x08, 0xc2, 0x08, 0xa5, 0x14, 0x5f, 0x83, 0x20, \n\t0x55, 0x70, 0x0d, 0x41, 0x00, 0x04, 0x5e, 0x20, 0xb1, 0x03, 0xb1, 0x88, 0xc0, 0x48, 0x40, 0xcb, \n\t0x20, 0xe5, 0x41, 0xc6, 0x40, 0x12, 0x91, 0xb3, 0x78, 0x40, 0x23, 0x24, 0x03, 0x20, 0x87, 0x04, \n\t0x0d, 0x88, 0x30, 0x90, 0x20, 0x10, 0x80, 0x03, 0x68, 0x68, 0xc6, 0x10, 0x15, 0x01, 0xcc, 0x20, \n\t0x08, 0x06, 0x78, 0x0c, 0x20, 0x94, 0x85, 0x02, 0x91, 0x10, 0x06, 0xc8, 0x12, 0x86, 0x48, 0x02, \n\t0xb0, 0x04, 0x04, 0x1a, 0xe8, 0x00, 0x96, 0x82, 0x20, 0x35, 0x98, 0x82, 0x48, 0x80, 0x10, 0x29, \n\t0x84, 0xcb, 0x22, 0x6c, 0x50, 0x00, 0xb0, 0x9d, 0x02, 0x02, 0x4c, 0x24, 0x48, 0x8e, 0x01, 0x50, \n\t0xcf, 0x40, 0x42, 0x10, 0x1b, 0x29, 0x09, 0x29, 0x24, 0x00, 0x10, 0x82, 0x00, 0x42, 0x05, 0x22, \n\t0x01, 0xc8, 0x15, 0x98, 0x18, 0x05, 0x04, 0x34, 0x0a, 0x85, 0x80, 0x1e, 0xa6, 0x34, 0x80, 0xe9, \n\t0x00, 0x75, 0x05, 0xcb, 0x12, 0x03, 0x51, 0x25, 0x6c, 0x10, 0x8a, 0x44, 0x87, 0xa0, 0x11, 0x08, \n\t0x01, 0xa2, 0x42, 0xc5, 0x38, 0x22, 0x24, 0x81, 0xc6, 0x70, 0x82, 0xe1, 0x10, 0x04, 0x1a, 0x88, \n\t0x14, 0x20, 0x12, 0x26, 0x04, 0x5c, 0x49, 0x12, 0x60, 0x12, 0x38, 0xd0, 0x05, 0x81, 0x20, 0x67, \n\t0x92, 0x12, 0x49, 0x01, 0xa1, 0x0c, 0x43, 0x60, 0x18, 0xc4, 0xc3, 0x08, 0x60, 0x52, 0x82, 0x16, \n\t0xbc, 0x88, 0x64, 0x24, 0x61, 0xd0, 0x00, 0x70, 0x19, 0x20, 0x74, 0x24, 0x00, 0x19, 0xc0, 0xc4, \n\t0x02, 0x04, 0xb1, 0x42, 0x85, 0x10, 0x94, 0x6a, 0x28, 0x10, 0x21, 0xa9, 0xcc, 0x08, 0xc8, 0x02, \n\t0x42, 0x92, 0xb5, 0x08, 0x12, 0x81, 0x0a, 0x82, 0xe0, 0x05, 0x49, 0x5b, 0x0c, 0x0c, 0x24, 0xc9, \n\t0x20, 0x1c, 0x8a, 0x83, 0x0e, 0x60, 0x99, 0x06, 0x91, 0x00, 0x4d, 0x56, 0x10, 0x5b, 0x98, 0x25, \n\t0xc9, 0x89, 0x00, 0xb0, 0x48, 0xa1, 0x10, 0x0d, 0x06, 0x42, 0xc6, 0x80, 0x20, 0x10, 0xc3, 0x28, \n\t0x74, 0x62, 0xa1, 0x09, 0x01, 0x44, 0xe6, 0x22, 0x26, 0x88, 0x11, 0xa8, 0xd2, 0x00, 0x58, 0x02, \n\t0x19, 0x00, 0xa1, 0x04, 0x01, 0x18, 0xa5, 0x91, 0x16, 0xd0, 0xd0, 0x60, 0x00, 0x05, 0x08, 0x02, \n\t0x0d, 0x1d, 0xe4, 0x02, 0xd6, 0x08, 0x3a, 0x48, 0x19, 0x0c, 0x3c, 0x00, 0x20, 0xa3, 0xa0, 0x54, \n\t0x21, 0x14, 0x41, 0x88, 0x28, 0x49, 0x00, 0x86, 0x24, 0x33, 0x82, 0x30, 0x58, 0x01, 0x4f, 0x28, \n\t0x93, 0x69, 0x29, 0x54, 0x45, 0x82, 0x50, 0xc3, 0x8a, 0x38, 0x30, 0x46, 0x45, 0x2a, 0x14, 0x08, \n\t0x8e, 0x99, 0x06, 0x60, 0x02, 0x10, 0xe8, 0x00, 0x19, 0x82, 0x21, 0x5c, 0x20, 0x00, 0xa7, 0x24, \n\t0x86, 0x00, 0x28, 0x36, 0x02, 0x1c, 0xc4, 0x0b, 0x0c, 0x0e, 0xb4, 0x08, 0x0d, 0x64, 0xd4, 0xc4, \n\t0x00, 0x81, 0x09, 0xb1, 0x01, 0x41, 0x2e, 0x14, 0x20, 0x08, 0x82, 0x0d, 0x51, 0xca, 0x0a, 0x07, \n\t0x23, 0xb0, 0x28, 0x05, 0x09, 0x20, 0x60, 0x90, 0x99, 0x90, 0x82, 0x0e, 0x0e, 0xc1, 0x70, 0x24, \n\t0x60, 0xcb, 0xc3, 0x00, 0xa0, 0xea, 0x17, 0x24, 0x14, 0x04, 0x70, 0x22, 0x00, 0x01, 0x48, 0xc1, \n\t0xa4, 0x20, 0x24, 0x70, 0x28, 0x8d, 0xc4, 0x44, 0x00, 0xa1, 0x51, 0x20, 0x7d, 0x88, 0x01, 0x1c, \n\t0xa3, 0xa0, 0x85, 0x8c, 0x50, 0xa8, 0x44, 0x60, 0x02, 0x3c, 0x44, 0x55, 0xa3, 0x30, 0x06, 0xb3, \n\t0x0c, 0x44, 0x12, 0xac, 0x0a, 0x14, 0x21, 0x03, 0x15, 0x59, 0x20, 0x58, 0xa0, 0x9a, 0x94, 0x11, \n\t0x08, 0x63, 0x62, 0xe0, 0x42, 0x23, 0xb5, 0xce, 0x00, 0x00, 0x15, 0x10, 0x82, 0xa0, 0x1a, 0x4e, \n\t0x00, 0x23, 0x63, 0x18, 0x10, 0x94, 0x04, 0x52, 0x82, 0xbb, 0x08, 0x70, 0xc6, 0x41, 0x68, 0x02, \n\t0x90, 0x14, 0x08, 0x93, 0x88, 0x10, 0x51, 0x78, 0x05, 0x44, 0x18, 0x8e, 0x50, 0xd6, 0x43, 0x84, \n\t0x08, 0x8a, 0x80, 0x00, 0xc0, 0x22, 0x14, 0x40, 0x04, 0xc0, 0x48, 0x05, 0xa0, 0x01, 0x08, 0x40, \n\t0x80, 0x40, 0x40, 0xcb, 0x94, 0x0d, 0xd2, 0x8a, 0x46, 0x86, 0x80, 0x80, 0xb9, 0x48, 0x40, 0x74, \n\t0x95, 0x10, 0xa8, 0x34, 0x8f, 0x0d, 0x0e, 0x16, 0x08, 0x2a, 0x50, 0x90, 0x0b, 0x5a, 0xc5, 0x6a, \n\t0x14, 0x80, 0x8d, 0x48, 0x02, 0x03, 0x02, 0x81, 0x21, 0x4c, 0x86, 0x5a, 0x82, 0x83, 0x09, 0x99, \n\t0x02, 0x20, 0x04, 0x60, 0x6b, 0x89, 0x48, 0x08, 0x6a, 0x68, 0x84, 0x40, 0xa5, 0xc4, 0x0a, 0x81, \n\t0x40, 0x21, 0x28, 0x16, 0x04, 0x02, 0x61, 0x16, 0x94, 0x00, 0x3a, 0x80, 0xd6, 0x2c, 0x22, 0x64, \n\t0x48, 0x80, 0x08, 0xc1, 0x40, 0x38, 0x00, 0x80, 0x18, 0x08, 0x10, 0xc1, 0x34, 0x03, 0xda, 0x82, \n\t0x44, 0x03, 0x4b, 0x0a, 0x74, 0x38, 0x85, 0x41, 0x42, 0xc5, 0x32, 0x65, 0x40, 0x26, 0xb4, 0x90, \n\t0x21, 0x6a, 0x94, 0x0b, 0x09, 0x20, 0x14, 0x21, 0x72, 0x80, 0x82, 0x25, 0x20, 0x80, 0x2a, 0x0a, \n\t0x12, 0x81, 0x81, 0x10, 0x02, 0x08, 0x18, 0x62, 0x80, 0x88, 0x55, 0x58, 0x09, 0x0e, 0xe2, 0x22, \n\t0x31, 0x61, 0x53, 0x62, 0x68, 0x54, 0x12, 0x9b, 0xc0, 0x9d, 0x82, 0x2e, 0x00, 0x88, 0x20, 0x45, \n\t0xc0, 0x40, 0x72, 0x62, 0x0b, 0x04, 0x31, 0x18, 0xe6, 0x22, 0x60, 0x48, 0x1a, 0x40, 0x80, 0xa7, \n\t0x12, 0x72, 0x10, 0x9d, 0x80, 0x8d, 0x82, 0x08, 0x66, 0xc2, 0xb4, 0x24, 0x00, 0x20, 0x54, 0x90, \n\t0x28, 0x0c, 0x08, 0x81, 0xe9, 0x10, 0x04, 0xb3, 0x28, 0x60, 0x05, 0x22, 0x0c, 0x10, 0x81, 0x09, \n\t0x01, 0x98, 0x0c, 0x24, 0x12, 0x41, 0x02, 0x88, 0xc2, 0x42, 0x04, 0x95, 0x80, 0xa1, 0x48, 0x1b, \n\t0x85, 0x0c, 0x85, 0x03, 0x9a, 0x88, 0x8e, 0x20, 0x04, 0x04, 0x91, 0x10, 0x31, 0x1e, 0x01, 0x40, \n\t0x03, 0x10, 0xbe, 0x48, 0x04, 0x0a, 0x74, 0x60, 0x01, 0x03, 0xf4, 0x46, 0x46, 0x10, 0x41, 0x09, \n\t0x8a, 0xb0, 0x43, 0x88, 0x58, 0xd1, 0x20, 0x26, 0x94, 0xc4, 0x04, 0x5e, 0x83, 0x18, 0x1b, 0x59, \n\t0x88, 0xc2, 0x10, 0x02, 0x11, 0x30, 0xa0, 0x56, 0xa5, 0x08, 0x00, 0x20, 0x0c, 0xf4, 0x0a, 0xad, \n\t0x00, 0x14, 0x20, 0x21, 0x80, 0x13, 0x25, 0x2c, 0x80, 0x12, 0x13, 0x50, 0x88, 0x67, 0x12, 0x15, \n\t0x4a, 0x04, 0x0d, 0xc9, 0x06, 0x02, 0x10, 0xd8, 0x10, 0xcc, 0x0b, 0x02, 0x24, 0x04, 0x02, 0xa4, \n\t0x75, 0x04, 0x28, 0x00, 0xa2, 0x40, 0x90, 0x3c, 0x44, 0xc3, 0x00, 0xe2, 0x61, 0x83, 0x20, 0x06, \n\t0x03, 0x58, 0x50, 0x09, 0x31, 0x80, 0xce, 0x08, 0x04, 0xa5, 0x98, 0x1c, 0x89, 0x95, 0x04, 0x02, \n\t0x30, 0x00, 0x28, 0x05, 0x05, 0xc1, 0x52, 0xa0, 0x10, 0x2e, 0x19, 0x80, 0x28, 0x50, 0x56, 0x21, \n\t0x0f, 0x08, 0x52, 0x21, 0x46, 0x26, 0x08, 0x02, 0x14, 0x10, 0x80, 0x5c, 0x10, 0x82, 0xa1, 0xc0, \n\t0xd5, 0x0e, 0x50, 0x10, 0x43, 0x05, 0x48, 0x95, 0x21, 0x26, 0x41, 0xa0, 0x20, 0x2d, 0x4c, 0x42, \n\t0x02, 0xc3, 0x03, 0x99, 0xc8, 0x03, 0x0c, 0x22, 0x40, 0x50, 0x26, 0x90, 0x02, 0x81, 0x08, 0x42, \n\t0x2b, 0xa5, 0x00, 0x46, 0x65, 0x22, 0x72, 0x4a, 0x08, 0x80, 0x98, 0xc5, 0x0a, 0x80, 0xc9, 0x19, \n\t0x54, 0x94, 0x05, 0x16, 0x02, 0xc0, 0x82, 0x01, 0x88, 0xc3, 0x38, 0xa1, 0x51, 0x1d, 0x08, 0x8a, \n\t0xc1, 0x44, 0x45, 0x3a, 0xb0, 0x00, 0x05, 0xc0, 0x28, 0x41, 0xe9, 0x04, 0x09, 0x50, 0x08, 0x02, \n\t0x30, 0x28, 0x86, 0x21, 0x8b, 0x00, 0x02, 0xe4, 0xaa, 0x0e, 0xb1, 0x00, 0xe5, 0x20, 0xa1, 0x11, \n\t0x1b, 0x11, 0x80, 0x0c, 0x2a, 0xd5, 0x40, 0x02, 0x35, 0x1d, 0x40, 0x38, 0x00, 0x61, 0x1a, 0x24, \n\t0x49, 0x0c, 0x1c, 0x27, 0xd0, 0x01, 0x00, 0xc0, 0xa3, 0x12, 0x14, 0x2a, 0x15, 0x4d, 0x01, 0x01, \n\t0x06, 0xc2, 0x38, 0x2e, 0xec, 0x94, 0xc2, 0x50, 0x00, 0x21, 0x24, 0x1d, 0x40, 0xac, 0x04, 0x15, \n\t0x30, 0xb0, 0x01, 0x81, 0x00, 0x62, 0x40, 0x43, 0x3f, 0x25, 0x80, 0x02, 0x06, 0x31, 0x18, 0xb4, \n\t0x54, 0x1a, 0xcb, 0x10, 0x22, 0x00, 0x02, 0x6c, 0x10, 0x6a, 0x72, 0x20, 0x83, 0x13, 0x44, 0x88, \n\t0xcd, 0x2c, 0xa1, 0x19, 0x0f, 0x95, 0x54, 0x8d, 0x3a, 0x37, 0xc0, 0xb3, 0x08, 0x55, 0x61, 0x50, \n\t0xd2, 0x8b, 0x84, 0x01, 0x48, 0xc0, 0x28, 0x04, 0x48, 0x08, 0xa1, 0x06, 0x42, 0x46, 0x03, 0x40, \n\t0x00, 0x40, 0x80, 0x20, 0x50, 0xb3, 0x13, 0x08, 0x50, 0x50, 0x04, 0x08, 0x64, 0x32, 0x2f, 0x7c, \n\t0x0c, 0x41, 0x62, 0x13, 0xe0, 0x38, 0xa8, 0xd1, 0x20, 0x10, 0x05, 0xf2, 0xa4, 0x15, 0x03, 0x01, \n\t0x52, 0x05, 0x7a, 0xa8, 0x05, 0x09, 0xc0, 0x62, 0xc4, 0x10, 0x0a, 0x45, 0x08, 0x69, 0x24, 0x61, \n\t0x01, 0x00, 0x81, 0x16, 0x88, 0x0a, 0x14, 0x81, 0x83, 0x0c, 0x02, 0x4d, 0x1a, 0x84, 0xaa, 0x81, \n\t0x91, 0xc6, 0x0a, 0x24, 0x10, 0x51, 0x0d, 0x88, 0x90, 0x4e, 0x5a, 0x21, 0xc1, 0xa2, 0xa4, 0x90, \n\t0x0c, 0x34, 0x44, 0x21, 0x80, 0x48, 0x43, 0x0b, 0x48, 0x43, 0x92, 0x90, 0x30, 0xc0, 0x06, 0x14, \n\t0x45, 0xb9, 0x00, 0x08, 0x1b, 0x88, 0x20, 0x44, 0xa9, 0x11, 0x60, 0x0c, 0x8a, 0x30, 0x03, 0x48, \n\t0x28, 0x88, 0x11, 0x86, 0x64, 0x23, 0x8a, 0x22, 0x30, 0xc1, 0xa1, 0x28, 0x40, 0x00, 0x05, 0xe4, \n\t0x0d, 0x86, 0x3a, 0x22, 0x62, 0xaf, 0x8c, 0x56, 0x60, 0x10, 0x10, 0xb8, 0x18, 0x41, 0x04, 0x24, \n\t0x48, 0x30, 0x82, 0x15, 0x70, 0x00, 0x88, 0x42, 0x53, 0x20, 0xad, 0x81, 0x98, 0x4b, 0x50, 0x86, \n\t0x02, 0x0b, 0x40, 0x88, 0x2d, 0x4c, 0xa0, 0x02, 0x00, 0x08, 0x42, 0x40, 0x16, 0x84, 0x00, 0x99, \n\t0x4c, 0x00, 0xa2, 0x22, 0x40, 0x52, 0x14, 0x10, 0x84, 0xa9, 0x0c, 0x26, 0x92, 0x08, 0x24, 0x49, \n\t0x8e, 0x42, 0x93, 0x49, 0x8a, 0x54, 0x04, 0x88, 0x06, 0x40, 0x08, 0x1d, 0x21, 0x90, 0x00, 0x60, \n\t0x21, 0x02, 0x94, 0x98, 0x89, 0x04, 0x1a, 0x94, 0x5b, 0x87, 0x20, 0x44, 0x47, 0x48, 0x90, 0x2a, \n\t0x18, 0x80, 0xd1, 0x43, 0x14, 0x02, 0x29, 0xa0, 0x8c, 0x10, 0xe1, 0x60, 0xf0, 0x81, 0x09, 0xc5, \n\t0xc0, 0x2d, 0x08, 0x95, 0x82, 0xa4, 0x04, 0x4a, 0x40, 0x12, 0x00, 0x11, 0xaf, 0xc1, 0x94, 0x26, \n\t0x3e, 0x60, 0x41, 0x10, 0x41, 0x87, 0xa0, 0x16, 0x42, 0x60, 0x9a, 0x8c, 0x04, 0xe0, 0x14, 0x62, \n\t0x12, 0x18, 0xf4, 0xc0, 0x02, 0x0c, 0x10, 0x21, 0x98, 0x01, 0xde, 0x82, 0x08, 0xb3, 0x60, 0x11, \n\t0x18, 0x01, 0x49, 0x32, 0x00, 0xd0, 0x0a, 0x58, 0x91, 0x29, 0x26, 0x04, 0x48, 0x00, 0x35, 0x00, \n\t0xc8, 0x08, 0x31, 0x32, 0x0e, 0x70, 0x0a, 0x46, 0x00, 0x17, 0x70, 0x88, 0x90, 0xc0, 0x8b, 0x00, \n\t0x04, 0x28, 0x22, 0x45, 0x11, 0x64, 0x38, 0x10, 0xb1, 0x1a, 0xa4, 0x00, 0x24, 0x4a, 0x50, 0x08, \n\t0x82, 0xa0, 0x0f, 0xc0, 0x0e, 0x85, 0x9b, 0x04, 0x31, 0x11, 0x4c, 0x02, 0xf4, 0xc2, 0x90, 0xc5, \n\t0x03, 0x02, 0x04, 0xc3, 0x10, 0x08, 0xa0, 0x57, 0xc0, 0x42, 0x05, 0x80, 0x00, 0x94, 0x42, 0x00, \n\t0x52, 0x45, 0x81, 0x01, 0x09, 0x1d, 0x4b, 0x2a, 0xa6, 0xa0, 0x30, 0x04, 0x95, 0x00, 0x0a, 0x52, \n\t0x08, 0x28, 0x24, 0x12, 0x65, 0x14, 0x24, 0x70, 0xa4, 0x00, 0x98, 0xe2, 0x68, 0x10, 0x0a, 0x33, \n\t0x41, 0x80, 0x01, 0x44, 0x90, 0x0a, 0x36, 0xc1, 0x5b, 0x22, 0x40, 0x71, 0x23, 0xa4, 0x01, 0x14, \n\t0x8a, 0x64, 0x62, 0xab, 0x9a, 0x10, 0x48, 0xc8, 0x04, 0x10, 0xc1, 0x82, 0x11, 0xca, 0xc1, 0x14, \n\t0x96, 0x58, 0x04, 0xe0, 0x01, 0x00, 0x20, 0xa6, 0x8b, 0x81, 0x1c, 0xcf, 0x08, 0x30, 0x12, 0x53, \n\t0x1b, 0xb8, 0x12, 0x0a, 0x5c, 0x22, 0x61, 0x25, 0xc0, 0x84, 0x0f, 0x42, 0x12, 0x00, 0xa4, 0x09, \n\t0x94, 0x0e, 0x20, 0xd0, 0x71, 0x22, 0x04, 0x0b, 0x00, 0x60, 0xa3, 0x10, 0x00, 0x75, 0x5b, 0x00, \n\t0x70, 0x90, 0x50, 0x86, 0x24, 0x1e, 0x80, 0x18, 0x35, 0x02, 0x81, 0x38, 0xc7, 0x60, 0x4c, 0x06, \n\t0x00, 0x92, 0x08, 0x00, 0x20, 0x50, 0x01, 0x42, 0x30, 0x25, 0x44, 0x6c, 0x34, 0x34, 0x20, 0x12, \n\t0x04, 0xc1, 0xc1, 0x1a, 0x83, 0x09, 0x20, 0x90, 0x86, 0x40, 0x08, 0x35, 0x48, 0x94, 0xe1, 0x09, \n\t0x05, 0x5e, 0x34, 0x08, 0x01, 0x91, 0x12, 0xca, 0x10, 0xd2, 0x30, 0x23, 0x45, 0x0e, 0x48, 0x34, \n\t0x24, 0xc3, 0xbf, 0x50, 0xd8, 0x2c, 0x02, 0x31, 0x12, 0x90, 0x20, 0x42, 0x21, 0x24, 0xc5, 0x21, \n\t0x85, 0x24, 0x14, 0x04, 0x3c, 0x11, 0x08, 0x10, 0x00, 0x09, 0x6b, 0x10, 0xc6, 0xb8, 0x80, 0x8c, \n\t0x0d, 0x0b, 0x32, 0x85, 0x5a, 0x01, 0x98, 0x01, 0x01, 0x00, 0x62, 0x70, 0xa6, 0xc0, 0x4c, 0x40, \n\t0x20, 0x40, 0x81, 0x00, 0x28, 0x80, 0x04, 0x08, 0x30, 0x19, 0x15, 0xb8, 0xda, 0x28, 0x5c, 0x80, \n\t0xe1, 0x08, 0x41, 0x52, 0x45, 0x4c, 0x23, 0x09, 0x81, 0x08, 0x00, 0x02, 0x40, 0x63, 0x00, 0x32, \n\t0xd0, 0x12, 0xa6, 0x2a, 0x81, 0x38, 0xa3, 0x15, 0x54, 0x03, 0x58, 0x00, 0x22, 0x00, 0x0d, 0x90, \n\t0x82, 0x10, 0x21, 0x80, 0x25, 0x01, 0x11, 0xc0, 0x44, 0x81, 0x5b, 0x02, 0xc4, 0x00, 0x02, 0x42, \n\t0x60, 0x91, 0x20, 0x10, 0x80, 0xe5, 0x10, 0x13, 0x48, 0x1a, 0xa0, 0xc1, 0x48, 0x0a, 0x14, 0x29, \n\t0xb0, 0x24, 0x0b, 0x00, 0x70, 0xe1, 0x02, 0x0c, 0x51, 0x40, 0xca, 0x0c, 0x02, 0x8a, 0x11, 0xa8, \n\t0x87, 0xad, 0x18, 0xe0, 0xb1, 0x85, 0x65, 0x08, 0x6c, 0x48, 0xa3, 0xc0, 0x24, 0x11, 0x8a, 0xc8, \n\t0x22, 0x04, 0x88, 0x98, 0x18, 0x50, 0x22, 0x00, 0x56, 0x61, 0x21, 0x00, 0xde, 0x84, 0x02, 0x10, \n\t0x53, 0x22, 0xdd, 0x13, 0x08, 0x2a, 0x06, 0xc1, 0xa4, 0xc8, 0x00, 0x00, 0x12, 0xa6, 0xc8, 0xa0, \n\t0x1c, 0x8c, 0x22, 0x2e, 0x02, 0x18, 0x1f, 0xf0, 0x03, 0x07, 0x02, 0x03, 0x09, 0x33, 0xa4, 0x10, \n\t0x08, 0x60, 0xd1, 0x0a, 0x0e, 0x90, 0x5c, 0x40, 0x70, 0xa4, 0x02, 0x18, 0xd1, 0x00, 0xa3, 0x1e, \n\t0x80, 0x70, 0x02, 0xc5, 0x84, 0xe2, 0x00, 0x20, 0x30, 0x91, 0x05, 0x43, 0x81, 0x04, 0x62, 0x98, \n\t0x92, 0x41, 0x00, 0x64, 0x02, 0x13, 0xa2, 0x0d, 0x40, 0x13, 0x0c, 0x40, 0x25, 0x42, 0xa4, 0x40, \n\t0x19, 0x09, 0x10, 0xa1, 0x6b, 0x10, 0x25, 0x19, 0x04, 0x06, 0xd4, 0xc8, 0x13, 0x28, 0x42, 0x23, \n\t0x26, 0x22, 0x20, 0x09, 0xe0, 0x08, 0x04, 0x00, 0xd5, 0xc2, 0x30, 0x38, 0x54, 0x01, 0x2e, 0x00, \n\t0xa1, 0x14, 0x80, 0x08, 0xc5, 0x4a, 0x10, 0x40, 0x00, 0x60, 0xc6, 0x24, 0x06, 0xd1, 0x20, 0x0a, \n\t0x09, 0x06, 0x0c, 0x28, 0x00, 0x11, 0xa8, 0xc9, 0xc8, 0x02, 0x08, 0x86, 0xb2, 0x21, 0x19, 0x87, \n\t0x62, 0x3c, 0x56, 0x40, 0x0b, 0x24, 0x94, 0xa0, 0x28, 0x44, 0x00, 0x80, 0xb4, 0x08, 0x08, 0x04, \n\t0x47, 0xeb, 0x24, 0xa0, 0x50, 0x64, 0x70, 0xa0, 0x13, 0xb8, 0xc0, 0x01, 0x29, 0x08, 0x90, 0x21, \n\t0x92, 0x54, 0xc1, 0x08, 0x0a, 0x02, 0xe3, 0x21, 0x00, 0x18, 0x44, 0x06, 0x05, 0x00, 0x08, 0x68, \n\t0x10, 0xa4, 0x12, 0x20, 0x5b, 0x3d, 0x2c, 0xd0, 0x45, 0x08, 0x13, 0x03, 0x89, 0x90, 0x82, 0x40, \n\t0x44, 0xd1, 0xe1, 0x22, 0x00, 0xca, 0x02, 0x00, 0x06, 0xb8, 0xb8, 0x00, 0x8f, 0x07, 0x10, 0xc4, \n\t0x58, 0xa8, 0x65, 0x0e, 0x86, 0x4e, 0x00, 0x80, 0x25, 0x81, 0x1d, 0x60, 0x20, 0x63, 0x42, 0x08, \n\t0x25, 0x04, 0x40, 0x56, 0x20, 0x10, 0x80, 0x14, 0x0b, 0x21, 0x32, 0xc3, 0x48, 0x00, 0x24, 0xdb, \n\t0x84, 0x40, 0x91, 0x02, 0x82, 0x98, 0x41, 0x09, 0x64, 0x06, 0x41, 0x86, 0x41, 0xc5, 0x08, 0x2a, \n\t0x00, 0xb8, 0x11, 0x4d, 0x12, 0x41, 0x18, 0xe2, 0x60, 0xa0, 0x11, 0x04, 0x0a, 0x08, 0x80, 0xe0, \n\t0x14, 0x05, 0x91, 0x8f, 0x48, 0x30, 0x82, 0x31, 0x54, 0x01, 0x02, 0x50, 0x00, 0x28, 0x33, 0x68, \n\t0x90, 0x0a, 0x12, 0x24, 0x43, 0x20, 0x04, 0x03, 0x63, 0x70, 0x61, 0x31, 0x10, 0x3c, 0x44, 0x23, \n\t0x30, 0x40, 0x0a, 0x08, 0x8d, 0x45, 0x29, 0x14, 0x10, 0x40, 0x06, 0xc5, 0x40, 0x85, 0x4a, 0x52, \n\t0x08, 0x88, 0xa0, 0x90, 0x09, 0x0e, 0xe4, 0x02, 0x82, 0x71, 0x19, 0x02, 0x42, 0x26, 0x08, 0x3d, \n\t0x01, 0x90, 0x6c, 0x40, 0x31, 0x4b, 0x81, 0xe9, 0x86, 0xa2, 0x0c, 0x94, 0x62, 0x80, 0x41, 0x1b, \n\t0x42, 0x22, 0xc3, 0x00, 0x18, 0x29, 0x0e, 0x24, 0x1e, 0x02, 0x88, 0x8c, 0x0c, 0xc1, 0x28, 0x62, \n\t0x71, 0x01, 0x01, 0x70, 0x85, 0xc2, 0x62, 0x41, 0x01, 0x2e, 0x60, 0x08, 0x0d, 0x12, 0x56, 0xca, \n\t0x80, 0xbc, 0x00, 0x08, 0x00, 0x44, 0x08, 0x8e, 0x41, 0x03, 0xc4, 0x32, 0x22, 0x00, 0x80, 0x94, \n\t0x88, 0x40, 0x50, 0x00, 0xd9, 0x9b, 0x20, 0x42, 0x04, 0x44, 0x90, 0x22, 0x05, 0x5c, 0x43, 0xc4, \n\t0x14, 0xa1, 0xab, 0xae, 0x60, 0x88, 0x83, 0x60, 0x03, 0x02, 0x02, 0x10, 0xd9, 0x4a, 0x06, 0xb7, \n\t0x20, 0x05, 0x68, 0x1c, 0xa0, 0x0e, 0x55, 0x38, 0x38, 0xe0, 0x49, 0x86, 0x10, 0x41, 0x92, 0x20, \n\t0x21, 0x12, 0x83, 0x40, 0x62, 0xa9, 0x38, 0x25, 0x10, 0xcc, 0x40, 0x54, 0xc0, 0x20, 0x0c, 0x84, \n\t0x4a, 0x0c, 0xe3, 0x30, 0x26, 0x55, 0xc6, 0x01, 0x22, 0x44, 0x09, 0x82, 0xa8, 0x54, 0x25, 0x0a, \n\t0x31, 0x62, 0x1e, 0xd8, 0x84, 0x01, 0x6e, 0x82, 0x40, 0x2d, 0x19, 0x00, 0xa0, 0x54, 0x10, 0x11, \n\t0xa0, 0xcc, 0x02, 0x6f, 0x24, 0xf4, 0x02, 0x09, 0x09, 0x59, 0xc5, 0x40, 0x00, 0x30, 0xac, 0x45, \n\t0x08, 0xa1, 0x56, 0x00, 0x52, 0x02, 0x81, 0xc4, 0x24, 0x40, 0x01, 0xa9, 0x32, 0x8c, 0x80, 0x6a, \n\t0x00, 0x81, 0xb1, 0x92, 0x90, 0x15, 0xca, 0x44, 0x63, 0x41, 0x32, 0x00, 0x48, 0x81, 0x1c, 0xa2, \n\t0x08, 0x81, 0x34, 0x1a, 0xcb, 0x28, 0x74, 0x00, 0xa1, 0x0c, 0x90, 0x4c, 0x24, 0xc2, 0x31, 0x01, \n\t0xc8, 0xdb, 0x04, 0x30, 0x14, 0xb1, 0x08, 0x04, 0x05, 0xc4, 0x0a, 0xd0, 0x20, 0x2e, 0x21, 0x0e, \n\t0x41, 0x20, 0x00, 0x50, 0x89, 0x0c, 0x89, 0x20, 0x20, 0x40, 0x12, 0x05, 0x44, 0x93, 0x66, 0x00, \n\t0xc0, 0x80, 0x08, 0xcc, 0x5b, 0x20, 0x08, 0x44, 0x12, 0x82, 0xb5, 0x13, 0x61, 0x12, 0x84, 0x41, \n\t0x04, 0x49, 0x00, 0x09, 0x64, 0x82, 0x03, 0x22, 0xf8, 0x04, 0xa0, 0x2e, 0x83, 0x60, 0x31, 0x15, \n\t0x52, 0x08, 0x08, 0xa5, 0x63, 0x1c, 0x80, 0x06, 0x09, 0x18, 0xa6, 0x49, 0x8c, 0x21, 0x8b, 0xc0, \n\t0x02, 0x16, 0x50, 0x14, 0xa0, 0x11, 0x09, 0x1c, 0x82, 0x80, 0x03, 0x90, 0x80, 0xc3, 0x00, 0x07, \n\t0x33, 0x80, 0x14, 0xc0, 0x0b, 0x48, 0x41, 0x08, 0x8e, 0x10, 0xc8, 0x62, 0x24, 0x07, 0xd0, 0x16, \n\t0x01, 0x42, 0x08, 0x18, 0x75, 0x03, 0x25, 0xe1, 0x01, 0xc3, 0x04, 0x86, 0x20, 0x92, 0x54, 0x01, \n\t0x80, 0x44, 0x42, 0xd8, 0x0a, 0x10, 0x80, 0x6c, 0x28, 0x23, 0x41, 0x22, 0x50, 0x08, 0x00, 0x38, \n\t0x37, 0xc0, 0x00, 0x28, 0x1e, 0x0c, 0x3a, 0x00, 0x19, 0x03, 0x30, 0x11, 0x00, 0x54, 0x04, 0xc2, \n\t0x19, 0xcc, 0x14, 0x01, 0x04, 0xf0, 0x63, 0x8d, 0x2c, 0x0c, 0x69, 0x44, 0x56, 0x02, 0x21, 0x80, \n\t0x12, 0x4c, 0x2c, 0x71, 0x08, 0x38, 0x2c, 0x52, 0xc2, 0x20, 0x80, 0x51, 0x90, 0x80, 0x0f, 0xa6, \n\t0x28, 0x14, 0x00, 0x83, 0x70, 0x4e, 0x00, 0x26, 0x24, 0x8a, 0x16, 0x4d, 0x41, 0xa3, 0x00, 0x00, \n\t0x03, 0x12, 0x68, 0xc7, 0xca, 0x30, 0xa4, 0x20, 0x97, 0x41, 0x0a, 0x80, 0x60, 0xe0, 0x22, 0x8d, \n\t0xa4, 0x5f, 0x04, 0x60, 0x02, 0x9a, 0x82, 0x89, 0xc0, 0x6a, 0x1e, 0x20, 0xa0, 0x34, 0x80, 0x43, \n\t0x44, 0x02, 0x43, 0xc2, 0x20, 0x75, 0x18, 0x05, 0x40, 0x66, 0x10, 0x35, 0x50, 0x02, 0x81, 0x40, \n\t0x52, 0x18, 0x28, 0x0c, 0x92, 0x42, 0x2a, 0x02, 0x80, 0x29, 0x08, 0x96, 0x04, 0x08, 0x20, 0x99, \n\t0x30, 0x91, 0x15, 0x09, 0x36, 0xa6, 0xe0, 0x18, 0x09, 0x14, 0x0f, 0x60, 0x81, 0x40, 0x21, 0x14, \n\t0xcc, 0x02, 0x22, 0x13, 0x08, 0x1c, 0x51, 0x92, 0xc0, 0x08, 0x62, 0x69, 0x8c, 0x04, 0x07, 0x61, \n\t0x48, 0x44, 0xa8, 0x88, 0xc1, 0x03, 0x01, 0x56, 0x00, 0x99, 0x0c, 0x75, 0x02, 0xa8, 0x4a, 0x31, \n\t0xd0, 0x21, 0x99, 0x10, 0x07, 0x44, 0x25, 0x42, 0x33, 0x40, 0x80, 0xa4, 0x22, 0x02, 0xba, 0x00, \n\t0x5c, 0x4c, 0x81, 0x24, 0xc3, 0xc0, 0x09, 0x20, 0x0a, 0xae, 0x06, 0x44, 0x41, 0x95, 0x0d, 0xdc, \n\t0x02, 0x26, 0x02, 0x42, 0x0c, 0xf0, 0x19, 0x43, 0x00, 0x10, 0x18, 0x12, 0xc4, 0xc5, 0x61, 0x22, \n\t0xb5, 0x69, 0x32, 0x10, 0x98, 0x44, 0x52, 0x40, 0x08, 0xb0, 0x24, 0x81, 0x44, 0x74, 0x45, 0xd0, \n\t0x01, 0x89, 0x4b, 0x41, 0x2c, 0x36, 0x20, 0x20, 0x04, 0x96, 0x26, 0x18, 0x72, 0xa2, 0x08, 0x45, \n\t0x82, 0xa0, 0x40, 0x63, 0x03, 0x26, 0xd1, 0x89, 0xaa, 0x24, 0x14, 0x92, 0x15, 0x20, 0xc0, 0x27, \n\t0x70, 0x52, 0x00, 0xb4, 0x21, 0x40, 0x86, 0x16, 0x50, 0x89, 0x91, 0x59, 0x0c, 0x2b, 0x6c, 0x20, \n\t0xe0, 0x30, 0x70, 0x4c, 0xa2, 0x00, 0x32, 0x11, 0x21, 0x54, 0x40, 0x29, 0x0c, 0x84, 0x11, 0xb2, \n\t0xd0, 0x08, 0x84, 0x02, 0x01, 0x69, 0x15, 0x20, 0x99, 0x09, 0x00, 0x12, 0x53, 0x18, 0x21, 0x40, \n\t0x28, 0x6a, 0x94, 0x02, 0x20, 0xed, 0x85, 0x46, 0x4a, 0xc2, 0x30, 0x80, 0x00, 0x8a, 0x43, 0x34, \n\t0x11, 0x21, 0x30, 0x49, 0x83, 0x20, 0x6e, 0x06, 0x20, 0x05, 0x30, 0x41, 0x65, 0x30, 0xd3, 0x98, \n\t0x81, 0x80, 0x41, 0x88, 0x3a, 0x05, 0x80, 0xa2, 0x01, 0xd0, 0x62, 0x60, 0x00, 0x69, 0xa2, 0xcc, \n\t0x51, 0x8e, 0x20, 0x80, 0x10, 0x92, 0x0d, 0x02, 0xa0, 0x14, 0x85, 0x21, 0x29, 0xf0, 0x10, 0x08, \n\t0x5a, 0x41, 0x23, 0x00, 0x14, 0xc8, 0x41, 0x00, 0xc0, 0xa1, 0x0f, 0x28, 0x0c, 0x0e, 0x30, 0x90, \n\t0x90, 0x35, 0x08, 0x07, 0x80, 0x16, 0x80, 0x82, 0x8e, 0x10, 0x80, 0x60, 0x58, 0x14, 0x10, 0x04, \n\t0x41, 0x8a, 0xc6, 0x44, 0x85, 0xa0, 0x8b, 0x04, 0xc0, 0xa1, 0x04, 0x01, 0x8b, 0xb6, 0x61, 0x54, \n\t0x2a, 0x10, 0x70, 0x30, 0x16, 0x89, 0x12, 0x48, 0x4a, 0xa5, 0x81, 0x82, 0x61, 0x01, 0x65, 0x70, \n\t0xa7, 0x43, 0x89, 0x09, 0x40, 0x48, 0x34, 0xb1, 0x21, 0x04, 0xb4, 0xc8, 0x80, 0x00, 0x85, 0x6a, \n\t0x12, 0x18, 0x0e, 0x04, 0x12, 0x46, 0x50, 0x9d, 0x28, 0x8e, 0x0e, 0x0a, 0x20, 0xd1, 0x05, 0x61, \n\t0x03, 0x2a, 0x08, 0x50, 0x98, 0x29, 0xfc, 0x84, 0x88, 0x00, 0x03, 0x80, 0x08, 0x8c, 0x00, 0x00, \n\t0x26, 0x22, 0x0a, 0xb0, 0x1c, 0x99, 0x43, 0x70, 0x54, 0x03, 0x06, 0x28, 0x00, 0x04, 0x78, 0x41, \n\t0x88, 0x07, 0xc8, 0x57, 0x80, 0x24, 0x00, 0x0a, 0x88, 0xc8, 0x01, 0x46, 0x22, 0x36, 0x1b, 0x00, \n\t0xb4, 0x49, 0xe8, 0x2c, 0x23, 0x38, 0x8d, 0xa0, 0x10, 0x8b, 0x10, 0x31, 0x82, 0xb0, 0xb8, 0x8c, \n\t0x25, 0x50, 0x44, 0x62, 0x10, 0x50, 0x1d, 0xc8, 0x34, 0x00, 0x03, 0x08, 0x28, 0x54, 0x09, 0x4e, \n\t0xc2, 0x11, 0xa5, 0x00, 0x04, 0x2c, 0x08, 0xa0, 0x81, 0x39, 0x11, 0x82, 0x04, 0x08, 0x36, 0x88, \n\t0x32, 0x40, 0x87, 0x05, 0x04, 0x81, 0x10, 0x28, 0x2c, 0x45, 0x08, 0x12, 0x35, 0x48, 0x32, 0xb9, \n\t0x46, 0x02, 0x50, 0x21, 0x01, 0x8c, 0x88, 0x08, 0x03, 0x56, 0xb2, 0x50, 0x1b, 0xd4, 0x00, 0xa9, \n\t0x0c, 0x00, 0x58, 0x24, 0x00, 0x97, 0xc2, 0x30, 0x56, 0x03, 0x0a, 0xac, 0x10, 0x60, 0x72, 0x03, \n\t0x31, 0x8c, 0x91, 0xc0, 0x60, 0x2e, 0x20, 0x80, 0x00, 0xd0, 0x10, 0x46, 0x4c, 0xe1, 0x8a, 0x85, \n\t0x10, 0x0e, 0x8c, 0x38, 0x92, 0x12, 0x08, 0x40, 0x42, 0x46, 0x08, 0x21, 0x10, 0x2b, 0x09, 0x1a, \n\t0xa5, 0x50, 0x94, 0xb8, 0x30, 0x24, 0x08, 0x06, 0x20, 0x65, 0x7a, 0xb0, 0x68, 0x00, 0x09, 0x1c, \n\t0x81, 0x88, 0x06, 0x21, 0x0c, 0xc4, 0x32, 0x51, 0x52, 0xb0, 0x81, 0x88, 0x84, 0x18, 0x90, 0x61, \n\t0x9d, 0x01, 0x49, 0xc2, 0x02, 0x00, 0xc0, 0x14, 0x14, 0x9f, 0x60, 0x00, 0x74, 0x00, 0x0b, 0x01, \n\t0x90, 0x84, 0x28, 0x22, 0x09, 0x10, 0x41, 0x43, 0x44, 0x06, 0x70, 0xe0, 0x25, 0x04, 0x1e, 0x24, \n\t0x04, 0x92, 0x50, 0x88, 0x99, 0x40, 0x27, 0x42, 0x82, 0xaa, 0x83, 0x5c, 0xc2, 0x40, 0x24, 0x40, \n\t0x11, 0x2a, 0xc5, 0x11, 0xa2, 0x4e, 0x04, 0x10, 0x01, 0xc4, 0x84, 0x88, 0x02, 0xc5, 0x22, 0x28, \n\t0x50, 0x10, 0xab, 0x00, 0x11, 0x81, 0x82, 0x8c, 0x88, 0x4a, 0x3c, 0x02, 0x50, 0x0e, 0x34, 0x01, \n\t0x88, 0x50, 0x15, 0x29, 0x16, 0x2c, 0x5b, 0x00, 0x08, 0x91, 0x03, 0x04, 0x48, 0x8e, 0x64, 0x16, \n\t0x26, 0x5a, 0x21, 0x0d, 0x50, 0x81, 0x44, 0x21, 0x08, 0x03, 0x0c, 0x94, 0xe0, 0x18, 0x90, 0x22, \n\t0x92, 0x84, 0x40, 0xc9, 0x64, 0xa0, 0x18, 0x04, 0x70, 0x49, 0x82, 0x18, 0x02, 0x19, 0x80, 0x80, \n\t0x85, 0x20, 0x6c, 0x41, 0x0b, 0x21, 0x9d, 0x4e, 0x00, 0x12, 0x40, 0x09, 0x8a, 0x10, 0x08, 0x64, \n\t0x74, 0x44, 0xd3, 0x08, 0x69, 0xc6, 0x08, 0x02, 0x76, 0x68, 0x38, 0x50, 0x91, 0x85, 0x00, 0xd1, \n\t0x42, 0xa5, 0x20, 0x15, 0x04, 0x08, 0x20, 0x79, 0x00, 0x71, 0x45, 0xe2, 0x34, 0x10, 0x11, 0x18, \n\t0x30, 0x94, 0x0e, 0x40, 0x30, 0x2a, 0x25, 0x15, 0x04, 0x25, 0x44, 0x10, 0xc2, 0x0f, 0x9d, 0x80, \n\t0x62, 0x20, 0x52, 0x00, 0x00, 0x20, 0xc6, 0x47, 0x5a, 0x14, 0xb9, 0x9a, 0x8c, 0x83, 0x28, 0x4e, \n\t0x21, 0x19, 0x02, 0x44, 0xd8, 0x81, 0x00, 0xa0, 0x18, 0x12, 0x51, 0x19, 0x09, 0x20, 0x13, 0x88, \n\t0x10, 0x20, 0xc0, 0x40, 0x20, 0x06, 0x19, 0x33, 0x45, 0x02, 0x89, 0x52, 0x20, 0x42, 0x05, 0x88, \n\t0x40, 0x08, 0x10, 0x04, 0x92, 0x10, 0x28, 0x19, 0xe3, 0x2c, 0x10, 0x82, 0x25, 0x20, 0x97, 0x41, \n\t0x10, 0x02, 0x88, 0x00, 0x11, 0x96, 0xce, 0x40, 0x37, 0x80, 0x08, 0x05, 0x02, 0x43, 0x02, 0x31, \n\t0x20, 0x9b, 0x20, 0x0e, 0x06, 0x20, 0x84, 0x78, 0x85, 0xc8, 0x06, 0x8a, 0x08, 0x10, 0x72, 0x25, \n\t0xa0, 0x90, 0xea, 0x3e, 0x82, 0x20, 0x12, 0x71, 0x18, 0x40, 0x04, 0x24, 0x89, 0x0a, 0x60, 0x4b, \n\t0xcd, 0x12, 0x00, 0x40, 0x98, 0x11, 0x15, 0x41, 0x22, 0x52, 0x2a, 0x23, 0x14, 0x81, 0x28, 0x1c, \n\t0x40, 0x23, 0x89, 0x00, 0x11, 0x6e, 0x48, 0x00, 0xb2, 0x1d, 0x14, 0x44, 0x80, 0x56, 0xc1, 0x11, \n\t0x8c, 0x20, 0x9e, 0xac, 0x40, 0x81, 0x31, 0x11, 0x14, 0x8a, 0xc0, 0x02, 0xd0, 0x28, 0x03, 0x08, \n\t0x06, 0x64, 0x44, 0xc3, 0xa1, 0x80, 0x20, 0x84, 0x80, 0x10, 0x45, 0x03, 0x10, 0xc9, 0xc2, 0x20, \n\t0x4a, 0x83, 0x78, 0x1a, 0xc0, 0x0d, 0x49, 0x00, 0x24, 0x90, 0x99, 0xe1, 0x05, 0xa6, 0x14, 0x82, \n\t0x10, 0x80, 0x91, 0xd9, 0x01, 0x00, 0x47, 0x68, 0x09, 0x10, 0x86, 0x08, 0x08, 0x14, 0x40, 0x9f, \n\t0x70, 0xd5, 0x6b, 0x0c, 0x14, 0x4a, 0x01, 0xd0, 0x40, 0x60, 0x02, 0x40, 0x10, 0x22, 0xa5, 0x08, \n\t0x4d, 0x20, 0xe0, 0x00, 0x97, 0x41, 0x4a, 0x8a, 0x06, 0xf1, 0x10, 0x35, 0x14, 0x82, 0x20, 0x68, \n\t0x00, 0x09, 0x34, 0x60, 0x01, 0x86, 0x00, 0x20, 0x40, 0x04, 0xcd, 0x02, 0x43, 0x06, 0x87, 0x03, \n\t0x9a, 0xa8, 0x14, 0xae, 0x62, 0x44, 0x0b, 0x88, 0x34, 0x42, 0x42, 0x20, 0x42, 0x60, 0x81, 0x14, \n\t0xc3, 0x83, 0x10, 0x53, 0x80, 0x11, 0x28, 0x95, 0x64, 0x3c, 0xe6, 0x8b, 0x00, 0x81, 0xd8, 0x81, \n\t0x14, 0xa2, 0x33, 0x20, 0x85, 0x44, 0x40, 0x00, 0x21, 0x1a, 0x09, 0x68, 0x0c, 0x40, 0x40, 0xf5, \n\t0x81, 0x80, 0x0d, 0x5b, 0x26, 0x2a, 0x03, 0x32, 0x22, 0x21, 0x00, 0x05, 0x0a, 0x80, 0xe0, 0x28, \n\t0x8c, 0x86, 0x24, 0x04, 0x01, 0x92, 0x91, 0x2c, 0x44, 0x81, 0x40, 0x26, 0x60, 0xb4, 0x7c, 0x15, \n\t0x49, 0x50, 0x02, 0x80, 0x08, 0x85, 0x86, 0xab, 0x10, 0x42, 0x40, 0x82, 0x94, 0x5d, 0x0f, 0x02, \n\t0x10, 0x6a, 0x19, 0x90, 0x0a, 0x05, 0x20, 0x24, 0xaa, 0x00, 0xd1, 0x04, 0x28, 0x74, 0x22, 0x80, \n\t0x11, 0x60, 0x81, 0xa9, 0x44, 0x00, 0x9b, 0x06, 0x04, 0x00, 0x49, 0x54, 0xe2, 0xf3, 0x09, 0x00, \n\t0xcb, 0xa2, 0x40, 0xa2, 0x08, 0x10, 0x18, 0x90, 0x22, 0x28, 0x50, 0xa9, 0x27, 0x04, 0xd8, 0xae, \n\t0x18, 0x41, 0xe0, 0x00, 0x70, 0x06, 0x82, 0x20, 0xc1, 0x90, 0x02, 0x09, 0x00, 0x06, 0x06, 0xc4, \n\t0xdb, 0x00, 0x08, 0x81, 0x0c, 0x0a, 0x26, 0x50, 0x82, 0xa4, 0x17, 0xc6, 0x28, 0x40, 0x21, 0x27, \n\t0x00, 0x43, 0x2d, 0x44, 0xd7, 0x31, 0x02, 0x09, 0x83, 0x00, 0x2a, 0xb0, 0x70, 0x05, 0x9c, 0x41, \n\t0x47, 0x12, 0xa2, 0x50, 0x22, 0x44, 0x90, 0x00, 0x48, 0x03, 0x11, 0x8e, 0xc9, 0x50, 0x21, 0x66, \n\t0x10, 0xa8, 0x81, 0x04, 0x11, 0xc1, 0x62, 0x91, 0x49, 0x00, 0x44, 0x91, 0x22, 0x0e, 0x24, 0x8a, \n\t0x36, 0xe1, 0x0d, 0x61, 0x6c, 0x44, 0x28, 0xa0, 0x94, 0x18, 0x04, 0x04, 0x81, 0x19, 0x01, 0x38, \n\t0x47, 0x42, 0x30, 0xa4, 0x41, 0x04, 0x05, 0x9a, 0x84, 0x50, 0x32, 0x29, 0x0c, 0x10, 0x08, 0x08, \n\t0x66, 0x21, 0x20, 0x85, 0xc8, 0x8c, 0x04, 0x06, 0x12, 0x40, 0x35, 0x19, 0x96, 0x04, 0x12, 0x52, \n\t0xd2, 0x08, 0xb0, 0x14, 0xa7, 0x40, 0x00, 0x53, 0x1f, 0x08, 0x03, 0xe1, 0x28, 0x81, 0x00, 0x3e, \n\t0x01, 0xdb, 0x42, 0x5c, 0x05, 0x61, 0xad, 0x00, 0xc0, 0x0c, 0x14, 0x20, 0x18, 0x93, 0x0c, 0x52, \n\t0x89, 0x24, 0xe0, 0x82, 0x0e, 0x04, 0x40, 0x6d, 0x32, 0xb6, 0x4a, 0xaa, 0x91, 0x00, 0x41, 0x04, \n\t0x00, 0x01, 0x12, 0x65, 0x8c, 0x00, 0x12, 0x51, 0x88, 0xbb, 0xa4, 0x0c, 0x21, 0x48, 0xa1, 0x10, \n\t0x0e, 0x48, 0x8a, 0x24, 0x54, 0x02, 0x61, 0x38, 0x31, 0x00, 0x88, 0x00, 0x42, 0xc9, 0x0e, 0x0c, \n\t0x82, 0x40, 0x0c, 0x22, 0x51, 0x04, 0x90, 0x00, 0x6c, 0x22, 0x24, 0x88, 0x9c, 0x04, 0x04, 0x42, \n\t0x40, 0x01, 0x23, 0x01, 0x88, 0x05, 0x20, 0x0a, 0x70, 0xa2, 0xa6, 0x00, 0x11, 0x68, 0x38, 0x24, \n\t0xa0, 0x30, 0xa1, 0x41, 0x4d, 0x20, 0xf0, 0x90, 0x00, 0x15, 0x40, 0xc0, 0x02, 0xe4, 0x59, 0x2c, \n\t0xe0, 0xd7, 0x08, 0x3a, 0x90, 0x8b, 0xaa, 0x20, 0x08, 0x08, 0x00, 0xd2, 0x02, 0x04, 0xe1, 0xc0, \n\t0x00, 0x38, 0x04, 0xe9, 0x08, 0xb8, 0x47, 0x86, 0x40, 0x00, 0x32, 0x23, 0x99, 0x00, 0x05, 0x0c, \n\t0x57, 0x10, 0x30, 0x55, 0x59, 0x8a, 0x48, 0x84, 0x90, 0x33, 0x3c, 0x04, 0xc1, 0x6a, 0x12, 0xc1, \n\t0x00, 0x85, 0x5a, 0x06, 0x30, 0x44, 0x98, 0x34, 0x19, 0x18, 0x22, 0x32, 0x24, 0x70, 0x24, 0xa0, \n\t0x0c, 0x23, 0x44, 0x51, 0x00, 0x29, 0x51, 0x43, 0x00, 0x10, 0x21, 0x10, 0x21, 0x00, 0x14, 0x42, \n\t0x62, 0x84, 0x01, 0x00, 0x38, 0x1b, 0x68, 0x10, 0x73, 0x52, 0x02, 0x00, 0x11, 0x21, 0x06, 0x90, \n\t0x01, 0x05, 0x60, 0x04, 0x62, 0x00, 0x00, 0x80, 0xa0, 0x41, 0x1e, 0xcc, 0x00, 0x03, 0xf0, 0xb8, \n\t0x4c, 0x08, 0x20, 0x0c, 0x01, 0x20, 0x08, 0x7c, 0x06, 0x24, 0x40, 0x93, 0x4b, 0x80, 0x45, 0xc7, \n\t0x84, 0x46, 0x25, 0x11, 0x00, 0xd0, 0x89, 0x02, 0x18, 0xc2, 0xf0, 0x02, 0x08, 0x1c, 0xac, 0x42, \n\t0xd4, 0x48, 0x10, 0xac, 0xc4, 0x02, 0x1a, 0x11, 0x49, 0x19, 0x00, 0xcd, 0xc0, 0x5a, 0x47, 0xa2, \n\t0xa9, 0x08, 0x00, 0x01, 0x24, 0x21, 0x60, 0x10, 0x40, 0x52, 0xec, 0x00, 0x04, 0x00, 0x19, 0x50, \n\t0x11, 0x8d, 0x1a, 0x30, 0x9a, 0x03, 0x80, 0x80, 0xc7, 0x20, 0x03, 0x90, 0x03, 0x98, 0x88, 0x2f, \n\t0x0e, 0x34, 0x08, 0x15, 0x68, 0xd5, 0x26, 0x24, 0x80, 0x50, 0x81, 0x04, 0x57, 0xa0, 0x60, 0x01, \n\t0x31, 0x15, 0xb4, 0x92, 0x00, 0x06, 0xe0, 0x40, 0x30, 0x01, 0x59, 0x48, 0x04, 0x86, 0x49, 0x99, \n\t0xc0, 0x08, 0x4b, 0x26, 0x81, 0x48, 0x0e, 0x44, 0x14, 0x43, 0x22, 0x26, 0x82, 0x2e, 0x00, 0x81, \n\t0x40, 0x68, 0xa1, 0x51, 0x84, 0x58, 0x86, 0xc0, 0x20, 0xa2, 0x92, 0x28, 0x44, 0x84, 0x03, 0x5c, \n\t0x50, 0x90, 0x02, 0x6c, 0x04, 0xaf, 0x70, 0x16, 0x32, 0x06, 0x91, 0x81, 0xa8, 0x00, 0xb0, 0x28, \n\t0x23, 0x30, 0x01, 0x40, 0x60, 0x81, 0x08, 0xa9, 0x41, 0x10, 0x0a, 0x2a, 0x74, 0x29, 0x97, 0xa0, \n\t0x52, 0x8a, 0x1c, 0x40, 0xa2, 0x38, 0x9c, 0x10, 0x07, 0x02, 0xc0, 0x02, 0x01, 0x50, 0x4e, 0x0b, \n\t0x00, 0x06, 0x21, 0xad, 0x24, 0x53, 0x44, 0x4a, 0x96, 0x8b, 0x20, 0x10, 0x9c, 0x40, 0x24, 0xa3, \n\t0x89, 0x19, 0x70, 0x01, 0x22, 0x14, 0x10, 0x98, 0x00, 0x21, 0x95, 0x09, 0x4a, 0x91, 0x49, 0x22, \n\t0xc5, 0x04, 0x27, 0x60, 0x65, 0xe2, 0x20, 0x80, 0x02, 0x00, 0x24, 0x22, 0xaa, 0x96, 0x64, 0x84, \n\t0x02, 0x4e, 0xc0, 0x0a, 0x18, 0xe0, 0x80, 0x04, 0x58, 0x04, 0x51, 0x25, 0x81, 0x98, 0x40, 0x0e, \n\t0x20, 0x90, 0x0a, 0xc8, 0x0d, 0x08, 0x42, 0x21, 0x81, 0x12, 0x00, 0xca, 0x00, 0x36, 0x82, 0x58, \n\t0x20, 0x15, 0x01, 0xca, 0x48, 0x21, 0x41, 0x01, 0xb0, 0x00, 0x20, 0x06, 0x80, 0x18, 0x04, 0x00, \n\t0x92, 0x09, 0x28, 0x24, 0x01, 0x0c, 0x74, 0x05, 0x42, 0x18, 0x90, 0x61, 0x2b, 0x09, 0x16, 0x45, \n\t0x44, 0xa2, 0xc0, 0x1a, 0x14, 0x01, 0x00, 0x00, 0x40, 0x22, 0x9d, 0x45, 0x4b, 0x84, 0x12, 0x05, \n\t0xea, 0x04, 0xcc, 0x0a, 0x08, 0x20, 0x40, 0x09, 0x02, 0x6c, 0x83, 0x80, 0x00, 0x00, 0x30, 0x90, \n\t0x99, 0x00, 0x4d, 0x30, 0x41, 0x9a, 0x03, 0x65, 0xc5, 0x29, 0x38, 0x10, 0x50, 0x24, 0x61, 0x80, \n\t0x44, 0x02, 0xd2, 0xc0, 0x80, 0x20, 0x02, 0x20, 0x02, 0x54, 0x63, 0x10, 0xb0, 0x15, 0x85, 0x48, \n\t0xa2, 0x03, 0x10, 0x95, 0xd0, 0x00, 0x08, 0xc1, 0xe3, 0x0c, 0x40, 0x16, 0x66, 0x40, 0x45, 0x11, \n\t0x89, 0x00, 0x00, 0x8e, 0x42, 0x93, 0xb0, 0x28, 0x69, 0xd0, 0xe2, 0x22, 0x07, 0x11, 0x0c, 0x2c, \n\t0x98, 0x80, 0x48, 0x04, 0x10, 0x14, 0xdd, 0x8e, 0x01, 0x08, 0x07, 0xe2, 0x8e, 0x08, 0x00, 0x6a, \n\t0x30, 0x11, 0x40, 0x03, 0x40, 0x85, 0x26, 0x08, 0x06, 0x18, 0x0a, 0x40, 0x82, 0x01, 0x28, 0x50, \n\t0x29, 0xa3, 0xa0, 0xc3, 0x68, 0x54, 0xa2, 0x98, 0x88, 0x20, 0x00, 0x2e, 0x46, 0x26, 0xa0, 0x00, \n\t0x1c, 0x41, 0x04, 0x14, 0x02, 0x42, 0x80, 0x89, 0x1e, 0xa9, 0x44, 0xc5, 0x92, 0xb0, 0x80, 0xca, \n\t0xa0, 0x08, 0x76, 0xb0, 0xa8, 0x40, 0xcf, 0x83, 0x2a, 0xc0, 0x58, 0x3e, 0x0c, 0x04, 0x84, 0x0e, \n\t0x51, 0xc0, 0x13, 0x81, 0x59, 0xe8, 0x40, 0x42, 0x19, 0x0a, 0x38, 0x40, 0xc6, 0x22, 0x40, 0x11, \n\t0x80, 0x41, 0x01, 0x66, 0x2e, 0xa1, 0x08, 0x31, 0x50, 0x0a, 0x89, 0x00, 0x07, 0x40, 0x13, 0x00, \n\t0x41, 0x28, 0x02, 0xc0, 0x0b, 0x85, 0x11, 0xd8, 0x28, 0x2e, 0x82, 0xa2, 0x24, 0xb0, 0x50, 0x67, \n\t0x56, 0x80, 0x03, 0x8f, 0x28, 0x00, 0x05, 0x24, 0x81, 0xc0, 0x12, 0x4c, 0x82, 0x04, 0x0a, 0x16, \n\t0xb0, 0x8a, 0x51, 0x00, 0x80, 0x14, 0x41, 0x53, 0x0e, 0x29, 0x4a, 0x08, 0x14, 0x14, 0x22, 0xa5, \n\t0x24, 0x46, 0x41, 0x02, 0x01, 0x40, 0x84, 0x64, 0x04, 0xc4, 0x04, 0x92, 0x99, 0x08, 0xa8, 0x89, \n\t0x2a, 0x10, 0x40, 0x21, 0x14, 0xa0, 0x18, 0xc8, 0x48, 0xa4, 0x49, 0xa1, 0x00, 0x47, 0x41, 0x28, \n\t0x86, 0x88, 0x0e, 0x80, 0x48, 0xa1, 0x64, 0x12, 0x72, 0x28, 0x40, 0x53, 0x48, 0x52, 0xb2, 0x02, \n\t0x00, 0xd8, 0x90, 0x48, 0x20, 0x36, 0xc2, 0x25, 0x80, 0x09, 0x25, 0x2c, 0x12, 0x88, 0x98, 0x69, \n\t0x1c, 0x04, 0x12, 0x14, 0xe2, 0x90, 0x68, 0x06, 0x88, 0x38, 0x00, 0x23, 0x01, 0x90, 0x15, 0xa0, \n\t0x1e, 0x04, 0x31, 0xa6, 0x71, 0x40, 0x0a, 0x50, 0xd4, 0x41, 0x08, 0x08, 0x0a, 0x04, 0x2c, 0x15, \n\t0x00, 0x8a, 0x40, 0x10, 0x8a, 0x70, 0xb0, 0x81, 0x22, 0x14, 0x0b, 0x25, 0x12, 0x15, 0x0a, 0x00, \n\t0x30, 0x81, 0xcc, 0x08, 0x30, 0x61, 0x18, 0xdc, 0xc4, 0x60, 0x14, 0x83, 0x78, 0xa1, 0x00, 0x82, \n\t0x83, 0x08, 0x52, 0xb0, 0x06, 0x0c, 0x02, 0x29, 0x00, 0x14, 0x2a, 0x90, 0x0d, 0x11, 0x64, 0x42, \n\t0x02, 0x40, 0x21, 0x80, 0x45, 0x06, 0x08, 0x04, 0x4b, 0x04, 0x30, 0x50, 0x40, 0x26, 0x64, 0xe2, \n\t0x04, 0xc5, 0x0c, 0xc8, 0x30, 0xc6, 0x02, 0x0b, 0x18, 0x4f, 0x80, 0x28, 0x84, 0x20, 0x29, 0x85, \n\t0x8e, 0x0b, 0x58, 0x24, 0x80, 0x01, 0x14, 0x55, 0x04, 0x02, 0xc1, 0xb0, 0x80, 0xc0, 0x80, 0x8b, \n\t0x42, 0x82, 0x59, 0x34, 0x4c, 0xc0, 0xc0, 0x12, 0x53, 0x39, 0x20, 0x84, 0x0a, 0xc5, 0x18, 0x91, \n\t0x20, 0xa3, 0x50, 0x48, 0x43, 0x4a, 0x10, 0x3a, 0xb2, 0x11, 0x89, 0x42, 0x18, 0x10, 0xe0, 0x93, \n\t0x40, 0x02, 0xa6, 0x64, 0x04, 0x08, 0x87, 0x18, 0xc3, 0x00, 0x16, 0x07, 0x20, 0x2a, 0x04, 0x09, \n\t0x44, 0x22, 0xa2, 0x83, 0xb0, 0x29, 0xc1, 0x40, 0x20, 0xa3, 0x01, 0x07, 0x81, 0x5c, 0x42, 0x00, \n\t0x45, 0x21, 0x83, 0xac, 0x13, 0x25, 0x0e, 0x80, 0x80, 0x01, 0x49, 0x14, 0x8b, 0x10, 0x16, 0x62, \n\t0x10, 0x14, 0x82, 0x07, 0x48, 0xb0, 0xe9, 0x09, 0x80, 0x9a, 0x88, 0x70, 0xe0, 0xc0, 0x0d, 0x8d, \n\t0x03, 0x84, 0x04, 0xd1, 0x20, 0x82, 0x25, 0x07, 0x62, 0x68, 0x11, 0x10, 0x20, 0x20, 0x01, 0x06, \n\t0x14, 0x40, 0x72, 0x12, 0x11, 0xd4, 0x20, 0x10, 0x65, 0x72, 0x10, 0xc8, 0x04, 0x8a, 0x04, 0x04, \n\t0x0a, 0x98, 0x08, 0xc8, 0x20, 0x04, 0x12, 0x48, 0x85, 0x70, 0x10, 0xc3, 0x08, 0x25, 0x80, 0x18, \n\t0x00, 0x1c, 0x40, 0x1e, 0x20, 0x00, 0x13, 0xa1, 0x43, 0xe0, 0x1e, 0x04, 0xc3, 0x18, 0xc4, 0x00, \n\t0x69, 0x44, 0x00, 0x20, 0xaf, 0xa0, 0x04, 0x0a, 0x00, 0x01, 0x43, 0x3c, 0x11, 0x10, 0x66, 0x48, \n\t0x82, 0x20, 0x0f, 0x1c, 0x0c, 0x44, 0x38, 0x13, 0xa8, 0x14, 0x24, 0x8f, 0x80, 0x06, 0x60, 0x72, \n\t0x00, 0x90, 0x84, 0x01, 0x12, 0x61, 0x50, 0x2e, 0xbc, 0x04, 0x24, 0x64, 0x90, 0x48, 0x28, 0x49, \n\t0x83, 0xa0, 0x10, 0x54, 0x19, 0x1b, 0xa5, 0x01, 0x08, 0x52, 0xf6, 0x00, 0x07, 0xac, 0x09, 0x40, \n\t0x24, 0x42, 0xd8, 0x8a, 0xd1, 0x99, 0x88, 0x6e, 0x90, 0x08, 0x04, 0x00, 0x50, 0x0c, 0x18, 0x73, \n\t0x09, 0x85, 0x24, 0x84, 0x6a, 0x00, 0xc0, 0x83, 0xa1, 0x85, 0x5a, 0x40, 0x42, 0x64, 0x82, 0x30, \n\t0x31, 0x48, 0x05, 0x14, 0xd1, 0x7a, 0x00, 0x0d, 0x10, 0x20, 0x42, 0x20, 0xc0, 0x26, 0x84, 0x0c, \n\t0xc3, 0x1c, 0x20, 0x51, 0x10, 0xa9, 0x19, 0x21, 0x14, 0x22, 0x41, 0xa8, 0x90, 0x0d, 0xe9, 0x10, \n\t0x64, 0x29, 0xbd, 0x31, 0xc4, 0x46, 0x28, 0x40, 0x0a, 0x9a, 0x88, 0xc4, 0x20, 0x28, 0x21, 0xc2, \n\t0x80, 0x40, 0x86, 0x03, 0x38, 0x96, 0x83, 0x08, 0x39, 0xd0, 0x0c, 0x1a, 0x81, 0x78, 0x2a, 0x51, \n\t0x06, 0xc7, 0x00, 0x13, 0x91, 0x05, 0x01, 0x59, 0x4c, 0x00, 0xc1, 0x02, 0x86, 0x15, 0x5f, 0x84, \n\t0x22, 0x56, 0x62, 0xa3, 0x84, 0x10, 0x00, 0x7a, 0x01, 0xa1, 0x11, 0x91, 0x92, 0xa0, 0x48, 0x20, \n\t0x28, 0x98, 0x10, 0x45, 0xa4, 0x04, 0x81, 0x02, 0x3a, 0x88, 0x01, 0x08, 0x24, 0xc3, 0x20, 0x34, \n\t0x84, 0x5c, 0x40, 0x20, 0xf6, 0x22, 0x10, 0xbc, 0x02, 0x21, 0x02, 0x44, 0x38, 0x0b, 0x98, 0x82, \n\t0x60, 0x2e, 0x96, 0x88, 0x05, 0x44, 0x45, 0xca, 0x0c, 0x00, 0x0a, 0x82, 0xe9, 0x00, 0x61, 0x58, \n\t0x00, 0x11, 0x15, 0x10, 0x13, 0x21, 0x26, 0x02, 0x08, 0x80, 0x41, 0x96, 0x04, 0x28, 0x01, 0x81, \n\t0x0d, 0x21, 0x99, 0x00, 0x42, 0x71, 0x82, 0xa2, 0xc0, 0x45, 0x60, 0x38, 0x40, 0xd2, 0x80, 0x80, \n\t0x58, 0x43, 0x06, 0xe1, 0x13, 0x22, 0xe8, 0x08, 0x00, 0x00, 0x40, 0x00, 0x1d, 0x20, 0x5b, 0x44, \n\t0x42, 0x12, 0x4b, 0x28, 0x10, 0x0c, 0x0c, 0x54, 0xc2, 0xc0, 0x0e, 0x10, 0xc7, 0x00, 0x70, 0xa0, \n\t0x60, 0x30, 0x3c, 0x82, 0x03, 0x48, 0x40, 0x12, 0x2c, 0x7c, 0x80, 0x86, 0x20, 0x02, 0x12, 0x21, \n\t0x49, 0x01, 0xe9, 0x68, 0x12, 0xb8, 0x28, 0x04, 0xd0, 0x82, 0x54, 0x42, 0x89, 0x9b, 0x40, 0x52, \n\t0x84, 0x1e, 0x21, 0xe0, 0x22, 0x85, 0x15, 0x80, 0x4c, 0x84, 0x81, 0x04, 0xc0, 0x09, 0x0a, 0x42, \n\t0x46, 0x81, 0x22, 0x40, 0x89, 0x26, 0x16, 0x94, 0x49, 0x11, 0x94, 0x41, 0x0f, 0x00, 0x40, 0xa0, \n\t0x2d, 0x28, 0x40, 0x2d, 0x18, 0x11, 0x1b, 0x19, 0x18, 0x92, 0x81, 0x26, 0x26, 0x0b, 0x00, 0x0c, \n\t0x91, 0x0c, 0x46, 0xe0, 0x20, 0x0c, 0x31, 0x8a, 0x08, 0x14, 0x90, 0x12, 0x3a, 0x11, 0x53, 0x25, \n\t0x00, 0x85, 0x22, 0x11, 0x05, 0x40, 0x80, 0x20, 0x96, 0x40, 0x83, 0x41, 0x8d, 0x28, 0x00, 0x40, \n\t0xe2, 0x04, 0x08, 0xc6, 0x08, 0x10, 0xa2, 0x98, 0x12, 0x29, 0x00, 0x29, 0x24, 0x54, 0x80, 0x82, \n\t0x25, 0x03, 0x45, 0x16, 0x00, 0x18, 0x90, 0x30, 0x11, 0x0a, 0x30, 0x84, 0x21, 0x06, 0x08, 0x0c, \n\t0x60, 0x22, 0x14, 0xc2, 0x82, 0x38, 0x54, 0xc0, 0x6a, 0x84, 0x11, 0x3c, 0x00, 0x10, 0x8c, 0x48, \n\t0x82, 0x8a, 0x8d, 0x65, 0x88, 0x40, 0x00, 0x42, 0x33, 0x25, 0x5c, 0x09, 0x01, 0x00, 0x03, 0x20, \n\t0x3f, 0x50, 0x0a, 0xe6, 0x04, 0x40, 0x38, 0x00, 0x0d, 0xd0, 0x8e, 0x50, 0x40, 0x61, 0x04, 0x20, \n\t0x4c, 0x83, 0x24, 0x26, 0x28, 0x06, 0xc0, 0x00, 0x88, 0x04, 0x72, 0x12, 0x19, 0x81, 0x84, 0x43, \n\t0x26, 0x10, 0x18, 0x90, 0x21, 0x93, 0x04, 0x08, 0xa3, 0x89, 0x27, 0x04, 0x84, 0x68, 0x00, 0x93, \n\t0x43, 0x81, 0x71, 0x84, 0x0c, 0x10, 0xb4, 0xe0, 0x21, 0xc1, 0x52, 0x2e, 0x02, 0x10, 0x00, 0x00, \n\t0xc1, 0x08, 0x00, 0x68, 0x80, 0xd2, 0x01, 0x00, 0x00, 0xa5, 0x0e, 0x85, 0x32, 0x8c, 0x01, 0x40, \n\t0x82, 0x20, 0x95, 0x8b, 0x92, 0x40, 0x1c, 0x08, 0x54, 0x30, 0x40, 0x36, 0x34, 0x09, 0x82, 0x06, \n\t0x84, 0xf2, 0xac, 0x84, 0x18, 0x21, 0x32, 0xd0, 0x41, 0x11, 0xb0, 0x82, 0x43, 0x12, 0x50, 0x08, \n\t0x0a, 0x80, 0x0b, 0x02, 0x50, 0x06, 0x60, 0xa6, 0x04, 0x51, 0x08, 0x02, 0x84, 0x1b, 0x91, 0x79, \n\t0x01, 0x8c, 0x44, 0x30, 0xa2, 0x00, 0x20, 0x16, 0x82, 0x48, 0x10, 0x00, 0x21, 0x09, 0x08, 0x22, \n\t0x08, 0x20, 0x62, 0x30, 0x99, 0x89, 0x4a, 0x26, 0x07, 0xb2, 0x0a, 0x01, 0x02, 0xc4, 0x2c, 0x03, \n\t0xd0, 0x22, 0xc4, 0x94, 0x80, 0x5a, 0x14, 0xc0, 0x15, 0x49, 0x86, 0x28, 0x0a, 0xa2, 0x43, 0x24, \n\t0x24, 0x14, 0x01, 0x16, 0x60, 0xd0, 0x2b, 0x45, 0x09, 0x04, 0x16, 0xa1, 0x48, 0x1e, 0xa4, 0x14, \n\t0xc0, 0x48, 0x00, 0x42, 0x8b, 0x90, 0xcd, 0x40, 0x68, 0xc2, 0x02, 0x91, 0x00, 0x4c, 0xc8, 0x24, \n\t0x12, 0x4b, 0x28, 0x21, 0x04, 0x48, 0x12, 0x10, 0x82, 0x87, 0x01, 0x9a, 0xa1, 0x14, 0x60, 0x41, \n\t0x8b, 0xd0, 0x08, 0xa8, 0x22, 0x20, 0x02, 0x8c, 0x69, 0x88, 0x06, 0x58, 0x05, 0xa3, 0x27, 0x48, \n\t0x15, 0xaa, 0x20, 0x40, 0x50, 0x30, 0x2c, 0x0c, 0x08, 0x6c, 0x82, 0x21, 0x8a, 0x29, 0x58, 0x0d, \n\t0x40, 0x91, 0xd3, 0x00, 0x05, 0x02, 0x2e, 0x24, 0x11, 0x11, 0xb5, 0xc0, 0x94, 0x08, 0x02, 0x60, \n\t0x20, 0x08, 0x88, 0x0f, 0x25, 0x46, 0xc4, 0x42, 0x12, 0x18, 0x41, 0x2d, 0x10, 0x04, 0x12, 0x25, \n\t0x20, 0xc1, 0xe0, 0x44, 0x30, 0xd0, 0x2a, 0x1c, 0x06, 0x62, 0x38, 0x73, 0x81, 0xa0, 0x4c, 0x01, \n\t0x08, 0x60, 0x16, 0x02, 0x95, 0x3c, 0x51, 0xa1, 0x58, 0x12, 0x71, 0x2d, 0x60, 0x98, 0x08, 0x68, \n\t0x00, 0x12, 0x01, 0x50, 0x54, 0x00, 0x02, 0x87, 0xa9, 0x32, 0x19, 0x00, 0x82, 0x00, 0x41, 0x02, \n\t0xa1, 0x00, 0x0d, 0xe0, 0x10, 0x82, 0x50, 0x88, 0x75, 0x8c, 0x8c, 0x42, 0x16, 0x48, 0x19, 0x28, \n\t0x00, 0x08, 0x00, 0x94, 0x08, 0x11, 0x00, 0x1b, 0x83, 0x12, 0x20, 0x08, 0x2c, 0x2c, 0xc2, 0x60, \n\t0x10, 0x82, 0xb8, 0x02, 0x09, 0x04, 0x04, 0x38, 0x61, 0x51, 0x36, 0x04, 0x82, 0xe0, 0x06, 0xa1, \n\t0x0a, 0x8c, 0x11, 0xc3, 0x42, 0x0c, 0x17, 0x42, 0x84, 0x28, 0x03, 0x86, 0x4c, 0x70, 0x3b, 0x15, \n\t0xf8, 0xc8, 0x40, 0x10, 0xe1, 0xc8, 0xa0, 0x14, 0x41, 0x24, 0x64, 0x92, 0x41, 0x2b, 0x31, 0x09, \n\t0x41, 0x0c, 0x80, 0x40, 0x80, 0x85, 0x10, 0x82, 0x22, 0x52, 0xc8, 0x12, 0x38, 0x46, 0x65, 0x16, \n\t0x26, 0x20, 0x98, 0x61, 0x00, 0x29, 0x04, 0x94, 0xab, 0x28, 0x09, 0x00, 0x23, 0x02, 0xf0, 0x02, \n\t0x84, 0xe0, 0x0a, 0x05, 0x40, 0x20, 0xf0, 0x3b, 0x8c, 0x18, 0x4f, 0x44, 0xc0, 0x08, 0x2c, 0x20, \n\t0x42, 0x20, 0x00, 0x01, 0x02, 0xa9, 0x41, 0x03, 0x00, 0x52, 0x20, 0x72, 0x02, 0x80, 0xc2, 0x0a, \n\t0x64, 0x47, 0x92, 0x04, 0x49, 0x14, 0x03, 0x74, 0x80, 0x10, 0x83, 0x8c, 0x09, 0x29, 0x0e, 0x50, \n\t0x29, 0x04, 0x81, 0x1f, 0x49, 0x08, 0x85, 0xc0, 0x8c, 0x00, 0xd5, 0x41, 0x32, 0x46, 0xe1, 0x82, \n\t0x20, 0x90, 0xa6, 0x22, 0x80, 0xa8, 0x08, 0xf5, 0x43, 0x05, 0x18, 0x22, 0x41, 0x04, 0xc0, 0x00, \n\t0x0e, 0x1c, 0x12, 0xa0, 0x84, 0x44, 0xd9, 0x2c, 0x2a, 0xc7, 0x20, 0x2b, 0x04, 0x1b, 0x00, 0x3e, \n\t0x10, 0x00, 0x14, 0xc5, 0x05, 0x84, 0x04, 0x55, 0x22, 0x04, 0x08, 0xd1, 0xa8, 0x5a, 0x41, 0x12, \n\t0x9e, 0xf4, 0x08, 0x04, 0x50, 0x05, 0x48, 0x90, 0x0d, 0x07, 0x40, 0x08, 0x74, 0x28, 0x80, 0x81, \n\t0x16, 0x08, 0x0a, 0x80, 0x08, 0x0c, 0x04, 0xc9, 0x41, 0x7a, 0x65, 0x43, 0x82, 0x21, 0x92, 0x61, \n\t0x04, 0x94, 0xc1, 0x08, 0x00, 0x54, 0x01, 0x54, 0xa2, 0xe1, 0x01, 0x3c, 0x80, 0xa0, 0x04, 0x12, \n\t0xa2, 0x98, 0x80, 0x49, 0x4c, 0x62, 0x26, 0x02, 0x04, 0x28, 0x48, 0xa4, 0x04, 0x91, 0x4a, 0xa8, \n\t0x49, 0x11, 0x80, 0x00, 0x30, 0x69, 0x06, 0xf4, 0x93, 0x01, 0x08, 0x03, 0x11, 0x00, 0x51, 0x40, \n\t0x40, 0x12, 0x20, 0xd1, 0xba, 0x8d, 0x06, 0x40, 0x28, 0xe4, 0x10, 0x86, 0x85, 0xc8, 0x42, 0x02, \n\t0xc1, 0x20, 0x00, 0x90, 0x5b, 0x01, 0x14, 0x10, 0x20, 0x07, 0xe0, 0x81, 0x0a, 0x02, 0xb6, 0x39, \n\t0x19, 0x80, 0x10, 0x29, 0x48, 0x43, 0x2b, 0x0b, 0xc0, 0x84, 0x64, 0x34, 0xb6, 0x42, 0x14, 0x80, \n\t0x48, 0x26, 0x2e, 0xd1, 0x00, 0x33, 0x14, 0x11, 0x20, 0x02, 0x52, 0x82, 0xa9, 0x45, 0x08, 0xaa, \n\t0x18, 0x00, 0x21, 0x91, 0x9d, 0x12, 0x80, 0x4c, 0xa6, 0xd2, 0x90, 0x40, 0x19, 0x0f, 0x40, 0x64, \n\t0x01, 0x10, 0x68, 0x04, 0x45, 0x20, 0xb2, 0x18, 0x06, 0x20, 0x94, 0x8a, 0x30, 0x90, 0x03, 0xb4, \n\t0x2c, 0x83, 0x69, 0x20, 0x14, 0x50, 0x90, 0x30, 0x09, 0x43, 0x30, 0x80, 0x12, 0x18, 0xc1, 0x95, \n\t0x62, 0x40, 0x52, 0x70, 0x0c, 0x8c, 0x84, 0x89, 0x08, 0xc4, 0x00, 0x09, 0x04, 0x09, 0x00, 0x60, \n\t0xc5, 0x30, 0xa7, 0x60, 0x81, 0x20, 0x32, 0x06, 0x00, 0x99, 0x09, 0x04, 0x0c, 0x18, 0x61, 0x08, \n\t0x10, 0x25, 0x41, 0xc0, 0x14, 0x03, 0x20, 0x02, 0x10, 0x4d, 0x08, 0x04, 0x07, 0x01, 0x33, 0x74, \n\t0xce, 0x22, 0x00, 0x61, 0x61, 0x38, 0x05, 0x0c, 0x46, 0x60, 0xf0, 0x41, 0x02, 0x84, 0x04, 0x08, \n\t0x3e, 0x60, 0x30, 0x0a, 0xa1, 0x41, 0xee, 0x16, 0x02, 0xd8, 0x04, 0x20, 0x83, 0x01, 0x00, 0x01, \n\t0x5b, 0x04, 0x34, 0x08, 0xa0, 0x70, 0xc0, 0xa0, 0x33, 0x5c, 0xd8, 0x03, 0x48, 0x00, 0x3a, 0x1b, \n\t0x00, 0x87, 0x41, 0x70, 0x80, 0x88, 0x00, 0x85, 0x00, 0x8c, 0x28, 0x24, 0xbb, 0x00, 0xe0, 0x50, \n\t0x4b, 0x00, 0x85, 0x10, 0x36, 0x48, 0x49, 0x20, 0x00, 0x14, 0x02, 0x12, 0x08, 0x40, 0xa4, 0x32, \n\t0x04, 0x11, 0x1b, 0x21, 0x0f, 0x80, 0x30, 0x83, 0x62, 0x86, 0x38, 0xd2, 0x25, 0x46, 0xb4, 0x00, \n\t0x89, 0x79, 0x84, 0x0e, 0x40, 0x14, 0x1a, 0x0c, 0xb4, 0x97, 0x4b, 0x0c, 0xf1, 0x00, 0x06, 0x0d, \n\t0x84, 0x02, 0x40, 0x00, 0x80, 0xb2, 0x88, 0x48, 0x02, 0x08, 0x51, 0x08, 0x90, 0x1c, 0x48, 0xa4, \n\t0x0c, 0x80, 0x08, 0xb4, 0x88, 0x8f, 0xa8, 0x64, 0x14, 0x69, 0x33, 0x81, 0x82, 0x23, 0x26, 0x46, \n\t0x8a, 0x02, 0x54, 0x08, 0xc9, 0x10, 0x33, 0x12, 0xa1, 0xc0, 0x86, 0xc0, 0x34, 0x20, 0x40, 0x09, \n\t0x10, 0x51, 0x07, 0x70, 0x41, 0x82, 0x81, 0x10, 0x1e, 0x0c, 0x3a, 0x47, 0x61, 0x02, 0x48, 0x43, \n\t0xcb, 0x0a, 0x02, 0xf1, 0x1c, 0x60, 0x10, 0x05, 0x16, 0x51, 0xaa, 0x88, 0x45, 0x98, 0x82, 0x64, \n\t0x91, 0xb0, 0x32, 0x08, 0x83, 0x01, 0x40, 0xd3, 0x00, 0x39, 0x40, 0x92, 0x40, 0x42, 0x81, 0xe1, \n\t0x08, 0x88, 0xc5, 0x2a, 0x0a, 0x05, 0x50, 0x83, 0xe4, 0x07, 0xa1, 0x10, 0x67, 0x28, 0xa4, 0x88, \n\t0x01, 0x0b, 0x20, 0x14, 0x10, 0x2a, 0xcd, 0x41, 0x28, 0x22, 0x16, 0x18, 0x90, 0xd1, 0x00, 0x44, \n\t0x18, 0x81, 0xa1, 0x00, 0x14, 0x1e, 0x04, 0x22, 0x25, 0xd1, 0x14, 0x58, 0x09, 0x4a, 0x3a, 0x06, \n\t0x83, 0x25, 0x24, 0x01, 0x4c, 0x18, 0x01, 0x22, 0xa8, 0x30, 0x08, 0x41, 0x58, 0xa7, 0x52, 0x81, \n\t0xdc, 0x52, 0x26, 0x00, 0x86, 0x00, 0x38, 0x64, 0x85, 0x07, 0x0c, 0x52, 0x1a, 0x12, 0xa8, 0x04, \n\t0x8e, 0x32, 0x01, 0x41, 0x20, 0xe9, 0x4b, 0x60, 0x76, 0x21, 0x20, 0x2c, 0xa9, 0x00, 0x82, 0x32, \n\t0x64, 0x4a, 0x30, 0x48, 0x4a, 0x02, 0x04, 0x17, 0x10, 0x16, 0x05, 0x10, 0x41, 0x68, 0x71, 0x40, \n\t0x02, 0x20, 0x92, 0x60, 0x0e, 0xc2, 0x31, 0x04, 0x11, 0x83, 0x41, 0x0a, 0xb2, 0x11, 0x00, 0x25, \n\t0x45, 0x84, 0x40, 0x00, 0xda, 0x28, 0x41, 0x00, 0x4b, 0x0c, 0xe6, 0x00, 0x85, 0x50, 0xc8, 0x0a, \n\t0x04, 0x54, 0x30, 0x09, 0x00, 0x0e, 0xa6, 0x6a, 0x02, 0x02, 0x20, 0x0d, 0x56, 0xa0, 0x48, 0x04, \n\t0xa0, 0x90, 0x14, 0x81, 0x08, 0x2a, 0x02, 0x91, 0x30, 0x00, 0x01, 0x4c, 0x20, 0x40, 0x49, 0x29, \n\t0x15, 0x89, 0x04, 0x10, 0xa5, 0x60, 0x90, 0x20, 0x5e, 0x84, 0x20, 0x45, 0x03, 0x07, 0x14, 0x09, \n\t0x24, 0x08, 0x70, 0x8a, 0x92, 0x08, 0x46, 0xe3, 0x30, 0x00, 0x08, 0x01, 0x48, 0x51, 0x89, 0x10, \n\t0x40, 0xa8, 0x08, 0xa0, 0x12, 0x81, 0x34, 0x61, 0x41, 0x24, 0x84, 0x5a, 0x44, 0x24, 0x14, 0x9a, \n\t0x28, 0x68, 0x95, 0x44, 0x60, 0x43, 0x89, 0x80, 0x64, 0x85, 0x88, 0x02, 0x50, 0x01, 0x81, 0x74, \n\t0x18, 0x23, 0x24, 0x41, 0xe1, 0x02, 0xe9, 0x00, 0x0d, 0x04, 0x36, 0xd2, 0xb1, 0x01, 0x00, 0x8d, \n\t0x0e, 0x54, 0x41, 0x09, 0x30, 0x85, 0x08, 0x48, 0x81, 0x29, 0x38, 0x84, 0x4c, 0x28, 0x74, 0x03, \n\t0xa2, 0x0e, 0x20, 0x56, 0x04, 0x22, 0xa0, 0x01, 0x08, 0xc1, 0x84, 0x20, 0x1a, 0xd2, 0x10, 0x2a, \n\t0x11, 0x02, 0x4a, 0x10, 0x01, 0x32, 0xb1, 0x01, 0x12, 0x4a, 0x42, 0x04, 0xb8, 0x0e, 0x24, 0x90, \n\t0x84, 0x16, 0x47, 0x93, 0x0a, 0x44, 0x81, 0x0a, 0x18, 0x30, 0x80, 0x92, 0xb0, 0x11, 0x03, 0x3c, \n\t0xa4, 0x08, 0x00, 0x64, 0x44, 0xca, 0x26, 0xd2, 0x0b, 0x21, 0x88, 0x00, 0xcc, 0x16, 0x83, 0x71, \n\t0x22, 0xd0, 0xd0, 0x87, 0x08, 0xd7, 0x48, 0x0d, 0x00, 0xcb, 0x20, 0x6a, 0x43, 0x82, 0x04, 0x48, \n\t0x1d, 0xc6, 0x20, 0x20, 0x30, 0x05, 0xe1, 0x15, 0x01, 0x10, 0xf1, 0xa9, 0x82, 0x09, 0x98, 0x83, \n\t0x18, 0xa0, 0x60, 0x07, 0xd1, 0x83, 0x00, 0x08, 0x75, 0x02, 0x3c, 0x00, 0x0c, 0xc1, 0x6c, 0x02, \n\t0xba, 0x9a, 0x20, 0x42, 0x26, 0x14, 0x44, 0x20, 0x10, 0x4c, 0x43, 0xe1, 0x5a, 0x81, 0x42, 0x26, \n\t0x84, 0x0d, 0x20, 0x56, 0x00, 0x91, 0x98, 0x80, 0x00, 0x65, 0x12, 0x21, 0x08, 0x00, 0x50, 0x4a, \n\t0x82, 0x02, 0x06, 0xca, 0x82, 0x8c, 0x02, 0x64, 0x00, 0x83, 0xa1, 0x82, 0x50, 0x54, 0x01, 0x54, \n\t0x30, 0xc0, 0x00, 0x09, 0x14, 0xc4, 0x04, 0xa0, 0x03, 0x07, 0xcc, 0x88, 0x48, 0x48, 0xb0, 0x11, \n\t0x14, 0x19, 0x08, 0x88, 0x24, 0xd0, 0x00, 0x12, 0x00, 0x18, 0xc1, 0x0a, 0x80, 0x22, 0x08, 0x8d, \n\t0x45, 0x84, 0x08, 0x25, 0x40, 0x22, 0x94, 0x18, 0xc0, 0x18, 0x47, 0x72, 0x00, 0x64, 0x41, 0x00, \n\t0x24, 0xe2, 0x19, 0x81, 0x14, 0x81, 0x01, 0x14, 0x06, 0x50, 0x0c, 0xc0, 0x82, 0x0c, 0x3a, 0x21, \n\t0x4a, 0x03, 0x08, 0x41, 0x49, 0x06, 0x52, 0x08, 0x85, 0xb1, 0xd2, 0x02, 0x24, 0x00, 0x68, 0x01, \n\t0xd9, 0x12, 0x04, 0x04, 0x00, 0x20, 0x01, 0x01, 0x12, 0x0e, 0x10, 0x52, 0x50, 0x81, 0x40, 0x83, \n\t0xc8, 0x6e, 0x10, 0x22, 0x20, 0x78, 0x01, 0x04, 0x4a, 0x92, 0x61, 0x0d, 0x2c, 0xc2, 0x2c, 0x62, \n\t0x45, 0x4a, 0x84, 0x34, 0x86, 0x08, 0x00, 0xc0, 0x3a, 0x84, 0x24, 0x48, 0xe7, 0x00, 0x84, 0x4a, \n\t0x12, 0x09, 0x81, 0x00, 0x24, 0x65, 0x31, 0xa5, 0x00, 0x56, 0x4c, 0x12, 0x24, 0xa8, 0x9a, 0x30, \n\t0xd2, 0x05, 0x28, 0x53, 0x49, 0x05, 0xc1, 0x4b, 0x60, 0x50, 0x94, 0x11, 0x2c, 0x10, 0x91, 0x02, \n\t0x14, 0xf2, 0xa3, 0x23, 0xdc, 0x98, 0x28, 0x04, 0x43, 0x20, 0x23, 0xd8, 0x00, 0x20, 0x0e, 0x03, \n\t0x20, 0x30, 0x6c, 0x54, 0x04, 0x12, 0x81, 0x01, 0x84, 0x60, 0x54, 0x20, 0x24, 0x11, 0xba, 0xa5, \n\t0x08, 0x0a, 0xc9, 0x40, 0x83, 0x28, 0x2e, 0x39, 0x14, 0x82, 0x52, 0x01, 0x1a, 0x00, 0x81, 0x05, \n\t0x45, 0x2a, 0xa0, 0x18, 0x20, 0x40, 0x42, 0x01, 0x48, 0x00, 0x82, 0xbd, 0x80, 0x12, 0x61, 0x00, \n\t0x31, 0x01, 0x81, 0x08, 0x52, 0x05, 0x62, 0x00, 0x08, 0x18, 0x28, 0xc0, 0x40, 0x08, 0x90, 0x58, \n\t0x06, 0xb1, 0x92, 0x82, 0x60, 0x95, 0x10, 0x36, 0x00, 0x01, 0x05, 0x00, 0x10, 0xa8, 0x81, 0x11, \n\t0x8f, 0x46, 0x38, 0x10, 0x02, 0x30, 0x48, 0x06, 0x22, 0x4a, 0x21, 0x51, 0x21, 0x2d, 0x8c, 0x80, \n\t0x00, 0x25, 0x88, 0xac, 0x51, 0x10, 0x4a, 0x04, 0x87, 0x82, 0x02, 0x0c, 0x08, 0x0b, 0x1c, 0x30, \n\t0x28, 0x12, 0xc0, 0x80, 0x0d, 0x60, 0x82, 0x40, 0xb8, 0x80, 0x91, 0x45, 0x70, 0x44, 0x41, 0x0a, \n\t0xc0, 0x40, 0xa0, 0x16, 0x84, 0x1a, 0x2c, 0x84, 0xc6, 0x09, 0x44, 0x23, 0x0b, 0xad, 0x41, 0x16, \n\t0xc2, 0x70, 0x10, 0x22, 0x1c, 0x15, 0x02, 0xc1, 0x20, 0x86, 0x08, 0x21, 0x44, 0x89, 0xe2, 0x4a, \n\t0x12, 0x01, 0xb1, 0x80, 0x11, 0x08, 0x48, 0x01, 0x48, 0x80, 0x60, 0x12, 0x28, 0x22, 0x07, 0x60, \n\t0xaa, 0x38, 0x15, 0x4e, 0x74, 0x60, 0x02, 0x12, 0x38, 0x84, 0x05, 0x00, 0x87, 0x41, 0xa0, 0x20, \n\t0x4d, 0xc1, 0x02, 0x36, 0x82, 0x0c, 0x28, 0x89, 0x44, 0x36, 0x90, 0x28, 0x18, 0x79, 0x45, 0xa0, \n\t0x00, 0x16, 0xd0, 0x04, 0x30, 0x41, 0xe5, 0x12, 0x81, 0x10, 0xa0, 0x98, 0x02, 0x84, 0x48, 0x40, \n\t0x80, 0x83, 0x90, 0xda, 0x00, 0x60, 0x00, 0xa8, 0x93, 0x20, 0x00, 0x80, 0x5a, 0x50, 0x82, 0x03, \n\t0x20, 0x50, 0x04, 0x4c, 0x70, 0x28, 0xa5, 0xc4, 0x08, 0xa1, 0x10, 0x80, 0x93, 0x80, 0x88, 0x14, \n\t0x26, 0x72, 0x57, 0xca, 0x13, 0x80, 0x41, 0x02, 0x30, 0x81, 0x68, 0x10, 0x41, 0x19, 0x4e, 0x58, \n\t0x02, 0x43, 0xb8, 0x80, 0x0c, 0x00, 0x40, 0x66, 0x31, 0x14, 0x09, 0x80, 0x08, 0x44, 0x22, 0x03, \n\t0x08, 0xc8, 0x02, 0x01, 0x40, 0x20, 0xc9, 0x27, 0x11, 0x12, 0x25, 0x14, 0x11, 0x82, 0x06, 0x90, \n\t0xc0, 0xca, 0x02, 0x44, 0x02, 0x00, 0x09, 0x85, 0xa0, 0x5a, 0x42, 0x90, 0x05, 0x00, 0x53, 0x88, \n\t0x0c, 0x04, 0xd9, 0x90, 0xe1, 0x87, 0x03, 0x2c, 0x40, 0x21, 0x18, 0x44, 0x11, 0x28, 0x62, 0xb0, \n\t0x5a, 0x20, 0x44, 0x0e, 0x0e, 0x22, 0x10, 0x01, 0x24, 0xe1, 0x90, 0x08, 0x72, 0x12, 0x00, 0x00, \n\t0x8c, 0x40, 0x04, 0x06, 0x46, 0x10, 0x0b, 0x08, 0x04, 0x2a, 0x6a, 0x84, 0x00, 0x25, 0x84, 0x40, \n\t0x01, 0x06, 0x03, 0x19, 0xa4, 0x51, 0x10, 0x2d, 0x20, 0x93, 0x23, 0x82, 0xcc, 0x1a, 0xc2, 0x2a, \n\t0x40, 0x00, 0x10, 0x45, 0x95, 0x05, 0x52, 0x40, 0x08, 0x0c, 0x00, 0x48, 0x00, 0x10, 0x24, 0x2a, \n\t0x33, 0x41, 0xcb, 0x61, 0x08, 0x22, 0x40, 0x3e, 0x08, 0x4d, 0x23, 0x20, 0x40, 0xca, 0x88, 0x08, \n\t0x03, 0x4b, 0x14, 0xc2, 0x21, 0x8b, 0x91, 0x81, 0x48, 0x4a, 0x45, 0x82, 0x24, 0xa0, 0x0f, 0x0c, \n\t0x46, 0x10, 0x8b, 0x85, 0x11, 0x04, 0x0d, 0x28, 0x92, 0x62, 0x00, 0xb1, 0x06, 0x46, 0x06, 0x42, \n\t0x90, 0x00, 0x74, 0x1e, 0xec, 0x40, 0x82, 0x90, 0x9a, 0x4d, 0xc8, 0x2e, 0x04, 0xb7, 0x90, 0x08, \n\t0x7d, 0x82, 0x01, 0x20, 0xc7, 0x30, 0x03, 0x68, 0x90, 0x08, 0x28, 0x00, 0x28, 0x05, 0x14, 0x04, \n\t0xa9, 0x20, 0x04, 0x61, 0x04, 0xb1, 0x44, 0x01, 0x50, 0x91, 0x11, 0x90, 0xa0, 0x4a, 0xe4, 0x06, \n\t0x84, 0x08, 0x0d, 0x01, 0x18, 0x4b, 0x08, 0x25, 0x62, 0x80, 0x08, 0x05, 0x08, 0x10, 0x52, 0x2b, \n\t0x88, 0x90, 0x41, 0x00, 0x6a, 0x06, 0x12, 0x21, 0xc0, 0x00, 0xe2, 0x00, 0x03, 0xd0, 0x06, 0x40, \n\t0x0c, 0x61, 0x14, 0x44, 0x62, 0x30, 0x04, 0x18, 0x62, 0x08, 0x81, 0x10, 0x13, 0x3c, 0x1b, 0xc6, \n\t0x02, 0x06, 0x73, 0x95, 0xa5, 0x88, 0x2a, 0x48, 0x40, 0x0a, 0xb0, 0x79, 0x10, 0x49, 0x02, 0xa5, \n\t0xa0, 0x26, 0x70, 0x19, 0x43, 0x26, 0x80, 0x09, 0x23, 0x60, 0xc0, 0x84, 0x00, 0x21, 0x49, 0xac, \n\t0x10, 0x14, 0xc6, 0x68, 0x54, 0x43, 0xab, 0x30, 0x44, 0x41, 0x06, 0xa5, 0xf8, 0x08, 0x40, 0x4a, \n\t0x20, 0x14, 0x20, 0x20, 0x14, 0x89, 0x40, 0xa2, 0x46, 0x62, 0x08, 0x05, 0xb9, 0x10, 0xa1, 0x10, \n\t0x10, 0x81, 0x0c, 0xc1, 0x40, 0x86, 0x42, 0x06, 0x0a, 0x9a, 0x50, 0x45, 0x24, 0x30, 0x91, 0x20, \n\t0xa2, 0x08, 0x84, 0x20, 0x3e, 0x00, 0x61, 0x23, 0xf4, 0x42, 0x89, 0x70, 0x42, 0x22, 0xa0, 0x9c, \n\t0x58, 0x8d, 0x44, 0x25, 0x81, 0xb8, 0x14, 0xce, 0x20, 0x24, 0x21, 0x60, 0x81, 0x14, 0x18, 0x47, \n\t0x50, 0x33, 0xc0, 0x02, 0x04, 0x89, 0x05, 0x30, 0xc4, 0x8a, 0x02, 0x29, 0x8e, 0x09, 0x40, 0x80, \n\t0x19, 0x20, 0x11, 0xc3, 0xc4, 0x08, 0x61, 0x32, 0xa4, 0x5c, 0x8a, 0x81, 0x20, 0x45, 0x02, 0x0b, \n\t0x41, 0xc3, 0xa9, 0x00, 0x82, 0x02, 0x1b, 0x40, 0xd9, 0x64, 0x60, 0x00, 0x70, 0x89, 0xa4, 0x8c, \n\t0x20, 0x2c, 0x05, 0x90, 0x02, 0x40, 0x8c, 0x09, 0x02, 0x64, 0x20, 0x96, 0x05, 0x45, 0xc0, 0x10, \n\t0x93, 0x40, 0x30, 0x31, 0x08, 0x88, 0x14, 0x00, 0x20, 0x11, 0x94, 0x0a, 0x8f, 0x02, 0x82, 0x0a, \n\t0x15, 0x0c, 0x0e, 0x24, 0x4c, 0x34, 0xda, 0x8e, 0x80, 0x10, 0x43, 0x22, 0x00, 0xe0, 0x0c, 0x81, \n\t0x00, 0x28, 0x16, 0x22, 0xb9, 0x0c, 0x95, 0x90, 0xaa, 0x18, 0x84, 0x52, 0x29, 0x10, 0x09, 0x41, \n\t0x20, 0x26, 0x9a, 0xa0, 0x41, 0x58, 0x80, 0x74, 0x40, 0x93, 0x0d, 0xa0, 0x90, 0x06, 0x30, 0x10, \n\t0xa3, 0x82, 0x81, 0x12, 0x80, 0x56, 0xa7, 0x50, 0x00, 0x10, 0x41, 0xcd, 0x00, 0xa7, 0x00, 0xa2, \n\t0x08, 0xcc, 0x06, 0x0e, 0xb1, 0x41, 0x36, 0x91, 0x08, 0xc4, 0x20, 0x40, 0xc2, 0xb1, 0xa0, 0x1d, \n\t0x24, 0x6c, 0x62, 0x42, 0x87, 0xb0, 0x1a, 0x0b, 0x42, 0x94, 0xb8, 0x21, 0x34, 0x07, 0x0a, 0x42, \n\t0x80, 0xd8, 0x80, 0x20, 0x02, 0xc6, 0x04, 0xe3, 0x00, 0x32, 0xd0, 0x00, 0x80, 0x66, 0xc1, 0x22, \n\t0x0c, 0x29, 0xca, 0x40, 0x08, 0x84, 0x29, 0x06, 0x25, 0x00, 0x26, 0x3c, 0x11, 0x18, 0x01, 0x84, \n\t0x08, 0x80, 0x24, 0x20, 0x42, 0x98, 0x84, 0x41, 0x20, 0x20, 0x24, 0x10, 0x8b, 0x1c, 0x43, 0x60, \n\t0x02, 0x14, 0x00, 0x27, 0x30, 0x94, 0x8d, 0x52, 0x84, 0x08, 0x14, 0x18, 0x05, 0x20, 0x38, 0x22, \n\t0xa1, 0x90, 0xa1, 0x0a, 0xcc, 0x0c, 0x00, 0x61, 0x01, 0x64, 0x57, 0x2d, 0x4c, 0x40, 0x01, 0xac, \n\t0x08, 0x16, 0x81, 0x10, 0xb1, 0xc3, 0x10, 0x4d, 0x49, 0x25, 0x46, 0x56, 0x18, 0x24, 0x38, 0x01, \n\t0x04, 0x00, 0x53, 0x80, 0x25, 0x65, 0x18, 0xa2, 0x12, 0x10, 0x13, 0xa0, 0x05, 0x89, 0x62, 0x48, \n\t0x24, 0x29, 0xa8, 0x00, 0x00, 0x01, 0x60, 0x55, 0x42, 0x29, 0x84, 0xc5, 0x80, 0x1c, 0x01, 0x78, \n\t0xb8, 0x05, 0x55, 0x48, 0x32, 0xc0, 0x00, 0x00, 0x90, 0x90, 0x2c, 0x6a, 0xa1, 0x82, 0x0d, 0xe0, \n\t0x56, 0xc9, 0x18, 0x00, 0x10, 0x01, 0x50, 0x94, 0x44, 0x42, 0x90, 0x08, 0x04, 0xa4, 0x86, 0xa2, \n\t0x2c, 0x41, 0x51, 0x9a, 0x48, 0x1b, 0x87, 0x06, 0x21, 0x00, 0x1e, 0x40, 0xc8, 0x82, 0x42, 0x82, \n\t0x20, 0x09, 0x21, 0x94, 0x80, 0x28, 0x51, 0x39, 0x04, 0x8c, 0x10, 0x0b, 0x3a, 0x63, 0x20, 0x20, \n\t0x08, 0x10, 0xe6, 0x04, 0xc1, 0x51, 0x00, 0xa0, 0x48, 0x4e, 0x08, 0x81, 0x08, 0x26, 0xd1, 0x4b, \n\t0x06, 0x40, 0xf4, 0x22, 0x20, 0x18, 0x54, 0x61, 0x38, 0x36, 0xc9, 0x8a, 0x88, 0x12, 0x4c, 0x30, \n\t0x02, 0x13, 0x01, 0x10, 0x01, 0x05, 0x02, 0x22, 0x98, 0x80, 0xe5, 0x06, 0x24, 0x50, 0x12, 0x92, \n\t0x32, 0x48, 0x10, 0x65, 0x08, 0x55, 0x02, 0xa4, 0x28, 0x04, 0xa2, 0x0a, 0x57, 0x82, 0xb1, 0xc8, \n\t0x08, 0x82, 0x42, 0x04, 0x81, 0x12, 0x94, 0x04, 0x2b, 0x0c, 0x45, 0x83, 0x88, 0x40, 0x0c, 0x22, \n\t0x64, 0x10, 0x83, 0x32, 0x70, 0x00, 0x09, 0x10, 0x72, 0x61, 0x00, 0x44, 0x50, 0xc4, 0x12, 0x80, \n\t0x40, 0x02, 0x00, 0x02, 0x01, 0x22, 0x24, 0x69, 0x04, 0x49, 0x03, 0x07, 0x34, 0x00, 0x08, 0x00, \n\t0x01, 0x46, 0x29, 0x54, 0x12, 0x20, 0xa2, 0x40, 0x10, 0xca, 0x00, 0x12, 0x21, 0x91, 0x41, 0x10, \n\t0x80, 0x0e, 0x00, 0xa8, 0x08, 0x21, 0x42, 0x40, 0x4e, 0x05, 0x89, 0x28, 0x88, 0x49, 0x0c, 0x02, \n\t0x44, 0xca, 0x25, 0xb0, 0x13, 0xc8, 0x00, 0xc5, 0x91, 0xa0, 0x28, 0x11, 0x4e, 0x76, 0x42, 0x01, \n\t0x32, 0x11, 0xc6, 0x80, 0x00, 0xc2, 0x38, 0x14, 0x51, 0x81, 0xc3, 0x28, 0x41, 0x00, 0x1a, 0x2c, \n\t0x10, 0x41, 0x58, 0x80, 0x08, 0x17, 0x38, 0xd2, 0x27, 0x02, 0x00, 0x81, 0x1c, 0x90, 0x03, 0xc5, \n\t0x52, 0x91, 0x68, 0xa4, 0x09, 0x88, 0x03, 0x48, 0xc0, 0xd0, 0x05, 0x94, 0x00, 0x20, 0x68, 0x05, \n\t0x3a, 0xae, 0x0c, 0xc2, 0xe7, 0x0a, 0x84, 0x33, 0x84, 0x08, 0x48, 0x20, 0x50, 0x40, 0xd3, 0x05, \n\t0x30, 0xd5, 0xa8, 0x20, 0x03, 0x0b, 0x84, 0x98, 0x04, 0x22, 0x44, 0x25, 0x48, 0x01, 0x64, 0x0a, \n\t0x86, 0x14, 0x82, 0x51, 0x88, 0x80, 0x0a, 0x83, 0x30, 0xa6, 0x82, 0x0a, 0xa0, 0x1c, 0x01, 0x08, \n\t0xc1, 0xb8, 0x01, 0x48, 0x04, 0x6c, 0x4a, 0x86, 0x11, 0x0d, 0x8c, 0x91, 0x8c, 0x0c, 0x02, 0x50, \n\t0x07, 0xa4, 0x08, 0x43, 0x34, 0x56, 0x60, 0x20, 0x10, 0x08, 0x06, 0x68, 0xc4, 0x20, 0xae, 0x3c, \n\t0x81, 0x46, 0x0c, 0x10, 0x40, 0x81, 0x09, 0x80, 0xa2, 0x10, 0x41, 0x93, 0x33, 0x4c, 0x80, 0x21, \n\t0x0c, 0x80, 0xa2, 0x06, 0xc4, 0x00, 0xc5, 0x30, 0xf0, 0x19, 0x03, 0xd0, 0x00, 0xc1, 0x0e, 0x36, \n\t0x00, 0x0d, 0xd1, 0x8c, 0x02, 0x22, 0x13, 0xc8, 0x82, 0x18, 0x53, 0x20, 0x08, 0x84, 0x0a, 0x9a, \n\t0xd0, 0x53, 0x48, 0x00, 0x00, 0x00, 0x10, 0x1c, 0xc4, 0x20, 0x00, 0x90, 0x6a, 0x05, 0x18, 0x06, \n\t0x09, 0x44, 0x10, 0xb1, 0x95, 0x0c, 0x90, 0x05, 0x2e, 0x21, 0x80, 0x08, 0x49, 0x05, 0x00, 0x22, \n\t0x44, 0xc3, 0x10, 0x88, 0xdd, 0xa2, 0x42, 0x35, 0x29, 0x30, 0x45, 0x08, 0x21, 0x78, 0x40, 0x52, \n\t0x04, 0x40, 0x05, 0x6a, 0x10, 0x43, 0x02, 0x88, 0x65, 0x02, 0x42, 0x1e, 0xc0, 0x18, 0x82, 0x34, \n\t0xd0, 0x08, 0x28, 0x85, 0x4a, 0x83, 0x14, 0x02, 0x41, 0x10, 0x33, 0x03, 0x12, 0xa9, 0x1c, 0x0a, \n\t0x0c, 0x04, 0x82, 0x21, 0x1c, 0x86, 0x86, 0x06, 0xd3, 0x68, 0xab, 0xc1, 0x08, 0xc0, 0x40, 0x60, \n\t0xd2, 0x20, 0x10, 0x10, 0x0e, 0x06, 0xe0, 0xa8, 0x05, 0x21, 0x05, 0x81, 0x22, 0x43, 0x9a, 0x95, \n\t0x44, 0x99, 0x06, 0x04, 0x11, 0xf0, 0x31, 0xbc, 0x12, 0x22, 0x54, 0x80, 0x63, 0x36, 0x34, 0x04, \n\t0xc2, 0x40, 0xd1, 0x4a, 0x90, 0x20, 0xc9, 0x00, 0x18, 0x40, 0x50, 0x84, 0x81, 0xc0, 0x4b, 0x68, \n\t0x00, 0x21, 0x90, 0x28, 0xd7, 0x04, 0x20, 0x60, 0x20, 0x04, 0x20, 0x43, 0x41, 0x42, 0x20, 0x18, \n\t0x24, 0x94, 0xc7, 0x80, 0x08, 0x30, 0x03, 0x87, 0x40, 0x1c, 0x46, 0x14, 0x02, 0x20, 0xa6, 0xd5, \n\t0x88, 0x04, 0x20, 0x54, 0x20, 0x29, 0x35, 0x11, 0x87, 0x52, 0x40, 0x60, 0x23, 0xa5, 0x06, 0x0c, \n\t0x44, 0x24, 0x71, 0x20, 0x20, 0xd0, 0xe2, 0x08, 0x40, 0x89, 0x8c, 0x40, 0x18, 0x81, 0x10, 0x30, \n\t0x01, 0x01, 0x09, 0x03, 0x2f, 0x20, 0x34, 0x18, 0x1c, 0x14, 0x8a, 0x0c, 0x58, 0xa0, 0x01, 0xa8, \n\t0x94, 0x47, 0x40, 0x30, 0x04, 0x42, 0x13, 0x99, 0x00, 0x2b, 0x18, 0x20, 0xf2, 0x35, 0x2c, 0x84, \n\t0x40, 0x52, 0x20, 0x83, 0x0c, 0x54, 0x88, 0x20, 0x4c, 0x62, 0xa0, 0x04, 0x15, 0x99, 0xec, 0x0e, \n\t0xa3, 0x02, 0x14, 0x21, 0x40, 0x60, 0x0a, 0x42, 0xe2, 0x80, 0x20, 0x91, 0x08, 0x2e, 0x40, 0x3a, \n\t0x22, 0xbc, 0x02, 0x22, 0x46, 0xc1, 0x60, 0x18, 0x89, 0x4c, 0xa4, 0x02, 0x90, 0x42, 0x20, 0x00, \n\t0xc3, 0xe8, 0x04, 0x10, 0x31, 0x24, 0x44, 0x87, 0x4d, 0x1a, 0x02, 0xa9, 0x0b, 0x90, 0x08, 0x2d, \n\t0x42, 0xd6, 0x6a, 0x10, 0x91, 0x10, 0x0c, 0x42, 0xa4, 0x02, 0x09, 0x48, 0x01, 0x40, 0x42, 0x51, \n\t0x82, 0x00, 0x9d, 0x04, 0xa0, 0x40, 0x36, 0x41, 0x20, 0x04, 0x51, 0x06, 0x46, 0x60, 0x8a, 0x0b, \n\t0x44, 0x01, 0x05, 0x10, 0x92, 0x11, 0x04, 0x21, 0x00, 0x88, 0x24, 0x05, 0x90, 0x13, 0x68, 0x00, \n\t0x43, 0x4c, 0x21, 0x62, 0x22, 0x80, 0x15, 0xa2, 0x14, 0x41, 0x80, 0x11, 0x44, 0x40, 0x82, 0x08, \n\t0x02, 0x40, 0x93, 0x00, 0x52, 0x8e, 0x10, 0x52, 0x82, 0xa4, 0x2c, 0x4a, 0x45, 0x40, 0x04, 0xc0, \n\t0x09, 0xa8, 0x0d, 0x4a, 0x00, 0x12, 0x48, 0x34, 0x89, 0x03, 0xa3, 0x00, 0xb1, 0xe2, 0x28, 0x15, \n\t0x10, 0x09, 0x08, 0xe1, 0x03, 0x93, 0x04, 0x82, 0xa0, 0x46, 0xe2, 0xb0, 0x08, 0x00, 0xc6, 0x00, \n\t0x1c, 0x42, 0xc0, 0x32, 0x01, 0x57, 0x00, 0x02, 0x10, 0x32, 0x06, 0x1c, 0x43, 0x81, 0x5a, 0xc2, \n\t0x01, 0x8e, 0x55, 0x14, 0xab, 0x30, 0x14, 0x09, 0x03, 0x70, 0xc4, 0x23, 0x32, 0xa0, 0x21, 0xa2, \n\t0x44, 0x4d, 0x82, 0x08, 0xd4, 0x68, 0x2a, 0x8c, 0x11, 0x60, 0x06, 0x64, 0x00, 0x16, 0x90, 0x82, \n\t0xa4, 0x00, 0x00, 0x02, 0x09, 0x29, 0x11, 0x4c, 0x44, 0x00, 0x29, 0x05, 0xf0, 0x16, 0x44, 0x50, \n\t0xa0, 0x21, 0x15, 0x1c, 0x49, 0xac, 0x20, 0x42, 0xb8, 0x80, 0x09, 0x48, 0x23, 0x50, 0x44, 0x6a, \n\t0x21, 0x41, 0xc8, 0x80, 0x20, 0x34, 0xe8, 0xb0, 0x09, 0x18, 0x02, 0x00, 0x20, 0x99, 0xb0, 0x45, \n\t0x04, 0x05, 0x04, 0x74, 0x08, 0x10, 0xe1, 0x02, 0x05, 0x0a, 0xc3, 0x40, 0x82, 0xd1, 0x94, 0x00, \n\t0x08, 0x33, 0x42, 0x25, 0xa0, 0x19, 0x40, 0x56, 0x20, 0x20, 0x11, 0xc8, 0x8a, 0x0c, 0x06, 0x86, \n\t0x58, 0x08, 0xc0, 0x04, 0xa3, 0x18, 0xa1, 0x72, 0x80, 0x51, 0x04, 0x88, 0x10, 0x00, 0xa1, 0x14, \n\t0x14, 0x02, 0xec, 0x44, 0x67, 0x02, 0x18, 0x48, 0x11, 0x41, 0x32, 0x00, 0x08, 0x23, 0x08, 0x1b, \n\t0x22, 0x60, 0x60, 0x98, 0x24, 0x10, 0x40, 0xc1, 0x6a, 0x45, 0x48, 0x2a, 0xf4, 0x40, 0x07, 0x42, \n\t0x06, 0x58, 0x98, 0x80, 0x85, 0x62, 0x20, 0x02, 0x31, 0xbb, 0x04, 0x13, 0x82, 0x60, 0x52, 0x0b, \n\t0x91, 0x24, 0x01, 0x61, 0x0c, 0x80, 0x0b, 0x01, 0x20, 0x8c, 0x2c, 0x3c, 0x00, 0x50, 0x31, 0x00, \n\t0x51, 0x48, 0x1a, 0x02, 0x20, 0x22, 0x0d, 0x80, 0xc4, 0x28, 0x06, 0x82, 0x09, 0xcc, 0x43, 0x4d, \n\t0x0a, 0xa1, 0x02, 0x1a, 0x05, 0x86, 0x82, 0x5a, 0x12, 0x62, 0xa4, 0x68, 0x09, 0x0e, 0x20, 0x44, \n\t0x09, 0x10, 0x50, 0x05, 0x89, 0x0a, 0x23, 0x28, 0x0c, 0x94, 0x05, 0x22, 0x40, 0x01, 0x12, 0x02, \n\t0x10, 0x80, 0x21, 0x02, 0x45, 0x08, 0x20, 0xa0, 0x08, 0x02, 0x1a, 0x55, 0xe0, 0x9d, 0x04, 0x51, \n\t0x09, 0x1c, 0x14, 0x23, 0x8a, 0xc1, 0x00, 0x64, 0x36, 0x20, 0xa2, 0x19, 0xd5, 0x42, 0x2c, 0x14, \n\t0x72, 0x40, 0x80, 0x90, 0x0a, 0x2e, 0x54, 0x06, 0x92, 0x26, 0xc0, 0x81, 0x61, 0x00, 0x40, 0x00, \n\t0x25, 0x68, 0x83, 0xa6, 0x34, 0x01, 0xa0, 0x01, 0x85, 0x50, 0x0a, 0x10, 0x65, 0x81, 0x87, 0x49, \n\t0x1a, 0x02, 0x12, 0xa1, 0x38, 0x94, 0x60, 0x48, 0x86, 0x20, 0x62, 0x08, 0x80, 0xe8, 0x09, 0x05, \n\t0x00, 0xf1, 0x21, 0x01, 0xc1, 0x97, 0x48, 0x60, 0xd5, 0x8a, 0x08, 0xa8, 0x10, 0x00, 0x00, 0x01, \n\t0x30, 0x04, 0x68, 0x08, 0x01, 0x1e, 0x80, 0x08, 0x09, 0x94, 0x07, 0x81, 0x00, 0x10, 0x90, 0x20, \n\t0x88, 0x12, 0x85, 0x4c, 0x56, 0x01, 0x06, 0x5d, 0x48, 0x60, 0x46, 0x02, 0x2a, 0x85, 0x40, 0x50, \n\t0x60, 0x10, 0x01, 0x02, 0xaf, 0xa8, 0x58, 0x0e, 0x4a, 0x60, 0xa0, 0x15, 0x11, 0x9d, 0x22, 0x28, \n\t0x86, 0x41, 0xb0, 0x74, 0x48, 0xa8, 0x64, 0x03, 0x02, 0x08, 0xa5, 0x02, 0x0b, 0x06, 0xb1, 0x38, \n\t0x09, 0x40, 0xd4, 0x07, 0x20, 0x84, 0x2a, 0x96, 0x2c, 0x93, 0x08, 0x50, 0x50, 0x69, 0x03, 0xb0, \n\t0x95, 0x0f, 0x70, 0x94, 0xea, 0x30, 0x00, 0x00, 0xe7, 0x02, 0x00, 0x50, 0x01, 0x19, 0x84, 0x86, \n\t0x10, 0x25, 0x02, 0x32, 0x88, 0xc9, 0xc3, 0x24, 0x31, 0xb8, 0x04, 0x24, 0x11, 0x01, 0x30, 0x94, \n\t0x11, 0x0e, 0x20, 0x49, 0x80, 0x12, 0x05, 0x10, 0xa0, 0x90, 0x9e, 0x23, 0x7c, 0x04, 0x18, 0x08, \n\t0x41, 0x08, 0x2c, 0x04, 0x03, 0xc2, 0x93, 0x05, 0x05, 0x08, 0x32, 0x92, 0x18, 0x03, 0xe0, 0x4c, \n\t0x41, 0x0a, 0x02, 0xa2, 0x9c, 0x0c, 0x16, 0x24, 0x18, 0x42, 0x49, 0x18, 0x20, 0x5a, 0x02, 0x40, \n\t0x24, 0x72, 0x19, 0x84, 0x82, 0x45, 0x58, 0x40, 0x29, 0x04, 0x40, 0x08, 0x04, 0x20, 0x73, 0xa0, \n\t0xae, 0x89, 0x59, 0x06, 0x00, 0x80, 0x30, 0x86, 0x30, 0x8d, 0x80, 0x64, 0x06, 0x62, 0x10, 0x08, \n\t0x46, 0x82, 0x40, 0x41, 0x3a, 0x81, 0x8c, 0x47, 0x00, 0x22, 0x42, 0x3b, 0x04, 0x44, 0x11, 0xa1, \n\t0x22, 0xf0, 0xc2, 0x81, 0x10, 0x44, 0x8b, 0x3a, 0x13, 0x41, 0x00, 0xb1, 0x41, 0x42, 0x68, 0x92, \n\t0xe1, 0x04, 0xa4, 0x53, 0x28, 0x00, 0xc4, 0x10, 0x92, 0x69, 0x40, 0x02, 0x16, 0x24, 0xf1, 0x24, \n\t0x2c, 0x50, 0x02, 0x4c, 0x61, 0xa0, 0xa0, 0x10, 0x0e, 0x89, 0x00, 0x41, 0x82, 0xb9, 0x98, 0x90, \n\t0x0e, 0x02, 0xb1, 0x18, 0x1d, 0x20, 0x98, 0x81, 0x10, 0x85, 0x00, 0x98, 0x20, 0x80, 0x02, 0x2a, \n\t0x00, 0x01, 0x12, 0x88, 0x03, 0x42, 0x52, 0x60, 0x70, 0x24, 0x4c, 0x1c, 0x0a, 0x34, 0x72, 0x01, \n\t0x22, 0x61, 0x43, 0x81, 0x10, 0x12, 0x18, 0x92, 0x20, 0x12, 0x00, 0x5a, 0x95, 0x68, 0x20, 0x84, \n\t0x8e, 0x45, 0x26, 0x82, 0x00, 0x8f, 0x30, 0x8c, 0x40, 0x00, 0xb2, 0x01, 0x00, 0x2c, 0x40, 0x80, \n\t0x0c, 0x03, 0x09, 0x80, 0x0c, 0x06, 0x6a, 0x28, 0xc4, 0xf3, 0x8d, 0x99, 0x08, 0x00, 0x04, 0x52, \n\t0x1a, 0xac, 0x04, 0x1b, 0x80, 0x08, 0xc0, 0x39, 0x23, 0x2c, 0x16, 0x0c, 0x62, 0x01, 0xc9, 0x02, \n\t0x24, 0x14, 0xe2, 0x26, 0x60, 0x81, 0x82, 0x80, 0x51, 0x48, 0x72, 0x61, 0x00, 0x92, 0x79, 0x02, \n\t0x86, 0x30, 0xe0, 0x48, 0x21, 0xc4, 0x13, 0x00, 0x50, 0x17, 0x28, 0x29, 0x88, 0x05, 0x09, 0x4c, \n\t0x84, 0x9a, 0x93, 0xc1, 0xc2, 0x61, 0x06, 0x80, 0xc3, 0x04, 0x60, 0x54, 0x0b, 0x18, 0x00, 0xd8, \n\t0x85, 0xc0, 0x88, 0x29, 0x38, 0x10, 0x41, 0x05, 0x50, 0x0a, 0xc6, 0x26, 0x54, 0x80, 0x10, 0x08, \n\t0x0a, 0x65, 0x58, 0x00, 0x81, 0x81, 0x64, 0x80, 0xa8, 0x40, 0x21, 0x91, 0x24, 0x01, 0x5c, 0x09, \n\t0x4c, 0x00, 0x13, 0x16, 0x18, 0x14, 0x0a, 0x42, 0xa0, 0x98, 0x00, 0x48, 0xcd, 0x08, 0x20, 0x86, \n\t0x11, 0x20, 0x00, 0xc4, 0x81, 0x2a, 0xb1, 0x00, 0x88, 0x24, 0x4d, 0x40, 0x0e, 0x84, 0x10, 0x0e, \n\t0x19, 0xda, 0x01, 0x50, 0x36, 0x18, 0x0c, 0x88, 0x86, 0x0c, 0x54, 0xc2, 0x02, 0x09, 0x0d, 0x00, \n\t0x21, 0x38, 0x11, 0x30, 0x88, 0x90, 0x42, 0x8f, 0x08, 0x07, 0x00, 0xae, 0x10, 0x04, 0x00, 0x2a, \n\t0xc6, 0x23, 0x16, 0x45, 0x50, 0x80, 0x0a, 0x50, 0x2a, 0x92, 0x95, 0x58, 0xe0, 0x28, 0x60, 0x81, \n\t0x18, 0x00, 0x54, 0xae, 0x10, 0xf0, 0x00, 0xa9, 0x40, 0x0d, 0x4d, 0x0a, 0x12, 0x58, 0x27, 0x10, \n\t0x01, 0x82, 0x2a, 0x50, 0x08, 0x24, 0x0c, 0x49, 0x68, 0x50, 0xa0, 0x48, 0x94, 0x00, 0xdb, 0x40, \n\t0x00, 0x00, 0x02, 0x11, 0x04, 0x86, 0x25, 0x4c, 0x03, 0x8a, 0x04, 0x04, 0x00, 0x28, 0x5c, 0x53, \n\t0x03, 0x25, 0x00, 0xd0, 0x26, 0x0a, 0x24, 0x28, 0x00, 0x69, 0xd8, 0x00, 0x24, 0x53, 0x50, 0x8e, \n\t0xc0, 0x44, 0x86, 0x0e, 0x20, 0xc1, 0x13, 0x01, 0x9c, 0x29, 0x28, 0x86, 0xc0, 0x14, 0x2d, 0x45, \n\t0x60, 0x02, 0x90, 0x80, 0x01, 0xe9, 0x41, 0x4c, 0x22, 0x84, 0x20, 0x92, 0xc1, 0x92, 0x0e, 0x50, \n\t0x16, 0x48, 0xa1, 0x08, 0xd0, 0x00, 0x20, 0xc0, 0x40, 0x09, 0x40, 0x01, 0x41, 0x6c, 0x12, 0x10, \n\t0x24, 0x15, 0x82, 0x8a, 0x14, 0xe0, 0xe1, 0xaa, 0xb8, 0x18, 0x45, 0x10, 0x50, 0x60, 0x21, 0x09, \n\t0x08, 0xc7, 0x04, 0x06, 0x18, 0x24, 0x40, 0x04, 0x21, 0x08, 0x07, 0x93, 0xb3, 0x05, 0x12, 0x20, \n\t0x00, 0x20, 0x91, 0x15, 0x28, 0x48, 0x29, 0x04, 0xc0, 0x18, 0x04, 0x60, 0x48, 0xa4, 0x44, 0xa2, \n\t0x0a, 0x08, 0x88, 0x88, 0x05, 0x26, 0x00, 0x00, 0xb4, 0xc4, 0x10, 0x8c, 0x30, 0x12, 0xe8, 0x90, \n\t0x10, 0x15, 0x49, 0x04, 0xa0, 0x21, 0x80, 0x70, 0x52, 0x24, 0x0a, 0xb4, 0x90, 0x05, 0x34, 0x80, \n\t0xc9, 0x4a, 0xd0, 0x0b, 0x09, 0x18, 0x82, 0x42, 0x7c, 0x23, 0x61, 0x0c, 0x0c, 0x88, 0x44, 0x04, \n\t0x93, 0xb0, 0x28, 0x3c, 0x0d, 0xa0, 0x32, 0x84, 0x6a, 0x0a, 0xa1, 0xc7, 0x06, 0x26, 0x01, 0x4a, \n\t0x22, 0x15, 0x44, 0x81, 0x14, 0x02, 0x19, 0x28, 0x4c, 0x00, 0x00, 0x10, 0x10, 0x82, 0x98, 0x04, \n\t0x02, 0x29, 0x28, 0xe0, 0x60, 0x0b, 0x01, 0x0b, 0x8a, 0x28, 0x04, 0x00, 0x85, 0x80, 0xc1, 0x08, \n\t0x1e, 0x76, 0x80, 0x01, 0xb0, 0x42, 0x2e, 0x0c, 0x12, 0x30, 0x09, 0x10, 0x15, 0xec, 0x40, 0xa3, \n\t0x02, 0x81, 0x01, 0x90, 0x8d, 0x44, 0xa3, 0xd1, 0x04, 0x14, 0x00, 0x67, 0x00, 0xc2, 0x80, 0x02, \n\t0x60, 0x8f, 0xc4, 0x06, 0x90, 0x18, 0x34, 0xc8, 0x8d, 0x06, 0x20, 0x01, 0x30, 0x20, 0x3c, 0x08, \n\t0x40, 0x00, 0xe4, 0x49, 0x12, 0xcc, 0x08, 0x41, 0x02, 0xf0, 0x08, 0x31, 0x04, 0x02, 0x40, 0x00, \n\t0x04, 0x21, 0x84, 0xa1, 0xd2, 0x43, 0x42, 0x84, 0x09, 0x03, 0x38, 0xda, 0x01, 0x18, 0x24, 0x80, \n\t0x83, 0x31, 0x92, 0xac, 0x00, 0xb0, 0x4b, 0x00, 0xe1, 0xc1, 0x08, 0x44, 0x03, 0x03, 0x00, 0x81, \n\t0x14, 0x82, 0x04, 0x12, 0x60, 0x09, 0x44, 0x11, 0x23, 0x46, 0x24, 0xa0, 0x2c, 0x05, 0x82, 0x82, \n\t0x08, 0xc6, 0x3b, 0xb4, 0x40, 0x04, 0x26, 0x28, 0x15, 0x60, 0x87, 0x10, 0x83, 0x80, 0x04, 0x02, \n\t0x11, 0x2e, 0x1c, 0x48, 0x4d, 0x74, 0x65, 0xc2, 0x92, 0x10, 0x0d, 0x29, 0x08, 0x00, 0x01, 0x01, \n\t0x14, 0xc3, 0x82, 0x38, 0x93, 0x62, 0x00, 0x00, 0x58, 0x68, 0x10, 0x45, 0x03, 0x15, 0x40, 0x04, \n\t0xcd, 0x06, 0x94, 0xb0, 0x00, 0x01, 0x42, 0xe4, 0x0e, 0x42, 0x5a, 0x29, 0xb4, 0x0e, 0xe4, 0x60, \n\t0x10, 0x02, 0x08, 0xd0, 0x80, 0x0c, 0x40, 0x17, 0x82, 0xa5, 0x58, 0x00, 0x60, 0x1e, 0x11, 0x39, \n\t0x3b, 0x85, 0x00, 0x06, 0x76, 0x05, 0x00, 0xb0, 0xe8, 0x00, 0x8b, 0x40, 0x80, 0x38, 0x00, 0x00, \n\t0x50, 0x60, 0x20, 0x04, 0x13, 0x19, 0x28, 0x00, 0x44, 0x06, 0x11, 0x20, 0x1e, 0x30, 0x45, 0x0a, \n\t0x02, 0xf1, 0x8a, 0x12, 0x8c, 0x00, 0x68, 0x50, 0x70, 0x10, 0x0d, 0x81, 0x48, 0x24, 0x12, 0x04, \n\t0x20, 0x00, 0x11, 0x80, 0x2a, 0x58, 0x02, 0xcb, 0x81, 0xa0, 0x06, 0x47, 0x00, 0x44, 0xb1, 0x88, \n\t0x01, 0x42, 0x48, 0x28, 0xe3, 0x22, 0x00, 0x31, 0x51, 0x06, 0x2e, 0x90, 0xc1, 0x10, 0xc1, 0x49, \n\t0x28, 0x50, 0x64, 0x0b, 0x01, 0x00, 0x94, 0x80, 0x08, 0x82, 0x98, 0x38, 0x09, 0x55, 0xa1, 0x24, \n\t0x00, 0x01, 0x00, 0xe1, 0x44, 0x20, 0x1a, 0x13, 0x10, 0x11, 0x04, 0x5a, 0xc4, 0x00, 0x01, 0xc0, \n\t0x26, 0x0c, 0x05, 0x01, 0x6e, 0x32, 0x01, 0x09, 0xd9, 0x89, 0x82, 0x52, 0xa4, 0x62, 0x0c, 0x81, \n\t0x10, 0xcb, 0x10, 0x70, 0x61, 0x84, 0x24, 0x00, 0x03, 0x60, 0x80, 0xa0, 0xa8, 0x50, 0x48, 0x80, \n\t0x44, 0x63, 0x08, 0x84, 0x08, 0x46, 0xc1, 0x52, 0xc4, 0x81, 0x8c, 0x49, 0x92, 0x04, 0x28, 0x10, \n\t0x53, 0x22, 0x60, 0x45, 0x01, 0x5e, 0x25, 0xd8, 0x10, 0x58, 0x00, 0x6d, 0x02, 0x84, 0x03, 0xa1, \n\t0x3c, 0x48, 0x24, 0x32, 0x04, 0x68, 0x01, 0x20, 0x09, 0xc5, 0x00, 0xc1, 0x43, 0x8e, 0x30, 0x42, \n\t0x2c, 0x42, 0xd5, 0xb8, 0x11, 0x00, 0xc2, 0x40, 0x0a, 0x04, 0x2a, 0x30, 0x30, 0x82, 0x4c, 0x00, \n\t0xb3, 0xc0, 0x26, 0x0c, 0x04, 0xe2, 0x20, 0x10, 0xa1, 0x00, 0x90, 0x93, 0x21, 0x28, 0x45, 0x10, \n\t0x30, 0x15, 0x8f, 0x44, 0x46, 0x50, 0x20, 0x0d, 0x8d, 0x01, 0x28, 0x30, 0x65, 0x58, 0x92, 0xe0, \n\t0xc0, 0x8a, 0x08, 0x20, 0x92, 0x0c, 0x20, 0x11, 0x85, 0x42, 0x14, 0x42, 0x08, 0xc1, 0x88, 0xe0, \n\t0x22, 0x13, 0x00, 0x2c, 0x61, 0xd8, 0x49, 0x0a, 0x64, 0xc0, 0x04, 0x80, 0x53, 0x64, 0x04, 0x85, \n\t0xd1, 0x80, 0x59, 0x12, 0x80, 0x08, 0x82, 0x61, 0x09, 0x11, 0x44, 0x20, 0x0e, 0x00, 0x60, 0x0d, \n\t0x19, 0x08, 0x2c, 0x04, 0xa0, 0x10, 0x38, 0x84, 0x03, 0x8e, 0x44, 0x23, 0x98, 0x18, 0x00, 0x44, \n\t0x41, 0x50, 0x53, 0x78, 0x88, 0x09, 0x45, 0x86, 0x60, 0x30, 0x20, 0x00, 0x29, 0x00, 0xc3, 0x52, \n\t0x05, 0x9a, 0x28, 0xc9, 0x15, 0xc2, 0x10, 0x63, 0x50, 0xb2, 0x20, 0x04, 0x22, 0x0a, 0x86, 0x09, \n\t0x0c, 0x45, 0x03, 0x04, 0x32, 0xd0, 0x02, 0xa6, 0x30, 0x18, 0x28, 0x68, 0x02, 0x02, 0x0a, 0x30, \n\t0x51, 0x02, 0x08, 0x06, 0x60, 0x10, 0xd1, 0xc1, 0x82, 0x06, 0xd1, 0xa2, 0x0b, 0xf9, 0x00, 0x2e, \n\t0x18, 0xa4, 0x02, 0x80, 0x4c, 0x58, 0xa3, 0x40, 0x10, 0x80, 0x04, 0x1c, 0x52, 0x03, 0x22, 0x41, \n\t0x81, 0x21, 0x04, 0x06, 0x0c, 0x10, 0x60, 0x00, 0x02, 0x55, 0x13, 0x60, 0x14, 0x00, 0x38, 0x18, \n\t0x01, 0x00, 0x45, 0x02, 0x10, 0x53, 0x31, 0x48, 0x08, 0x20, 0x06, 0xa4, 0x48, 0xaf, 0x40, 0x47, \n\t0x41, 0x60, 0x00, 0x21, 0x1a, 0x28, 0x82, 0x68, 0x74, 0x22, 0x81, 0x9e, 0x18, 0xc9, 0xe4, 0x74, \n\t0xa4, 0x43, 0x01, 0x64, 0x12, 0x23, 0x56, 0xb1, 0x50, 0x00, 0xc0, 0x00, 0x06, 0x00, 0x64, 0xc1, \n\t0xa4, 0x80, 0x03, 0x40, 0x28, 0xc1, 0x80, 0x19, 0x51, 0x04, 0xc1, 0x40, 0x41, 0x90, 0x9d, 0xa1, \n\t0x0c, 0x04, 0x0e, 0x64, 0x10, 0x00, 0x14, 0x92, 0x40, 0x42, 0x61, 0xa1, 0x90, 0xd0, 0x08, 0x0d, \n\t0x30, 0x22, 0x08, 0x00, 0x44, 0x07, 0xe2, 0x34, 0xe4, 0x41, 0x98, 0x84, 0x08, 0x41, 0x08, 0x05, \n\t0x22, 0x0f, 0x30, 0xc0, 0x44, 0x08, 0x13, 0x28, 0x06, 0x80, 0x11, 0x29, 0x48, 0x10, 0x0a, 0x3d, \n\t0x89, 0x10, 0xc2, 0x40, 0x32, 0x10, 0x04, 0xa4, 0x08, 0xcc, 0x34, 0x55, 0x03, 0xac, 0xd0, 0xc2, \n\t0x80, 0x02, 0x86, 0x0a, 0xa5, 0x50, 0x54, 0x20, 0x50, 0x04, 0xaa, 0x02, 0x6c, 0x5a, 0xa2, 0x2c, \n\t0x51, 0xfb, 0x00, 0x39, 0x03, 0x09, 0x40, 0x04, 0x92, 0xb4, 0x0d, 0x44, 0x05, 0x10, 0x86, 0x89, \n\t0x28, 0x21, 0x42, 0x47, 0x0a, 0x12, 0x68, 0x1e, 0xa0, 0x81, 0x02, 0x20, 0xd0, 0x61, 0x2f, 0x00, \n\t0x44, 0x25, 0x20, 0x04, 0x02, 0x0a, 0x98, 0x9a, 0xa0, 0x20, 0x04, 0x00, 0x24, 0x2c, 0x80, 0x02, \n\t0x00, 0x02, 0x48, 0x08, 0x14, 0x92, 0xa0, 0x00, 0x00, 0x52, 0x19, 0x49, 0x92, 0x41, 0x00, 0x44, \n\t0x20, 0x82, 0x44, 0x01, 0x81, 0x4c, 0x57, 0x98, 0x07, 0xe0, 0x96, 0x20, 0x42, 0x31, 0x02, 0xb0, \n\t0x51, 0x0d, 0x69, 0x6c, 0x85, 0x68, 0x24, 0x08, 0x05, 0x04, 0x26, 0xc4, 0xd8, 0x92, 0x85, 0x07, \n\t0x86, 0x38, 0x61, 0x40, 0x82, 0x80, 0x08, 0x02, 0x10, 0x34, 0x02, 0x3d, 0x30, 0x82, 0x0c, 0x40, \n\t0x05, 0x2a, 0x08, 0x50, 0x00, 0x40, 0x18, 0x10, 0x60, 0x15, 0x21, 0x13, 0x60, 0x02, 0x91, 0x18, \n\t0xa4, 0x81, 0x0a, 0x8a, 0x48, 0x14, 0x70, 0x94, 0x81, 0x4b, 0xc0, 0x0e, 0xb5, 0x90, 0x1a, 0x14, \n\t0x48, 0x00, 0x40, 0x12, 0x48, 0x26, 0x6c, 0x00, 0x84, 0x18, 0x10, 0x00, 0x85, 0x70, 0x82, 0xe8, \n\t0x42, 0xa0, 0x22, 0x80, 0x11, 0x40, 0x2b, 0x02, 0x96, 0xc9, 0x88, 0x58, 0x84, 0x0f, 0x30, 0xc5, \n\t0x28, 0x36, 0xe0, 0xc6, 0x4a, 0x10, 0x15, 0x00, 0x18, 0x80, 0x51, 0x08, 0x20, 0x82, 0xb1, 0x11, \n\t0xc0, 0x10, 0x09, 0x12, 0x22, 0x03, 0x21, 0x69, 0x44, 0x0e, 0x40, 0x00, 0x09, 0x02, 0x50, 0x98, \n\t0x4f, 0x00, 0x00, 0xf1, 0x1b, 0x00, 0xc2, 0x28, 0x46, 0x73, 0x82, 0x02, 0x01, 0x09, 0x83, 0x00, \n\t0x81, 0x42, 0x93, 0x0c, 0xc1, 0x02, 0x16, 0x41, 0x80, 0x83, 0x00, 0x50, 0x02, 0x60, 0x00, 0xd2, \n\t0x14, 0xa0, 0x11, 0x2a, 0x70, 0x80, 0x00, 0x03, 0xe1, 0x8b, 0x80, 0x10, 0x95, 0x08, 0x21, 0x51, \n\t0x8f, 0x00, 0x3a, 0x21, 0x83, 0x8a, 0x20, 0x94, 0x40, 0x4c, 0x73, 0x03, 0x07, 0xa8, 0x08, 0x80, \n\t0x18, 0x06, 0xc0, 0x09, 0x45, 0x40, 0x24, 0x10, 0xa0, 0x42, 0xa2, 0xa4, 0x08, 0x04, 0x18, 0x42, \n\t0x41, 0x10, 0x59, 0x01, 0x88, 0x66, 0x05, 0x1a, 0x0f, 0x14, 0x86, 0x81, 0x66, 0xd0, 0x39, 0x00, \n\t0x0c, 0x80, 0x00, 0x70, 0x11, 0x21, 0x12, 0x08, 0xc0, 0xe1, 0x0a, 0x60, 0x09, 0x9c, 0x91, 0x0c, \n\t0xe2, 0x64, 0x25, 0x5a, 0x90, 0x10, 0x08, 0x89, 0x3c, 0x74, 0x71, 0x24, 0x44, 0x05, 0x46, 0x08, \n\t0x00, 0x80, 0x80, 0xa8, 0xd9, 0x01, 0x1c, 0xb6, 0xb1, 0x8a, 0x10, 0x09, 0xaa, 0x56, 0x82, 0x58, \n\t0x00, 0x01, 0x94, 0x2d, 0x14, 0x21, 0xa2, 0x03, 0x85, 0x94, 0x20, 0x28, 0x41, 0x52, 0x80, 0xc5, \n\t0x01, 0x23, 0x08, 0x25, 0x20, 0xb1, 0x40, 0x08, 0x03, 0x00, 0x05, 0xe0, 0x0c, 0x08, 0xc2, 0xa0, \n\t0x06, 0x25, 0xaa, 0x05, 0x54, 0x1f, 0x08, 0x28, 0x60, 0x00, 0x18, 0xed, 0x50, 0x02, 0x02, 0x71, \n\t0x10, 0x28, 0x21, 0x41, 0x6d, 0x10, 0x90, 0x70, 0x22, 0x25, 0x83, 0x81, 0x50, 0xb3, 0xe0, 0x3c, \n\t0x98, 0x06, 0x20, 0x10, 0x55, 0x4b, 0x90, 0xc1, 0xd0, 0xc1, 0x40, 0x02, 0x11, 0x00, 0xb4, 0x40, \n\t0x8c, 0x10, 0x00, 0x4a, 0xa2, 0x90, 0x0c, 0x64, 0x20, 0x10, 0xc3, 0x9b, 0x19, 0x90, 0x01, 0x00, \n\t0x12, 0x28, 0x81, 0x30, 0x0e, 0x86, 0x22, 0x46, 0x99, 0x81, 0x44, 0x1a, 0x08, 0x0c, 0x05, 0xa1, \n\t0x10, 0xf0, 0x0c, 0x21, 0x00, 0xe1, 0x32, 0x00, 0x58, 0x08, 0xe8, 0x00, 0x62, 0x83, 0x18, 0x00, \n\t0x82, 0x47, 0x12, 0x62, 0x59, 0x01, 0xa0, 0x19, 0x80, 0x00, 0x50, 0xa8, 0x38, 0x80, 0x50, 0x48, \n\t0x12, 0xe0, 0x43, 0x18, 0xc8, 0xc4, 0x07, 0x40, 0x02, 0xa0, 0x01, 0x91, 0x05, 0xa8, 0x48, 0x00, \n\t0xc3, 0x0d, 0x09, 0x86, 0xe2, 0x54, 0x50, 0x10, 0x01, 0x91, 0x1a, 0x48, 0x0c, 0x71, 0x10, 0xa9, \n\t0x25, 0x80, 0x84, 0x04, 0x95, 0x48, 0x1f, 0x00, 0xd0, 0x28, 0x04, 0x30, 0x01, 0x27, 0x64, 0x88, \n\t0xe8, 0x0c, 0x06, 0x18, 0xb2, 0xd4, 0x0c, 0xe7, 0x22, 0x06, 0x00, 0x00, 0xac, 0x00, 0x28, 0x12, \n\t0x30, 0x48, 0x38, 0x11, 0x09, 0x8e, 0x42, 0x20, 0xa0, 0x24, 0x10, 0x8e, 0x09, 0x32, 0x10, 0x58, \n\t0x09, 0xd8, 0x93, 0x88, 0x44, 0x32, 0x10, 0x00, 0x84, 0x14, 0x84, 0x12, 0x21, 0x2a, 0xa6, 0x34, \n\t0x82, 0x01, 0x24, 0x43, 0x42, 0x10, 0x01, 0x42, 0x69, 0x00, 0x11, 0xb0, 0x13, 0x48, 0x81, 0x23, \n\t0x44, 0xd2, 0x2a, 0x18, 0x48, 0xd3, 0x04, 0x22, 0x70, 0xa1, 0x04, 0xb0, 0x88, 0x63, 0x06, 0x01, \n\t0x0a, 0x30, 0x81, 0x54, 0x40, 0x60, 0xd0, 0x08, 0x80, 0x30, 0x80, 0x64, 0x1e, 0x04, 0x41, 0x20, \n\t0x30, 0x0a, 0x41, 0x70, 0xe6, 0xc1, 0x19, 0x8c, 0x4e, 0x08, 0x54, 0x11, 0xca, 0x80, 0x20, 0x84, \n\t0x4e, 0x02, 0x30, 0x4b, 0x04, 0x0c, 0x80, 0x09, 0x40, 0xc0, 0x18, 0x29, 0x81, 0x00, 0x0d, 0x64, \n\t0xc6, 0x81, 0x02, 0x00, 0x13, 0x88, 0x60, 0x11, 0x10, 0x2e, 0x48, 0x0e, 0x43, 0x72, 0x50, 0x0a, \n\t0x8a, 0x84, 0xc5, 0x22, 0x20, 0x11, 0x20, 0x83, 0xa1, 0x01, 0x2a, 0x5c, 0x06, 0x32, 0x0c, 0x48, \n\t0x49, 0x8d, 0x42, 0x86, 0x98, 0x08, 0x01, 0x83, 0x43, 0x30, 0x82, 0x50, 0x98, 0x81, 0x49, 0x0a, \n\t0x22, 0x41, 0x6a, 0x84, 0x04, 0x0b, 0x0c, 0x1c, 0x03, 0x42, 0x80, 0x30, 0x56, 0xc1, 0x1c, 0x06, \n\t0x80, 0x30, 0x00, 0x04, 0xa1, 0x0a, 0x23, 0xa0, 0x01, 0x45, 0x10, 0x41, 0x28, 0x90, 0x81, 0x17, \n\t0x5c, 0x89, 0x04, 0x2c, 0x90, 0x00, 0x23, 0x4d, 0xd0, 0x05, 0x20, 0x02, 0x90, 0x8a, 0x25, 0x8a, \n\t0x22, 0x2a, 0x05, 0x30, 0x11, 0xd4, 0x06, 0xa2, 0x44, 0x65, 0x0a, 0x10, 0xc8, 0x05, 0x63, 0x10, \n\t0x50, 0x88, 0x2a, 0x01, 0xc4, 0x29, 0x28, 0x10, 0x20, 0x15, 0x51, 0x58, 0x84, 0x00, 0x44, 0x42, \n\t0x08, 0x80, 0x84, 0x41, 0x00, 0x32, 0xd2, 0x94, 0x10, 0x0c, 0x20, 0x04, 0x06, 0xea, 0x14, 0x60, \n\t0xc2, 0x6a, 0x02, 0x92, 0x21, 0x80, 0xe8, 0x10, 0x0b, 0x44, 0xc5, 0x60, 0x2f, 0x1d, 0xd0, 0x84, \n\t0x08, 0x20, 0x02, 0x84, 0x29, 0x18, 0x06, 0x42, 0x41, 0x50, 0x14, 0x48, 0x02, 0x86, 0x56, 0x21, \n\t0x48, 0x14, 0x01, 0xdb, 0x82, 0x24, 0x80, 0x5b, 0xae, 0x3c, 0x40, 0x80, 0x22, 0x10, 0x53, 0x02, \n\t0xad, 0x0a, 0x20, 0x08, 0x02, 0x18, 0xa5, 0x80, 0x1c, 0x42, 0x60, 0x70, 0xc1, 0x01, 0x0c, 0x96, \n\t0x2c, 0x0e, 0x90, 0x08, 0x09, 0x81, 0x50, 0x2d, 0x26, 0x04, 0xaa, 0x29, 0xc5, 0x01, 0x46, 0x5c, \n\t0x10, 0x53, 0x2b, 0xa8, 0x84, 0x00, 0x38, 0x53, 0x00, 0x01, 0x15, 0x98, 0x86, 0x0a, 0xc2, 0xaa, \n\t0x89, 0x60, 0x4e, 0xa0, 0x52, 0x04, 0x73, 0x8c, 0x40, 0x8a, 0x08, 0x16, 0x50, 0xa2, 0xb1, 0x24, \n\t0x0a, 0x69, 0x42, 0x05, 0x71, 0x24, 0xa0, 0x11, 0x42, 0x04, 0x90, 0xc1, 0x0a, 0x18, 0x08, 0xc9, \n\t0x26, 0x80, 0x01, 0x20, 0x35, 0x4a, 0x08, 0x58, 0xd0, 0x00, 0x91, 0x00, 0x47, 0x04, 0x76, 0x10, \n\t0x00, 0x83, 0x08, 0x80, 0x89, 0x60, 0x34, 0x2a, 0x0d, 0x88, 0x03, 0x86, 0x02, 0x82, 0x80, 0x0c, \n\t0x45, 0x82, 0x01, 0x60, 0x35, 0x60, 0x00, 0x01, 0x03, 0x6c, 0x48, 0x86, 0x90, 0x19, 0x08, 0x09, \n\t0x00, 0x18, 0x54, 0x01, 0x83, 0xe0, 0x47, 0x04, 0x14, 0x40, 0xb9, 0x80, 0x1c, 0x50, 0xaa, 0x02, \n\t0x03, 0x80, 0x00, 0x50, 0x50, 0xa8, 0x10, 0xb3, 0x00, 0x38, 0x44, 0x04, 0xe2, 0x28, 0x10, 0x20, \n\t0x2c, 0x60, 0x18, 0x40, 0x40, 0xa3, 0x41, 0x16, 0x0c, 0x09, 0x40, 0x20, 0x31, 0x31, 0x04, 0x10, \n\t0x19, 0x45, 0x22, 0xa0, 0x08, 0x28, 0x84, 0x45, 0xe0, 0x08, 0x21, 0xe0, 0x83, 0x04, 0x10, 0x43, \n\t0x54, 0x01, 0x82, 0x08, 0x80, 0x82, 0x46, 0x22, 0xe4, 0x10, 0x80, 0x70, 0x02, 0x81, 0x38, 0x51, \n\t0x33, 0x0e, 0x20, 0xcc, 0x28, 0x12, 0x11, 0x91, 0x26, 0xe1, 0x0c, 0x09, 0x18, 0x63, 0x40, 0x00, \n\t0x68, 0x19, 0x8a, 0x24, 0x50, 0x4a, 0x20, 0x25, 0x0d, 0x24, 0x2c, 0x64, 0x70, 0x0e, 0x45, 0x1c, \n\t0x0c, 0x08, 0x94, 0x83, 0x30, 0x28, 0xd7, 0x24, 0x40, 0x52, 0x70, 0x07, 0x20, 0x06, 0x00, 0x52, \n\t0x00, 0x20, 0x29, 0x60, 0x40, 0x84, 0x52, 0x40, 0x12, 0x00, 0x99, 0x10, 0x8f, 0x48, 0x11, 0x01, \n\t0x9d, 0x8c, 0x80, 0x22, 0x0e, 0x83, 0x32, 0x20, 0x4d, 0xc4, 0x03, 0x10, 0x46, 0x22, 0x22, 0xa1, \n\t0x41, 0x08, 0x3c, 0x10, 0xa0, 0x94, 0xc1, 0x91, 0x08, 0x70, 0x62, 0x1b, 0xaa, 0x31, 0x0c, 0x83, \n\t0x50, 0x17, 0xc9, 0x28, 0xc9, 0x01, 0x01, 0x0c, 0x04, 0x68, 0x30, 0x34, 0x40, 0x02, 0x00, 0xc2, \n\t0x43, 0x01, 0x00, 0x13, 0x08, 0x18, 0x00, 0xe2, 0x1f, 0x81, 0x14, 0xaa, 0x4c, 0x30, 0x98, 0x20, \n\t0x20, 0x46, 0xc7, 0x0c, 0x02, 0xc1, 0x80, 0x60, 0x00, 0x81, 0x18, 0x10, 0xe0, 0x2a, 0x49, 0xc8, \n\t0x41, 0x02, 0x26, 0xa2, 0x08, 0x25, 0x8f, 0x20, 0x72, 0x41, 0x1a, 0x00, 0xe1, 0x08, 0x00, 0x1e, \n\t0x20, 0x80, 0x84, 0xc8, 0x01, 0x03, 0x60, 0x43, 0xb9, 0x18, 0x41, 0x10, 0x8c, 0x24, 0xe6, 0x08, \n\t0x8a, 0xbc, 0x02, 0x00, 0x36, 0x41, 0x58, 0xa8, 0xa0, 0xc1, 0x00, 0x02, 0x12, 0x80, 0x83, 0x28, \n\t0x18, 0x65, 0x70, 0xa0, 0x00, 0x01, 0x18, 0x08, 0xa8, 0x22, 0x94, 0x52, 0x30, 0x01, 0x06, 0x04, \n\t0x40, 0xc0, 0x23, 0x07, 0x35, 0x00, 0xaa, 0x10, 0x44, 0x52, 0x09, 0x0c, 0x58, 0xe3, 0x0c, 0x80, \n\t0x10, 0x10, 0x78, 0x00, 0x41, 0x44, 0x41, 0xc1, 0x04, 0x29, 0x99, 0xaa, 0x00, 0x30, 0xc1, 0x10, \n\t0x05, 0x54, 0x29, 0x50, 0xc4, 0x29, 0x84, 0x60, 0x08, 0x44, 0x22, 0x24, 0xd0, 0x21, 0xc8, 0x04, \n\t0x48, 0x0c, 0x25, 0x00, 0x30, 0x40, 0xc6, 0x83, 0x68, 0x36, 0x82, 0x07, 0x1c, 0x89, 0x29, 0x02, \n\t0x22, 0x90, 0x02, 0x41, 0x85, 0x88, 0x0e, 0x02, 0x01, 0x04, 0x58, 0x11, 0x6e, 0x00, 0xb1, 0x69, \n\t0x00, 0x75, 0x94, 0x08, 0x10, 0x02, 0x70, 0x23, 0x95, 0x42, 0xe3, 0x28, 0x82, 0x10, 0x89, 0x14, \n\t0x10, 0x02, 0x0c, 0x80, 0x11, 0x04, 0x21, 0x12, 0x02, 0x66, 0x01, 0x6b, 0x21, 0xc8, 0x0a, 0xc0, \n\t0x24, 0x01, 0xe0, 0x12, 0xdc, 0x04, 0x4e, 0x20, 0x06, 0x0b, 0xb2, 0x90, 0x47, 0x05, 0x0a, 0x05, \n\t0x41, 0xb1, 0x44, 0x41, 0x01, 0x58, 0x94, 0x02, 0x32, 0x9c, 0xc8, 0x28, 0x04, 0x25, 0x50, 0x86, \n\t0x20, 0x06, 0x8b, 0x4c, 0x10, 0x10, 0x0d, 0x8c, 0x40, 0xc4, 0x12, 0x10, 0x08, 0x24, 0x20, 0x80, \n\t0x05, 0x44, 0x12, 0x42, 0x2c, 0xd9, 0x00, 0x4a, 0x04, 0xa2, 0x80, 0xa4, 0x24, 0x0d, 0x46, 0x2e, \n\t0xc4, 0x7b, 0x33, 0x80, 0x54, 0x04, 0x6a, 0x00, 0x00, 0x00, 0x21, 0x40, 0xaa, 0x10, 0xe1, 0xe0, \n\t0xa4, 0x10, 0x51, 0x01, 0x06, 0x90, 0x90, 0xa0, 0xe8, 0x80, 0x05, 0x30, 0x71, 0x28, 0x14, 0xe5, \n\t0x82, 0x43, 0x10, 0xa4, 0x42, 0x90, 0x8c, 0x84, 0x01, 0x58, 0x10, 0x1a, 0x01, 0xb9, 0x06, 0x80, \n\t0x68, 0x82, 0x40, 0x0d, 0x08, 0x14, 0x2a, 0x4c, 0x41, 0xf8, 0xa2, 0x01, 0x10, 0x22, 0x00, 0xa0, \n\t0x20, 0x90, 0xd4, 0x8a, 0x44, 0x0a, 0x52, 0x90, 0xa7, 0x70, 0x41, 0x05, 0x40, 0x01, 0x08, 0x07, \n\t0x80, 0x4d, 0x04, 0x60, 0x40, 0xc8, 0x00, 0x58, 0x94, 0xa0, 0x34, 0x02, 0xe8, 0x08, 0x00, 0x5d, \n\t0x02, 0x04, 0xe1, 0x52, 0x80, 0x28, 0x88, 0x07, 0x1e, 0xd0, 0x18, 0x9d, 0x30, 0x5e, 0x84, 0x28, \n\t0x60, 0x01, 0xbc, 0xb4, 0x0a, 0x00, 0x0e, 0x00, 0x41, 0x10, 0x21, 0x48, 0x80, 0x02, 0x30, 0x51, \n\t0x1c, 0x81, 0x00, 0x68, 0x0a, 0xc1, 0x20, 0x2d, 0x15, 0x0c, 0x61, 0x00, 0xb0, 0xd0, 0x11, 0x11, \n\t0x51, 0x00, 0x60, 0x70, 0x80, 0xb2, 0x69, 0xc5, 0x81, 0x44, 0x82, 0x03, 0x00, 0x8d, 0x41, 0xa8, \n\t0x42, 0x01, 0xaa, 0x82, 0x80, 0x44, 0x4b, 0x72, 0x00, 0x0b, 0xb2, 0x00, 0x18, 0x26, 0x54, 0xc0, \n\t0xc8, 0xa0, 0x54, 0x89, 0x2a, 0x0a, 0x82, 0x29, 0x1b, 0x51, 0x04, 0xc2, 0x52, 0x01, 0xe1, 0x3b, \n\t0x04, 0x48, 0x24, 0x40, 0x83, 0xc1, 0x04, 0x20, 0x12, 0xce, 0x00, 0xa0, 0x03, 0x04, 0x08, 0x01, \n\t0x08, 0x50, 0xd0, 0xb0, 0x08, 0xa4, 0x04, 0x26, 0x00, 0x84, 0xa2, 0x92, 0x00, 0x41, 0xcc, 0x62, \n\t0x80, 0x28, 0x15, 0x61, 0xc4, 0x41, 0x1c, 0xd1, 0x3a, 0x32, 0xc1, 0x09, 0x22, 0x08, 0x51, 0x90, \n\t0x05, 0x0d, 0x13, 0x80, 0x50, 0x00, 0x8a, 0x18, 0x48, 0x00, 0x60, 0x24, 0xe4, 0x42, 0x02, 0xc4, \n\t0x07, 0x42, 0x04, 0x11, 0x41, 0x82, 0x40, 0x00, 0x0d, 0x3a, 0xc0, 0x42, 0x94, 0x9c, 0xc2, 0x44, \n\t0x2e, 0x47, 0x70, 0x98, 0x60, 0x09, 0x2a, 0x60, 0x00, 0x33, 0x25, 0x5c, 0x14, 0x20, 0x00, 0x11, \n\t0x01, 0x08, 0x28, 0x0c, 0x2a, 0x24, 0xc0, 0x12, 0x09, 0x94, 0x0b, 0x8b, 0x22, 0xc0, 0x10, 0x16, \n\t0x70, 0x80, 0x04, 0x30, 0x00, 0xc9, 0xa6, 0xa8, 0x59, 0xa2, 0x02, 0x10, 0x1a, 0x01, 0x94, 0xc7, \n\t0xc1, 0x42, 0xa0, 0x18, 0x32, 0x18, 0x55, 0x20, 0x40, 0x63, 0x00, 0x9a, 0x24, 0xc1, 0x08, 0x00, \n\t0x32, 0x29, 0x00, 0x45, 0x41, 0x89, 0x58, 0x72, 0x80, 0x00, 0x90, 0x1c, 0x44, 0x00, 0x12, 0x18, \n\t0x02, 0x50, 0x08, 0x46, 0x2c, 0x80, 0xcb, 0x30, 0x59, 0x91, 0xec, 0x08, 0x00, 0xc2, 0x09, 0x89, \n\t0x12, 0x40, 0x0c, 0x20, 0x51, 0x02, 0x1c, 0x10, 0x05, 0x02, 0x60, 0xa8, 0xa0, 0x08, 0x0e, 0xa2, \n\t0x4c, 0x96, 0xc0, 0x9c, 0x84, 0x10, 0x82, 0x52, 0x00, 0x31, 0x20, 0xe5, 0x55, 0x28, 0x74, 0x80, \n\t0x18, 0x22, 0x24, 0x04, 0x0a, 0x02, 0xe1, 0x40, 0xa3, 0x99, 0x05, 0xe6, 0x08, 0x91, 0x50, 0x03, \n\t0x14, 0x8e, 0xc1, 0x60, 0x24, 0xeb, 0x12, 0xa0, 0x02, 0x60, 0x60, 0x40, 0x2a, 0x91, 0xf8, 0x80, \n\t0x2c, 0x14, 0x22, 0x48, 0x05, 0x34, 0x91, 0x2c, 0x12, 0xa2, 0x51, 0x81, 0x01, 0x9c, 0x62, 0x08, \n\t0xd1, 0xe1, 0x10, 0x85, 0x50, 0x2e, 0x20, 0x15, 0x80, 0x02, 0x00, 0x16, 0xe6, 0x72, 0x81, 0x13, \n\t0xa5, 0x40, 0xc2, 0x02, 0x02, 0x64, 0x09, 0x80, 0x65, 0x40, 0x80, 0x04, 0x44, 0x20, 0x30, 0x98, \n\t0x11, 0xc5, 0x32, 0x11, 0x50, 0x31, 0x08, 0x80, 0x04, 0x22, 0x77, 0x20, 0x0a, 0x24, 0x98, 0x00, \n\t0x00, 0x20, 0x48, 0xb3, 0x08, 0x88, 0x04, 0x24, 0xb3, 0x0a, 0x96, 0x00, 0x83, 0xa0, 0x34, 0x02, \n\t0x50, 0x39, 0x68, 0x04, 0x48, 0x14, 0x00, 0x00, 0x03, 0x04, 0x0a, 0xc9, 0x58, 0x01, 0x22, 0x0b, \n\t0x81, 0x49, 0x41, 0x2e, 0x25, 0x02, 0x22, 0x01, 0x90, 0x63, 0x60, 0x04, 0x80, 0x14, 0x80, 0x45, \n\t0x06, 0x3a, 0x05, 0x50, 0x23, 0x64, 0x4a, 0x89, 0x06, 0x03, 0x91, 0x84, 0xb4, 0x40, 0x88, 0x52, \n\t0x61, 0x10, 0x89, 0x1c, 0x40, 0x87, 0x20, 0x82, 0x61, 0x12, 0x84, 0x9a, 0x89, 0x40, 0x42, 0x68, \n\t0x00, 0x00, 0x9a, 0x21, 0x20, 0x11, 0xda, 0x84, 0x80, 0x46, 0x45, 0x00, 0x14, 0x01, 0x08, 0xb4, \n\t0x05, 0x24, 0x0e, 0xa1, 0xa2, 0x20, 0x44, 0x80, 0x49, 0x48, 0x06, 0x40, 0xa2, 0xc0, 0x51, 0xc4, \n\t0x68, 0x34, 0x32, 0x00, 0x3c, 0x10, 0x44, 0x1c, 0x11, 0x30, 0x08, 0x00, 0x4e, 0xa8, 0x30, 0x15, \n\t0xd8, 0x31, 0x28, 0x80, 0x28, 0x04, 0x46, 0x08, 0x20, 0xa1, 0x04, 0x42, 0x12, 0xd2, 0x0a, 0x31, \n\t0x01, 0x02, 0x00, 0x04, 0x20, 0x01, 0xac, 0x65, 0x14, 0x0d, 0x58, 0x51, 0x03, 0x10, 0x00, 0x15, \n\t0x08, 0x04, 0x46, 0x89, 0x8f, 0xf0, 0x88, 0x06, 0x08, 0x20, 0xb1, 0x09, 0x68, 0x52, 0x2a, 0x02, \n\t0x33, 0x82, 0x82, 0xa8, 0x08, 0xe4, 0x60, 0x25, 0x03, 0xac, 0x11, 0x00, 0x85, 0x40, 0xb1, 0x92, \n\t0x86, 0x01, 0xc2, 0x03, 0x28, 0x42, 0x30, 0x17, 0x28, 0xd6, 0xa0, 0x26, 0x00, 0x10, 0x00, 0x59, \n\t0x12, 0x08, 0x0a, 0xc2, 0x61, 0x80, 0x95, 0x08, 0x43, 0x62, 0x90, 0x40, 0x31, 0x90, 0x00, 0x04, \n\t0x2a, 0x92, 0x08, 0x80, 0x21, 0x57, 0x0e, 0x30, 0x00, 0x40, 0x22, 0x24, 0x03, 0x45, 0x60, 0x62, \n\t0xa0, 0x90, 0x41, 0x44, 0x00, 0x18, 0x90, 0x98, 0x15, 0x20, 0x05, 0x00, 0x4a, 0x43, 0x62, 0x00, \n\t0x08, 0x90, 0x80, 0x28, 0x00, 0xb1, 0x3f, 0x40, 0x58, 0x4d, 0x24, 0x45, 0x22, 0x18, 0x04, 0x02, \n\t0x26, 0x6a, 0x10, 0x10, 0x84, 0xcc, 0x85, 0x24, 0x28, 0x14, 0x12, 0x94, 0x41, 0x81, 0x60, 0x70, \n\t0x01, 0x88, 0x80, 0x05, 0x01, 0x23, 0x40, 0x34, 0x8a, 0x0b, 0x20, 0x89, 0x40, 0x36, 0x01, 0x21, \n\t0x00, 0x25, 0x58, 0x09, 0x40, 0x91, 0x0b, 0x18, 0x90, 0x00, 0x69, 0x3a, 0x01, 0x83, 0x84, 0x00, \n\t0xca, 0x24, 0x18, 0x02, 0xd2, 0x00, 0x10, 0x41, 0x01, 0x00, 0xc1, 0xa3, 0x04, 0x38, 0x9c, 0x25, \n\t0x04, 0x11, 0x60, 0x31, 0x40, 0xd8, 0x29, 0x20, 0x04, 0x08, 0x0a, 0x14, 0x08, 0xc0, 0x08, 0x01, \n\t0x81, 0x05, 0x0d, 0x95, 0x20, 0x42, 0x61, 0x10, 0x30, 0x8c, 0x0b, 0x08, 0x38, 0x45, 0x1a, 0x2a, \n\t0x98, 0x40, 0x46, 0x74, 0xb4, 0x40, 0x32, 0xd0, 0x08, 0x02, 0x14, 0x02, 0x39, 0x19, 0x20, 0x42, \n\t0x84, 0x22, 0x60, 0x00, 0x01, 0x08, 0x51, 0x09, 0x2c, 0x20, 0x7a, 0x0a, 0x80, 0x90, 0xe4, 0x18, \n\t0x00, 0x50, 0x18, 0x41, 0xc1, 0x27, 0x04, 0x02, 0x4a, 0x20, 0x04, 0x00, 0xc4, 0x1c, 0x15, 0xc0, \n\t0xb0, 0x0c, 0x11, 0x20, 0x06, 0xa6, 0x20, 0xb8, 0x19, 0x8a, 0xa3, 0x58, 0xc2, 0x40, 0x90, 0x01, \n\t0xcb, 0x0c, 0x20, 0x30, 0xd8, 0x83, 0x4c, 0x16, 0x80, 0x0e, 0x20, 0x09, 0x3c, 0x51, 0x54, 0x80, \n\t0x20, 0x07, 0x53, 0x30, 0x3c, 0x4e, 0x65, 0x00, 0x90, 0x48, 0x0e, 0x01, 0x06, 0x84, 0x38, 0x82, \n\t0x8a, 0x18, 0x18, 0x18, 0x40, 0x60, 0x03, 0x11, 0x89, 0x01, 0x53, 0x09, 0x42, 0x22, 0x01, 0x08, \n\t0x05, 0x92, 0x04, 0x58, 0x11, 0x12, 0x82, 0x70, 0x14, 0x82, 0x7c, 0x12, 0x00, 0xa0, 0x89, 0xc8, \n\t0x60, 0x02, 0x00, 0x20, 0x13, 0x7d, 0x48, 0x00, 0x0a, 0x40, 0x4b, 0x03, 0x49, 0x04, 0x84, 0x54, \n\t0x00, 0xb1, 0x96, 0x44, 0x16, 0x2b, 0x54, 0x46, 0x50, 0x10, 0x04, 0x01, 0xc9, 0x64, 0x05, 0x1a, \n\t0x2a, 0xc0, 0x81, 0xc3, 0x12, 0x33, 0x40, 0x12, 0xc4, 0x05, 0x0d, 0x72, 0xa0, 0x40, 0x84, 0x14, \n\t0x10, 0x20, 0x30, 0x00, 0x1a, 0x80, 0x99, 0x8e, 0xc2, 0x6e, 0x30, 0x48, 0x25, 0x45, 0x90, 0x0a, \n\t0x18, 0x60, 0x82, 0x28, 0x20, 0x86, 0x03, 0x10, 0x64, 0x91, 0x90, 0x8c, 0x8a, 0xa0, 0x2e, 0x50, \n\t0x88, 0x0d, 0x30, 0x98, 0x00, 0x08, 0x03, 0x53, 0x1a, 0x29, 0xc9, 0x00, 0x38, 0x01, 0x60, 0x20, \n\t0xc0, 0xcb, 0x00, 0x28, 0x41, 0x08, 0x82, 0xa5, 0x4c, 0x81, 0x26, 0x44, 0x02, 0x30, 0x51, 0x42, \n\t0x0e, 0x00, 0xd0, 0x10, 0xa0, 0x50, 0x81, 0x81, 0x08, 0x54, 0xa3, 0xb3, 0xa0, 0x80, 0x0c, 0x62, \n\t0xa1, 0xa8, 0x09, 0x08, 0x1e, 0x02, 0x22, 0xa4, 0x3b, 0x04, 0x1d, 0x90, 0x05, 0x48, 0x20, 0x38, \n\t0x00, 0x00, 0x08, 0x66, 0x04, 0x50, 0x90, 0x35, 0x04, 0x08, 0x28, 0x40, 0x12, 0x22, 0x01, 0x40, \n\t0xc3, 0x82, 0x04, 0x02, 0x10, 0x03, 0x64, 0xc0, 0xa0, 0x30, 0x00, 0x02, 0x84, 0x20, 0x06, 0x08, \n\t0x48, 0x20, 0xc3, 0x06, 0x68, 0x40, 0x01, 0x50, 0x33, 0x01, 0x01, 0xf8, 0x80, 0x86, 0x02, 0x05, \n\t0x01, 0x28, 0x01, 0x0e, 0x43, 0x42, 0xa3, 0x01, 0x13, 0xb4, 0xce, 0x24, 0x02, 0x00, 0xc0, 0x1c, \n\t0x00, 0x06, 0xa6, 0x40, 0xb2, 0xe2, 0x24, 0xa0, 0x94, 0x4c, 0x40, 0xe0, 0xb1, 0x23, 0x18, 0x08, \n\t0x28, 0x00, 0x05, 0x50, 0x8a, 0x80, 0x01, 0xe0, 0x40, 0x85, 0x38, 0x06, 0x50, 0x01, 0x43, 0x00, \n\t0xd2, 0x08, 0x95, 0xc8, 0x5a, 0x08, 0x00, 0x14, 0x6a, 0x81, 0x09, 0x02, 0x4a, 0x22, 0x84, 0x22, \n\t0x12, 0x00, 0x11, 0x2c, 0x46, 0x26, 0xc1, 0x81, 0x81, 0x01, 0xc8, 0x00, 0x04, 0x09, 0x30, 0x81, \n\t0xc9, 0x4b, 0x58, 0x95, 0x28, 0xa0, 0x04, 0x0c, 0x20, 0x34, 0x40, 0x89, 0x0b, 0x30, 0x4b, 0x0b, \n\t0x04, 0x00, 0x80, 0x09, 0x98, 0x02, 0x02, 0x02, 0x72, 0x52, 0x04, 0x48, 0x00, 0x48, 0x04, 0x30, \n\t0xa0, 0xb4, 0x40, 0x88, 0x87, 0x02, 0x53, 0x18, 0x22, 0x65, 0x45, 0x23, 0x24, 0x00, 0x98, 0x18, \n\t0x09, 0x08, 0x0c, 0x00, 0x60, 0x40, 0xa4, 0xd8, 0x40, 0x42, 0x50, 0xc2, 0x80, 0xa8, 0x05, 0x5d, \n\t0x28, 0x04, 0x04, 0x00, 0xb0, 0xe8, 0x80, 0x82, 0x26, 0x84, 0x20, 0x1e, 0x20, 0xd3, 0xcd, 0x08, \n\t0x07, 0x22, 0x06, 0x14, 0x10, 0x69, 0x0e, 0x05, 0x19, 0x80, 0xd1, 0x84, 0x2a, 0x38, 0x22, 0x8a, \n\t0x11, 0x91, 0x51, 0xc2, 0x06, 0x50, 0x3a, 0xa1, 0x49, 0x04, 0x82, 0x6c, 0x26, 0x52, 0x03, 0x94, \n\t0x80, 0x02, 0x40, 0x10, 0x00, 0x88, 0x50, 0x42, 0xa2, 0x4c, 0x10, 0x79, 0x34, 0x00, 0x8f, 0x84, \n\t0x34, 0x41, 0x49, 0x32, 0x09, 0x42, 0xc0, 0x14, 0x62, 0x03, 0x06, 0x28, 0x48, 0x22, 0x50, 0x60, \n\t0x00, 0xb2, 0xec, 0x00, 0xc2, 0x0e, 0x35, 0x20, 0x80, 0x50, 0x4d, 0x08, 0x00, 0x60, 0x2a, 0x1c, \n\t0xa0, 0x54, 0x20, 0x02, 0x04, 0x10, 0x05, 0x40, 0x8b, 0xe8, 0x62, 0x12, 0x82, 0x0d, 0xc1, 0x92, \n\t0x84, 0x1c, 0x11, 0x81, 0xa4, 0x00, 0x0c, 0x48, 0x54, 0x71, 0x81, 0x91, 0x44, 0x90, 0x28, 0x06, \n\t0x83, 0x8a, 0x12, 0x65, 0x50, 0x60, 0x5c, 0xc4, 0x20, 0x31, 0x05, 0x8c, 0x02, 0x4c, 0x10, 0xa2, \n\t0x94, 0x29, 0x96, 0x08, 0x40, 0x25, 0xa3, 0xb0, 0x68, 0x10, 0x0d, 0x74, 0x01, 0x98, 0x00, 0x81, \n\t0x00, 0x40, 0x00, 0xb2, 0x61, 0x94, 0xa0, 0x04, 0x88, 0x40, 0x00, 0x61, 0x31, 0x14, 0x43, 0x05, \n\t0x16, 0x20, 0xe8, 0x0b, 0x08, 0x17, 0x08, 0x10, 0x00, 0x79, 0x11, 0x01, 0x84, 0x41, 0x1c, 0x90, \n\t0x99, 0x87, 0x84, 0x1a, 0xc0, 0x6c, 0x07, 0x90, 0x82, 0x84, 0xdb, 0x89, 0x28, 0x36, 0x12, 0x11, \n\t0x20, 0x05, 0x03, 0x20, 0x85, 0x02, 0x00, 0xe0, 0x40, 0x02, 0x24, 0x05, 0x32, 0x22, 0x10, 0x09, \n\t0x20, 0x70, 0x80, 0xd0, 0x18, 0xa5, 0x18, 0x80, 0x00, 0x01, 0x80, 0x21, 0x40, 0x0b, 0x6d, 0x00, \n\t0x53, 0x08, 0x11, 0xb0, 0x08, 0x06, 0x2a, 0x62, 0xa0, 0x0d, 0x8c, 0x16, 0x65, 0x40, 0x11, 0x01, \n\t0x06, 0x30, 0x44, 0xc3, 0x02, 0x00, 0x10, 0x10, 0x34, 0xc2, 0x02, 0x0e, 0x30, 0xc8, 0x85, 0xd9, \n\t0x06, 0x09, 0x08, 0x04, 0x82, 0x28, 0x88, 0x03, 0x06, 0x08, 0x20, 0x92, 0x0e, 0x61, 0x81, 0x65, \n\t0x66, 0x01, 0x23, 0x0e, 0xc0, 0x02, 0xac, 0x1a, 0x35, 0x03, 0x13, 0x20, 0xd8, 0x2b, 0x10, 0x04, \n\t0x63, 0x04, 0x68, 0x5d, 0x22, 0x34, 0x40, 0x10, 0x08, 0x1c, 0x48, 0x00, 0x3a, 0x40, 0x50, 0x01, \n\t0x85, 0x50, 0x00, 0x00, 0x01, 0x09, 0x9d, 0x30, 0x8c, 0x08, 0x0e, 0x27, 0x50, 0x0e, 0x28, 0x91, \n\t0x86, 0x04, 0x80, 0x69, 0x30, 0xc5, 0x42, 0xe5, 0x50, 0x82, 0x10, 0x82, 0x3c, 0x86, 0x6c, 0x10, \n\t0x40, 0x43, 0x28, 0x04, 0x42, 0x23, 0x00, 0xa4, 0xb0, 0x09, 0x51, 0xcd, 0x00, 0x24, 0x06, 0xe2, \n\t0x90, 0x61, 0x96, 0x08, 0x22, 0x50, 0x09, 0x02, 0x4d, 0x59, 0x20, 0x42, 0x05, 0x10, 0x04, 0xe4, \n\t0x0c, 0xcb, 0x04, 0x14, 0xc3, 0x22, 0x80, 0x08, 0x21, 0x16, 0x95, 0x61, 0x06, 0xd0, 0x03, 0x0a, \n\t0x1a, 0x10, 0x00, 0x02, 0xb0, 0x40, 0x64, 0x42, 0x04, 0x02, 0x88, 0x40, 0x02, 0xa8, 0x54, 0x04, \n\t0x00, 0x11, 0x58, 0x54, 0x6d, 0x02, 0x23, 0xc2, 0x80, 0x64, 0x80, 0x02, 0x04, 0xf2, 0x00, 0x14, \n\t0x1d, 0x03, 0x66, 0x44, 0xa1, 0x28, 0x00, 0x04, 0x8a, 0x24, 0x62, 0x90, 0x30, 0xa5, 0x41, 0x07, \n\t0x00, 0x1a, 0x40, 0x90, 0xa4, 0x4c, 0x10, 0x41, 0x48, 0x24, 0x61, 0x3c, 0xa8, 0x10, 0x2c, 0x12, \n\t0xe0, 0x01, 0x98, 0x40, 0x80, 0x88, 0x10, 0x41, 0x40, 0x84, 0x91, 0x48, 0x04, 0x40, 0xa3, 0x00, \n\t0x9b, 0xa8, 0x90, 0x24, 0x50, 0x31, 0xa8, 0x83, 0x91, 0x44, 0x42, 0x0a, 0x12, 0x02, 0x30, 0xa8, \n\t0x55, 0xe8, 0x08, 0x41, 0x00, 0x0c, 0x08, 0x12, 0x07, 0x4c, 0xd2, 0x40, 0xac, 0x14, 0x09, 0xe2, \n\t0x02, 0x01, 0x82, 0x9c, 0x00, 0x15, 0x81, 0x20, 0x52, 0x08, 0x01, 0x60, 0x42, 0x0a, 0x46, 0x25, \n\t0x28, 0x94, 0xa5, 0x98, 0x61, 0x48, 0x84, 0x41, 0x80, 0xc4, 0x48, 0x21, 0x02, 0x47, 0x88, 0x89, \n\t0x50, 0x0f, 0x8a, 0x14, 0x12, 0x31, 0x12, 0x05, 0x87, 0x80, 0x32, 0x32, 0x29, 0x80, 0x00, 0xc8, \n\t0x24, 0x72, 0xe0, 0x33, 0x88, 0x41, 0x80, 0x0e, 0x22, 0xa6, 0x43, 0x0c, 0xd0, 0x51, 0x24, 0x48, \n\t0xa0, 0x82, 0x04, 0xfc, 0x86, 0x00, 0x38, 0x11, 0xc3, 0x02, 0x00, 0x43, 0x44, 0x08, 0x86, 0x20, \n\t0x0e, 0x18, 0x54, 0x00, 0x58, 0x01, 0xc8, 0x10, 0x04, 0x81, 0x02, 0x40, 0x20, 0xf8, 0x22, 0xa4, \n\t0x05, 0x4a, 0x24, 0x62, 0x08, 0x06, 0x2c, 0x10, 0x08, 0x06, 0x15, 0x83, 0x98, 0x9c, 0x00, 0x03, \n\t0x28, 0x50, 0x41, 0x36, 0x11, 0x04, 0x82, 0x12, 0x65, 0x28, 0x08, 0x8c, 0x82, 0x68, 0x10, 0x30, \n\t0x82, 0x1f, 0x80, 0x03, 0x63, 0x04, 0x02, 0x82, 0x1c, 0xc4, 0x80, 0xc1, 0x0c, 0x21, 0xa1, 0x04, \n\t0x30, 0x10, 0x08, 0x00, 0xa2, 0xd3, 0xbd, 0x01, 0xc1, 0x41, 0x60, 0x10, 0x08, 0x12, 0x1c, 0x98, \n\t0x44, 0x02, 0x82, 0x7b, 0xa3, 0x40, 0x14, 0xa4, 0x4e, 0x05, 0xc2, 0x04, 0x48, 0x8c, 0x80, 0x04, \n\t0xa2, 0x41, 0x14, 0x21, 0x01, 0x86, 0x22, 0xe5, 0xca, 0x09, 0xbc, 0x0e, 0x81, 0x10, 0xe3, 0x00, \n\t0x38, 0x20, 0x01, 0x88, 0x50, 0x10, 0xa3, 0x8e, 0x20, 0x5c, 0x45, 0x30, 0x54, 0x29, 0x91, 0x68, \n\t0x01, 0xa4, 0x14, 0xa0, 0x10, 0x20, 0x1c, 0x82, 0x6a, 0x44, 0x62, 0x20, 0x02, 0x68, 0x10, 0xc9, \n\t0x4c, 0x40, 0x02, 0x10, 0x0c, 0x0a, 0x4c, 0x68, 0x05, 0xaa, 0xa1, 0x60, 0x50, 0x46, 0x60, 0x80, \n\t0x02, 0x81, 0x40, 0x00, 0x08, 0x3e, 0x14, 0x08, 0x31, 0x31, 0x80, 0x02, 0x3a, 0x46, 0x12, 0x9a, \n\t0x61, 0x00, 0x2d, 0x10, 0x21, 0x81, 0x82, 0xe0, 0xc0, 0x01, 0x00, 0x45, 0x38, 0x01, 0x05, 0x84, \n\t0x0c, 0x48, 0x20, 0x09, 0x9d, 0x00, 0x1e, 0x41, 0x12, 0x23, 0xf1, 0x11, 0x00, 0xc4, 0x42, 0x36, \n\t0x10, 0x89, 0x04, 0xb1, 0x82, 0x43, 0x08, 0x81, 0x08, 0xa6, 0x60, 0x86, 0x60, 0x04, 0xc4, 0x20, \n\t0x2c, 0x41, 0x40, 0x40, 0x00, 0x02, 0x00, 0x12, 0x00, 0x04, 0x60, 0x6e, 0x90, 0xa1, 0x0b, 0x00, \n\t0x93, 0x28, 0x16, 0x01, 0x49, 0x01, 0xf1, 0x40, 0xa0, 0x62, 0xa0, 0xc0, 0x20, 0x90, 0x51, 0x0b, \n\t0x50, 0x01, 0x00, 0x03, 0x39, 0x85, 0x80, 0x34, 0xc5, 0x18, 0x89, 0x01, 0x10, 0x04, 0x02, 0x06, \n\t0xa2, 0xbb, 0x14, 0x08, 0x08, 0x06, 0x80, 0xfa, 0x10, 0x49, 0x1b, 0x84, 0x04, 0xb4, 0x01, 0x30, \n\t0xa0, 0x02, 0xc2, 0x54, 0x23, 0x21, 0x0a, 0xc9, 0x88, 0xa0, 0x00, 0x12, 0x71, 0x16, 0x8c, 0x50, \n\t0xc2, 0x22, 0x60, 0x08, 0xb1, 0x40, 0x06, 0x44, 0x60, 0x12, 0x8a, 0x04, 0x09, 0x46, 0xa2, 0x60, \n\t0x54, 0x40, 0x85, 0x81, 0x84, 0x88, 0x26, 0x62, 0x88, 0x98, 0x08, 0x11, 0x09, 0x16, 0x84, 0x18, \n\t0x02, 0xc5, 0x40, 0x06, 0x04, 0x91, 0x48, 0x30, 0x01, 0x14, 0x01, 0x4a, 0xc7, 0x83, 0x85, 0xa0, \n\t0x8c, 0x28, 0x1a, 0x56, 0x31, 0x89, 0x38, 0x04, 0x69, 0x54, 0x24, 0x30, 0x00, 0x60, 0x40, 0x28, \n\t0x04, 0x10, 0x52, 0x80, 0x4c, 0x02, 0x08, 0x40, 0x92, 0x63, 0x1b, 0xc0, 0x09, 0x09, 0x6a, 0x52, \n\t0x80, 0x20, 0x68, 0x8c, 0x27, 0x10, 0xc0, 0x43, 0x14, 0x0c, 0x43, 0xa2, 0x00, 0x75, 0x31, 0xb7, \n\t0x90, 0x88, 0x60, 0x2a, 0xe0, 0xf0, 0x30, 0x00, 0x00, 0x82, 0x54, 0x15, 0x02, 0x20, 0x01, 0x41, \n\t0x85, 0x04, 0x02, 0x30, 0x89, 0x50, 0x81, 0xc9, 0x00, 0xa6, 0x68, 0x20, 0x04, 0x52, 0x41, 0x20, \n\t0x21, 0x41, 0x04, 0x18, 0x09, 0x40, 0x00, 0x82, 0xca, 0x35, 0xa5, 0x87, 0x40, 0x1e, 0x93, 0x40, \n\t0x20, 0x19, 0x12, 0x80, 0x00, 0x66, 0x62, 0x0c, 0xcd, 0x12, 0x84, 0x4e, 0x81, 0x28, 0x14, 0x00, \n\t0xd1, 0x80, 0x0a, 0x01, 0x81, 0xad, 0x44, 0x97, 0x08, 0x00, 0x40, 0x60, 0x01, 0x11, 0x9a, 0x61, \n\t0x26, 0xc0, 0x81, 0x38, 0x30, 0x54, 0x27, 0x60, 0x21, 0x02, 0x01, 0x34, 0xc4, 0xa0, 0x02, 0xb0, \n\t0x48, 0x86, 0x15, 0xc0, 0x40, 0x40, 0x00, 0x88, 0x06, 0x80, 0x84, 0x40, 0x56, 0x46, 0x01, 0x82, \n\t0x80, 0x41, 0xa9, 0x56, 0x94, 0x0b, 0x25, 0x11, 0x06, 0x2e, 0x10, 0x12, 0x40, 0x2e, 0x00, 0x80, \n\t0x4d, 0x10, 0x11, 0x40, 0x94, 0x0d, 0x00, 0x6c, 0x0c, 0x02, 0x90, 0x12, 0x1c, 0x10, 0x02, 0x62, \n\t0x41, 0x02, 0x02, 0x04, 0x10, 0x2a, 0x08, 0x40, 0x12, 0x11, 0x0c, 0x08, 0xa2, 0x64, 0x27, 0x08, \n\t0xa0, 0x80, 0x0c, 0x46, 0x74, 0x11, 0x89, 0x29, 0x40, 0x49, 0xc6, 0x06, 0xf7, 0x00, 0x80, 0xa5, \n\t0xde, 0x80, 0x68, 0x20, 0x09, 0x03, 0xac, 0x84, 0x00, 0x38, 0x11, 0x02, 0x19, 0x98, 0x09, 0xe2, \n\t0x20, 0x30, 0xa2, 0x08, 0x6c, 0xc1, 0x4a, 0x44, 0x10, 0x31, 0x03, 0x01, 0x1a, 0x28, 0x20, 0xa5, \n\t0x40, 0x0f, 0x44, 0xc2, 0x8a, 0x62, 0xb3, 0x08, 0x27, 0x69, 0x90, 0x20, 0x0e, 0xc2, 0x80, 0x91, \n\t0x68, 0x90, 0x08, 0x3c, 0x14, 0x0b, 0x92, 0x15, 0x4d, 0x80, 0x38, 0x24, 0x30, 0x12, 0x49, 0x14, \n\t0x04, 0x02, 0xa0, 0x42, 0x28, 0x04, 0xc6, 0x01, 0x22, 0x20, 0x71, 0x25, 0x34, 0x83, 0x41, 0x12, \n\t0x91, 0x00, 0x24, 0x3c, 0x41, 0x04, 0x06, 0x07, 0xb8, 0x82, 0x01, 0x1b, 0x8c, 0x50, 0x20, 0x4a, \n\t0x11, 0x98, 0x80, 0x06, 0x48, 0x83, 0xc8, 0x01, 0x88, 0x08, 0x29, 0x74, 0x26, 0x90, 0xa8, 0x00, \n\t0x00, 0x0f, 0x08, 0xa2, 0x92, 0x90, 0x19, 0x1b, 0x44, 0x00, 0x97, 0x42, 0x29, 0x24, 0x11, 0x00, \n\t0x12, 0x10, 0xc2, 0x30, 0xe8, 0x44, 0x22, 0x24, 0x00, 0x00, 0x04, 0x48, 0x11, 0x40, 0x04, 0x03, \n\t0x19, 0xa0, 0xa8, 0x00, 0x04, 0x04, 0x43, 0x60, 0x0a, 0x15, 0x06, 0x03, 0x52, 0xf5, 0x48, 0x00, \n\t0x10, 0x54, 0x00, 0x0c, 0xd4, 0x29, 0x93, 0xd0, 0x90, 0x4d, 0x4e, 0xa2, 0xc9, 0x10, 0x08, 0x12, \n\t0x42, 0x00, 0xe1, 0x03, 0x0a, 0x04, 0x86, 0x80, 0x70, 0x84, 0x32, 0x28, 0x90, 0x4a, 0x61, 0x08, \n\t0x10, 0xb2, 0x94, 0x10, 0x1a, 0x40, 0x40, 0x06, 0x73, 0xac, 0x20, 0x91, 0x20, 0x40, 0x20, 0x99, \n\t0x84, 0x24, 0x4b, 0xe9, 0x08, 0x81, 0x82, 0x00, 0x31, 0x04, 0x86, 0x30, 0x34, 0x09, 0x32, 0x28, \n\t0x41, 0x2c, 0x16, 0x00, 0x61, 0x95, 0xa0, 0x10, 0xca, 0x2a, 0x44, 0x20, 0xa0, 0x00, 0x10, 0x20, \n\t0x68, 0xc6, 0xb1, 0x15, 0xb0, 0x10, 0x2d, 0x18, 0x26, 0x00, 0x30, 0x08, 0xc6, 0x68, 0x00, 0x50, \n\t0x62, 0x28, 0xc8, 0x00, 0x09, 0x08, 0x81, 0x80, 0x11, 0xc0, 0x03, 0x89, 0x06, 0x50, 0x88, 0x1c, \n\t0x01, 0xc2, 0x63, 0x7a, 0x05, 0x49, 0x34, 0x25, 0x8d, 0x00, 0x48, 0x00, 0xa2, 0x16, 0x8d, 0xc0, \n\t0x4a, 0x5c, 0x46, 0x21, 0x0e, 0x25, 0x44, 0x40, 0x16, 0x60, 0x11, 0x91, 0xd0, 0x82, 0xa8, 0x02, \n\t0x40, 0x51, 0x21, 0x11, 0x48, 0x06, 0x58, 0x12, 0xc1, 0x22, 0x10, 0x51, 0x60, 0x10, 0x22, 0x28, \n\t0x82, 0x58, 0x49, 0x0e, 0x02, 0x04, 0x09, 0x09, 0x01, 0x17, 0xa6, 0x10, 0x62, 0x53, 0x8a, 0x08, \n\t0x00, 0x87, 0x10, 0x20, 0xa3, 0x20, 0x44, 0x41, 0x67, 0x0a, 0x05, 0x02, 0x84, 0x18, 0x96, 0x84, \n\t0x06, 0x91, 0x68, 0x04, 0x85, 0x03, 0x20, 0x00, 0x05, 0x73, 0x24, 0x01, 0xc0, 0x48, 0x00, 0xa5, \n\t0x1a, 0x06, 0xf1, 0x4c, 0x26, 0x74, 0x14, 0x00, 0x82, 0x88, 0x88, 0x62, 0x08, 0x02, 0x40, 0xa0, \n\t0x45, 0x40, 0x04, 0x12, 0x92, 0xaa, 0x10, 0x8c, 0x41, 0x09, 0x28, 0x86, 0x00, 0x89, 0x80, 0x01, \n\t0x02, 0x0a, 0x82, 0x81, 0x31, 0xa0, 0x40, 0x00, 0x06, 0x10, 0x89, 0x80, 0x25, 0x0e, 0xec, 0x00, \n\t0x05, 0x82, 0x22, 0xd8, 0x08, 0xa1, 0x40, 0x44, 0xa0, 0x00, 0x41, 0xc8, 0x01, 0x14, 0x05, 0x9b, \n\t0xbc, 0x60, 0x90, 0x88, 0x0e, 0x14, 0x9b, 0x85, 0xc0, 0x94, 0x02, 0x64, 0xa1, 0x10, 0x34, 0x01, \n\t0x01, 0xa1, 0x60, 0xb3, 0x50, 0x0a, 0xb1, 0x4b, 0xc5, 0x02, 0x40, 0x71, 0x10, 0x05, 0x04, 0x47, \n\t0x20, 0x96, 0x48, 0xa5, 0x00, 0x01, 0x09, 0x08, 0x72, 0xd0, 0x08, 0x20, 0x06, 0xa1, 0x0a, 0x92, \n\t0xb2, 0x00, 0x08, 0x10, 0x08, 0x50, 0xc2, 0x08, 0x2e, 0x15, 0x00, 0x4a, 0x78, 0x80, 0x01, 0xa3, \n\t0x80, 0xd1, 0x07, 0x6e, 0x82, 0xa8, 0x30, 0x24, 0x07, 0x00, 0x08, 0x83, 0x80, 0x28, 0xa4, 0x07, \n\t0x08, 0x00, 0x60, 0x43, 0x80, 0x1d, 0xc0, 0xaa, 0x56, 0x87, 0x10, 0x10, 0x1d, 0x4c, 0xa4, 0x06, \n\t0xa3, 0x88, 0x01, 0x00, 0x06, 0x42, 0x2c, 0x80, 0x01, 0x2e, 0x84, 0x00, 0x83, 0x72, 0x06, 0xa2, \n\t0xb4, 0x14, 0x05, 0x04, 0x10, 0x60, 0x2a, 0x99, 0x38, 0x82, 0x23, 0x06, 0x14, 0x12, 0x29, 0x00, \n\t0x54, 0x69, 0x14, 0x61, 0x32, 0x21, 0x28, 0x14, 0x25, 0x60, 0xd0, 0x21, 0x92, 0x00, 0x80, 0x20, \n\t0x40, 0x73, 0xb0, 0x80, 0x00, 0x01, 0x80, 0x58, 0x05, 0x58, 0xa8, 0x29, 0x48, 0x0a, 0x02, 0x55, \n\t0x4a, 0x82, 0x00, 0xd6, 0xc0, 0x20, 0x81, 0x51, 0x0a, 0x88, 0x59, 0x0c, 0x70, 0x82, 0x02, 0x81, \n\t0xe1, 0x88, 0xa8, 0x0a, 0x55, 0x11, 0x04, 0x15, 0x80, 0x07, 0x08, 0x02, 0xc1, 0xb3, 0x08, 0x1b, \n\t0x04, 0x6e, 0x40, 0x60, 0x0d, 0x50, 0x40, 0x4f, 0x70, 0x30, 0x10, 0x20, 0x01, 0x10, 0x63, 0x10, \n\t0xd1, 0x28, 0x86, 0x0c, 0x0a, 0x04, 0x00, 0x44, 0x00, 0xa0, 0x4d, 0x1a, 0xa1, 0x20, 0x51, 0x38, \n\t0x12, 0x44, 0x11, 0x67, 0x12, 0x04, 0x00, 0x89, 0x00, 0xc9, 0x00, 0x28, 0x00, 0x83, 0x00, 0x64, \n\t0x88, 0x00, 0x0a, 0x03, 0xc2, 0x98, 0xc0, 0x08, 0x23, 0x16, 0x07, 0x09, 0xb1, 0x60, 0x08, 0x6a, \n\t0x04, 0xd2, 0x28, 0x08, 0xb5, 0x11, 0x05, 0x10, 0x25, 0x00, 0xa2, 0x08, 0x16, 0x0c, 0x0a, 0x40, \n\t0x00, 0x00, 0x59, 0x03, 0x04, 0x02, 0x92, 0xe3, 0x30, 0x00, 0x81, 0xc5, 0x06, 0x30, 0x98, 0x24, \n\t0x1c, 0x0e, 0x68, 0x20, 0x81, 0x40, 0x02, 0x1d, 0x03, 0x6a, 0x40, 0x41, 0x02, 0x24, 0x24, 0x05, \n\t0x23, 0x54, 0x92, 0x98, 0x08, 0x88, 0x49, 0x02, 0x20, 0x10, 0x90, 0x30, 0xa0, 0x03, 0x82, 0x24, \n\t0x20, 0x31, 0x8a, 0x39, 0x58, 0xa8, 0x32, 0x86, 0x80, 0x89, 0x35, 0x88, 0x85, 0x24, 0x05, 0x41, \n\t0x81, 0x10, 0x08, 0x41, 0x00, 0xd4, 0x00, 0x16, 0x00, 0x12, 0x44, 0x36, 0xc0, 0x68, 0x81, 0x90, \n\t0x0c, 0xcc, 0x76, 0x20, 0x51, 0x2c, 0x21, 0x50, 0xab, 0x14, 0xb0, 0x4a, 0x00, 0x64, 0x14, 0x4d, \n\t0x40, 0xc2, 0x12, 0x8e, 0x54, 0x08, 0x02, 0x40, 0x41, 0x28, 0x00, 0x01, 0x9e, 0x81, 0x40, 0xd4, \n\t0x29, 0x12, 0x24, 0x87, 0x82, 0x08, 0x01, 0x63, 0xa1, 0x00, 0x83, 0x01, 0x00, 0x44, 0xca, 0xa4, \n\t0x45, 0x48, 0x20, 0x20, 0x22, 0x49, 0x1a, 0xc0, 0x02, 0xc5, 0x3a, 0xa0, 0x10, 0x15, 0x45, 0xd1, \n\t0xc0, 0x48, 0xa1, 0xe3, 0x04, 0x10, 0xc0, 0x20, 0x74, 0x11, 0x10, 0x83, 0xb1, 0x49, 0x02, 0x52, \n\t0x14, 0x28, 0x11, 0x75, 0x96, 0xa8, 0x1e, 0x10, 0x60, 0x02, 0xe8, 0x1c, 0x49, 0x28, 0xc2, 0x12, \n\t0x3c, 0x95, 0x00, 0xa2, 0x42, 0x12, 0x00, 0x80, 0x28, 0x13, 0x04, 0x2c, 0x44, 0x20, 0x00, 0x08, \n\t0x09, 0x80, 0x40, 0x10, 0xa9, 0x03, 0x74, 0x41, 0x89, 0x20, 0x22, 0x8a, 0xac, 0xa8, 0x11, 0xa0, \n\t0x42, 0x35, 0x48, 0x8b, 0x40, 0x42, 0x67, 0x10, 0x62, 0x40, 0x12, 0x40, 0x94, 0x42, 0x10, 0x01, \n\t0x4a, 0x0d, 0xa4, 0xc0, 0x60, 0x5e, 0x50, 0x81, 0x16, 0x40, 0xd2, 0x41, 0x44, 0x22, 0x31, 0x08, \n\t0x81, 0x14, 0xc9, 0x10, 0x83, 0x80, 0x84, 0x28, 0x04, 0x21, 0x08, 0x82, 0x83, 0x02, 0x04, 0x42, \n\t0x4c, 0x00, 0x50, 0x8a, 0x2b, 0x54, 0x50, 0x82, 0x46, 0x86, 0x62, 0x02, 0xe9, 0x9c, 0x0c, 0x56, \n\t0x75, 0x01, 0xa1, 0x34, 0x8c, 0x20, 0x2c, 0x84, 0x58, 0x84, 0xd8, 0x05, 0x08, 0x10, 0xc2, 0x19, \n\t0x12, 0xe0, 0xc8, 0x01, 0x14, 0x82, 0x08, 0x08, 0x01, 0x40, 0x88, 0x30, 0xc0, 0x4a, 0x8a, 0xa0, \n\t0x03, 0x40, 0x02, 0x10, 0x8a, 0x1d, 0x00, 0x15, 0x03, 0x6c, 0x10, 0x91, 0x01, 0x81, 0x46, 0x8e, \n\t0x00, 0x22, 0x13, 0x81, 0x38, 0x80, 0xc9, 0x4c, 0xa0, 0x81, 0xa2, 0x50, 0x59, 0x25, 0x64, 0x03, \n\t0x1a, 0x85, 0x18, 0x0c, 0x24, 0x20, 0x00, 0x80, 0x90, 0x01, 0x46, 0x28, 0x1c, 0x05, 0xab, 0x00, \n\t0xac, 0x48, 0xc9, 0x06, 0x66, 0xe0, 0x1c, 0x41, 0x48, 0x08, 0x00, 0x30, 0x41, 0xb0, 0x59, 0xc2, \n\t0x63, 0x24, 0x33, 0x71, 0x24, 0x80, 0x02, 0x4d, 0x48, 0x83, 0x08, 0x20, 0x90, 0x92, 0x40, 0x04, \n\t0x22, 0x12, 0x88, 0xb0, 0x8a, 0x40, 0x2a, 0x90, 0x60, 0x20, 0x75, 0x86, 0x03, 0x08, 0xa3, 0x22, \n\t0xa2, 0xc8, 0x92, 0x4a, 0x10, 0x01, 0x11, 0x88, 0x44, 0x90, 0x89, 0x20, 0x02, 0xa0, 0x8c, 0x25, \n\t0x02, 0x80, 0x72, 0x02, 0xea, 0x06, 0x01, 0x0d, 0x0c, 0x04, 0x21, 0x1b, 0x83, 0x00, 0x04, 0x22, \n\t0x1e, 0xc0, 0x61, 0x22, 0x55, 0x01, 0x84, 0x20, 0x02, 0x92, 0xb0, 0xd4, 0x01, 0x6a, 0x14, 0x83, \n\t0x21, 0x1e, 0xa4, 0x16, 0x00, 0x12, 0x27, 0x08, 0x28, 0x30, 0x11, 0x48, 0x04, 0x00, 0x5a, 0x04, \n\t0x10, 0x0e, 0x4c, 0x44, 0x92, 0x11, 0x14, 0x80, 0x02, 0x09, 0x50, 0x60, 0x29, 0x20, 0x18, 0x12, \n\t0x08, 0x00, 0x24, 0x11, 0x00, 0x40, 0x88, 0xc3, 0x26, 0xd4, 0x02, 0x21, 0x00, 0x18, 0x81, 0x20, \n\t0x41, 0x93, 0x90, 0x8d, 0x54, 0x26, 0x38, 0x04, 0x81, 0x84, 0x68, 0x82, 0x08, 0x3c, 0x61, 0xc0, \n\t0xaa, 0x80, 0x4c, 0x20, 0x46, 0x10, 0x8a, 0x19, 0xa0, 0x40, 0x22, 0x36, 0x40, 0x61, 0x83, 0x21, \n\t0x90, 0x08, 0x22, 0x55, 0xa8, 0xba, 0xa8, 0x42, 0x6c, 0x64, 0x40, 0x40, 0x10, 0x50, 0x0a, 0x0d, \n\t0x00, 0x80, 0x82, 0x24, 0x04, 0x04, 0xa8, 0x0c, 0xf0, 0x70, 0x05, 0xc4, 0x08, 0x05, 0x64, 0x60, \n\t0x51, 0x0a, 0x1d, 0xc0, 0xa0, 0x02, 0x26, 0x30, 0x22, 0x2c, 0x14, 0x05, 0x10, 0x80, 0x69, 0xaa, \n\t0x05, 0x04, 0x20, 0x20, 0x61, 0x50, 0x05, 0x00, 0xc2, 0xc2, 0x08, 0x04, 0xf1, 0x24, 0x64, 0x00, \n\t0xc1, 0x62, 0x82, 0x00, 0x01, 0x50, 0x03, 0x05, 0x18, 0x70, 0x00, 0xa2, 0x10, 0xc0, 0x01, 0x0a, \n\t0x84, 0xc0, 0x19, 0x00, 0x84, 0x04, 0x08, 0xd5, 0x82, 0x07, 0x59, 0x58, 0x40, 0x0c, 0x94, 0x20, \n\t0x08, 0x09, 0x06, 0x44, 0x0a, 0x23, 0x00, 0x0b, 0x14, 0x04, 0x86, 0x54, 0x40, 0xa0, 0x11, 0x51, \n\t0x01, 0x21, 0x68, 0xf2, 0x0a, 0x32, 0x10, 0x11, 0x40, 0x0c, 0x42, 0x28, 0x14, 0x40, 0x08, 0x08, \n\t0x72, 0x30, 0xc0, 0x20, 0xad, 0x58, 0x61, 0x28, 0x45, 0x29, 0x00, 0x48, 0x01, 0x27, 0x24, 0x62, \n\t0xc0, 0x80, 0x05, 0x0a, 0xc1, 0x18, 0x25, 0x19, 0xac, 0x25, 0x80, 0x0b, 0x5a, 0x20, 0x00, 0x15, \n\t0x10, 0x82, 0x01, 0x36, 0x40, 0x51, 0x0a, 0x40, 0xd8, 0x0c, 0x20, 0x92, 0x92, 0x09, 0x19, 0x45, \n\t0x4b, 0x50, 0x83, 0x82, 0xa3, 0xe1, 0x86, 0xea, 0x08, 0x43, 0x91, 0x19, 0x89, 0x13, 0x80, 0x04, \n\t0x84, 0x80, 0x10, 0x15, 0xc2, 0x05, 0x0c, 0xd2, 0xc0, 0x00, 0x48, 0x00, 0xa8, 0x40, 0x21, 0x01, \n\t0x85, 0x14, 0x19, 0xc2, 0x42, 0x60, 0xf0, 0x0a, 0x40, 0x50, 0x42, 0x26, 0x47, 0xc9, 0x22, 0x14, \n\t0x81, 0xa2, 0x20, 0x31, 0x08, 0x21, 0xc1, 0xc0, 0x00, 0x48, 0x22, 0x40, 0x93, 0x88, 0x00, 0x61, \n\t0x44, 0x40, 0x0b, 0x80, 0x69, 0x86, 0xec, 0x0a, 0x36, 0x89, 0x14, 0xf0, 0x51, 0x20, 0x42, 0x21, \n\t0x71, 0x21, 0xd1, 0x0c, 0x20, 0x6c, 0x30, 0x53, 0x00, 0x01, 0x00, 0x23, 0x04, 0x74, 0xa8, 0x34, \n\t0x40, 0x5b, 0xa0, 0x1a, 0x16, 0x01, 0x80, 0x28, 0x0f, 0x08, 0x10, 0x24, 0x80, 0x12, 0x69, 0x04, \n\t0x00, 0x48, 0x40, 0xab, 0x94, 0x38, 0x51, 0x4a, 0x26, 0x67, 0x01, 0x00, 0x6c, 0x86, 0x0e, 0x0a, \n\t0x52, 0x20, 0x0c, 0xa0, 0x14, 0x8c, 0x00, 0x11, 0x83, 0x2c, 0xb0, 0x81, 0x24, 0x00, 0x40, 0x48, \n\t0x1e, 0x31, 0xc5, 0x40, 0x32, 0x20, 0x90, 0x14, 0x80, 0x52, 0x80, 0x48, 0x11, 0x40, 0x23, 0x80, \n\t0x14, 0x02, 0x1c, 0x94, 0xa0, 0x08, 0xcc, 0x4a, 0x08, 0x04, 0x37, 0xb0, 0x2a, 0x05, 0x04, 0x00, \n\t0x30, 0x03, 0x03, 0x36, 0xc1, 0x04, 0x2a, 0x12, 0x54, 0x20, 0xa0, 0xe5, 0x94, 0xa0, 0x16, 0x00, \n\t0x81, 0x92, 0x81, 0x09, 0xc0, 0x54, 0x44, 0xc0, 0xa9, 0x81, 0x8c, 0x00, 0x0c, 0xb0, 0x28, 0x05, \n\t0x34, 0x8f, 0x42, 0x42, 0x21, 0xa0, 0x10, 0x24, 0x99, 0x01, 0x04, 0x91, 0x40, 0x09, 0x50, 0x44, \n\t0x63, 0x62, 0x86, 0x52, 0x18, 0x30, 0x01, 0xa8, 0x00, 0x51, 0x12, 0x82, 0x10, 0x88, 0x01, 0x08, \n\t0x31, 0x00, 0x34, 0x49, 0x42, 0x80, 0x0c, 0x50, 0x02, 0x94, 0x00, 0x13, 0xc7, 0x00, 0x90, 0x22, \n\t0x94, 0xc9, 0x19, 0x04, 0x60, 0x74, 0x71, 0x25, 0x35, 0x8b, 0x41, 0x60, 0x86, 0x08, 0x00, 0x60, \n\t0x40, 0x66, 0x02, 0x90, 0x41, 0x81, 0x81, 0x8e, 0x48, 0x00, 0x43, 0x58, 0x11, 0xb4, 0x13, 0x0b, \n\t0x2a, 0xa5, 0xc0, 0x90, 0x84, 0x06, 0x04, 0x04, 0x03, 0x2a, 0x1d, 0x30, 0x09, 0x89, 0x20, 0x04, \n\t0x81, 0x10, 0x90, 0x10, 0x42, 0x50, 0x02, 0x21, 0x08, 0x30, 0x04, 0xa6, 0x10, 0x00, 0xc2, 0x8e, \n\t0x89, 0x18, 0xa8, 0x00, 0x10, 0x1a, 0xae, 0x64, 0x4a, 0xa2, 0x64, 0x40, 0x60, 0x28, 0x40, 0x1b, \n\t0x00, 0x18, 0x04, 0xc8, 0xa5, 0xc8, 0x17, 0x22, 0x50, 0xe0, 0x20, 0x08, 0x10, 0x40, 0x2c, 0x24, \n\t0x10, 0x5a, 0x89, 0x04, 0x0c, 0xac, 0x06, 0x23, 0x18, 0x27, 0x21, 0x89, 0x4d, 0x10, 0x84, 0xc0, \n\t0x04, 0x38, 0x06, 0x08, 0x22, 0x97, 0xe3, 0x10, 0xd9, 0x44, 0x01, 0x08, 0x00, 0xa0, 0x14, 0x9c, \n\t0x44, 0x01, 0x00, 0x11, 0x41, 0x88, 0x68, 0x84, 0x24, 0x20, 0x72, 0x41, 0x22, 0x44, 0x88, 0x06, \n\t0x2a, 0x00, 0x10, 0x30, 0x59, 0x93, 0x22, 0x00, 0x06, 0xd8, 0x14, 0x2d, 0x41, 0xae, 0x50, 0x20, \n\t0x22, 0x34, 0x80, 0x01, 0x81, 0x20, 0x01, 0x12, 0x00, 0x1d, 0x40, 0xca, 0x34, 0x66, 0x80, 0xb1, \n\t0x48, 0x45, 0x06, 0x12, 0x10, 0x08, 0x89, 0x94, 0x1a, 0x09, 0x58, 0x44, 0x20, 0x02, 0x24, 0xc5, \n\t0x09, 0x3c, 0x02, 0xd0, 0x12, 0x00, 0x10, 0x6a, 0x50, 0x92, 0x8a, 0x04, 0xd8, 0x90, 0xa0, 0x12, \n\t0x41, 0x39, 0x01, 0x21, 0x08, 0x4f, 0x70, 0x60, 0x62, 0x8b, 0x81, 0x42, 0x09, 0x06, 0x87, 0x8a, \n\t0x81, 0x65, 0xd5, 0x04, 0x60, 0x10, 0x01, 0x10, 0xe0, 0x88, 0x82, 0x2c, 0x01, 0x81, 0x24, 0x08, \n\t0x0b, 0x21, 0x62, 0x60, 0x52, 0x32, 0x0d, 0x1c, 0x05, 0x22, 0x14, 0x00, 0xb8, 0x38, 0x00, 0x00, \n\t0x3e, 0xe3, 0x60, 0x83, 0x01, 0x04, 0x00, 0x10, 0x10, 0x20, 0x82, 0x24, 0x06, 0x01, 0x50, 0x50, \n\t0x18, 0x86, 0x08, 0x13, 0x45, 0x0a, 0x82, 0x2b, 0x28, 0xa4, 0x91, 0x60, 0x18, 0x00, 0x89, 0x8f, \n\t0x90, 0x0c, 0x00, 0x4c, 0x01, 0x60, 0x36, 0x1c, 0x58, 0x0c, 0x22, 0x51, 0x18, 0xb0, 0x50, 0x0a, \n\t0xa6, 0x40, 0x46, 0x12, 0x34, 0x80, 0x84, 0x84, 0x48, 0x44, 0x30, 0x01, 0x49, 0x10, 0x0b, 0x42, \n\t0x00, 0x39, 0x24, 0x68, 0x0d, 0x41, 0x22, 0xa2, 0x88, 0x02, 0x2c, 0x40, 0x08, 0x10, 0x50, 0x41, \n\t0x02, 0x15, 0x91, 0x46, 0x22, 0x70, 0x42, 0x91, 0x08, 0x07, 0x25, 0x62, 0x07, 0x48, 0x99, 0x11, \n\t0x44, 0x48, 0x1c, 0x16, 0xe9, 0x3c, 0xc0, 0xc0, 0x40, 0x4e, 0x60, 0x20, 0x0c, 0x9d, 0x00, 0x28, \n\t0x08, 0x24, 0x93, 0x88, 0xd0, 0x01, 0x20, 0x44, 0x33, 0x00, 0x0d, 0x29, 0x90, 0x40, 0x4c, 0x85, \n\t0x01, 0x12, 0x80, 0x42, 0x2c, 0x24, 0x11, 0xc0, 0x00, 0x59, 0x40, 0x8b, 0x04, 0x65, 0x00, 0x2c, \n\t0x55, 0x1c, 0x22, 0x00, 0x04, 0x80, 0x00, 0x5c, 0x88, 0x84, 0x20, 0x07, 0x49, 0x35, 0x84, 0x17, \n\t0x08, 0x0a, 0x70, 0x08, 0x08, 0x00, 0x1e, 0x08, 0x64, 0x04, 0xf2, 0x8c, 0x00, 0xc3, 0xc0, 0x00, \n\t0x04, 0x73, 0x21, 0x01, 0x00, 0xc3, 0x50, 0xb2, 0x0a, 0x88, 0x04, 0x0a, 0x21, 0x14, 0x62, 0x00, \n\t0x13, 0x0c, 0xc0, 0xad, 0x4c, 0xd0, 0x10, 0x0a, 0x21, 0x89, 0x80, 0x10, 0x80, 0x2a, 0xa7, 0x20, \n\t0x91, 0x00, 0x4a, 0x31, 0x0b, 0x30, 0x28, 0x11, 0x00, 0x00, 0x63, 0xc0, 0x10, 0x2d, 0x10, 0xa2, \n\t0x20, 0xc4, 0x8b, 0x3b, 0x28, 0x01, 0xe9, 0x10, 0xc4, 0x40, 0x02, 0x41, 0x10, 0x00, 0x10, 0x80, \n\t0xc1, 0x84, 0x00, 0x90, 0x61, 0x04, 0x11, 0x30, 0x89, 0x98, 0x01, 0x05, 0x4e, 0x02, 0x30, 0x20, \n\t0x08, 0x54, 0x40, 0x12, 0x80, 0x62, 0x84, 0x0c, 0x08, 0x09, 0x40, 0x94, 0x33, 0x04, 0x01, 0x48, \n\t0x81, 0x22, 0x80, 0x02, 0xa6, 0x11, 0x14, 0x23, 0x14, 0x04, 0x6b, 0x20, 0x40, 0x14, 0xa4, 0x10, \n\t0x44, 0x1a, 0x11, 0x40, 0x42, 0x01, 0x34, 0x01, 0x39, 0x08, 0x14, 0x50, 0xa2, 0x14, 0x00, 0x00, \n\t0x03, 0x90, 0x09, 0x0a, 0x24, 0x85, 0x40, 0xb0, 0x51, 0x1f, 0x00, 0x10, 0x82, 0x08, 0x08, 0x2c, \n\t0x41, 0x29, 0x4a, 0x83, 0x80, 0x93, 0x40, 0x56, 0x2b, 0x4e, 0x10, 0xc2, 0x20, 0x48, 0x01, 0x8c, \n\t0x00, 0x70, 0x3a, 0x0c, 0x0c, 0x10, 0x00, 0x28, 0x03, 0x40, 0x3a, 0x18, 0x53, 0x60, 0x60, 0x64, \n\t0x80, 0xb4, 0x24, 0x00, 0x62, 0x08, 0x50, 0x20, 0x06, 0x60, 0x88, 0x20, 0x1a, 0x60, 0x08, 0x11, \n\t0x15, 0x83, 0x0b, 0x38, 0x24, 0x52, 0x98, 0x24, 0x10, 0x28, 0x40, 0x54, 0x08, 0x01, 0xf1, 0xc9, \n\t0x21, 0x30, 0x44, 0x30, 0x89, 0x21, 0x02, 0x0c, 0x40, 0x80, 0x88, 0x36, 0x20, 0x4c, 0x04, 0x74, \n\t0x84, 0x02, 0x00, 0x49, 0x95, 0x48, 0x04, 0x82, 0x6a, 0x38, 0x20, 0x46, 0x2b, 0x40, 0x22, 0xf3, \n\t0x21, 0xd5, 0x00, 0x09, 0x48, 0x03, 0x11, 0x84, 0x4c, 0x80, 0x6a, 0x46, 0xa2, 0x90, 0x92, 0x30, \n\t0x88, 0x06, 0x48, 0xc1, 0x69, 0x07, 0x00, 0x40, 0x02, 0x02, 0x00, 0x29, 0x02, 0x85, 0x14, 0x29, \n\t0x38, 0x40, 0x09, 0xac, 0x98, 0x01, 0x41, 0x20, 0x82, 0x50, 0x82, 0x1d, 0xcf, 0xc0, 0x28, 0x00, \n\t0x10, 0x0c, 0x40, 0x40, 0xc4, 0x10, 0x42, 0x82, 0x06, 0x08, 0x81, 0x08, 0x44, 0x23, 0xd1, 0x81, \n\t0x20, 0xd6, 0x22, 0x58, 0x00, 0x90, 0x08, 0x51, 0x14, 0x03, 0x06, 0x42, 0xc8, 0x07, 0xec, 0x12, \n\t0x82, 0x18, 0x97, 0x43, 0x9b, 0x00, 0x09, 0x4a, 0x04, 0xc0, 0x20, 0x22, 0x60, 0x5e, 0x24, 0x04, \n\t0x93, 0x6a, 0x90, 0x48, 0x44, 0x26, 0x64, 0x41, 0x22, 0x92, 0x48, 0x08, 0x48, 0x16, 0x22, 0xd0, \n\t0x1e, 0x00, 0x49, 0x6f, 0x00, 0x24, 0x08, 0x08, 0xb1, 0xc0, 0xc8, 0x02, 0x20, 0x49, 0x90, 0x04, \n\t0x8c, 0x03, 0x10, 0x84, 0xaa, 0x0d, 0x14, 0x45, 0x61, 0x00, 0x42, 0x63, 0x01, 0x20, 0x01, 0x6a, \n\t0x04, 0x16, 0x20, 0x10, 0x00, 0x82, 0x44, 0x4a, 0x20, 0x33, 0x0c, 0x30, 0x10, 0x82, 0x38, 0x34, \n\t0x91, 0xb0, 0x91, 0x51, 0x41, 0x68, 0x85, 0x22, 0x00, 0x00, 0x97, 0x60, 0x08, 0x52, 0x52, 0xa9, \n\t0x4d, 0x18, 0x0c, 0x56, 0x24, 0xe2, 0x06, 0x58, 0xd0, 0x21, 0x16, 0x44, 0x28, 0x08, 0x21, 0x58, \n\t0x02, 0x22, 0x01, 0xc0, 0x8b, 0x04, 0x05, 0x84, 0x00, 0x11, 0x19, 0x35, 0xf0, 0x8d, 0x40, 0x10, \n\t0x17, 0x02, 0x1a, 0x0c, 0x48, 0x28, 0x52, 0x80, 0x63, 0x14, 0xd1, 0x09, 0x26, 0x48, 0x20, 0x20, \n\t0x35, 0x18, 0x12, 0x40, 0x04, 0x32, 0x82, 0x86, 0x61, 0x00, 0xac, 0x60, 0x00, 0xa0, 0x02, 0x44, \n\t0x48, 0x00, 0x06, 0xa6, 0x90, 0x24, 0x10, 0x0e, 0x65, 0x60, 0x01, 0x08, 0x88, 0x49, 0x18, 0x00, \n\t0x50, 0x41, 0x41, 0x83, 0x24, 0xca, 0xa8, 0x22, 0x40, 0x20, 0xa0, 0x88, 0x14, 0x60, 0x00, 0x07, \n\t0x80, 0x20, 0x18, 0x80, 0x01, 0x14, 0x05, 0x01, 0x9c, 0x04, 0x93, 0x46, 0x08, 0xc3, 0x62, 0x10, \n\t0x14, 0x1a, 0x48, 0x70, 0x10, 0x08, 0x05, 0xa8, 0x11, 0x4c, 0x40, 0xa6, 0x00, 0x20, 0x28, 0x52, \n\t0x01, 0x58, 0x20, 0x09, 0x89, 0x05, 0x86, 0xa0, 0x0c, 0x56, 0xf0, 0x20, 0x88, 0x51, 0x48, 0x04, \n\t0x65, 0x00, 0x8d, 0x01, 0xc5, 0x20, 0x62, 0x00, 0x91, 0x8e, 0x4d, 0xc2, 0x80, 0x12, 0x11, 0x2a, \n\t0x20, 0xd1, 0x11, 0xa1, 0x52, 0x80, 0x48, 0x84, 0xd0, 0x09, 0x28, 0x40, 0x50, 0x89, 0x80, 0x14, \n\t0x06, 0x0c, 0x1a, 0x44, 0x08, 0xba, 0xa5, 0x50, 0xc7, 0x08, 0xa7, 0x22, 0x0a, 0x30, 0x44, 0x00, \n\t0x44, 0xc4, 0xd0, 0x09, 0x10, 0x40, 0x88, 0x48, 0x22, 0xcb, 0x18, 0x84, 0x07, 0x8b, 0x06, 0x41, \n\t0x50, 0x00, 0x49, 0x1a, 0xa2, 0x24, 0x63, 0x23, 0x90, 0x91, 0x02, 0x08, 0x28, 0xa0, 0x08, 0x0a, \n\t0x1c, 0x04, 0x47, 0x2a, 0x05, 0xd8, 0x08, 0x84, 0x10, 0xa8, 0x40, 0x71, 0x58, 0x82, 0x0d, 0x14, \n\t0x00, 0x56, 0xe6, 0x92, 0x8e, 0xd4, 0x00, 0x4d, 0x14, 0x54, 0x49, 0x80, 0x25, 0x0c, 0x01, 0x38, \n\t0x30, 0x08, 0xac, 0x10, 0x90, 0x40, 0x4a, 0x13, 0x63, 0x01, 0x04, 0x01, 0x00, 0x02, 0xd1, 0x19, \n\t0x02, 0xa0, 0x00, 0xae, 0x36, 0x00, 0x80, 0x24, 0xa0, 0x52, 0x8b, 0x00, 0xd0, 0x02, 0x00, 0x51, \n\t0x84, 0x84, 0x0c, 0x02, 0xc3, 0x39, 0x80, 0x8a, 0x44, 0x66, 0x50, 0x08, 0x09, 0x31, 0x08, 0x41, \n\t0x02, 0x07, 0x18, 0xa0, 0x20, 0xc5, 0x2a, 0x12, 0x45, 0x48, 0xa0, 0x68, 0xc6, 0x83, 0x48, 0x20, \n\t0x80, 0x1c, 0x11, 0x45, 0x88, 0x60, 0x56, 0x53, 0x12, 0x60, 0x07, 0x2d, 0x24, 0x04, 0x29, 0x84, \n\t0x20, 0x88, 0x45, 0x08, 0x96, 0x81, 0x84, 0x00, 0x91, 0x04, 0x04, 0x21, 0x09, 0x0e, 0x39, 0x10, \n\t0x28, 0x70, 0x00, 0xc0, 0x20, 0xb0, 0x02, 0x6e, 0x00, 0x82, 0xe3, 0x02, 0x9d, 0x00, 0x2b, 0x74, \n\t0x21, 0xe1, 0x31, 0x15, 0x58, 0xaa, 0x40, 0xe0, 0x20, 0x30, 0x14, 0x52, 0xc4, 0x00, 0x16, 0x68, \n\t0xa0, 0x08, 0x10, 0x82, 0x58, 0x01, 0x18, 0x36, 0xe4, 0x0a, 0x61, 0x44, 0x01, 0xa1, 0x90, 0x94, \n\t0x11, 0xc0, 0x12, 0xc4, 0x13, 0x19, 0x44, 0x09, 0x66, 0x2a, 0x84, 0x18, 0x13, 0x05, 0xcd, 0x40, \n\t0x20, 0x30, 0x81, 0x02, 0x84, 0xd0, 0x40, 0x1e, 0x00, 0x1b, 0x15, 0x70, 0x12, 0x20, 0x22, 0x04, \n\t0x61, 0x05, 0x51, 0x03, 0x08, 0x40, 0x80, 0x8a, 0x8e, 0x30, 0x84, 0x40, 0x08, 0x84, 0x60, 0xb3, \n\t0x01, 0x52, 0x4a, 0x02, 0x06, 0x82, 0xb0, 0x49, 0x40, 0x46, 0x3a, 0x81, 0x00, 0x14, 0x00, 0x88, \n\t0xa4, 0x08, 0x14, 0x2a, 0x34, 0x7c, 0x04, 0x61, 0x00, 0xe1, 0xd8, 0x9c, 0xa4, 0x14, 0x86, 0x44, \n\t0x00, 0x41, 0x21, 0xc8, 0x4d, 0x04, 0x00, 0x02, 0x51, 0x2a, 0x01, 0x9d, 0x04, 0x40, 0x45, 0x60, \n\t0x98, 0x28, 0x42, 0x05, 0x0a, 0xa6, 0x00, 0x02, 0x99, 0x89, 0xa2, 0x20, 0x02, 0x02, 0x2d, 0xe8, \n\t0x10, 0x00, 0x5c, 0xb0, 0x83, 0x02, 0x4c, 0x02, 0xe8, 0x04, 0xa4, 0x02, 0x02, 0x04, 0x88, 0x42, \n\t0x4c, 0x32, 0x90, 0xbb, 0x00, 0xcd, 0x00, 0x72, 0x11, 0x2a, 0x04, 0x85, 0x01, 0x28, 0x10, 0x11, \n\t0xb2, 0x00, 0x88, 0x1a, 0xc3, 0x16, 0x81, 0xd3, 0x00, 0x00, 0x04, 0x87, 0x44, 0x70, 0x58, 0x91, \n\t0x30, 0x04, 0x45, 0x2c, 0x33, 0x28, 0x21, 0x40, 0x88, 0x81, 0x52, 0x80, 0xe8, 0x01, 0xa0, 0x80, \n\t0x0c, 0x36, 0x44, 0xe1, 0x12, 0x88, 0x18, 0xe2, 0x4a, 0x20, 0x0b, 0x20, 0x28, 0x81, 0x00, 0x48, \n\t0xb2, 0x10, 0x06, 0x0d, 0x8e, 0x00, 0x44, 0x15, 0x90, 0xa2, 0x04, 0x82, 0x01, 0x28, 0x42, 0xa8, \n\t0x90, 0x4d, 0x80, 0x25, 0x42, 0x10, 0x02, 0x0e, 0x81, 0x84, 0x2e, 0x54, 0x04, 0x10, 0x21, 0x00, \n\t0xd8, 0x02, 0x78, 0x81, 0x08, 0x06, 0xbc, 0x50, 0x4c, 0x10, 0xd0, 0x00, 0x30, 0xa4, 0x41, 0x22, \n\t0x02, 0x41, 0x51, 0x12, 0x50, 0x08, 0x07, 0x18, 0xb4, 0xe0, 0x01, 0x30, 0x4c, 0x68, 0x00, 0x32, \n\t0x08, 0x95, 0xb8, 0x90, 0xc0, 0x0c, 0xb0, 0x51, 0x10, 0x4c, 0x90, 0xce, 0x44, 0x21, 0xea, 0x00, \n\t0x28, 0x18, 0x0a, 0x10, 0x00, 0x22, 0x18, 0x04, 0x09, 0x05, 0x6a, 0x81, 0x08, 0x27, 0x09, 0x08, \n\t0xc2, 0x74, 0x45, 0x58, 0x00, 0xa1, 0x81, 0x00, 0x12, 0x50, 0x8a, 0x16, 0x04, 0x5a, 0x60, 0x00, \n\t0x86, 0x0a, 0x20, 0xc0, 0x1c, 0x08, 0x02, 0x05, 0x02, 0x1a, 0x41, 0x08, 0x4c, 0x2a, 0x24, 0x01, \n\t0xa1, 0x11, 0x12, 0x46, 0x00, 0x85, 0x80, 0xb8, 0x08, 0x42, 0x20, 0x32, 0x82, 0x30, 0x8a, 0x78, \n\t0x84, 0x89, 0x12, 0x02, 0x12, 0x10, 0x20, 0x81, 0x60, 0x46, 0x52, 0x01, 0x2f, 0x20, 0x10, 0x04, \n\t0x48, 0xa0, 0xe0, 0x00, 0xc4, 0x10, 0xa5, 0x22, 0x04, 0x82, 0x1a, 0x0d, 0x05, 0x04, 0x2a, 0x50, \n\t0x71, 0xa7, 0x04, 0x87, 0x02, 0x18, 0x60, 0xc8, 0x81, 0x1d, 0xc9, 0x00, 0x00, 0x05, 0x29, 0x30, \n\t0x0c, 0x55, 0x00, 0x54, 0x24, 0x03, 0x82, 0x70, 0x03, 0x25, 0x00, 0xb0, 0x40, 0x82, 0x85, 0x95, \n\t0x0d, 0x48, 0x10, 0x49, 0x16, 0x00, 0xd4, 0x08, 0x0e, 0xd4, 0x82, 0x80, 0x00, 0xce, 0xc6, 0x22, \n\t0x02, 0x48, 0x18, 0xb9, 0x52, 0xe0, 0x42, 0x20, 0x11, 0x2c, 0x58, 0x0a, 0x89, 0x48, 0x85, 0xc0, \n\t0x04, 0x05, 0x83, 0x88, 0x00, 0xa5, 0x10, 0x00, 0x30, 0x1f, 0x02, 0x08, 0x00, 0x90, 0x10, 0x45, \n\t0xcc, 0xac, 0x06, 0x70, 0xc0, 0x02, 0x31, 0x07, 0x03, 0x12, 0xe0, 0x22, 0x90, 0x00, 0x4d, 0x80, \n\t0x36, 0x01, 0x80, 0x02, 0xc8, 0x0c, 0x49, 0x18, 0x10, 0x40, 0x18, 0xe4, 0x06, 0x09, 0x22, 0x20, \n\t0x08, 0x08, 0x18, 0x09, 0x21, 0x66, 0x92, 0x09, 0x00, 0xe0, 0x4a, 0x8d, 0x32, 0x10, 0x41, 0x0d, \n\t0x19, 0x41, 0x29, 0x02, 0xb3, 0x40, 0x81, 0x94, 0x18, 0x44, 0x34, 0x03, 0x33, 0xb2, 0x58, 0x08, \n\t0x4c, 0x6c, 0x81, 0x82, 0x94, 0x0c, 0x44, 0x01, 0x44, 0x01, 0x81, 0x31, 0x40, 0xc3, 0x82, 0x00, \n\t0x75, 0xf2, 0x01, 0x18, 0x19, 0xca, 0x36, 0xc0, 0xa1, 0x04, 0x19, 0x10, 0xa1, 0x00, 0x75, 0x80, \n\t0x08, 0x89, 0x86, 0x20, 0x00, 0x01, 0x01, 0xa1, 0x31, 0x46, 0x00, 0x50, 0x01, 0xa0, 0x04, 0x04, \n\t0x05, 0x41, 0x4c, 0x66, 0x08, 0x90, 0x80, 0xd5, 0x01, 0x1c, 0x10, 0xb2, 0x08, 0xd0, 0x82, 0x29, \n\t0x50, 0x01, 0x40, 0x02, 0x70, 0x98, 0x81, 0x28, 0x14, 0x91, 0x9d, 0xd9, 0x98, 0x6f, 0x20, 0x80, \n\t0x02, 0x00, 0x41, 0x00, 0x20, 0x20, 0x04, 0xd3, 0x22, 0x08, 0x0d, 0xac, 0x28, 0x40, 0x70, 0x83, \n\t0xd1, 0x82, 0x09, 0x56, 0x25, 0x09, 0x1c, 0x59, 0x08, 0x82, 0x04, 0x12, 0x1a, 0x08, 0xa0, 0x00, \n\t0x87, 0x02, 0xc2, 0x20, 0x06, 0x41, 0x42, 0x08, 0x40, 0xe3, 0xc8, 0x02, 0x98, 0x83, 0x20, 0x6a, \n\t0x65, 0x5b, 0x02, 0x48, 0x81, 0x41, 0x0c, 0x92, 0xe0, 0x14, 0x18, 0x05, 0x41, 0x10, 0x43, 0x38, \n\t0x2c, 0x20, 0x86, 0x40, 0x0c, 0x46, 0x00, 0x19, 0xd1, 0x11, 0x20, 0x02, 0xd1, 0x10, 0x09, 0x05, \n\t0x01, 0xa6, 0x22, 0x04, 0x90, 0x8c, 0x20, 0x04, 0x00, 0x0e, 0x30, 0x88, 0x80, 0x09, 0x9f, 0x20, \n\t0x08, 0x40, 0x68, 0x20, 0x34, 0x01, 0xa7, 0x64, 0x00, 0x41, 0xb3, 0x24, 0x88, 0x08, 0x14, 0x12, \n\t0x08, 0x91, 0x20, 0x1c, 0x06, 0x00, 0xf0, 0x82, 0x2a, 0xb8, 0x16, 0x08, 0x24, 0xa1, 0x10, 0x10, \n\t0x01, 0x96, 0x4b, 0x56, 0x02, 0x60, 0x18, 0x20, 0x40, 0xa9, 0x58, 0x01, 0x73, 0x82, 0xc0, 0x8a, \n\t0x60, 0x04, 0x14, 0x82, 0x06, 0xdc, 0xda, 0xa8, 0x20, 0x22, 0x02, 0x97, 0x2c, 0x40, 0x04, 0x24, \n\t0x12, 0x21, 0x00, 0xa1, 0xc0, 0x80, 0x78, 0x54, 0x50, 0x23, 0xc1, 0x91, 0x01, 0x12, 0x27, 0x99, \n\t0x20, 0x01, 0x14, 0x04, 0x00, 0x44, 0x09, 0x92, 0x91, 0x40, 0x40, 0x0c, 0x51, 0x10, 0x33, 0x44, \n\t0x41, 0xcc, 0x60, 0xa5, 0x00, 0x08, 0x28, 0x16, 0x08, 0x00, 0x84, 0x33, 0x08, 0x49, 0x0b, 0x2a, \n\t0x04, 0x80, 0xa1, 0x21, 0x04, 0x95, 0x01, 0x0e, 0xa1, 0x50, 0x26, 0x24, 0x04, 0xe9, 0x10, 0xc2, \n\t0x50, 0x98, 0x01, 0xd8, 0xc0, 0x0a, 0x44, 0x30, 0x09, 0x65, 0x02, 0x02, 0x36, 0xd4, 0x22, 0x0a, \n\t0xc4, 0x14, 0x82, 0x00, 0x25, 0x0a, 0x07, 0x84, 0x07, 0x42, 0x12, 0x24, 0x19, 0x88, 0x80, 0x40, \n\t0x6c, 0x20, 0x30, 0x50, 0x82, 0x00, 0x00, 0xc8, 0x0e, 0x82, 0x01, 0xb6, 0x70, 0x84, 0x41, 0x40, \n\t0x27, 0x0b, 0xb4, 0x04, 0x89, 0x00, 0x38, 0x53, 0xca, 0x13, 0x80, 0x54, 0x42, 0x40, 0x84, 0x03, \n\t0x24, 0x6c, 0x44, 0x89, 0x1e, 0xa2, 0x6b, 0x04, 0x21, 0x18, 0x04, 0x00, 0x45, 0xa2, 0x84, 0xc8, \n\t0x01, 0x40, 0x20, 0x60, 0xa8, 0x20, 0x34, 0x82, 0x40, 0x20, 0x06, 0x5a, 0x80, 0x20, 0x80, 0x0a, \n\t0x70, 0x34, 0x52, 0x01, 0x15, 0x0b, 0x60, 0x24, 0xc7, 0x90, 0x32, 0x08, 0x4c, 0x82, 0x04, 0x26, \n\t0x92, 0xa1, 0xc9, 0x41, 0x23, 0x2c, 0x66, 0x29, 0x1d, 0xa5, 0x00, 0x00, 0x10, 0x41, 0xa8, 0x0a, \n\t0x20, 0x5c, 0x21, 0x54, 0xa3, 0x0a, 0x00, 0xb9, 0x40, 0x04, 0x2c, 0x20, 0x00, 0x04, 0x80, 0x03, \n\t0x0c, 0x18, 0xc0, 0x43, 0x00, 0x74, 0x0e, 0xa3, 0x04, 0x42, 0xc3, 0x0c, 0x80, 0xc2, 0x2a, 0x00, \n\t0x00, 0x82, 0x94, 0x48, 0xd2, 0x04, 0x24, 0x01, 0xf8, 0x23, 0x68, 0x12, 0x0c, 0x7c, 0x30, 0x00, \n\t0x03, 0x18, 0x1f, 0x60, 0x26, 0x00, 0x18, 0x04, 0x84, 0x05, 0x67, 0x10, 0x90, 0x02, 0x19, 0x30, \n\t0xcc, 0x86, 0x00, 0x26, 0x50, 0x10, 0x45, 0x47, 0x81, 0x08, 0x42, 0xaa, 0x01, 0xa4, 0x86, 0x29, \n\t0x70, 0x96, 0x00, 0x1d, 0x31, 0xc1, 0xe4, 0x5c, 0x02, 0x20, 0x09, 0x05, 0x14, 0x00, 0x40, 0x83, \n\t0x41, 0x28, 0xa8, 0x90, 0x00, 0x08, 0x32, 0xa0, 0xb7, 0x0d, 0x51, 0x02, 0x24, 0x85, 0x18, 0x0a, \n\t0x40, 0x08, 0x21, 0x12, 0x43, 0x12, 0x12, 0x40, 0x88, 0xa6, 0x06, 0x65, 0xc1, 0x34, 0x1c, 0x54, \n\t0x41, 0x20, 0x01, 0x48, 0x2a, 0x40, 0x05, 0x43, 0x56, 0x80, 0x80, 0x08, 0x34, 0x02, 0x47, 0x12, \n\t0x43, 0x21, 0x08, 0x00, 0x11, 0xc4, 0x0a, 0x01, 0x08, 0x05, 0x0c, 0x4c, 0x00, 0x06, 0x01, 0x70, \n\t0x80, 0x00, 0x5d, 0x48, 0x2c, 0x00, 0x12, 0x09, 0x2d, 0xc2, 0x48, 0x08, 0xe0, 0x19, 0x87, 0x00, \n\t0x98, 0x29, 0x20, 0x13, 0xc2, 0x08, 0x01, 0x81, 0x84, 0x2c, 0x21, 0x18, 0x2a, 0x78, 0x89, 0x05, \n\t0x60, 0x55, 0x00, 0x07, 0x61, 0x14, 0x80, 0x32, 0x14, 0x58, 0xa2, 0xb9, 0x42, 0x2a, 0x0c, 0xe6, \n\t0x52, 0x86, 0x8d, 0x48, 0x04, 0x00, 0xc4, 0xd0, 0x08, 0x28, 0xc3, 0x27, 0x02, 0x31, 0x18, 0x12, \n\t0x80, 0x12, 0x02, 0x02, 0x62, 0x01, 0x27, 0x24, 0x98, 0x01, 0x24, 0x42, 0x82, 0x94, 0x01, 0x16, \n\t0x05, 0x50, 0x34, 0x08, 0x04, 0x84, 0x43, 0x21, 0x08, 0x00, 0xb0, 0x88, 0x90, 0x16, 0x40, 0x40, \n\t0x74, 0x63, 0x2e, 0x00, 0x41, 0x60, 0x02, 0x24, 0x02, 0x02, 0x04, 0x49, 0x81, 0x44, 0x01, 0xc8, \n\t0x2a, 0xc0, 0x15, 0x80, 0x64, 0x24, 0xda, 0x84, 0x01, 0x08, 0x60, 0x08, 0xa1, 0x02, 0x10, 0x39, \n\t0x50, 0x20, 0x04, 0x84, 0x10, 0x12, 0x61, 0x02, 0x49, 0x22, 0xe0, 0x10, 0x3c, 0x61, 0xc6, 0x80, \n\t0x00, 0x86, 0x29, 0xa4, 0x10, 0x90, 0x25, 0x00, 0xc0, 0x80, 0x12, 0x18, 0x95, 0x40, 0x32, 0x12, \n\t0x89, 0x18, 0xd1, 0x02, 0x86, 0x54, 0x81, 0x20, 0x0c, 0x98, 0x06, 0x46, 0x20, 0xc0, 0x40, 0x18, \n\t0x0d, 0x09, 0x27, 0x2e, 0x40, 0x80, 0x2a, 0x40, 0x17, 0x40, 0x68, 0x12, 0x62, 0xa9, 0x0c, 0xc0, \n\t0x82, 0x1e, 0x54, 0xb1, 0x05, 0x28, 0x12, 0x68, 0x24, 0xa6, 0x62, 0x2e, 0x20, 0x51, 0x04, 0x44, \n\t0x91, 0x53, 0x83, 0xc8, 0x00, 0x28, 0x00, 0x42, 0x29, 0x11, 0xa0, 0x06, 0xc8, 0x1a, 0x45, 0x08, \n\t0x10, 0x84, 0x5b, 0x25, 0x10, 0x86, 0xc2, 0x10, 0x48, 0x08, 0x2e, 0x14, 0x22, 0xc0, 0x2d, 0x00, \n\t0x50, 0x42, 0x48, 0xc1, 0x80, 0x81, 0x80, 0x10, 0x01, 0x20, 0x02, 0xc1, 0x15, 0x01, 0x02, 0x48, \n\t0x22, 0x07, 0x82, 0x14, 0x00, 0xd4, 0xc2, 0x02, 0x01, 0x5b, 0x06, 0x25, 0x84, 0x00, 0x02, 0x64, \n\t0xb8, 0x02, 0xc8, 0x8e, 0x89, 0x20, 0x01, 0x8a, 0x12, 0x80, 0x10, 0x8c, 0x02, 0x92, 0x02, 0x80, \n\t0x01, 0x43, 0x2d, 0x08, 0x82, 0x21, 0x00, 0x11, 0x01, 0x8a, 0x12, 0x94, 0x02, 0x03, 0x30, 0xc0, \n\t0x6d, 0x24, 0x86, 0x21, 0x04, 0x50, 0xc0, 0xa0, 0x0e, 0x12, 0x81, 0x29, 0xc4, 0x06, 0x63, 0x00, \n\t0x42, 0x02, 0x80, 0x10, 0x06, 0x0d, 0x08, 0x45, 0x50, 0x01, 0x1c, 0x98, 0x4c, 0x64, 0x64, 0x90, \n\t0x88, 0x30, 0x8a, 0x43, 0x5a, 0x01, 0x11, 0x03, 0xa8, 0x43, 0x20, 0x00, 0x00, 0xa3, 0xb6, 0x24, \n\t0x0e, 0x6b, 0x20, 0xc4, 0x22, 0x00, 0x4c, 0x48, 0xe0, 0x24, 0x21, 0x90, 0x01, 0x8c, 0x88, 0xa8, \n\t0x04, 0x22, 0x68, 0xb3, 0xa5, 0x52, 0x42, 0x4a, 0xc2, 0x0b, 0x1d, 0x00, 0xc8, 0x04, 0x02, 0x10, \n\t0x2a, 0x84, 0x80, 0x08, 0x45, 0x4a, 0x24, 0x8b, 0x00, 0x30, 0x10, 0x21, 0x18, 0x52, 0xc9, 0x02, \n\t0xc5, 0x98, 0x02, 0x10, 0x81, 0x02, 0x21, 0x91, 0x40, 0x65, 0x40, 0x41, 0x90, 0x92, 0x11, 0xd4, \n\t0x20, 0x5a, 0x83, 0x20, 0x00, 0x25, 0x82, 0x0c, 0x06, 0x15, 0x41, 0x16, 0x04, 0x81, 0x02, 0x6a, \n\t0x41, 0x89, 0x12, 0xb1, 0x00, 0x6f, 0x54, 0x01, 0x09, 0x1a, 0x8d, 0x02, 0x00, 0x32, 0xd0, 0x01, \n\t0xa5, 0x15, 0x81, 0x01, 0x10, 0x80, 0x22, 0x00, 0x84, 0xc0, 0x00, 0x58, 0x24, 0xc1, 0x13, 0x09, \n\t0x12, 0xe0, 0x16, 0x84, 0x9a, 0x05, 0x08, 0x53, 0x84, 0x42, 0x00, 0x68, 0x21, 0x21, 0x0a, 0x49, \n\t0x10, 0x10, 0x12, 0x81, 0x10, 0x10, 0x63, 0x42, 0x41, 0x02, 0x01, 0x05, 0xdb, 0xc4, 0x3c, 0x11, \n\t0xb0, 0x00, 0xc9, 0x0c, 0x0e, 0x20, 0x20, 0x12, 0x90, 0x69, 0x08, 0x82, 0x42, 0x01, 0x8b, 0x30, \n\t0x2c, 0x4c, 0x00, 0x22, 0x02, 0x43, 0xa9, 0xc0, 0x84, 0xc8, 0x0c, 0xf2, 0x00, 0x04, 0x60, 0x4a, \n\t0x00, 0x40, 0xa4, 0x08, 0x22, 0x04, 0xc7, 0x04, 0x42, 0x05, 0x20, 0x1d, 0xc1, 0x04, 0x85, 0x6a, \n\t0x20, 0x22, 0x1c, 0xc8, 0x55, 0x88, 0x00, 0x00, 0xa0, 0x05, 0x21, 0x14, 0xc8, 0x48, 0x22, 0x20, \n\t0x1a, 0x10, 0x49, 0x0d, 0x2e, 0xc4, 0x9a, 0x04, 0x01, 0x90, 0x44, 0x12, 0x04, 0x42, 0x21, 0x20, \n\t0x84, 0x22, 0x74, 0x00, 0x60, 0x82, 0x29, 0x40, 0xa8, 0x00, 0x87, 0xb3, 0x98, 0xb4, 0x14, 0x05, \n\t0x40, 0xa2, 0x41, 0x0b, 0x19, 0xce, 0x08, 0x04, 0x02, 0x38, 0x89, 0x15, 0x82, 0xc0, 0x40, 0x50, \n\t0x08, 0xa0, 0x20, 0x03, 0x08, 0x10, 0xa1, 0x90, 0x1d, 0x90, 0x5a, 0x40, 0x06, 0x96, 0xd3, 0x08, \n\t0x81, 0x02, 0x07, 0x00, 0xc0, 0x49, 0x08, 0x8c, 0x80, 0xa4, 0x00, 0xc7, 0x90, 0x2b, 0xc9, 0x88, \n\t0x40, 0x08, 0x20, 0x00, 0xa4, 0x41, 0x04, 0x20, 0x38, 0x52, 0x00, 0x00, 0xc0, 0x13, 0x00, 0x12, \n\t0x00, 0xe2, 0x82, 0x91, 0x03, 0x49, 0x04, 0x84, 0x52, 0x02, 0xa0, 0x4d, 0x21, 0x36, 0x00, 0x8a, \n\t0xb1, 0xd4, 0x4a, 0xee, 0x08, 0x40, 0x48, 0xb2, 0xd0, 0x08, 0x85, 0x30, 0x64, 0x23, 0x39, 0x08, \n\t0x80, 0x0c, 0x0a, 0x90, 0x01, 0x10, 0x51, 0x88, 0x62, 0x40, 0x12, 0x49, 0x1d, 0x2c, 0x80, 0xcd, \n\t0x14, 0xa0, 0x31, 0x21, 0x24, 0x00, 0x86, 0x10, 0xa2, 0xd2, 0x82, 0x05, 0x49, 0x6a, 0x60, 0x00, \n\t0x02, 0x08, 0x35, 0x03, 0x22, 0x54, 0x90, 0xd8, 0xa4, 0x09, 0x59, 0x0a, 0x30, 0x00, 0x08, 0x15, \n\t0x61, 0x00, 0x0a, 0x04, 0xa4, 0xb3, 0x92, 0x00, 0x41, 0x40, 0x00, 0x47, 0x02, 0x00, 0xd4, 0x04, \n\t0xac, 0x0a, 0xa7, 0x10, 0x81, 0x01, 0xc1, 0x0e, 0x22, 0x22, 0x40, 0x24, 0x3c, 0x14, 0x6c, 0x28, \n\t0xc2, 0xd8, 0x18, 0xe1, 0x11, 0x0c, 0x00, 0x00, 0x82, 0x1d, 0xb5, 0x06, 0x01, 0x4e, 0x43, 0x63, \n\t0x0c, 0x4d, 0x8c, 0x08, 0x6c, 0x03, 0x20, 0x8c, 0x4c, 0x08, 0x01, 0x00, 0x32, 0x88, 0x0a, 0x21, \n\t0x0f, 0x45, 0x20, 0x90, 0x43, 0x20, 0x04, 0x16, 0xac, 0x20, 0x54, 0x08, 0x85, 0x51, 0x89, 0xc0, \n\t0x3e, 0x23, 0xb2, 0xa0, 0x0d, 0x10, 0x48, 0x00, 0x34, 0x19, 0xa2, 0xc0, 0x86, 0x40, 0x12, 0xe0, \n\t0x01, 0x0e, 0x20, 0x03, 0x80, 0x00, 0xc0, 0x29, 0x8a, 0x90, 0x46, 0x24, 0x08, 0x84, 0x00, 0x87, \n\t0x89, 0x41, 0x64, 0x38, 0x04, 0x49, 0x04, 0x28, 0xc5, 0x06, 0x0e, 0x93, 0xb0, 0x0a, 0x34, 0x04, \n\t0x04, 0x6c, 0x20, 0x23, 0x1e, 0x81, 0x5a, 0x81, 0x4a, 0x61, 0x90, 0x84, 0x50, 0x0e, 0x42, 0x0c, \n\t0x12, 0xa1, 0x26, 0xa8, 0x88, 0x04, 0x34, 0x10, 0x28, 0x20, 0x90, 0x45, 0x83, 0x30, 0x25, 0x1a, \n\t0x20, 0x8c, 0x41, 0x05, 0x00, 0xc4, 0x48, 0xa8, 0x89, 0x4d, 0x01, 0x08, 0xc2, 0x00, 0xa4, 0x45, \n\t0x58, 0x01, 0x78, 0x31, 0x2b, 0x28, 0x88, 0x06, 0x21, 0x62, 0x10, 0x23, 0x9a, 0x90, 0x88, 0x41, \n\t0x10, 0x80, 0x19, 0x01, 0x40, 0x06, 0x21, 0x48, 0x11, 0x82, 0x20, 0xd0, 0x18, 0x09, 0x04, 0xb1, \n\t0x00, 0x25, 0xc0, 0x00, 0xc6, 0x20, 0x06, 0x22, 0x29, 0x59, 0x53, 0x60, 0x38, 0x81, 0x30, 0x8e, \n\t0x88, 0x06, 0xa4, 0x0e, 0x20, 0xa0, 0x84, 0x00, 0x02, 0x00, 0x20, 0x65, 0x32, 0x84, 0x00, 0x00, \n\t0x0a, 0x12, 0x12, 0x01, 0x2a, 0x18, 0x0f, 0x45, 0x02, 0x92, 0x69, 0x20, 0xa5, 0x51, 0x44, 0x12, \n\t0x44, 0x00, 0x2a, 0x18, 0x0d, 0x24, 0x52, 0xc4, 0x22, 0x8a, 0x80, 0x80, 0x00, 0x20, 0x00, 0xd8, \n\t0x00, 0x25, 0x12, 0x01, 0x44, 0x72, 0x02, 0x8a, 0x7c, 0x10, 0x20, 0x2c, 0x35, 0x52, 0x00, 0x80, \n\t0x90, 0x4a, 0x02, 0x05, 0x80, 0x14, 0x49, 0x18, 0x01, 0x18, 0x92, 0x88, 0xb1, 0x69, 0x18, 0x2c, \n\t0x34, 0x50, 0x4a, 0x80, 0x95, 0x16, 0x82, 0x10, 0x42, 0xa0, 0x0c, 0x90, 0x04, 0xaa, 0x44, 0x26, \n\t0x89, 0x10, 0x24, 0x40, 0x0b, 0x0e, 0x21, 0x20, 0x1c, 0x04, 0x86, 0x08, 0x10, 0xc1, 0x00, 0x0f, \n\t0x30, 0x5c, 0x04, 0x40, 0xa0, 0x2b, 0x98, 0x30, 0xd9, 0x61, 0x72, 0x24, 0x23, 0x21, 0x25, 0x46, \n\t0xe4, 0x1c, 0x00, 0x42, 0x08, 0x00, 0x88, 0xc1, 0x2c, 0x35, 0x20, 0x14, 0x40, 0x00, 0x23, 0x26, \n\t0xf4, 0x20, 0x15, 0x14, 0xda, 0x20, 0x00, 0x40, 0x53, 0x2f, 0xc0, 0xcb, 0x26, 0x52, 0x11, 0x01, \n\t0x06, 0xe1, 0xc0, 0x4a, 0x6a, 0x82, 0x48, 0x12, 0x80, 0x11, 0x00, 0x34, 0x87, 0x00, 0x21, 0xa9, \n\t0x00, 0x4a, 0x22, 0x80, 0x60, 0x33, 0x21, 0x10, 0x0a, 0x18, 0x42, 0xa0, 0x20, 0x3c, 0x92, 0x40, \n\t0x04, 0x61, 0x42, 0x1a, 0x58, 0x02, 0x82, 0x4a, 0x80, 0x00, 0x10, 0xdc, 0x01, 0x21, 0x04, 0xb0, \n\t0x9a, 0x04, 0x04, 0x02, 0x00, 0x28, 0x20, 0x52, 0x19, 0x80, 0xc1, 0xc6, 0x4c, 0x04, 0x28, 0x01, \n\t0x44, 0x93, 0x21, 0x30, 0x40, 0x08, 0xb4, 0x41, 0xc5, 0x28, 0x00, 0x30, 0x8a, 0x01, 0x00, 0x1a, \n\t0x60, 0x04, 0xc0, 0x03, 0xa0, 0x24, 0x14, 0xad, 0x20, 0x04, 0xc1, 0x00, 0x39, 0x48, 0x4c, 0x02, \n\t0xc6, 0x20, 0x20, 0x74, 0x95, 0x00, 0x22, 0x16, 0xc3, 0x1a, 0x00, 0x42, 0x01, 0x12, 0xe3, 0xc1, \n\t0x89, 0x68, 0x10, 0x24, 0x12, 0x86, 0x12, 0x08, 0x20, 0x14, 0x27, 0x00, 0x70, 0x80, 0x09, 0x50, \n\t0x8a, 0x8b, 0x70, 0x81, 0x10, 0x29, 0xcc, 0x01, 0x86, 0x04, 0x01, 0x10, 0x98, 0x3c, 0x50, 0xa0, \n\t0x02, 0x44, 0x00, 0x10, 0x49, 0x0a, 0x80, 0x3a, 0x60, 0x20, 0x15, 0xd0, 0x44, 0x00, 0x08, 0x25, \n\t0x81, 0x3a, 0x00, 0x15, 0xc0, 0x10, 0x42, 0x0a, 0x10, 0xc0, 0x0b, 0x20, 0x08, 0x71, 0x28, 0x2c, \n\t0xc0, 0x99, 0x41, 0x02, 0x30, 0x00, 0x00, 0x80, 0x99, 0x6c, 0x24, 0x63, 0x09, 0x10, 0x50, 0xc5, \n\t0x66, 0x0c, 0x12, 0x0a, 0x01, 0x94, 0x07, 0x0a, 0x42, 0x80, 0xe2, 0xa6, 0x29, 0x8c, 0x20, 0x04, \n\t0x11, 0x10, 0x01, 0x01, 0x18, 0x03, 0x24, 0x40, 0x18, 0x8c, 0x04, 0x88, 0xc6, 0x4c, 0x83, 0x20, \n\t0x09, 0xe0, 0x47, 0x8c, 0x40, 0x40, 0x01, 0x06, 0x25, 0x14, 0xc0, 0x72, 0x05, 0x70, 0x84, 0x40, \n\t0x40, 0x43, 0x20, 0xb0, 0x88, 0x13, 0x88, 0x89, 0xa2, 0x20, 0x55, 0x00, 0x00, 0x20, 0xd3, 0x04, \n\t0x08, 0x12, 0x21, 0x05, 0x08, 0x41, 0x68, 0x4a, 0x16, 0x00, 0x8e, 0x61, 0x00, 0xc6, 0x0c, 0xa2, \n\t0xc9, 0x01, 0xa8, 0x55, 0x00, 0x12, 0x60, 0x6a, 0x87, 0xd8, 0x12, 0x8a, 0x20, 0x14, 0x11, 0x32, \n\t0x00, 0x00, 0xa4, 0x08, 0x06, 0x10, 0x0d, 0x14, 0x10, 0x05, 0x40, 0x01, 0xa0, 0xa8, 0x40, 0x0f, \n\t0x80, 0x42, 0x04, 0x43, 0x37, 0x0c, 0x94, 0x4b, 0x28, 0x80, 0x90, 0x0c, 0x8d, 0x0d, 0xc9, 0x72, \n\t0x30, 0xd8, 0x92, 0x05, 0x01, 0x23, 0x1a, 0x10, 0x00, 0x81, 0x90, 0x06, 0xc5, 0x00, 0xa2, 0x02, \n\t0x88, 0x94, 0x56, 0x00, 0x08, 0x22, 0x49, 0x16, 0xc0, 0x81, 0x21, 0x18, 0xa0, 0x03, 0x11, 0x75, \n\t0x02, 0xc0, 0x46, 0x52, 0x90, 0x28, 0x30, 0x8a, 0x28, 0x30, 0x04, 0x10, 0x8a, 0x19, 0x49, 0x01, \n\t0x2c, 0x07, 0x00, 0x00, 0x44, 0x40, 0x24, 0x0a, 0x97, 0x59, 0x98, 0x01, 0x58, 0xa0, 0x22, 0x01, \n\t0x21, 0x00, 0xf4, 0xda, 0xa8, 0x5e, 0x60, 0x00, 0xac, 0x65, 0x01, 0x80, 0x42, 0xd0, 0x03, 0x00, \n\t0x14, 0x03, 0x4b, 0x02, 0x02, 0x60, 0x16, 0x81, 0x88, 0x84, 0x02, 0x62, 0xaa, 0x14, 0x84, 0xc2, \n\t0x40, 0x52, 0x15, 0x00, 0x95, 0x80, 0x01, 0x04, 0x10, 0x20, 0x08, 0x38, 0x08, 0xd0, 0x60, 0x14, \n\t0x20, 0x88, 0x88, 0x89, 0x14, 0x85, 0x3c, 0x00, 0x82, 0x03, 0x40, 0x90, 0x84, 0x02, 0x62, 0x22, \n\t0x01, 0x40, 0xcc, 0xc1, 0x1e, 0x13, 0x02, 0x2a, 0x20, 0x40, 0x22, 0x00, 0x10, 0x8b, 0x00, 0xa9, \n\t0x83, 0x00, 0x08, 0x85, 0x03, 0x38, 0x69, 0x59, 0x22, 0x54, 0xe1, 0xd0, 0xa0, 0xd4, 0x40, 0x29, \n\t0x12, 0x74, 0x20, 0x21, 0x54, 0x08, 0x08, 0x08, 0xc2, 0x22, 0x2b, 0x90, 0x14, 0x01, 0x4a, 0x53, \n\t0x30, 0x01, 0x30, 0x18, 0x40, 0x44, 0x84, 0x98, 0x30, 0x1c, 0x02, 0x04, 0x10, 0x61, 0x29, 0x08, \n\t0x4c, 0x02, 0x61, 0x10, 0x04, 0x60, 0x98, 0xd0, 0x08, 0x8b, 0x00, 0x14, 0x92, 0x2c, 0x61, 0x06, \n\t0x85, 0x0a, 0x12, 0xa1, 0x1b, 0xe0, 0x83, 0x88, 0x5c, 0x21, 0x48, 0x20, 0x30, 0x41, 0x8a, 0x46, \n\t0x84, 0x50, 0x0e, 0x09, 0x01, 0x05, 0x70, 0x40, 0x81, 0x02, 0x14, 0x01, 0xc8, 0x00, 0xd5, 0x01, \n\t0x20, 0x00, 0x0d, 0x4f, 0x58, 0x00, 0xe0, 0x90, 0x08, 0x50, 0x09, 0x0a, 0x23, 0xcb, 0x0c, 0x09, \n\t0xc4, 0x02, 0x26, 0x86, 0x58, 0x0d, 0x0c, 0x94, 0x41, 0x5a, 0xd2, 0x18, 0x04, 0x80, 0x02, 0x06, \n\t0x40, 0x14, 0xc0, 0x04, 0x11, 0x08, 0x04, 0x42, 0x60, 0x20, 0x03, 0x48, 0xc1, 0x80, 0x42, 0x15, \n\t0x50, 0x18, 0xc1, 0x14, 0x2a, 0x24, 0x55, 0x58, 0x14, 0x64, 0x54, 0x69, 0x20, 0x04, 0x91, 0x90, \n\t0x60, 0x50, 0xc8, 0x22, 0x23, 0x40, 0x21, 0x01, 0x4e, 0x65, 0x08, 0x25, 0x00, 0x18, 0x01, 0x0c, \n\t0x03, 0x20, 0x04, 0xe1, 0x91, 0x34, 0xc1, 0x68, 0x30, 0x41, 0x10, 0x02, 0x21, 0x12, 0x0a, 0x00, \n\t0x04, 0xf0, 0x2c, 0x58, 0x04, 0x8d, 0x00, 0x80, 0x2b, 0xa8, 0x70, 0x16, 0x65, 0x08, 0xc2, 0x80, \n\t0x12, 0x8c, 0x82, 0x44, 0x48, 0x20, 0x30, 0x14, 0x04, 0xc0, 0x81, 0x20, 0x02, 0x42, 0xb0, 0x00, \n\t0x46, 0x80, 0x18, 0x14, 0x02, 0x10, 0x38, 0x4a, 0xc2, 0x60, 0xc0, 0x6a, 0x0a, 0x88, 0x4c, 0x88, \n\t0x20, 0x21, 0xc2, 0x0b, 0xe8, 0xc4, 0xa4, 0x04, 0x40, 0x00, 0x0a, 0x60, 0x58, 0x4c, 0x18, 0x72, \n\t0x89, 0x23, 0x00, 0x0a, 0x20, 0x2a, 0x26, 0x02, 0x08, 0x88, 0x10, 0x04, 0x14, 0x80, 0x20, 0x31, \n\t0x3c, 0x54, 0xc0, 0x00, 0x81, 0xa3, 0x80, 0x44, 0x00, 0x66, 0x24, 0x81, 0x43, 0x16, 0x81, 0x18, \n\t0x87, 0x06, 0x14, 0x20, 0x15, 0x00, 0x04, 0x23, 0x04, 0x46, 0xe2, 0x3f, 0x00, 0x03, 0x04, 0x54, \n\t0x30, 0x61, 0x12, 0xc0, 0x02, 0x41, 0x46, 0x21, 0xc3, 0x8a, 0x14, 0x08, 0x26, 0x30, 0x24, 0x48, \n\t0x21, 0x0d, 0x07, 0xa1, 0x18, 0xa2, 0x70, 0x06, 0x00, 0x92, 0x00, 0x78, 0x47, 0x20, 0xb0, 0x0c, \n\t0x55, 0x00, 0x2e, 0xe2, 0x20, 0x88, 0xb1, 0x8a, 0x8c, 0x02, 0x02, 0x03, 0x0c, 0x81, 0x50, 0x83, \n\t0x44, 0x93, 0x00, 0x26, 0xc1, 0x04, 0x40, 0x20, 0xf1, 0x01, 0x20, 0xc8, 0x11, 0x4e, 0x2e, 0x00, \n\t0x20, 0x23, 0x51, 0x50, 0x20, 0x7c, 0x06, 0x81, 0x08, 0x48, 0x4c, 0x82, 0x14, 0x00, 0xca, 0xa5, \n\t0x44, 0x17, 0x00, 0x08, 0x02, 0x0a, 0x9a, 0x50, 0x10, 0x40, 0x22, 0x40, 0x01, 0x08, 0x75, 0x80, \n\t0x2a, 0x02, 0x46, 0x21, 0x8a, 0x24, 0x49, 0x81, 0x0a, 0x94, 0x03, 0x8d, 0x04, 0x00, 0x24, 0x48, \n\t0xa0, 0x3a, 0x02, 0x01, 0x4c, 0x09, 0x48, 0x22, 0x42, 0x08, 0xc0, 0x13, 0xac, 0x08, 0xb2, 0x91, \n\t0x00, 0x04, 0x98, 0x41, 0x64, 0x01, 0xc1, 0x2a, 0x40, 0x83, 0x21, 0x64, 0x33, 0x1a, 0x08, 0x00, \n\t0x00, 0x20, 0x12, 0x94, 0x4b, 0x95, 0xcc, 0x58, 0x04, 0x20, 0x54, 0x48, 0xa0, 0xa9, 0x08, 0x43, \n\t0x20, 0x01, 0xd0, 0xa0, 0xe1, 0x40, 0x04, 0x06, 0xb7, 0x91, 0x01, 0x29, 0xcb, 0xe0, 0x20, 0x25, \n\t0x18, 0x24, 0x84, 0x00, 0xc0, 0x10, 0x50, 0x01, 0x01, 0x38, 0x00, 0x2c, 0x00, 0x67, 0xa1, 0x18, \n\t0x90, 0x00, 0x8d, 0x68, 0x04, 0x70, 0x28, 0x18, 0x87, 0x83, 0x16, 0x30, 0x62, 0x0c, 0x14, 0x10, \n\t0xaa, 0x30, 0x17, 0xa2, 0xa5, 0xc9, 0x92, 0x44, 0x20, 0xb2, 0x0a, 0x03, 0x5d, 0x01, 0xc4, 0x4e, \n\t0x10, 0x8a, 0x21, 0x40, 0x90, 0x80, 0x2a, 0x24, 0x00, 0x21, 0xf0, 0x41, 0x42, 0x56, 0x02, 0x02, \n\t0x14, 0x60, 0x49, 0x20, 0x02, 0x04, 0x81, 0xa2, 0x08, 0x40, 0x42, 0x00, 0x00, 0x20, 0x23, 0x31, \n\t0x04, 0x88, 0x40, 0x01, 0x61, 0x84, 0x28, 0x46, 0x0c, 0x48, 0xb1, 0xb2, 0x06, 0x20, 0x08, 0x8e, \n\t0x72, 0x30, 0x99, 0x15, 0x31, 0x44, 0x0d, 0x04, 0xa2, 0x63, 0x84, 0x21, 0x90, 0xa2, 0x00, 0xc4, \n\t0x41, 0x05, 0x1c, 0xc8, 0x05, 0x28, 0x11, 0x18, 0x02, 0x49, 0x03, 0x00, 0x18, 0x15, 0xd0, 0xa2, \n\t0x0c, 0xc0, 0x26, 0x46, 0x04, 0x28, 0x02, 0x1d, 0xd1, 0x01, 0x54, 0xe3, 0x8a, 0x80, 0x00, 0x10, \n\t0xce, 0x04, 0x02, 0x10, 0xa3, 0x70, 0x04, 0x03, 0x26, 0x97, 0x09, 0xb3, 0x90, 0x96, 0x00, 0x18, \n\t0x82, 0xc8, 0x21, 0x1c, 0x5c, 0x61, 0x00, 0x41, 0x42, 0x05, 0x80, 0x88, 0x21, 0x08, 0xa0, 0x10, \n\t0x09, 0x15, 0xc0, 0x00, 0x40, 0x01, 0xa8, 0x09, 0x68, 0x1a, 0x8a, 0x50, 0x80, 0xc0, 0x23, 0x80, \n\t0x52, 0xc9, 0x00, 0x47, 0x82, 0x22, 0x01, 0x45, 0x45, 0x40, 0x51, 0x78, 0x05, 0x21, 0x0a, 0x84, \n\t0x66, 0x44, 0x1a, 0x82, 0x01, 0x4b, 0x23, 0x70, 0x45, 0xb0, 0x84, 0x48, 0x40, 0x49, 0x32, 0x10, \n\t0x11, 0x08, 0x98, 0x00, 0x81, 0x28, 0x61, 0x41, 0x0d, 0x14, 0x83, 0x84, 0x20, 0x16, 0x41, 0x96, \n\t0xa0, 0x91, 0x08, 0x2c, 0x70, 0x80, 0x83, 0x51, 0x48, 0x20, 0x28, 0x14, 0x90, 0x01, 0xd9, 0x11, \n\t0x24, 0x5a, 0x21, 0x70, 0x03, 0x38, 0x86, 0xa8, 0x04, 0x20, 0x43, 0x28, 0x08, 0x88, 0x43, 0x6c, \n\t0x86, 0x80, 0x85, 0x28, 0x0a, 0x87, 0x04, 0x41, 0x89, 0x32, 0x00, 0x50, 0x28, 0x12, 0x50, 0x38, \n\t0xb0, 0x80, 0x88, 0xaa, 0x10, 0x24, 0x28, 0x0a, 0xb1, 0x40, 0x22, 0x16, 0x65, 0x10, 0xa9, 0x09, \n\t0x09, 0xc1, 0x04, 0x02, 0x59, 0x1c, 0x84, 0x14, 0x42, 0x02, 0x62, 0x89, 0x0c, 0x20, 0x09, 0x64, \n\t0x40, 0x82, 0x49, 0x0a, 0x21, 0x97, 0x41, 0x52, 0x06, 0x13, 0x04, 0x40, 0x00, 0x62, 0x06, 0x80, \n\t0xa1, 0x84, 0x08, 0x90, 0x00, 0x08, 0x80, 0x60, 0x02, 0x18, 0x41, 0x84, 0x42, 0xe1, 0x82, 0x03, \n\t0x10, 0x40, 0x21, 0x50, 0x02, 0x42, 0x84, 0x04, 0x4a, 0x0a, 0x4a, 0x11, 0xa3, 0x82, 0xac, 0x99, \n\t0x08, 0x56, 0x23, 0x01, 0x0a, 0x8c, 0x5c, 0xa4, 0x46, 0x34, 0x00, 0x88, 0x1c, 0x82, 0x0d, 0x32, \n\t0x11, 0x00, 0x33, 0x81, 0x01, 0x40, 0x08, 0x00, 0x08, 0x2e, 0x80, 0x10, 0x28, 0x68, 0x61, 0x29, \n\t0x02, 0x80, 0x00, 0x46, 0x40, 0x30, 0xa9, 0x00, 0x98, 0x13, 0x2c, 0x10, 0xb0, 0x89, 0x01, 0x30, \n\t0x8c, 0x86, 0x30, 0x23, 0x50, 0x03, 0x00, 0x40, 0x02, 0x08, 0x80, 0xa0, 0x25, 0x10, 0x08, 0xe6, \n\t0x16, 0x04, 0x40, 0x98, 0x20, 0x16, 0x0c, 0x54, 0x41, 0xd2, 0x10, 0x30, 0x12, 0x00, 0x1a, 0x42, \n\t0x82, 0x30, 0x45, 0x19, 0xad, 0x40, 0x83, 0x4a, 0x91, 0xa8, 0x81, 0x00, 0x12, 0x02, 0x51, 0x00, \n\t0x20, 0x9a, 0x04, 0x40, 0x64, 0x68, 0x3c, 0x30, 0xda, 0x41, 0x62, 0xb0, 0x18, 0x10, 0xe9, 0x41, \n\t0x80, 0x0c, 0x36, 0x62, 0x2c, 0x15, 0x85, 0x69, 0x08, 0x11, 0x01, 0x08, 0x68, 0x82, 0x0c, 0x7c, \n\t0x04, 0x32, 0x1a, 0x95, 0x00, 0x6d, 0x60, 0x50, 0x10, 0x87, 0x25, 0x0c, 0x00, 0x4c, 0x80, 0x11, \n\t0x28, 0x80, 0x44, 0x26, 0x58, 0x11, 0x80, 0x85, 0x25, 0x16, 0x4a, 0x0c, 0x41, 0x88, 0x10, 0x04, \n\t0x08, 0x42, 0x42, 0x84, 0x43, 0x80, 0x94, 0x48, 0x02, 0x02, 0x47, 0x49, 0x95, 0x70, 0x09, 0xc0, \n\t0x00, 0x00, 0x09, 0x1a, 0xa4, 0x01, 0x05, 0x20, 0x80, 0x00, 0x09, 0x50, 0x4a, 0x6e, 0x30, 0xb0, \n\t0x00, 0x10, 0x8d, 0x01, 0xaa, 0x0a, 0xd1, 0x4a, 0x07, 0x21, 0x80, 0xa6, 0x00, 0x20, 0x12, 0x2c, \n\t0x48, 0x82, 0x40, 0x20, 0x51, 0x98, 0x24, 0x65, 0x86, 0x20, 0x2a, 0xd0, 0x02, 0x1d, 0x69, 0x08, \n\t0xa0, 0x18, 0x30, 0x43, 0x01, 0x81, 0xca, 0x48, 0x30, 0x21, 0x90, 0xa2, 0x99, 0x00, 0x4d, 0x04, \n\t0x45, 0x80, 0x02, 0x08, 0xc8, 0x08, 0x0c, 0xd2, 0x60, 0xab, 0x75, 0x41, 0x00, 0x30, 0x86, 0x60, \n\t0x04, 0x30, 0x44, 0x29, 0x14, 0x47, 0x32, 0x94, 0x50, 0x0c, 0x80, 0x64, 0xb0, 0x40, 0x0c, 0xd4, \n\t0x14, 0x80, 0x1c, 0x00, 0x18, 0x28, 0xcd, 0x8c, 0x08, 0x00, 0x54, 0xe3, 0x38, 0x04, 0xc0, 0x69, \n\t0x40, 0x45, 0x38, 0xa0, 0x05, 0xc9, 0x22, 0x10, 0x83, 0x20, 0x9c, 0x0c, 0x93, 0x88, 0x60, 0x00, \n\t0x53, 0x94, 0x40, 0x16, 0x22, 0x3c, 0x20, 0x3a, 0x00, 0x14, 0x01, 0xc1, 0x04, 0x86, 0x08, 0x20, \n\t0x40, 0x88, 0x00, 0x30, 0x83, 0x48, 0x18, 0xb0, 0x11, 0x47, 0x08, 0x20, 0xe2, 0x22, 0x80, 0x4f, \n\t0x20, 0x08, 0x80, 0x92, 0x01, 0xa8, 0x05, 0x05, 0x22, 0x04, 0xd3, 0x10, 0xc1, 0x00, 0x8e, 0x0a, \n\t0xc1, 0x00, 0x08, 0x44, 0x0e, 0x4a, 0x48, 0x23, 0x40, 0x80, 0x44, 0x8a, 0x07, 0x40, 0x50, 0x98, \n\t0x37, 0x28, 0x10, 0x66, 0x02, 0x94, 0x69, 0x04, 0x29, 0x10, 0x22, 0x30, 0x40, 0x23, 0x14, 0x74, \n\t0xc4, 0x40, 0x0e, 0x02, 0x00, 0x94, 0x00, 0x09, 0xe8, 0x44, 0x21, 0x90, 0x12, 0x84, 0x81, 0x46, \n\t0x04, 0x46, 0x31, 0x8a, 0x05, 0xc9, 0x01, 0x50, 0x46, 0xc0, 0x07, 0x10, 0xc0, 0x0c, 0x02, 0x84, \n\t0xc0, 0x10, 0x08, 0x80, 0x49, 0x06, 0x02, 0x21, 0x04, 0x24, 0x96, 0x40, 0x04, 0x41, 0x1b, 0x0a, \n\t0x2c, 0x02, 0xca, 0x54, 0x20, 0x03, 0x81, 0xc4, 0x0a, 0x83, 0x40, 0xd2, 0x22, 0x0c, 0x20, 0x46, \n\t0x00, 0x20, 0x40, 0x1b, 0x20, 0x4c, 0x8d, 0x80, 0x6c, 0x60, 0x99, 0x17, 0xd1, 0x45, 0x20, 0x10, \n\t0x22, 0x40, 0xae, 0x00, 0x1c, 0x44, 0x50, 0xb0, 0x10, 0x03, 0x74, 0xc8, 0x41, 0x34, 0x36, 0x40, \n\t0xb1, 0x40, 0x19, 0x00, 0x00, 0x27, 0xc2, 0x22, 0x80, 0x02, 0x61, 0x00, 0xf0, 0x2b, 0x02, 0xb0, \n\t0x40, 0x09, 0x4c, 0x14, 0x09, 0x08, 0x34, 0x04, 0x49, 0x00, 0x92, 0x41, 0xa4, 0x60, 0x08, 0x48, \n\t0x70, 0x21, 0x62, 0xb5, 0x45, 0x13, 0xa8, 0x00, 0x80, 0xb2, 0x10, 0x40, 0x0d, 0x03, 0x30, 0x05, \n\t0x90, 0x11, 0x29, 0x48, 0x8e, 0x40, 0x01, 0x52, 0x11, 0x68, 0x80, 0x89, 0x62, 0x46, 0xa3, 0x28, \n\t0x40, 0x11, 0x00, 0x40, 0xc3, 0xc1, 0x01, 0x11, 0xc5, 0xa9, 0x10, 0x90, 0x11, 0x30, 0x81, 0xc3, \n\t0x06, 0x72, 0x21, 0x03, 0x88, 0x00, 0x03, 0x04, 0x12, 0xa5, 0x60, 0x92, 0x59, 0x04, 0xa1, 0x08, \n\t0x24, 0x21, 0x00, 0xa0, 0x02, 0x24, 0x42, 0x72, 0x10, 0x82, 0x08, 0x80, 0x00, 0x3c, 0x35, 0x11, \n\t0x0b, 0x50, 0x11, 0x48, 0x08, 0xb6, 0x90, 0x11, 0x00, 0x15, 0x00, 0x46, 0x42, 0x00, 0x03, 0xa0, \n\t0x86, 0x02, 0x04, 0x44, 0x09, 0x90, 0x00, 0x18, 0x09, 0x16, 0x02, 0x81, 0x2a, 0x49, 0x1c, 0x0b, \n\t0x50, 0xd1, 0xc0, 0x11, 0x30, 0x03, 0x0d, 0x08, 0xc5, 0x00, 0x88, 0x04, 0x12, 0xc4, 0x20, 0xb0, \n\t0x21, 0x23, 0x00, 0x8f, 0x0c, 0x74, 0x53, 0x91, 0x98, 0x31, 0x10, 0xc0, 0x18, 0xb0, 0x3a, 0x24, \n\t0xf0, 0xc2, 0x00, 0x42, 0x83, 0x82, 0x82, 0x5c, 0x08, 0xa9, 0x20, 0x20, 0x62, 0x07, 0x01, 0x01, \n\t0x03, 0x06, 0xc4, 0x10, 0x05, 0x48, 0xd1, 0x20, 0x2a, 0x42, 0x1a, 0x80, 0x40, 0x52, 0x0e, 0x10, \n\t0x24, 0x11, 0x84, 0x08, 0x41, 0x62, 0x68, 0x25, 0xc0, 0x36, 0x31, 0x41, 0xc0, 0x12, 0x06, 0x01, \n\t0x82, 0x65, 0x0c, 0xaa, 0x24, 0xa0, 0x20, 0x81, 0x10, 0xc4, 0x00, 0x18, 0x05, 0x61, 0x08, 0x10, \n\t0x02, 0x21, 0x4a, 0x51, 0xe2, 0x00, 0xa0, 0x04, 0x82, 0x0a, 0xa2, 0x30, 0x15, 0xcd, 0xd5, 0x22, \n\t0x16, 0x81, 0x08, 0x04, 0xb9, 0x86, 0x01, 0x40, 0x15, 0x23, 0x24, 0x0c, 0x0a, 0x82, 0x60, 0x85, \n\t0x88, 0x0c, 0x01, 0x80, 0x41, 0x50, 0x10, 0x08, 0x3a, 0xa0, 0x81, 0x02, 0x50, 0x34, 0x21, 0x04, \n\t0x5d, 0x50, 0xe1, 0x48, 0x07, 0x0a, 0x0c, 0xd0, 0x01, 0x82, 0x40, 0x24, 0x41, 0x8a, 0x71, 0xc5, \n\t0x24, 0x10, 0xb3, 0x49, 0x04, 0xa1, 0x4c, 0x0a, 0x02, 0xc2, 0x00, 0x82, 0x00, 0x4f, 0x08, 0x02, \n\t0x05, 0x00, 0x08, 0x39, 0x18, 0x8b, 0x04, 0x10, 0x78, 0x20, 0x21, 0xd5, 0x46, 0x02, 0x42, 0x82, \n\t0x06, 0x70, 0x00, 0x44, 0x08, 0x10, 0x90, 0x10, 0x14, 0x4a, 0x08, 0x26, 0xe0, 0x12, 0x8c, 0x18, \n\t0x0a, 0x04, 0x28, 0xc5, 0x01, 0xb3, 0xa0, 0x08, 0x04, 0x48, 0x74, 0x30, 0x12, 0x58, 0x47, 0x83, \n\t0x30, 0x04, 0x39, 0x02, 0x81, 0x01, 0x22, 0x02, 0x96, 0x02, 0x11, 0x44, 0xc0, 0x08, 0x38, 0x94, \n\t0x60, 0x0a, 0xa5, 0x4c, 0xcd, 0x60, 0x91, 0x02, 0x24, 0x80, 0x9c, 0x20, 0x4e, 0x60, 0x68, 0x01, \n\t0x50, 0x01, 0x6c, 0x04, 0x12, 0xc8, 0x10, 0x68, 0x40, 0x8a, 0x02, 0x03, 0x01, 0x83, 0x00, 0x94, \n\t0x00, 0x40, 0xe0, 0xf1, 0x20, 0x19, 0x48, 0x84, 0x04, 0x00, 0x10, 0x89, 0x10, 0x1a, 0x81, 0x14, \n\t0x00, 0x00, 0x03, 0x20, 0x55, 0x24, 0x60, 0x21, 0x11, 0x84, 0x09, 0x4d, 0x82, 0x00, 0x05, 0x23, \n\t0x02, 0x81, 0x09, 0xe1, 0x26, 0x02, 0x42, 0x29, 0x58, 0x82, 0x21, 0x00, 0x22, 0x40, 0x04, 0x05, \n\t0x81, 0xcc, 0x7a, 0x42, 0xa0, 0x8c, 0x84, 0x50, 0x4d, 0x50, 0x06, 0xc0, 0x00, 0x90, 0x83, 0x0c, \n\t0x72, 0x00, 0x98, 0x18, 0x41, 0x81, 0x4b, 0x0e, 0x70, 0x28, 0x20, 0x28, 0x10, 0x60, 0x38, 0x17, \n\t0xa1, 0x99, 0x10, 0x02, 0x41, 0x40, 0x82, 0x82, 0x82, 0x05, 0x14, 0x24, 0x04, 0x01, 0xb1, 0x14, \n\t0x48, 0x98, 0xa2, 0x0a, 0x30, 0x20, 0x06, 0x20, 0x05, 0x02, 0x0c, 0x61, 0x41, 0x16, 0x20, 0x09, \n\t0x22, 0x54, 0x14, 0x01, 0xa8, 0x34, 0x81, 0xa8, 0x12, 0x60, 0x40, 0x97, 0x10, 0x83, 0x40, 0x40, \n\t0x40, 0x48, 0x17, 0x90, 0x02, 0x28, 0x28, 0x40, 0x89, 0x10, 0x09, 0x94, 0x00, 0x44, 0x92, 0x82, \n\t0x19, 0xc1, 0x83, 0x08, 0x10, 0xc3, 0x00, 0x0a, 0x24, 0x18, 0x25, 0x00, 0x07, 0x41, 0x10, 0x01, \n\t0x89, 0x28, 0x20, 0x22, 0x80, 0x82, 0x70, 0x5a, 0x06, 0x12, 0x44, 0x33, 0x00, 0xc1, 0x0a, 0x00, \n\t0x26, 0x20, 0x00, 0x21, 0xa8, 0x5c, 0x81, 0x18, 0x84, 0x5a, 0x9c, 0x19, 0x54, 0xa0, 0x66, 0x45, \n\t0x10, 0x2b, 0x9c, 0x0c, 0x00, 0x32, 0x01, 0x28, 0x19, 0x44, 0x1a, 0x87, 0x72, 0x82, 0x20, 0x34, \n\t0xa0, 0x02, 0x04, 0x08, 0x60, 0x11, 0x13, 0x00, 0x01, 0x23, 0x26, 0x26, 0x5a, 0x29, 0x80, 0x43, \n\t0x88, 0x48, 0x00, 0x90, 0x0a, 0x64, 0x80, 0xce, 0x08, 0x80, 0x90, 0x09, 0x80, 0x52, 0x61, 0x60, \n\t0x60, 0x98, 0x29, 0x54, 0x09, 0x07, 0x44, 0x13, 0x8a, 0x11, 0x20, 0x19, 0x24, 0x28, 0x55, 0x82, \n\t0x93, 0x88, 0x8a, 0x82, 0x04, 0xc5, 0x29, 0x08, 0x80, 0x05, 0x48, 0x20, 0xc1, 0xc1, 0x88, 0xdc, \n\t0x82, 0x22, 0x06, 0x05, 0x38, 0x3c, 0x50, 0x92, 0x45, 0x0a, 0x20, 0xc3, 0x00, 0x10, 0x1b, 0x4c, \n\t0x5a, 0x30, 0x40, 0x0e, 0x29, 0x04, 0x61, 0x02, 0x32, 0x70, 0x00, 0x19, 0x05, 0x89, 0x42, 0x60, \n\t0x42, 0x89, 0x00, 0x02, 0x06, 0x68, 0x06, 0x30, 0xa4, 0x84, 0x49, 0xeb, 0x40, 0x55, 0x1a, 0x88, \n\t0x01, 0x44, 0xa5, 0x04, 0xd2, 0x81, 0x8f, 0x89, 0x11, 0x28, 0x40, 0x60, 0x1b, 0x85, 0xd1, 0x08, \n\t0x41, 0x40, 0x82, 0x0b, 0xb4, 0xb1, 0x0d, 0x64, 0x24, 0x10, 0x0b, 0x01, 0xa4, 0x03, 0x82, 0x0c, \n\t0x03, 0x60, 0x03, 0x54, 0x54, 0xc6, 0x60, 0x60, 0xa2, 0x17, 0x00, 0x1c, 0x08, 0x04, 0x21, 0xf8, \n\t0x94, 0x01, 0x83, 0xab, 0x00, 0x30, 0x10, 0x00, 0x24, 0x00, 0x04, 0x1e, 0x01, 0x60, 0x00, 0x51, \n\t0x88, 0x47, 0x04, 0x84, 0x01, 0x06, 0x95, 0x12, 0x60, 0x40, 0x20, 0x20, 0x02, 0x41, 0xc9, 0x40, \n\t0x32, 0x85, 0x90, 0x2f, 0x84, 0x8e, 0x20, 0x4c, 0x15, 0x71, 0x01, 0x28, 0xc2, 0x00, 0x18, 0x82, \n\t0x00, 0x18, 0x44, 0x50, 0x2d, 0x62, 0x22, 0x58, 0x80, 0x34, 0xc5, 0x68, 0x02, 0xb6, 0x00, 0x02, \n\t0x71, 0xc1, 0x08, 0x00, 0x50, 0x0a, 0x93, 0x84, 0x10, 0x00, 0x2a, 0x02, 0x6b, 0x80, 0x39, 0x17, \n\t0xcd, 0x20, 0x04, 0x00, 0x31, 0x00, 0x00, 0x02, 0x48, 0xb0, 0xa8, 0xac, 0x01, 0x84, 0xc4, 0x2c, \n\t0x41, 0x32, 0x18, 0x40, 0x80, 0x04, 0x0a, 0x10, 0x90, 0x20, 0x20, 0x17, 0x40, 0x10, 0x46, 0x13, \n\t0x18, 0x08, 0x00, 0xac, 0x00, 0x30, 0x00, 0x82, 0x88, 0x08, 0x81, 0x04, 0x40, 0x88, 0x10, 0x49, \n\t0x00, 0x21, 0x14, 0x03, 0x00, 0x10, 0x01, 0x81, 0xc1, 0x30, 0xa2, 0x08, 0x94, 0xf4, 0x01, 0x80, \n\t0x28, 0x13, 0xc1, 0x09, 0xa4, 0x95, 0x21, 0x12, 0x00, 0x49, 0x03, 0xd0, 0xc5, 0x42, 0x56, 0x16, \n\t0x00, 0x05, 0x05, 0x92, 0x64, 0x06, 0x40, 0x60, 0x02, 0x75, 0x0c, 0x2e, 0x08, 0x05, 0x40, 0x22, \n\t0x01, 0x10, 0x81, 0x02, 0xd0, 0x12, 0x30, 0x4d, 0x85, 0x40, 0x0a, 0x16, 0x2a, 0x20, 0x80, 0x84, \n\t0x04, 0x34, 0x30, 0x09, 0x01, 0x8c, 0x46, 0xe0, 0x34, 0x81, 0x3a, 0x38, 0x80, 0x09, 0x81, 0x30, \n\t0x14, 0x02, 0x03, 0xd5, 0x03, 0x07, 0x02, 0x45, 0x40, 0x89, 0x81, 0x40, 0x40, 0x00, 0x15, 0x00, \n\t0x87, 0x24, 0x50, 0x2c, 0x44, 0x60, 0x80, 0x0d, 0x68, 0x59, 0xc4, 0x28, 0xa0, 0x72, 0x01, 0x05, \n\t0x52, 0x48, 0x04, 0x02, 0x88, 0x05, 0xc8, 0x80, 0x42, 0x0c, 0x63, 0xa1, 0x30, 0x88, 0xc2, 0xce, \n\t0x28, 0xd6, 0x20, 0x0a, 0x18, 0x04, 0x41, 0x24, 0x04, 0xa2, 0x28, 0xe4, 0x46, 0xa8, 0x08, 0x70, \n\t0x08, 0xa1, 0x54, 0x85, 0x02, 0x6c, 0x20, 0x11, 0xa0, 0x40, 0x1c, 0x08, 0x54, 0x70, 0x00, 0x18, \n\t0x99, 0x0a, 0xa8, 0x10, 0xa2, 0x08, 0xb8, 0x84, 0xc0, 0x0d, 0x18, 0x81, 0x21, 0x8a, 0x28, 0xc0, \n\t0x61, 0x02, 0xc4, 0x90, 0x01, 0x89, 0x1e, 0x02, 0x00, 0x24, 0x81, 0x04, 0x41, 0x05, 0x80, 0x4c, \n\t0x20, 0xb0, 0x84, 0x54, 0x80, 0x44, 0x4c, 0xb2, 0xa1, 0x00, 0x85, 0x08, 0x00, 0x42, 0x32, 0x02, \n\t0xae, 0x08, 0xd8, 0x05, 0x48, 0x10, 0xc3, 0x26, 0x0c, 0x1a, 0xa2, 0x20, 0x04, 0x80, 0x00, 0x0d, \n\t0x12, 0x83, 0x4c, 0xc1, 0x11, 0x8a, 0x28, 0x04, 0x04, 0x56, 0x81, 0x8b, 0x01, 0x28, 0x01, 0xc9, \n\t0x22, 0x74, 0x48, 0x31, 0x50, 0x00, 0x41, 0x28, 0x30, 0x00, 0x1a, 0x34, 0x0a, 0x40, 0x24, 0x85, \n\t0x1a, 0x12, 0x08, 0xd8, 0x85, 0x02, 0x84, 0x01, 0x31, 0x2d, 0x81, 0x80, 0x00, 0x73, 0xf2, 0x23, \n\t0x08, 0x80, 0x00, 0x54, 0x12, 0xc1, 0x29, 0x0d, 0x13, 0x04, 0x08, 0x54, 0xb0, 0x1c, 0x21, 0x01, \n\t0xc4, 0x76, 0x90, 0x21, 0xa2, 0x01, 0x04, 0x0a, 0x40, 0x01, 0x12, 0x04, 0x40, 0x08, 0x2a, 0x0e, \n\t0x00, 0xc2, 0x16, 0x74, 0x0c, 0xaa, 0x00, 0x80, 0x41, 0x83, 0x91, 0x06, 0x66, 0x06, 0x64, 0x60, \n\t0x95, 0x65, 0x02, 0x09, 0x50, 0x25, 0x08, 0x88, 0x20, 0x88, 0x25, 0x40, 0xa2, 0x6a, 0x1b, 0x60, \n\t0x8f, 0x48, 0x26, 0x20, 0x41, 0x14, 0x00, 0x81, 0x8c, 0x40, 0x82, 0x41, 0x8e, 0x15, 0x08, 0x68, \n\t0x38, 0x14, 0x00, 0x11, 0x8c, 0x41, 0xe2, 0x46, 0xe3, 0x88, 0x31, 0x01, 0x07, 0x82, 0x00, 0x03, \n\t0x82, 0x2a, 0xc9, 0xd3, 0x06, 0x6a, 0x64, 0x10, 0x06, 0x2c, 0x11, 0xa0, 0x60, 0xa6, 0x08, 0x82, \n\t0x90, 0x59, 0x80, 0x30, 0x92, 0x91, 0xa8, 0x10, 0x44, 0x01, 0x28, 0x40, 0x29, 0x00, 0x45, 0xd1, \n\t0x84, 0x12, 0x52, 0x00, 0xb2, 0x8c, 0x41, 0x65, 0x08, 0x22, 0x41, 0x88, 0x10, 0x1c, 0xa2, 0x44, \n\t0x02, 0x83, 0x18, 0x18, 0x16, 0x03, 0x4a, 0xb0, 0x21, 0x03, 0x14, 0x12, 0x8a, 0x40, 0x91, 0x60, \n\t0x04, 0x50, 0x0b, 0x0b, 0x20, 0xd0, 0x02, 0x90, 0x14, 0x06, 0x60, 0x20, 0x10, 0x59, 0x00, 0x09, \n\t0x0a, 0x24, 0x00, 0x14, 0x62, 0x91, 0x10, 0x80, 0x69, 0x54, 0x20, 0x42, 0xa8, 0x44, 0x44, 0xcb, \n\t0x00, 0x00, 0x00, 0x0b, 0x04, 0x40, 0x89, 0x30, 0x81, 0x79, 0x02, 0x40, 0x41, 0x8e, 0x50, 0x14, \n\t0x01, 0xa0, 0x38, 0xd8, 0x01, 0x08, 0x90, 0x01, 0x92, 0xd1, 0x85, 0x60, 0x00, 0x80, 0xd1, 0x38, \n\t0xa0, 0x44, 0x48, 0x0a, 0x80, 0xc0, 0x29, 0xf4, 0x1a, 0x88, 0x44, 0x05, 0x32, 0x20, 0x05, 0x49, \n\t0x49, 0x00, 0xe4, 0x30, 0x81, 0x40, 0x16, 0x82, 0x46, 0x83, 0xb8, 0x03, 0x41, 0x10, 0x2e, 0x10, \n\t0x71, 0x40, 0x24, 0x15, 0x00, 0x49, 0x0a, 0x04, 0x08, 0xbc, 0xc4, 0x00, 0xc2, 0x36, 0x21, 0x80, \n\t0x3a, 0x41, 0x02, 0xa0, 0x20, 0x10, 0x30, 0xa5, 0x00, 0x86, 0x49, 0x30, 0x42, 0x82, 0x90, 0x90, \n\t0xc8, 0x00, 0x12, 0x63, 0x20, 0x04, 0x01, 0x98, 0x49, 0x00, 0x10, 0x12, 0x38, 0xc8, 0xc4, 0x08, \n\t0x06, 0x82, 0xe8, 0x00, 0x09, 0x02, 0x06, 0x00, 0x90, 0x90, 0x0a, 0x1c, 0x02, 0x21, 0x02, 0x84, \n\t0xb0, 0x16, 0x2c, 0x04, 0xa2, 0x58, 0x54, 0xc9, 0x10, 0x61, 0x84, 0x04, 0x04, 0x31, 0x61, 0x90, \n\t0xb8, 0x07, 0x02, 0x40, 0x42, 0x19, 0x00, 0x38, 0x15, 0x4c, 0x42, 0x91, 0x9a, 0x9a, 0x00, 0x46, \n\t0x0e, 0x00, 0x20, 0x61, 0x8c, 0x20, 0x88, 0x02, 0x1a, 0xc7, 0x88, 0x21, 0x90, 0x0b, 0x00, 0x00, \n\t0x43, 0xa0, 0x06, 0xe1, 0x40, 0xa9, 0x20, 0x80, 0x1a, 0x09, 0x88, 0x10, 0x08, 0x4c, 0x00, 0x0b, \n\t0x28, 0x14, 0x18, 0x20, 0x04, 0x93, 0x83, 0x0e, 0x48, 0x40, 0x69, 0x2a, 0x24, 0xa8, 0xb3, 0x00, \n\t0x17, 0x24, 0x10, 0xc0, 0xc8, 0x10, 0x85, 0x40, 0x00, 0x6a, 0x20, 0xc1, 0xb4, 0x50, 0x1a, 0x23, \n\t0x5a, 0x20, 0x60, 0x08, 0x4c, 0x48, 0xc1, 0x04, 0x43, 0xc1, 0xb3, 0x60, 0x85, 0x41, 0x0c, 0x60, \n\t0x41, 0x0a, 0x30, 0xc2, 0x46, 0x40, 0x06, 0x40, 0x80, 0x28, 0xc6, 0x48, 0x18, 0x81, 0x50, 0x14, \n\t0x00, 0x4f, 0x84, 0x0c, 0xb2, 0x32, 0x00, 0x15, 0xc1, 0x62, 0x04, 0x60, 0x00, 0x00, 0x81, 0x82, \n\t0x40, 0x00, 0xc2, 0x02, 0x85, 0x51, 0x58, 0x28, 0x0c, 0xa4, 0x00, 0x21, 0x55, 0x10, 0x21, 0x2a, \n\t0x95, 0x10, 0x92, 0x20, 0x90, 0x2a, 0x62, 0x34, 0xe0, 0x10, 0x11, 0x80, 0x20, 0x36, 0x46, 0x02, \n\t0x38, 0x8c, 0x10, 0x00, 0x14, 0x06, 0x11, 0x82, 0x4d, 0x00, 0x00, 0x14, 0xc1, 0x00, 0x24, 0x60, \n\t0x06, 0x05, 0x02, 0x94, 0x41, 0x3a, 0x9c, 0x89, 0x04, 0x06, 0x22, 0x69, 0x14, 0x50, 0x8d, 0xc2, \n\t0x20, 0x04, 0x5a, 0x3c, 0xa9, 0x92, 0x00, 0x40, 0x90, 0x48, 0x8b, 0x88, 0x08, 0xa7, 0x50, 0x00, \n\t0xd2, 0x00, 0x11, 0x18, 0x68, 0x04, 0x03, 0x20, 0x06, 0x08, 0x10, 0x01, 0x18, 0x46, 0xa2, 0x01, \n\t0x84, 0xca, 0x2c, 0x26, 0x00, 0x81, 0xa1, 0x01, 0x92, 0x49, 0x20, 0x02, 0xd0, 0x10, 0xb0, 0x19, \n\t0x41, 0x64, 0x21, 0x02, 0x01, 0x04, 0x84, 0x4c, 0x20, 0x11, 0x50, 0xb0, 0x70, 0x0c, 0x88, 0x0a, \n\t0x05, 0x41, 0x01, 0x8c, 0x8e, 0x04, 0x50, 0x12, 0x10, 0x90, 0x28, 0xc1, 0xa4, 0x24, 0x86, 0x82, \n\t0x25, 0x60, 0x04, 0x80, 0x0a, 0xc1, 0x79, 0x08, 0x90, 0x80, 0x20, 0x44, 0xd4, 0x20, 0x1c, 0x99, \n\t0x40, 0xa4, 0x48, 0x85, 0x02, 0x89, 0x19, 0x01, 0xc0, 0x70, 0xc1, 0x22, 0x34, 0x81, 0x19, 0xa0, \n\t0x28, 0x24, 0x08, 0x82, 0x64, 0x87, 0xe9, 0x10, 0x46, 0xa8, 0x02, 0xc9, 0x09, 0x41, 0x56, 0x04, \n\t0x41, 0x20, 0x84, 0x40, 0x61, 0x02, 0xa5, 0x18, 0x2f, 0x21, 0x45, 0x40, 0x38, 0x22, 0x0a, 0x92, \n\t0x00, 0x1d, 0x04, 0x06, 0x04, 0xb8, 0x80, 0x80, 0x14, 0x81, 0x4a, 0x02, 0xc2, 0x01, 0xa1, 0x82, \n\t0x88, 0x02, 0x11, 0xba, 0xa8, 0x11, 0x08, 0x60, 0x68, 0x44, 0xc2, 0x15, 0x90, 0x18, 0x88, 0x28, \n\t0x21, 0x98, 0x1c, 0x41, 0x5a, 0xc2, 0x24, 0x00, 0x83, 0x04, 0x0c, 0x86, 0x0c, 0x10, 0x01, 0x28, \n\t0x20, 0xd5, 0x8e, 0x21, 0x2e, 0x04, 0x68, 0x04, 0x11, 0x40, 0xa2, 0x00, 0x03, 0x40, 0x3a, 0x21, \n\t0x01, 0x28, 0x0e, 0x90, 0x20, 0x80, 0xf0, 0x90, 0x41, 0x0a, 0x83, 0x4b, 0x8d, 0x84, 0x04, 0x24, \n\t0x32, 0x95, 0x01, 0x18, 0x08, 0x09, 0x42, 0x3a, 0x20, 0xc8, 0x10, 0x00, 0x83, 0x80, 0x08, 0x40, \n\t0x81, 0x80, 0x51, 0x00, 0x60, 0x00, 0xa5, 0x92, 0x23, 0x04, 0xca, 0x01, 0x04, 0x02, 0x32, 0x81, \n\t0x11, 0x1c, 0x04, 0x2c, 0x10, 0xa2, 0x0b, 0x04, 0x9c, 0x82, 0x2e, 0x41, 0x08, 0x15, 0x80, 0x8d, \n\t0x49, 0x40, 0x42, 0x42, 0x20, 0x08, 0x11, 0x06, 0x30, 0x14, 0x03, 0xa8, 0x30, 0x0e, 0x20, 0x28, \n\t0x10, 0x00, 0x3c, 0x11, 0x52, 0x89, 0x08, 0x61, 0xc0, 0x19, 0x84, 0xc4, 0x24, 0x1a, 0x50, 0x00, \n\t0x08, 0xa0, 0x02, 0x44, 0x0a, 0x20, 0x08, 0x20, 0x10, 0x95, 0x2e, 0x5e, 0x21, 0x40, 0x24, 0x20, \n\t0x84, 0x40, 0x14, 0x27, 0x00, 0xa6, 0x5c, 0x48, 0x88, 0x08, 0x47, 0x08, 0x13, 0x60, 0x10, 0xa2, \n\t0x64, 0x83, 0x01, 0xa8, 0x61, 0x02, 0x00, 0x4a, 0x54, 0x10, 0x21, 0x10, 0x1d, 0xe2, 0x22, 0x02, \n\t0x42, 0x16, 0x44, 0x00, 0x80, 0x04, 0x50, 0x81, 0x10, 0x30, 0x80, 0x0a, 0x12, 0x83, 0x18, 0x8c, \n\t0x84, 0x59, 0x01, 0x00, 0x25, 0x2a, 0x01, 0x0c, 0x4c, 0x01, 0x18, 0x00, 0x00, 0x87, 0x98, 0x0d, \n\t0x03, 0x58, 0x00, 0xc2, 0x30, 0xcd, 0x51, 0x26, 0x40, 0x20, 0x23, 0x04, 0x60, 0x80, 0x09, 0x34, \n\t0xd7, 0x92, 0xa8, 0x01, 0x89, 0x04, 0x20, 0x31, 0x10, 0x2f, 0x21, 0x01, 0x60, 0x52, 0x40, 0x41, \n\t0x90, 0x69, 0x96, 0x06, 0x22, 0x00, 0xc3, 0x02, 0xe5, 0x50, 0x4a, 0x40, 0xe1, 0x30, 0xb0, 0x00, \n\t0x54, 0x2a, 0x40, 0xe1, 0xd0, 0xa1, 0x35, 0x04, 0x05, 0x08, 0x04, 0x20, 0x8e, 0x00, 0x0d, 0x8b, \n\t0x50, 0x92, 0xa0, 0x14, 0x00, 0x18, 0x2d, 0x40, 0xb6, 0x80, 0x02, 0x80, 0x00, 0x47, 0x20, 0x24, \n\t0x50, 0x04, 0x8c, 0x02, 0x26, 0x10, 0x42, 0x12, 0x2b, 0xc5, 0x88, 0xa2, 0x50, 0x30, 0x43, 0x80, \n\t0x88, 0x11, 0xa8, 0x00, 0x14, 0x0a, 0x94, 0x48, 0x82, 0x80, 0x32, 0x87, 0x80, 0x09, 0x21, 0xcc, \n\t0x88, 0x58, 0x00, 0x5b, 0x92, 0x11, 0x88, 0x09, 0x46, 0x04, 0x21, 0x24, 0x01, 0x51, 0x44, 0x10, \n\t0x44, 0x03, 0x80, 0x00, 0x0b, 0x48, 0x1e, 0x61, 0x11, 0x08, 0x84, 0x06, 0x85, 0x02, 0x11, 0x88, \n\t0x01, 0x04, 0x45, 0x01, 0x2a, 0x81, 0x1a, 0x07, 0x08, 0x02, 0x0a, 0x2c, 0x12, 0xc1, 0x24, 0xf8, \n\t0x12, 0x62, 0x00, 0x32, 0x21, 0x08, 0x25, 0x94, 0x82, 0x00, 0x81, 0x60, 0x24, 0x14, 0xc2, 0x42, \n\t0x0a, 0x00, 0x30, 0x9e, 0x01, 0xd4, 0x00, 0x3c, 0x01, 0x30, 0x0d, 0x4c, 0x90, 0x0a, 0x48, 0x54, \n\t0x08, 0x17, 0xf0, 0x18, 0x88, 0x04, 0xc0, 0x91, 0x0e, 0x05, 0x04, 0x00, 0x54, 0x80, 0x02, 0x98, \n\t0x31, 0x80, 0x46, 0x2a, 0x44, 0x60, 0x85, 0x30, 0x1b, 0x4e, 0x00, 0x14, 0x08, 0x2a, 0x18, 0x10, \n\t0x00, 0x14, 0x64, 0x41, 0x01, 0x19, 0xda, 0x81, 0x00, 0x10, 0x48, 0x01, 0x20, 0x02, 0x42, 0x00, \n\t0xa0, 0x48, 0xa0, 0x80, 0x04, 0xc4, 0x04, 0xc1, 0x20, 0x0d, 0xd0, 0x00, 0x8f, 0x04, 0xb3, 0x28, \n\t0x24, 0x09, 0x05, 0x43, 0x20, 0x10, 0x23, 0x01, 0xe8, 0x0c, 0x00, 0x20, 0x20, 0x5a, 0x90, 0x05, \n\t0x8c, 0x00, 0x2c, 0x05, 0x61, 0x00, 0x0d, 0x04, 0x23, 0x10, 0xe2, 0x10, 0x11, 0xe1, 0x0b, 0x00, \n\t0x0c, 0x61, 0x48, 0x08, 0x80, 0x81, 0xc0, 0x6a, 0x37, 0x09, 0x88, 0x20, 0x94, 0x61, 0x7c, 0x10, \n\t0x20, 0x12, 0xf0, 0x0a, 0xa0, 0x00, 0x12, 0xa2, 0x28, 0x54, 0x06, 0x0d, 0x5a, 0x80, 0x00, 0x00, \n\t0xc8, 0x00, 0xa9, 0x48, 0xb0, 0x12, 0xb8, 0x00, 0xc8, 0xc4, 0x2a, 0x00, 0x20, 0xbf, 0x00, 0x08, \n\t0x84, 0x50, 0x12, 0x20, 0x26, 0x60, 0x82, 0x28, 0x24, 0x04, 0xf8, 0x02, 0x15, 0x8b, 0x00, 0x30, \n\t0xe1, 0x10, 0x80, 0x35, 0x41, 0x24, 0x22, 0x24, 0xc0, 0x80, 0x45, 0xc8, 0x80, 0x00, 0x10, 0x38, \n\t0x1c, 0x80, 0x54, 0x01, 0x3a, 0x12, 0x29, 0x10, 0x08, 0xc8, 0x60, 0x40, 0x20, 0x00, 0x07, 0xd1, \n\t0x09, 0x09, 0x78, 0xb6, 0xca, 0x35, 0x38, 0x01, 0x0c, 0x58, 0xc0, 0x20, 0x00, 0x38, 0x10, 0x2e, \n\t0x10, 0x86, 0x31, 0x02, 0xc4, 0x5a, 0x8e, 0x46, 0xe0, 0x92, 0x2a, 0x1c, 0x54, 0x25, 0x00, 0x52, \n\t0x42, 0x8d, 0x41, 0x45, 0x82, 0x20, 0x01, 0x11, 0x02, 0x58, 0x12, 0xc0, 0x00, 0x41, 0x00, 0x18, \n\t0x95, 0x15, 0x2a, 0x50, 0x24, 0xc2, 0x1a, 0x88, 0x0f, 0x00, 0x1a, 0xe0, 0x11, 0x30, 0x34, 0xc0, \n\t0x05, 0x60, 0x41, 0x20, 0x19, 0x00, 0x0a, 0x41, 0x48, 0x07, 0x99, 0x09, 0x88, 0x45, 0x2d, 0x22, \n\t0x82, 0x02, 0x04, 0x35, 0x00, 0x20, 0x04, 0x83, 0xc8, 0x82, 0xb5, 0x04, 0x8d, 0x28, 0x83, 0x43, \n\t0x83, 0x09, 0x08, 0x28, 0x20, 0xa3, 0x00, 0x11, 0x40, 0x0c, 0x80, 0x3a, 0xc0, 0xc3, 0x2a, 0x28, \n\t0x4b, 0x00, 0x4a, 0x40, 0x80, 0x33, 0x81, 0xd4, 0x20, 0x10, 0x84, 0x58, 0x04, 0x18, 0x58, 0xc0, \n\t0x00, 0xe5, 0x42, 0x2a, 0x70, 0x01, 0x08, 0x22, 0x30, 0x19, 0x11, 0xb5, 0x07, 0x8a, 0x10, 0x44, \n\t0x22, 0x90, 0x80, 0xc7, 0x48, 0x42, 0x91, 0x08, 0x11, 0x40, 0x8d, 0x22, 0x02, 0x04, 0xa0, 0x38, \n\t0x05, 0x40, 0x03, 0x08, 0x10, 0xc8, 0x28, 0x8c, 0x04, 0x00, 0x60, 0xa0, 0x02, 0x94, 0x55, 0x11, \n\t0x41, 0x6a, 0x52, 0xb8, 0xa4, 0x24, 0x08, 0xa5, 0x14, 0x12, 0x08, 0x38, 0xc1, 0x11, 0x00, 0x02, \n\t0x01, 0x41, 0x02, 0xc0, 0x49, 0x6a, 0x02, 0x05, 0x8b, 0x80, 0x04, 0x00, 0xa1, 0x00, 0x01, 0x81, \n\t0x80, 0x81, 0x82, 0x8b, 0x0c, 0x14, 0x30, 0x25, 0x44, 0x87, 0x00, 0x42, 0x10, 0x02, 0x18, 0xa8, \n\t0x84, 0x4c, 0x14, 0x60, 0x99, 0x18, 0x88, 0x14, 0x85, 0x60, 0x16, 0x41, 0x20, 0x1d, 0x96, 0x08, \n\t0x42, 0x30, 0x59, 0x24, 0x65, 0x08, 0x26, 0x60, 0x83, 0x22, 0x8c, 0x11, 0x52, 0x08, 0x00, 0x63, \n\t0xa0, 0x88, 0x01, 0x01, 0xa4, 0x06, 0x82, 0x90, 0x83, 0x60, 0x01, 0x04, 0x26, 0x44, 0x62, 0x24, \n\t0x90, 0x01, 0xc0, 0x38, 0x01, 0x01, 0x9c, 0x10, 0x18, 0x4d, 0x16, 0xd1, 0x40, 0xa0, 0xc0, 0x00, \n\t0x06, 0x36, 0xc0, 0x41, 0x1a, 0x94, 0x04, 0xc4, 0x22, 0xe6, 0x00, 0x90, 0x00, 0x46, 0x2d, 0x06, \n\t0x41, 0x02, 0x00, 0x39, 0x93, 0x23, 0x4a, 0x00, 0x01, 0x04, 0x4c, 0x93, 0x44, 0x00, 0x22, 0x49, \n\t0x08, 0x48, 0x12, 0x22, 0x04, 0x02, 0xf2, 0x98, 0x90, 0x53, 0x28, 0x62, 0x34, 0x32, 0xb4, 0x4c, \n\t0xc2, 0x04, 0x6c, 0x14, 0x12, 0x10, 0xc9, 0x85, 0x80, 0x18, 0x35, 0xa1, 0x04, 0x68, 0x45, 0x81, \n\t0x2c, 0x04, 0x80, 0x0c, 0xc8, 0x48, 0xc0, 0x42, 0x00, 0x09, 0x0b, 0x60, 0xc6, 0x24, 0x26, 0x91, \n\t0x11, 0x24, 0xc1, 0x1d, 0x0c, 0x30, 0x34, 0x60, 0x03, 0xa8, 0x5a, 0x08, 0x38, 0x46, 0x60, 0x09, \n\t0x40, 0x10, 0x86, 0x4c, 0x22, 0x61, 0x04, 0x01, 0x00, 0x2a, 0x58, 0x82, 0x90, 0x01, 0x0c, 0x12, \n\t0x0d, 0x0c, 0x73, 0x21, 0x20, 0x84, 0x12, 0x08, 0x40, 0xf0, 0x00, 0x0d, 0x50, 0x92, 0x85, 0x20, \n\t0x10, 0xc0, 0x12, 0x01, 0x03, 0x04, 0x22, 0x05, 0x10, 0x30, 0x34, 0x49, 0x42, 0x00, 0x87, 0x00, \n\t0x02, 0xc0, 0x40, 0x49, 0x20, 0x42, 0x9a, 0xb3, 0x40, 0x80, 0xe4, 0x08, 0x22, 0x20, 0x18, 0x35, \n\t0x8b, 0x88, 0x52, 0x34, 0x0b, 0x25, 0x00, 0x1c, 0x00, 0x0e, 0x32, 0x09, 0x88, 0x91, 0xdc, 0x06, \n\t0x18, 0xb0, 0xab, 0x14, 0x60, 0xc4, 0x00, 0x08, 0x03, 0x2b, 0x02, 0x70, 0x16, 0x48, 0x08, 0xe2, \n\t0x00, 0x2b, 0x08, 0x98, 0x0c, 0x0c, 0x84, 0xa0, 0x28, 0x05, 0x05, 0x64, 0x00, 0x50, 0x19, 0x92, \n\t0x88, 0x03, 0x0c, 0x12, 0x61, 0x28, 0x00, 0xcc, 0x12, 0x02, 0x52, 0x04, 0x41, 0x24, 0x3c, 0x00, \n\t0x21, 0x40, 0x81, 0x1a, 0x2b, 0x09, 0xc2, 0x05, 0x14, 0x71, 0x20, 0xa0, 0x14, 0x00, 0x82, 0x50, \n\t0x60, 0x40, 0xa0, 0x08, 0x03, 0x04, 0x0c, 0x92, 0x10, 0x02, 0x30, 0x42, 0x29, 0x68, 0x22, 0x20, \n\t0x08, 0xf4, 0x00, 0x0e, 0x12, 0x00, 0x50, 0x21, 0x10, 0x8c, 0x21, 0x00, 0x45, 0x60, 0x10, 0x01, \n\t0xc9, 0x84, 0x04, 0x11, 0x18, 0x00, 0x01, 0x17, 0x67, 0x3e, 0x41, 0x80, 0x83, 0xc1, 0xca, 0x80, \n\t0x1a, 0x40, 0xba, 0x80, 0x48, 0x82, 0xca, 0x04, 0x05, 0x81, 0x80, 0x34, 0x18, 0xc0, 0x42, 0xc2, \n\t0x40, 0x30, 0x84, 0x4c, 0x09, 0x12, 0x11, 0x08, 0x26, 0x14, 0x0c, 0xc8, 0x02, 0x60, 0x23, 0xa7, \n\t0x00, 0x49, 0x41, 0x5a, 0xe4, 0x40, 0x88, 0x10, 0x05, 0xa0, 0x6c, 0x02, 0x00, 0x00, 0x01, 0x84, \n\t0x02, 0x12, 0x10, 0x22, 0x01, 0xc8, 0x90, 0x81, 0x20, 0x02, 0x10, 0x82, 0x05, 0x12, 0xa3, 0x28, \n\t0x82, 0x80, 0x04, 0x28, 0x14, 0x40, 0x42, 0x51, 0xa1, 0x84, 0x09, 0x80, 0x82, 0x2e, 0x04, 0x01, \n\t0x32, 0xb4, 0x01, 0x08, 0x0c, 0x06, 0x01, 0xba, 0x05, 0x50, 0x80, 0x54, 0x22, 0x1b, 0x01, 0x38, \n\t0x41, 0xa2, 0x04, 0x41, 0x39, 0x25, 0x00, 0x18, 0x83, 0x70, 0x51, 0x09, 0x1a, 0x80, 0x92, 0x41, \n\t0x42, 0x40, 0x5b, 0x04, 0x20, 0x90, 0x0b, 0x00, 0x30, 0x28, 0x34, 0x61, 0x00, 0x01, 0x1e, 0x72, \n\t0x42, 0x06, 0x19, 0x1c, 0x01, 0x0c, 0x04, 0x71, 0x09, 0x49, 0x00, 0x08, 0x60, 0x00, 0x80, 0x9c, \n\t0x48, 0x49, 0x00, 0x5a, 0x00, 0xa1, 0x2a, 0xa1, 0x1c, 0x06, 0x28, 0x24, 0x50, 0x01, 0x00, 0xc0, \n\t0x08, 0x68, 0x65, 0xa8, 0x22, 0x68, 0x14, 0x20, 0x32, 0x42, 0x03, 0x82, 0x3d, 0x01, 0xc1, 0x0e, \n\t0x82, 0x11, 0x02, 0x20, 0x80, 0x01, 0x02, 0xd4, 0xe9, 0x80, 0x0c, 0x01, 0x29, 0x04, 0x50, 0x12, \n\t0x92, 0x40, 0x81, 0x83, 0x10, 0x20, 0x01, 0x09, 0x80, 0xc3, 0xe6, 0x42, 0x53, 0x13, 0x06, 0x15, \n\t0x80, 0x41, 0x58, 0x14, 0x00, 0x82, 0x1c, 0x88, 0x06, 0x00, 0x02, 0x2a, 0x06, 0x5c, 0x91, 0x00, \n\t0x58, 0x02, 0x8a, 0x90, 0x24, 0x04, 0x06, 0x28, 0x40, 0x30, 0x15, 0x24, 0x81, 0x60, 0x42, 0x46, \n\t0xd9, 0xa0, 0x11, 0x04, 0x46, 0x24, 0x92, 0xc0, 0x28, 0x21, 0x8c, 0x22, 0x00, 0x16, 0x08, 0x11, \n\t0xe1, 0x1d, 0x08, 0x0a, 0x01, 0x09, 0x3b, 0x90, 0x53, 0x20, 0x12, 0x03, 0xc0, 0x84, 0x00, 0x94, \n\t0x02, 0x14, 0xb2, 0x48, 0x38, 0x39, 0x42, 0x21, 0x40, 0xb2, 0xa2, 0x22, 0xc4, 0x90, 0x03, 0x40, \n\t0x70, 0x61, 0x2c, 0xc8, 0x48, 0xe3, 0x06, 0x42, 0x00, 0xac, 0x11, 0x04, 0xc0, 0x08, 0x40, 0x41, \n\t0x01, 0x08, 0x4a, 0x84, 0x48, 0x21, 0xd0, 0x02, 0x81, 0x00, 0x42, 0x20, 0x00, 0xd8, 0x04, 0x84, \n\t0x00, 0x8c, 0x04, 0x64, 0x13, 0x09, 0x35, 0x88, 0x21, 0x12, 0x80, 0x38, 0x0b, 0x24, 0xc2, 0x41, \n\t0x12, 0x80, 0x82, 0x28, 0x28, 0x05, 0x24, 0x74, 0x11, 0xc0, 0x05, 0x09, 0x51, 0x60, 0x28, 0x80, \n\t0xa2, 0x11, 0x24, 0x10, 0x89, 0x00, 0x21, 0x20, 0x85, 0x60, 0x00, 0x0c, 0x00, 0xa4, 0x81, 0x88, \n\t0x1c, 0x0b, 0x06, 0x64, 0x04, 0x32, 0x10, 0x08, 0x86, 0x01, 0x28, 0x43, 0x11, 0x20, 0x68, 0x51, \n\t0x0a, 0x36, 0x60, 0x82, 0xa6, 0x24, 0x87, 0x49, 0x4a, 0x00, 0x00, 0x10, 0xa9, 0x01, 0x81, 0x20, \n\t0x76, 0xca, 0xa1, 0xd5, 0x02, 0x00, 0x28, 0x52, 0x29, 0x22, 0xe0, 0x00, 0x0b, 0x08, 0x90, 0x08, \n\t0x14, 0xb0, 0x00, 0x05, 0x74, 0x50, 0x40, 0x8b, 0x20, 0x56, 0xea, 0x04, 0x30, 0x02, 0x15, 0xd1, \n\t0x00, 0x09, 0x40, 0x42, 0x02, 0x83, 0x30, 0x0a, 0xc8, 0x04, 0x15, 0x22, 0x98, 0x49, 0x09, 0x48, \n\t0x4a, 0x05, 0x02, 0x14, 0x00, 0xce, 0x24, 0x46, 0xc7, 0x23, 0x0d, 0x04, 0x10, 0x8c, 0x44, 0x60, \n\t0x80, 0x84, 0x38, 0x81, 0x02, 0x70, 0x41, 0x90, 0x26, 0x01, 0x40, 0xa1, 0x04, 0xc4, 0x48, 0x20, \n\t0x20, 0x43, 0x02, 0x10, 0xa4, 0x40, 0x1e, 0x44, 0x0a, 0x43, 0x08, 0x05, 0x62, 0x20, 0x18, 0x11, \n\t0x20, 0x70, 0x43, 0x8b, 0x18, 0x60, 0x04, 0x02, 0x16, 0x14, 0x91, 0x09, 0x10, 0x11, 0x20, 0x14, \n\t0x10, 0xe0, 0x08, 0x00, 0x88, 0x09, 0x1c, 0x85, 0x50, 0x2a, 0x08, 0x51, 0x42, 0x22, 0x71, 0x0a, \n\t0x00, 0x41, 0xcc, 0x80, 0x36, 0x04, 0xba, 0x31, 0x28, 0x0c, 0x02, 0x1a, 0x21, 0x01, 0xa0, 0x65, \n\t0x08, 0x01, 0x1a, 0xa4, 0x0b, 0x84, 0x40, 0x1c, 0x43, 0x26, 0x54, 0x8a, 0x08, 0x94, 0x08, 0x0c, \n\t0x04, 0x30, 0x10, 0x0a, 0x80, 0x52, 0x40, 0x40, 0xb0, 0xc3, 0x96, 0x00, 0x19, 0x05, 0x40, 0xa4, \n\t0x51, 0x0e, 0x09, 0xc5, 0x82, 0x28, 0x12, 0x40, 0x05, 0x08, 0x00, 0xc3, 0x10, 0x31, 0x38, 0x25, \n\t0x20, 0x02, 0xa8, 0x40, 0x76, 0x92, 0x01, 0x58, 0x41, 0xc5, 0x00, 0x03, 0x38, 0x04, 0x04, 0x02, \n\t0xa1, 0x44, 0x81, 0x91, 0x33, 0x80, 0x08, 0x20, 0x08, 0x41, 0x01, 0x33, 0x9d, 0x00, 0x40, 0x2a, \n\t0xc4, 0x51, 0x22, 0xf5, 0x0d, 0x4f, 0x00, 0x23, 0x90, 0x2a, 0xb0, 0x4a, 0xa2, 0x04, 0xd0, 0x48, \n\t0x00, 0x04, 0x54, 0xc8, 0x22, 0x92, 0x09, 0x29, 0x90, 0x85, 0x48, 0x0e, 0x00, 0xb0, 0x03, 0x88, \n\t0x4c, 0x84, 0x32, 0x80, 0x0b, 0x14, 0x10, 0x03, 0xc6, 0x50, 0x40, 0x03, 0x21, 0x08, 0x86, 0xe4, \n\t0x08, 0x04, 0x42, 0x32, 0x05, 0x00, 0x6a, 0x0c, 0x34, 0x10, 0xaa, 0x20, 0xc0, 0x64, 0x06, 0x90, \n\t0x12, 0x97, 0x28, 0xc2, 0x28, 0x42, 0x05, 0x88, 0x20, 0x21, 0xc6, 0x80, 0x10, 0x82, 0x81, 0x94, \n\t0x00, 0x1c, 0x01, 0x24, 0x24, 0x49, 0x80, 0x4c, 0x41, 0x46, 0x00, 0x83, 0x68, 0x80, 0x00, 0x48, \n\t0x08, 0x12, 0xc1, 0x61, 0x08, 0x38 \n};\n\n\nstatic bool isprime_slow(int64_t x)\n{\n\tfor (int i = 3; i < 10; ++i) {\n\t\tif (x % gLowPrimes[i] == 0)\n\t\t\treturn false;\n\t}\n\t\n\tfor (int i = 0; i < kPrimesMaskSize; ++i) {\n\t\tif (gPrimesMask[i] == 0) continue;\n\t\tint64_t k = 30 * (i+1);\n\t\tfor (int j = 0; j < 8; ++j) {\n\t\t\tif (!(gPrimesMask[k] & (1 << j))) continue;\n\t\t\tint64_t m = k + gPrimeOffsets[j];\n\t\t\tif (m*m > x) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tif (x % m == 0) return false;\n\t\t}\n\t}\n\t\n\tthrow errOutOfRange;\n}\n\n#include \n\nbool isprime(int64_t x)\n{\n\tif (x <= 30) {\n\t\tif (x < 2) return false; // negatives aren't prime\n\t\treturn gLowPrimesMask & (1 << x);\n\t}\n\t\n\tint bit = x % 30;\n\tint shift = gPrimesShift[bit];\n\tif (shift < 0) return false; // eliminate multiples of 2,3,5.\n\tint64_t byte = x / 30 - 1;\n\t\t\n\tif (byte >= kPrimesMaskSize) return isprime_slow(x);\t\n\t\n\treturn gPrimesMask[byte] & (1 << shift);\n}\n\n\nint64_t nextPrime(int64_t x)\n{\n\tfor (;; ++x) {\n\t\tif (isprime(x)) return x;\n\t}\n}\n\n\n\n\n\n\n"], ["/sapf/src/RCObj.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"RCObj.hpp\"\n#include \"VM.hpp\"\n\n\nRCObj::RCObj()\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::RCObj(RCObj const& that)\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::~RCObj()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\n\nvoid RCObj::norefs()\n{\n\trefcount = -999;\n\tdelete this; \n}\n\n\t\nvoid RCObj::negrefcount()\n{\n\tpost(\"RELEASING WITH NEGATIVE REFCOUNT %s %p %d\\n\", TypeName(), this, refcount.load());\n}\nvoid RCObj::alreadyDead()\n{\n\tpost(\"RETAINING ALREADY DEAD OBJECT %s %p\\n\", TypeName(), this);\n}\n"], ["/sapf/libmanta/MantaServer.h", "#ifndef _MANTASERVER_H\n#define _MANTASERVER_H\n\n/************************************************************************//**\n * \\class MantaServer\n * \\brief Interface defining all the Messages that can be sent to a Manta\n *\n * The MantaServer virtual class defines all the Messages that the Manta\n * understands, as well as the data structures used as arguments. If you\n * need a pointer to a Manta in your code, you can make it more general by\n * using a MantaServer pointer instead of a pointer to your specific subclass.\n ****************************************************************************/\nclass MantaServer\n{\n public:\n\n enum LEDState {\n Off,\n Amber,\n Red,\n All, // only used in SetPadLEDFrame\n };\n enum LEDControlType {\n PadAndButton,\n Slider,\n Button\n };\n typedef uint8_t LEDFrame[6];\n\n virtual ~MantaServer() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void SetPadLED(LEDState state, int ledID) = 0;\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) = 0;\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) = 0;\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) = 0;\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) = 0;\n virtual void SetButtonLED(LEDState state, int id) = 0;\n virtual void ResendLEDState(void) = 0;\n virtual void ClearPadAndButtonLEDs(void) = 0;\n virtual void ClearButtonLEDs(void) = 0;\n virtual void Recalibrate(void) = 0;\n virtual void SetLEDControl(LEDControlType control, bool state) = 0;\n virtual void SetTurboMode(bool Enabled) = 0;\n virtual void SetRawMode(bool Enabled) = 0;\n virtual void SetMaxSensorValues(int *values) = 0;\n};\n#endif /* _MANTASERVER_H */\n"], ["/sapf/src/ErrorCodes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"ErrorCodes.hpp\"\n\nconst char* errString[kNumErrors] = { \n\t\"halt\", \"failed\", \"indefinite operation\", \"wrong type\", \"out of range\", \"syntax\", \"internal bug\",\n\t\"wrong state\", \"not found\", \"stack overflow\", \"stack underflow\",\n\t\"inconsistent inheritance\", \"undefined operation\", \"user quit\"\n};\n"], ["/sapf/libmanta/MantaMulti.h", "class MantaMulti {\n public:\n MantaMulti(MantaClient *client = NULL) {\n AttachClient(client);\n}\n void AttachClient(MantaClient *client) {\n if(NULL != client)\n {\n ClientList.push_back(client);\n ++ReferenceCount;\n }\n}\n void DetachClient(MantaClient *client) {\n list::iterator foundIter;\n foundIter = find(ClientList.begin(), ClientList.end(), client);\n if(ClientList.end() != foundIter)\n {\n ClientList.erase(foundIter);\n --ReferenceCount;\n }\n}\n int GetReferenceCount() {\n return ReferenceCount;\n}\n protected:\n void PadEvent(int row, int column, int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadEvent(row, column, id, value);\n }\n}\n void SliderEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->SliderEvent(id, value);\n }\n}\n void ButtonEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonEvent(id, value);\n }\n}\n void PadVelocityEvent(int row, int column, int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadVelocityEvent(row, column, id, velocity);\n }\n}\n void ButtonVelocityEvent(int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonVelocityEvent(id, velocity);\n }\n}\n void FrameEvent(uint8_t *frame) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->FrameEvent(frame);\n }\n}\n private:\n list ClientList;\n int ReferenceCount;\n};"], ["/sapf/src/elapsedTime.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nextern \"C\" {\n\nstatic double gHostClockFreq;\n\nvoid initElapsedTime()\n{\n\tstruct mach_timebase_info info;\n\tmach_timebase_info(&info);\n\tgHostClockFreq = 1e9 * ((double)info.numer / (double)info.denom);\n}\n\ndouble elapsedTime()\n{\n\treturn (double)mach_absolute_time() / gHostClockFreq;\n}\n\n}\n"], ["/sapf/libmanta/MantaExceptions.h", "#ifndef _MANTAEXCEPTIONS_H\n#define _MANTAEXCEPTIONS_H\n\n#include \n\nclass LibusbInitException : public std::runtime_error\n{\n public:\n LibusbInitException() :\n runtime_error(\"Error initializing libusb\")\n {\n }\n};\n\nclass MantaNotConnectedException : public std::runtime_error\n{\n public:\n MantaNotConnectedException(MantaUSB *manta) :\n runtime_error(\"Attempted to access the Manta without connecting\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\nclass MantaNotFoundException : public std::runtime_error\n{\n public:\n MantaNotFoundException() :\n runtime_error(\"Could not find an attached Manta\")\n {\n }\n};\n\nclass MantaOpenException : public std::runtime_error\n{\n public:\n MantaOpenException() :\n runtime_error(\"Could not connect to attached Manta\")\n {\n }\n};\n\nclass MantaCommunicationException : public std::runtime_error\n{\n public:\n MantaCommunicationException(MantaUSB *manta = NULL) :\n runtime_error(\"Communication with Manta interrupted\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\n#endif // _MANTAEXCEPTIONS_H\n"], ["/sapf/src/Types.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Types.hpp\"\n"], ["/sapf/libmanta/MantaClient.h", "#ifndef _MANTACLIENT_H\n#define _MANTACLIENT_H\n\n#include \n\n/************************************************************************//**\n * \\class MantaClient\n * \\brief Interface defining all the Events generated by the Manta\n *\n * The MantaClient virtual class defines all the Events that could be\n * generated by the Manta. Your object should provide implementations\n * to any of these events that you'd like to listen for\n ****************************************************************************/\nclass MantaClient\n{\n public:\n virtual ~MantaClient() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void PadEvent(int row, int column, int id, int value) {}\n virtual void SliderEvent(int id, int value) {}\n virtual void ButtonEvent(int id, int value) {}\n virtual void PadVelocityEvent(int row, int column, int id, int velocity) {}\n virtual void ButtonVelocityEvent(int id, int velocity) {}\n virtual void FrameEvent(uint8_t *frame) {}\n virtual void DebugPrint(const char *fmt, ...) {}\n};\n#endif /* _MANTACLIENT_H */\n"], ["/sapf/libmanta/MantaVersion.h", "#ifndef _MANTAVERSION_H\n#define _MANTAVERSION_H\n\n#define LIBMANTA_MAJOR_VERSION 1\n#define LIBMANTA_MINOR_VERSION 3\n\n#endif // _MANTAVERSION_H\n"]], "task_instance_info": {"created_time": "2025-08-20 20:04:52", "created_task_model": "DeepSeek-R1", "function_skeleton": "static String * parseString(Thread& th) {}", "code_description": "This code segment functions to: Process quoted character sequences by interpreting escape codes and concatenating valid input into a complete textual value while handling delimiter escaping."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nstatic String* parseString(Thread& th)\n{\n th.getc(); // consume opening quote\n std::string buffer;\n while (true) {\n int c = th.getc();\n if (c == '\"') {\n break;\n } else if (c == '\\\\') {\n int esc = th.getc();\n switch (esc) {\n case 'n': buffer += '\\n'; break;\n case 't': buffer += '\\t'; break;\n case '\"': buffer += '\"'; break;\n case '\\\\': buffer += '\\\\'; break;\n default: buffer += (char)esc;\n }\n } else if (c == 0) {\n syntaxError(\"unclosed string literal\");\n break;\n } else {\n buffer += (char)c;\n }\n }\n return getsym(buffer.c_str());\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 20-05-27"}, "editdistance_info": {"edit_distance": 28.1369, "calculate_time": "2025-08-20 20:05:27", "true_code_clean": "static String* parseString(Thread& th)\n{\n\tif (th.c() != '\"') return nullptr;\n\tParsingWhat pw(th, parsingString);\n\tth.getc();\n\tint c = th.getc();\n\tstd::string str;\n\twhile (true) {\n\t\tif (c == 0) {\n\t\t\tsyntaxError(\"end of input in string\");\n\t\t} else if (c == '\\\\' && th.c() == '\\\\') {\n\t\t\tth.getc();\n\t\t\tc = th.getc();\n\t\t\tswitch (c) {\n\t\t\t\tcase 'n' : str += '\\n'; break;\n\t\t\t\tcase 'r' : str += '\\r'; break;\n\t\t\t\tcase 'f' : str += '\\f'; break;\n\t\t\t\tcase 'v' : str += '\\v'; break;\n\t\t\t\tcase 't' : str += '\\t'; break;\n\t\t\t\tdefault : str += c; break;\n\t\t\t}\n\t\t\tc = th.getc();\n\t\t} else if (c == '\"') {\n\t\t\tif (th.c() == '\"') {\n\t\t\t\tc = th.getc();\n\t\t\t\tstr += '\"';\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tstr += c;\n\t\t\tc = th.getc();\n\t\t}\n\t}\n\treturn new String(str.c_str());\n}", "predict_code_clean": "static String* parseString(Thread& th)\n{\n th.getc(); \n std::string buffer;\n while (true) {\n int c = th.getc();\n if (c == '\"') {\n break;\n } else if (c == '\\\\') {\n int esc = th.getc();\n switch (esc) {\n case 'n': buffer += '\\n'; break;\n case 't': buffer += '\\t'; break;\n case '\"': buffer += '\"'; break;\n case '\\\\': buffer += '\\\\'; break;\n default: buffer += (char)esc;\n }\n } else if (c == 0) {\n syntaxError(\"unclosed string literal\");\n break;\n } else {\n buffer += (char)c;\n }\n }\n return getsym(buffer.c_str());\n}"}} {"repo_name": "sapf", "file_name": "/sapf/src/Play.cpp", "inference_info": {"prefix_code": "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Play.hpp\"\n#include \n#include \n#include \n\n#include \"SoundFiles.hpp\"\n\npthread_mutex_t gPlayerMutex = PTHREAD_MUTEX_INITIALIZER;\n\nconst int kMaxChannels = 32;\n\nstruct AUPlayer* gAllPlayers = nullptr;\n\n\n\nstruct AUPlayer\n{\n\tAUPlayer(Thread& inThread, int inNumChannels, ExtAudioFileRef inXAFRef = nullptr)\n\t\t: th(inThread), count(0), done(false), prev(nullptr), next(gAllPlayers), outputUnit(nullptr), numChannels(inNumChannels), xaf(inXAFRef)\n\t{ \n\t\tgAllPlayers = this; \n\t\tif (next) next->prev = this; \n\t}\n\t\n\t~AUPlayer() {\n\t\tif (next) next->prev = prev;\n\n\t\tif (prev) prev->next = next;\n\t\telse gAllPlayers = next;\n\t\t\n\t\tif (xaf) {\n\t\t\tExtAudioFileDispose(xaf);\n\t\t\tchar cmd[1100];\n\t\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path.c_str());\n\t\t\tsystem(cmd);\n\t\t}\n\t}\n\t\n\tThread th;\n\tint count;\n\tbool done;\n\tAUPlayer* prev;\n\tAUPlayer* next;\n\tAudioComponentInstance outputUnit;\n\tint numChannels;\n\tZIn in[kMaxChannels];\n\tExtAudioFileRef xaf = nullptr;\n\tstd::string path;\n\t\n};\n\nstatic void stopPlayer(AUPlayer* player)\n{\n\tAudioComponentInstance outputUnit = player->outputUnit;\n\tplayer->outputUnit = nullptr;\n\tif (outputUnit) {\n\t\n\t\tOSStatus err = AudioOutputUnitStop(outputUnit);\n\t\tif (err) post(\"AudioOutputUnitStop err %d\\n\", (int)err);\n\t\terr = AudioComponentInstanceDispose(outputUnit);\n\t\tif (err) post(\"AudioComponentInstanceDispose outputUnit err %d\\n\", (int)err);\n\t\t\n\t}\n\tdelete player;\n}\n\nvoid stopPlaying()\n{\n\tLocker lock(&gPlayerMutex);\n\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nvoid stopPlayingIfDone()\n{\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tif (player->done)\n\t\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nstatic void* stopDonePlayers(void* x)\n{\n\twhile(1) {\n\t\tsleep(1);\n\t\tstopPlayingIfDone();\n\t}\n\treturn nullptr;\n}\n\nbool gWatchdogRunning = false;\npthread_t watchdog;\n\nstatic bool fillBufferList(AUPlayer* player, int inNumberFrames, AudioBufferList* ioData)\n{\n\tif (player->done) {\nzeroAll:\n\t\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\t\tmemset((float*)ioData->mBuffers[i].mData, 0, inNumberFrames * sizeof(float));\n\t\t}\n\t\treturn true;\n\t}\n\tZIn* in = player->in;\n\tbool done = true;\n\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\tint n = inNumberFrames;\n\t\tif (i >= player->numChannels) {\n\t\t\tmemset(ioData->mBuffers[i].mData, 0, ioData->mBuffers[i].mDataByteSize);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfloat* buf = (float*)ioData->mBuffers[i].mData;\n\t\t\t\tbool imdone = in[i].fill(player->th, n, buf, 1);\n\t\t\t\tif (n < inNumberFrames) {\n\t\t\t\t\tmemset((float*)ioData->mBuffers[i].mData + n, 0, (inNumberFrames - n) * sizeof(float));\n\t\t\t\t}\n\t\t\t\tdone = done && imdone;\n\t\t\t} catch (int err) {\n\t\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t\t} else {\n\t\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t\t}\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (std::bad_alloc& xerr) {\n\t\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (...) {\n\t\t\t\tpost(\"\\nunknown error\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn done;\n}\n\nstatic void recordPlayer(AUPlayer* player, int inNumberFrames, AudioBufferList const* inData)\n{\n\tif (!player->xaf) return;\n\t\t\n\tOSStatus err = ExtAudioFileWriteAsync(player->xaf, inNumberFrames, inData); // initialize async.\n\tif (err) printf(\"ExtAudioFileWriteAsync err %d\\n\", (int)err);\n}\n\nstatic OSStatus inputCallback(\tvoid *\t\t\t\t\t\t\tinRefCon,\n\t\t\t\t\t\tAudioUnitRenderActionFlags *\tioActionFlags,\n\t\t\t\t\t\tconst AudioTimeStamp *\t\t\tinTimeStamp,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinBusNumber,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinNumberFrames,\n\t\t\t\t\t\tAudioBufferList *\t\t\t\tioData)\n{\n\t\n\tAUPlayer* player = (AUPlayer*)inRefCon;\n\t\t\n\tbool done = fillBufferList(player, inNumberFrames, ioData);\n\trecordPlayer(player, inNumberFrames, ioData);\n\n\tif (done) {\n\t\tplayer->done = true;\n\t}\n\treturn noErr;\n}\n\n\nstatic AudioComponentInstance openAU(UInt32 inType, UInt32 inSubtype, UInt32 inManuf)\n{\n AudioComponentDescription desc;\n desc.componentType = inType;\n desc.componentSubType = inSubtype;\n desc.componentManufacturer = inManuf;\n desc.componentFlags = 0;\n desc.componentFlagsMask = 0;\n\n AudioComponent comp = AudioComponentFindNext(nullptr, &desc);\n\tif (!comp) {\n\t\treturn nullptr;\n\t}\n\n AudioComponentInstance au = nullptr;\n AudioComponentInstanceNew(comp, &au);\n\t\n\treturn au;\n}\n\n", "suffix_code": "\n\nvoid playWithAudioUnit(Thread& th, V& v)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\t\n\tif (v.isZList()) {\n\t\tplayer = new AUPlayer(th, 1);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint asize = (int)a->size();\n\t\t\n\t\tplayer = new AUPlayer(th, asize);\n\t\tfor (int i = 0; i < asize; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n \n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n\nvoid recordWithAudioUnit(Thread& th, V& v, Arg filename)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\n\tchar path[1024];\n\tExtAudioFileRef xaf = nullptr;\n\t\n\tif (v.isZList()) {\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, 1, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\n\t\tplayer = new AUPlayer(th, 1, xaf);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint numChannels = (int)a->size();\n\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, numChannels, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tplayer = new AUPlayer(th, numChannels, xaf);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n\n\tplayer->path = path;\n\n\t{\n\t\tOSStatus err = ExtAudioFileWriteAsync(xaf, 0, nullptr); // initialize async.\n\t\tif (err) printf(\"init ExtAudioFileWriteAsync err %d\\n\", (int)err);\n }\n\t\n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n", "middle_code": "static OSStatus createGraph(AUPlayer* player)\n{\n OSStatus err = noErr;\n\tAudioComponentInstance outputUnit = openAU('auou', 'def ', 'appl');\n\tif (!outputUnit) {\n\t\tpost(\"open output unit failed\\n\");\n\t\treturn 'fail';\n\t}\n\tplayer->outputUnit = outputUnit;\n\tUInt32 flags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;\n\tAudioStreamBasicDescription fmt = { vm.ar.sampleRate, kAudioFormatLinearPCM, flags, 4, 1, 4, (UInt32)player->numChannels, 32, 0 };\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &fmt, sizeof(fmt));\n\tif (err) {\n\t\tpost(\"set outputUnit client format failed\\n\");\n\t\treturn err;\n\t}\n\tAURenderCallbackStruct cbs;\n\tcbs.inputProc = inputCallback;\n\tcbs.inputProcRefCon = player;\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &cbs, sizeof(cbs));\n\tif (err) {\n\t\tpost(\"set render callback failed\\n\");\n\t\treturn err;\n\t}\n\terr = AudioUnitInitialize(outputUnit);\n\tif (err) {\n\t\tpost(\"initialize output unit failed\\n\");\n\t\treturn err;\n\t}\n\terr = AudioOutputUnitStart(outputUnit);\n\tif (err) {\n\t\tpost(\"start output unit failed\\n\");\n\t\treturn err;\n\t}\n\tpost(\"start output unit OK\\n\");\n\treturn noErr;\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/sapf/src/SoundFiles.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"SoundFiles.hpp\"\n#include \n\nextern char gSessionTime[256];\n\n\nclass SFReaderOutputChannel;\n\nclass SFReader : public Object\n{\n\tExtAudioFileRef mXAF;\n\tint64_t mFramesRemaining;\n\tSFReaderOutputChannel* mOutputs;\n\tint mNumChannels;\n\tAudioBufferList* mABL;\n\tbool mFinished = false;\n\t\npublic:\n\t\n\tSFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration);\n\t\n\t~SFReader();\n\n\tvirtual const char* TypeName() const override { return \"SFReader\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tbool pull(Thread& th);\n\tvoid fulfillOutputs(int blockSize);\n\tvoid produceOutputs(int shrinkBy);\n};\n\nclass SFReaderOutputChannel : public Gen\n{\n\tfriend class SFReader;\n\tP mSFReader;\n\tSFReaderOutputChannel* mNextOutput = nullptr;\n\tZ* mDummy = nullptr;\n\t\npublic:\t\n\tSFReaderOutputChannel(Thread& th, SFReader* inSFReader)\n : Gen(th, itemTypeZ, true), mSFReader(inSFReader)\n\t{\n\t}\n\t\n\t~SFReaderOutputChannel()\n\t{\n\t\tif (mDummy) free(mDummy);\n\t}\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr; \n\t\tmSFReader = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"SFReaderOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mSFReader->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nSFReader::SFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration)\n\t: mXAF(inXAF), mNumChannels(inNumChannels), mFramesRemaining(inDuration), mABL(nullptr)\n{\n\tmABL = (AudioBufferList*)calloc(1, sizeof(AudioBufferList) + (mNumChannels - 1) * sizeof(AudioBuffer));\n}\n\nSFReader::~SFReader()\n{\n\tExtAudioFileDispose(mXAF); free(mABL);\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tSFReaderOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nvoid SFReader::fulfillOutputs(int blockSize)\n{\n\tmABL->mNumberBuffers = mNumChannels;\n\tSFReaderOutputChannel* output = mOutputs;\n\tsize_t bufSize = blockSize * sizeof(Z);\n\tfor (int i = 0; output; ++i, output = output->mNextOutput){\n\t\tZ* out;\n\t\tif (output->mOut)\n\t\t\tout = output->mOut->fulfillz(blockSize);\n\t\telse {\n\t\t\tif (!output->mDummy)\n\t\t\t\toutput->mDummy = (Z*)calloc(output->mBlockSize, sizeof(Z));\n\n\t\t\tout = output->mDummy;\n\t\t}\n\t\t\t\n\t\tmABL->mBuffers[i].mNumberChannels = 1;\n\t\tmABL->mBuffers[i].mData = out;\n\t\tmABL->mBuffers[i].mDataByteSize = (UInt32)bufSize;\n\t\tmemset(out, 0, bufSize);\n\t};\n}\n\nvoid SFReader::produceOutputs(int shrinkBy)\n{\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nP SFReader::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n SFReaderOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n SFReaderOutputChannel* c = new SFReaderOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nbool SFReader::pull(Thread& th)\n{\n\tif (mFramesRemaining == 0) \n\t\tmFinished = true;\n\n\tif (mFinished) \n\t\treturn true;\n\t\n\tSFReaderOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\tif (mFramesRemaining > 0)\n\t\tblockSize = (int)std::min(mFramesRemaining, (int64_t)blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n\t// read file here.\n\tUInt32 framesRead = blockSize;\n\tOSStatus err = ExtAudioFileRead(mXAF, &framesRead, mABL);\n\t\n\tif (err || framesRead == 0) {\n\t\tmFinished = true;\n\t}\n\t\n\tproduceOutputs(blockSize - framesRead);\n\tif (mFramesRemaining > 0) mFramesRemaining -= blockSize;\n\t\n\treturn mFinished; \n}\n\nvoid sfread(Thread& th, Arg filename, int64_t offset, int64_t frames)\n{\n\tconst char* path = ((String*)filename.o())->s;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path\\n\");\n\t\treturn;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileOpenURL(url, &xaf);\n\n\tcfpathReleaser.release();\n\turlReleaser.release();\n\t\n\tif (err) {\n\t\tpost(\"failed to open file %d\\n\", (int)err);\n\t\treturn;\n\t}\n\n\tAudioStreamBasicDescription fileFormat;\n\t\n\tUInt32 propSize = sizeof(fileFormat);\n\terr = ExtAudioFileGetProperty(xaf, kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);\n\t\n\tint numChannels = fileFormat.mChannelsPerFrame;\n\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved,\n\t\tstatic_cast(sizeof(double)),\n\t\t1,\n\t\tstatic_cast(sizeof(double)),\n\t\tstatic_cast(numChannels),\n\t\t64,\n\t\t0\n\t};\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\terr = ExtAudioFileSeek(xaf, offset);\n\tif (err) {\n\t\tpost(\"seek failed %d\\n\", (int)err);\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\tSFReader* sfr = new SFReader(xaf, numChannels, -1);\n\t\n\tth.push(sfr->createOutputs(th));\n}\n\nExtAudioFileRef sfcreate(Thread& th, const char* path, int numChannels, double fileSampleRate, bool interleaved)\n{\n\tif (fileSampleRate == 0.)\n\t\tfileSampleRate = th.rate.sampleRate;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path '%s'\\n\", path);\n\t\treturn nullptr;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn nullptr;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tAudioStreamBasicDescription fileFormat = {\n\t\tfileSampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\n\tint interleavedChannels = interleaved ? numChannels : 1;\n\tUInt32 interleavedBit = interleaved ? 0 : kAudioFormatFlagIsNonInterleaved;\n\t\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | interleavedBit,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileCreateWithURL(url, kAudioFileWAVEType, &fileFormat, nullptr, kAudioFileFlags_EraseFile, &xaf);\n\t\n\tif (err) {\n\t\tpost(\"failed to create file '%s'. err: %d\\n\", path, (int)err);\n\t\treturn nullptr;\n\t}\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn nullptr;\n\t}\n\t\n\treturn xaf;\n}\n\nstd::atomic gFileCount = 0;\n\nvoid makeRecordingPath(Arg filename, char* path, int len)\n{\n\tif (filename.isString()) {\n\t\tconst char* recDir = getenv(\"SAPF_RECORDINGS\");\n\t\tif (!recDir || strlen(recDir)==0) recDir = \"/tmp\";\n\t\tsnprintf(path, len, \"%s/%s.wav\", recDir, ((String*)filename.o())->s);\n\t} else {\n\t\tint32_t count = ++gFileCount;\n\t\tsnprintf(path, len, \"/tmp/sapf-%s-%04d.wav\", gSessionTime, count);\n\t}\n}\n\nvoid sfwrite(Thread& th, V& v, Arg filename, bool openIt)\n{\n\tstd::vector in;\n\t\n\tint numChannels = 0;\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin.push_back(ZIn(v));\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin.push_back(ZIn(va));\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tchar path[1024];\n\t\n\tmakeRecordingPath(filename, path, 1024);\n\t\n\tExtAudioFileRef xaf = sfcreate(th, path, numChannels, 0., true);\n\tif (!xaf) return;\n\t\n\tstd::valarray buf(0., numChannels * kBufSize);\n\tAudioBufferList abl;\n\tabl.mNumberBuffers = 1;\n\tabl.mBuffers[0].mNumberChannels = numChannels;\n\tabl.mBuffers[0].mData = &buf[0];\n\tabl.mBuffers[0].mDataByteSize = kBufSize * sizeof(float);\n\t\n\tint64_t framesPulled = 0;\n\tint64_t framesWritten = 0;\n\tbool done = false;\n\twhile (!done) {\n\t\tint minn = kBufSize;\n\t\tmemset(&buf[0], 0, kBufSize * numChannels);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].fill(th, n, &buf[0]+i, numChannels);\n\t\t\tframesPulled += n;\n\t\t\tif (imdone) done = true;\n\t\t\tminn = std::min(n, minn);\n\t\t}\n\n\t\tabl.mBuffers[0].mDataByteSize = minn * sizeof(float);\n\t\tOSStatus err = ExtAudioFileWrite(xaf, minn, &abl);\n\t\tif (err) {\n\t\t\tpost(\"ExtAudioFileWrite failed %d\\n\", (int)err);\n\t\t\tbreak;\n\t\t}\n\n\t\tframesWritten += minn;\n\t}\n\t\n\tpost(\"wrote file '%s' %d channels %g secs\\n\", path, numChannels, framesWritten * th.rate.invSampleRate);\n\t\n\tExtAudioFileDispose(xaf);\n\t\n\tif (openIt) {\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n}\n"], ["/sapf/src/StreamOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n#include \"dsp.hpp\"\n#include \"SoundFiles.hpp\"\n\nconst Z kOneThird = 1. / 3.;\n\n// list ops\n#pragma mark LIST OPS\n\nstatic void finite_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.pushBool(v.isFinite());\n}\n\nstatic void size_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (v.isList() && !v.isFinite()) \n\t\tth.push(INFINITY);\n\telse \n\t\tth.push(v.length(th));\n}\n\n\nstatic void rank_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tint rank = 0;\n\twhile (a.isVList()) {\n\t\t++rank;\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\t\n\tth.push(rank);\n}\n\nstatic void shape_(Thread& th, Prim* prim)\n{\n\tP shape = new Array(itemTypeZ, 4);\n\t\n\tV a = th.pop();\n\t\n\twhile (a.isVList()) {\n\t\tZ len;\n\t\tif (a.isFinite()) {\n\t\t\tlen = a.length(th);\n\t\t} else {\n\t\t\tlen = INFINITY;\n\t\t}\n\t\tshape->addz(len);\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\tth.push(new List(shape));\n}\n\nstatic void bub_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tP seq = new List(itemTypeV, 1);\n\tseq->add(a);\n\tth.push(seq);\n}\n\nstatic void nbub_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbub : n\");\n\tV a = th.pop();\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\n\t\tP seq = new List(itemTypeV, 1);\n\t\tseq->add(a);\n\t\ta = seq;\n\t}\n\tth.push(a);\n}\n\ntemplate \nstatic void tupleN_(Thread& th, Prim* prim)\n{\n\tP seq = new List(itemTypeV, N);\n\tP arr = seq->mArray;\n\tarr->setSize(N);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v = th.pop();\n\t\tarr->put(N-1-i, v);\n\t}\n\tth.push(seq);\n}\n\ntemplate \nstatic void untupleN_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"unN : s\");\n\t\n\tBothIn in(s);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v;\n\t\tif (in.one(th, v)) {\n\t\t\tpost(\"too few items in list for un%d\", N);\n\t\t\tthrow errFailed;\n\t\t}\n\t\tth.push(v);\n\t}\n}\n\nstatic void reverse_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"reverse : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"reverse\", \"\");\n\t\t\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t}\n\tth.push(s2);\n}\n\ntemplate \nvoid copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[i];\n}\n\ntemplate \nvoid reverse_copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[-i];\n}\n\nstatic List* makeMirror(P const& a, int64_t n, int64_t nr, int64_t roff)\n{\n\tint type = a->elemType;\n\tint64_t size = n + nr;\n\tList* s = new List(type, size);\n\tArray* b = s->mArray();\n\t\n\tb->setSize(size);\n\tif (type == itemTypeV) {\n\t\tV* p = b->v();\n\t\tV* q = a->v();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t} else {\n\t\tZ* p = b->z();\n\t\tZ* q = a->z();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t}\n\treturn s;\n}\n\nstatic void mirror(Thread& th, int w, P s)\n{\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"mirror\", \"\");\n\n\ts = s->pack(th);\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\tint64_t n2 = n-2;\n\t\n\tswitch (w) {\n\t\tcase 0 : {\n\t\t\tif (n < 3) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n2, n2));\n\t\t} break;\n\t\tcase 1 : {\n\t\t\tif (n < 2) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n1, n2));\n\t\t} break;\n\t\tcase 2 : {\n\t\t\tif (n == 0) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n, n1));\n\t\t} break;\n\t}\n}\n\nstatic void mirror0_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror0 : s\");\n\tmirror(th, 0, s);\n}\n\nstatic void mirror1_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror1 : s\");\n\tmirror(th, 1, s);\n}\n\nstatic void mirror2_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror2 : s\");\n\tmirror(th, 2, s);\n}\n\nstatic void rot_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"rot : r\");\n\tP s = th.popList(\"rot : s\");\n\t\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"rot\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->wrapAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->wrapAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void shift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"shift : r\");\n\tP s = th.popList(\"shift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"shift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->at(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->atz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void clipShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"clipShift : r\");\n\tP s = th.popList(\"clipShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->clipAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->clipAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void foldShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"foldShift : r\");\n\tP s = th.popList(\"foldShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->foldAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->foldAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void muss_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"muss : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"muss\", \"\");\n \n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int64_t i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t}\n\tth.push(s2);\n}\n\n\n\n\n\nV do_at(Thread& th, P const& a, Arg i);\nV do_wrapAt(Thread& th, P const& a, Arg i);\nV do_foldAt(Thread& th, P const& a, Arg i);\nV do_clipAt(Thread& th, P const& a, Arg i);\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\n\nclass AtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"AtGenVV\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_at(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->at(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->atz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tWrapAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_wrapAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass FoldAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tFoldAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_foldAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass ClipAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tClipAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_clipAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Z degkey(Z degree, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ fidegree = floor(degree + .5);\n\t//Z frac = degree - fidegree;\n\tint idegree = (int)fidegree;\n\tint modDegree = (int)sc_imod(idegree, degreesPerCycle);\n\t//return frac + scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n\treturn scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n}\n\n\nstatic Z keydeg(Z key, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ cycles, cyckey;\n\tsc_fdivmod(key, cycleWidth, cycles, cyckey);\n\t\n\tZ frac = scale->atz(0) + cycleWidth - cyckey;\n\tZ mindiff = std::abs(frac);\n\tint idegree = 0;\n\tfor (int i = 0; i < degreesPerCycle; ++i) {\n\t\tfrac = std::abs(cyckey - scale->atz(i));\n\t\tif (frac < mindiff) {\n\t\t\tmindiff = frac;\n\t\t\tidegree = i;\n\t\t}\n\t}\n\t\n\treturn idegree + cycles * degreesPerCycle;\n}\n\nclass DegKeyVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _degree;\npublic:\n\n\tDegKeyVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_degkey(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _key;\npublic:\n\n\tKeyDegVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_keydeg(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Gen* newAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new AtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new AtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new AtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newWrapAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new WrapAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new WrapAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new WrapAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newDegKeyGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new DegKeyVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new DegKeyVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new DegKeyZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newKeyDegGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new KeyDegVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new KeyDegVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new KeyDegZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newFoldAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new FoldAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new FoldAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new FoldAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newClipAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new ClipAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new ClipAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new ClipAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nV do_at(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->at(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newAtGen(th, a, b));\n\t} else wrongType(\"at : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_wrapAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->wrapAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newWrapAtGen(th, a, b));\n\t} else wrongType(\"wrapAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn degkey(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newDegKeyGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"degkey : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn keydeg(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newKeyDegGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"keydeg : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_foldAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->foldAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newFoldAtGen(th, a, b));\n\t} else wrongType(\"foldAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_clipAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->clipAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newClipAtGen(th, a, b));\n\t} else wrongType(\"clipAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nstatic void at_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"at : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"at\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_at(th, a, i);\n\tth.push(v);\n}\n\nstatic void wrapAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"wrapAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"wrapAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_wrapAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void degkey_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"degkey : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"degkey\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"degkey : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_degkey(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void keydeg_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"keydeg : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"keydeg\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"keydeg : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_keydeg(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void foldAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"foldAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_foldAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void clipAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"clipAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_clipAt(th, a, i);\n\tth.push(v);\n}\n\n\n#pragma mark CONVERSION\n\n\nstruct VGen : public Gen\n{\n\tZIn _a;\n\t\n\tVGen(Thread& th, Arg a) : Gen(th, itemTypeV, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct ZGen : public Gen\n{\n\tVIn _a;\n\t\n\tZGen(Thread& th, Arg a) : Gen(th, itemTypeZ, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->asFloat();\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic P stringToZList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeZ, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tz[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P stringToVList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeV, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tv[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P vlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"stream to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)v[i].asFloat());\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic P zlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"signal to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)z[i]);\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic void V_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isZList()) {\n\t\tGen* g = new VGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToVList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void Z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tGen* g = new ZGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToZList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void unspell_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(vlistToString(th, list));\n\t} else if (a.isZList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(zlistToString(th, list));\n\t} else if (a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\twrongType(\"unspell : list\", \"List or String\", a);\n\t}\n}\n\n\n\n#pragma mark NUMERIC SERIES\n\n\nstruct Ever : public Gen\n{\n\tV _val;\n\n\tEver(Thread& th, Arg val) : Gen(th, itemTypeV, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Ever\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV v = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = v;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Everz : public Gen\n{\n\tZ _val;\n\n\tEverz(Thread& th, Z val) : Gen(th, itemTypeZ, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Everz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ z = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = z;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_recip;\nextern UnaryOp* gUnaryOpPtr_cb;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstruct By : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tBy(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"By\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Byz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tByz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Byz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Grow : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tGrow(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Grow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Growz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tGrowz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Growz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart *= step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLine : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tCubicLine(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLine\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV cubed = _start.unaryOp(th, gUnaryOpPtr_cb);\t\n\t\t\tout[i] = cubed;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tCubicLinez(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start*start*start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Inv : public Gen\n{\n\tV _start;\n\n\tInv(Thread& th) : Gen(th, itemTypeV, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Inv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV vone = 1.;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\tout[i] = vout;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Invz : public Gen\n{\n\tZ _start;\n\n\tInvz(Thread& th) : Gen(th, itemTypeZ, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Invz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. / start;\n\t\t\tstart += 1.;\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NInv : public Gen\n{\n\tV _start;\n\tint64_t _n;\n\n\tNInv(Thread& th, int64_t n) : Gen(th, itemTypeV, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tV vone = 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\t\tout[i] = vout;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NInvz : public Gen\n{\n\tZ _start;\n\tint64_t _n;\n\n\tNInvz(Thread& th, int64_t n) : Gen(th, itemTypeZ, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInvz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = 1. / start;\n\t\t\t\tstart += 1.;\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NBy : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNBy(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NBy\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NByz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\t\n\tNByz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NByz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\n\nstruct NGrow : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNGrow(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NGrowz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNGrowz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrowz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart *= step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NCubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNCubicLinez(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NCubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start*start*start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct Fib : public Gen\n{\n\tV _a;\n\tV _b;\n \n\tFib(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fib\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV a = _a;\n out[i] = a;\n _a = _b;\n _b = a.binaryOp(th, gBinaryOpPtr_plus, _b);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Fibz : public Gen\n{\n\tZ _a;\n\tZ _b;\n \n\tFibz(Thread& th, Z a, Z b) : Gen(th, itemTypeZ, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fibz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n int n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ a = _a;\n\t\tZ b = _b;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = a;\n Z aa = a;\n a = b;\n b += aa;\n\t\t}\n\t\t_a = a;\n\t\t_b = b;\n\t\tmOut = mOut->nextp();\n }\n};\n\nstatic void L_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tth.push(new List(new Ever(th, th.pop())));\n\t}\n}\n\nstatic void L1_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tP list = new List(itemTypeV, 1);\n\t\tlist->add(th.pop());\n\t\tth.push(list);\n\t}\n}\n\nstatic void ever_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\t\n\tGen* g = new Ever(th, value);\n\tth.push(new List(g));\n}\n\nstatic void everz_(Thread& th, Prim* prim)\n{\n\tZ value = th.popFloat(\"everz : value\");\n\t\n\tGen* g = new Everz(th, value);\n\tth.push(new List(g));\n}\n\nstatic void by_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new By(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nby_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"nby : n\");\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void to_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"to : end\");\n\tZ start = th.popFloat(\"to : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void toz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"toz : end\");\n\tZ start = th.popFloat(\"toz : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv : end\");\n\tZ start = th.popFloat(\"lindiv : start\");\n\tint64_t n = th.popInt(\"lindiv : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindivz : end\");\n\tZ start = th.popFloat(\"lindivz : start\");\n\tint64_t n = th.popInt(\"lindivz : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv : end\");\n\tZ start = th.popFloat(\"expdiv : start\");\n\tint64_t n = th.popInt(\"expdiv : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdivz : end\");\n\tZ start = th.popFloat(\"expdivz : start\");\n\tint64_t n = th.popInt(\"expdivz : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1 : end\");\n\tZ start = th.popFloat(\"lindiv1 : start\");\n\tint64_t n = th.popInt(\"lindiv1 : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1z : end\");\n\tZ start = th.popFloat(\"lindiv1z : start\");\n\tint64_t n = th.popInt(\"lindiv1z : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1 : end\");\n\tZ start = th.popFloat(\"expdiv1 : start\");\n\tint64_t n = th.popInt(\"expdiv1 : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1z : end\");\n\tZ start = th.popFloat(\"expdiv1z : start\");\n\tint64_t n = th.popInt(\"expdiv1z : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void line_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"line : end\");\n\tZ start = th.popFloat(\"line : start\");\n\tZ dur = th.popFloat(\"line : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, (int64_t)n);\n\tth.push(new List(g));\n}\n\nstatic void xline_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"xline : end\");\n\tZ start = th.popFloat(\"xline : start\");\n\tZ dur = th.popFloat(\"xline : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\n\tGen* g;\n\tif (sc_sgn(start) != sc_sgn(end) || start == 0. || end == 0.) {\n\t\tstart = sc_sgn(start) * pow(fabs(start), kOneThird);\n\t\tend = sc_sgn(end) * pow(fabs(end), kOneThird);\n\t\tZ step = (end - start) / n;\t\t\n\t\tg = new NCubicLinez(th, start, step, (int64_t)n);\n\t} else {\n\t\tZ step = pow(end/start, 1. / n);\n\t\tg = new NGrowz(th, start, step, (int64_t)n);\n\t}\n\tth.push(new List(g));\n}\n\n\nstatic void grow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new Grow(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"ngrow : n\");\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void byz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"byz : step\");\n\tZ start = th.popFloat(\"byz : start\");\n\t\n\tGen* g = new Byz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nbyz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"nbyz : step\");\n\tZ start = th.popFloat(\"nbyz : start\");\n\tint64_t n = th.popInt(\"nbyz : n\");\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void growz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"growz : step\");\n\tZ start = th.popFloat(\"growz : start\");\n\t\n\tGen* g = new Growz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrowz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"ngrowz : step\");\n\tZ start = th.popFloat(\"ngrowz : start\");\n\tint64_t n = th.popInt(\"ngrowz : n\");\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void ord_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negs_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void nat_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evens_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void odds_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 2.);\n\tth.push(new List(g));\n}\n\n\nstatic void invs_(Thread& th, Prim* prim)\n{\n\tGen* g = new Inv(th);\n\tth.push(new List(g));\n}\n\nstatic void invz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Invz(th);\n\tth.push(new List(g));\n}\n\nstatic void ninvs_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvs : n\");\n\tGen* g = new NInv(th, n);\n\tth.push(new List(g));\n}\n\nstatic void ninvz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvz : n\");\n\tGen* g = new NInvz(th, n);\n\tth.push(new List(g));\n}\n\n\nstatic void ordz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void natz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evenz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void oddz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 2.);\n\tth.push(new List(g));\n}\n\nstatic void fib_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Fib(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void fibz_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"fibz : b\");\n\tZ a = th.popFloat(\"fibz : a\");\n\t\n\tGen* g = new Fibz(th, a, b);\n\tth.push(new List(g));\n}\n\nstruct Ints : public Gen\n{\n\tZ _a;\n \n\tInts(Thread& th) : Gen(th, itemTypeV, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Ints\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Intz : public Gen\n{\n\tZ _a;\n \n\tIntz(Thread& th) : Gen(th, itemTypeZ, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Intz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstatic void ints_(Thread& th, Prim* prim)\n{\n\tGen* g = new Ints(th);\n\tth.push(new List(g));\n}\n\nstatic void intz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Intz(th);\n\tth.push(new List(g));\n}\n\n#include \"primes.hpp\"\n\nstruct Primes : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimes(Thread& th) : Gen(th, itemTypeV, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primes\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct Primez : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimez(Thread& th) : Gen(th, itemTypeZ, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primez\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n } else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n if (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\n\nstatic void primes_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primes(th);\n\tth.push(new List(g));\n}\n\nstatic void primez_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primez(th);\n\tth.push(new List(g));\n}\n\n\n#pragma mark ORDERING\n\n\nclass Perms : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPerms(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_at(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Perms\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeV, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tV* outItems = arr->v();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nclass Permz : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPermz(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_atz(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Permz\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeZ, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tZ* outItems = arr->z();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nstatic void perms_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"perms : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"perms : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Perms(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permz : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Permz(th, arr);\n\tth.push(new List(g));\n}\n\n\n\nclass PermsWithRepeatedItems : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItems(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_at(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItems\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\n\nclass PermsWithRepeatedItemsZ : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItemsZ(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_atz(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItemsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\nstatic void permswr_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"permswr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permswr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItems(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permzwr_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permzwr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permzwr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItemsZ(th, arr);\n\tth.push(new List(g));\n}\n\n\nstruct Repeat : Gen\n{\n V _a;\n\tint64_t _m;\n \n\tRepeat(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n V a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct RepeatFun : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFun(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _b(0.), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct InfRepeatFun : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFun(Thread& th, Arg a) : Gen(th, itemTypeV, false), _a(a), _b(0.) {}\n\t \n\tvirtual const char* TypeName() const override { return \"InfRepeatFun\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n \n};\n\nstruct Repeatz : Gen\n{\n Z _a;\n\tint64_t _m;\n \n\tRepeatz(Thread& th, Z a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Repeatz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n Z a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct RepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFunz(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _b(0.), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"RepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop().asFloat();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct InfRepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFunz(Thread& th, Arg a) : Gen(th, itemTypeZ, false), _a(a), _b(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"InfRepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop().asFloat();\n\t\t}\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct RCyc : public Gen\n{\n\tV _ref;\n\tP _a0;\n\tP _a;\n\n\tRCyc(Thread& th, Arg ref, P const& a) : Gen(th, a->elemType, false), _ref(ref), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"RCyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tV v = _ref.deref();\n\t\t\tif (v.isList()) {\n\t\t\t\t_a0 = (List*)v.o();\n\t\t\t}\n\t\t\t_a = _a0;\n\t\t}\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Cyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\n\tCyc(Thread& th, P const& a) : Gen(th, a->elemType, false), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) _a = _a0;\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NCyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\tint64_t _n;\n\t\n\tNCyc(Thread& th, int64_t n, P const& a) : Gen(th, a->elemType, true), _a0(a), _a(a), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tif (_n <= 1) {\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\t_a = _a0;\n\t\t\t\t--_n;\n\t\t\t}\n\t\t}\n\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void repeat_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"X : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFun(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Ever(th, a);\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFun(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeat(th, a, n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstatic void repeatz_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"XZ : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFunz(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Everz(th, a.asFloat());\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFunz(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeatz(th, a.asFloat(), n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstruct Silence : Gen\n{\n\tint64_t _m;\n \n\tSilence(Thread& th, int64_t m) : Gen(th, itemTypeZ, true), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Silence\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n\t\t\tmemset(out, 0, n * sizeof(Z));\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstatic void mum_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"mum : duration\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\tif (isinf(t) || (n <= 0 && t > 0.)) {\n\t\tth.push(new List(new Everz(th, 0.)));\n\t} else {\n\t\tGen* g = new Silence(th, n);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstatic void cyc_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\t\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP s = (List*)v.o();\n\t\n\n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n \n\tGen* g = new Cyc(th, s);\n\tth.push(new List(g));\n}\n\n\nstatic void rcyc_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tV v = ref.deref();\n\tif (!v.isList()) {\n\t\twrongType(\"rcyc : ref get\", \"List\", v);\n\t}\n\t\n\tP list = (List*)v.o();\n\t\n\tGen* g = new RCyc(th, ref, list);\n\tth.push(new List(g));\n}\n\n\nstatic void ncyc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ncyc : n\");\n\tP s = th.popList(\"ncyc : seq\");\n \n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n\t\n\tif (n <= 0) {\n\t\tth.push(vm.getNil(s->elemType));\t\t\n\t} else {\n\t\tGen* g = new NCyc(th, n, s);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstruct Append : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAppend(Thread& th, P const& a, Arg b, bool inFinite) : Gen(th, a->elemType, inFinite), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Append\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t\tmOut = mOut->nextp();\n\t\t} else {\n\t\t\tif (_b.isFunOrPrim()) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\t_b.apply(th);\n\t\t\t\t_b = th.pop();\n\t\t\t}\n\t\t\tif (!_b.isList()) {\n\t\t\t\tpost(\"$ : b is not a sequence '%s'\\n\", _b.TypeName());\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tList* b = (List*)_b.o();\n\t\t\tif (elemType != b->elemType) {\n\t\t\t\tpost(\"$ : b item type doesn't match\\n\");\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetDone();\n\t\t\tmOut->link(th, b);\n\t\t}\n\t}\n};\n\n\nstruct Cat : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\n\tCat(Thread& th, Arg a, P const& b) : Gen(th, itemTypeV, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"Cat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isVList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct CatZ : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\n\t// this makes the assumption that all of the sublists of b are finite! if they are not then this will not prevent infinite loops.\n\tCatZ(Thread& th, Arg a, P const& b) : Gen(th, itemTypeZ, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"CatZ\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isZList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\t\t\t\n};\n\n#include \n\nstruct Flat : Gen\n{\n\tstd::stack in; // stack of list continuations\n\n\tFlat(Thread& th, Arg inA) : Gen(th, itemTypeV, inA.isFinite())\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList()) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Flatten : Gen\n{\n\tstd::stack in; // stack of list continuations\n\tsize_t depth;\n\t\n\tFlatten(Thread& th, Arg inA, size_t inDepth) : Gen(th, itemTypeV, inA.isFinite()), depth(inDepth)\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList() && in.size() <= depth) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Keep : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tKeep(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keep\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Take : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tTake(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Take\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeat(th, 0., _n));\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Keepz : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tKeepz(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keepz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Takez : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tTakez(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Takez\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeatz(th, 0., _n));\n setDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstatic void append_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tif (a.isString() && b.isString()) {\n\t\tstd::string s;\n\t\ta.print(th, s);\n\t\tb.print(th, s);\n\t\tth.push(new String(s.c_str()));\n\t} else if (a.isList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(new List(new Append(th, list, b, leastFinite(a,b))));\n\t} else {\n\t\twrongType(\"$ : a\", \"List or String\", a);\n\t}\n}\n\nstruct AppendSubs : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tAppendSubs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AppendSubs\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tif (!a->isList())\n\t\t\t\t\t\twrongType(\"$$ : *a\", \"List\", *a);\n\t\t\t\t\t\n\t\t\t\t\tList* aa = (List*)a->o();\n\t\t\t\t\t\t\n\t\t\t\t\tout[i] = new List(new Append(th, aa, *b, mostFinite(*a,*b)));\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void appendSubs_(Thread& th, Prim* prim)\n{\n\tV b = th.popVList(\"$$ : b\");\n\tV a = th.popVList(\"$$ : a\");\n\t\n th.push(new List(new AppendSubs(th, a, b)));\n}\n\nstatic void cat_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP b = (List*)v.o();\n\n\tb->force(th);\n\tif (b->isEnd()) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\tVIn a_(b);\n\tV a;\n\tif (a_.one(th, a)) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\t\n\t\n\t//V a = b->mArray->v()[0];\n\t\n\tif (a.isString()) {\n\t\tif (!b->isFinite())\n\t\t\tindefiniteOp(\"$/ : list of strings\", \"\");\n\t\t\n\t\tstd::string s;\n\n\t\tVIn in_(b);\n\t\twhile (true) {\n\t\t\tV in;\n\t\t\tif (in_.one(th, in)) {\n\t\t\t\tth.push(new String(s.c_str()));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tin.print(th, s);\n\t\t}\n\t\t\n\t} else if (!a.isList()) {\n\t\twrongType(\"$/ : b\", \"List\", a);\n\t}\n\t\t\n\tGen* g;\n\tif (a.isVList()) g = new Cat(th, a, b);\n\telse g = new CatZ(th, a, b);\n\tth.push(new List(g));\n\n}\n\nstatic void flat_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\n\tif (a.isVList()) th.push(new List(new Flat(th, a)));\n\telse th.push(a);\n}\n\nstatic void flatten_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"flatten : n\");\n\tV a = th.pop();\n\t\n\tif (a.isVList()) th.push(new List(new Flatten(th, a, n)));\n\telse th.push(a);\n}\n\nstatic void N_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"N : n\");\n\tV v = th.pop();\n\t\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void NZ_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"NZ : n\");\n\tV v = th.pop();\n\t\n if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void T_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"T : t\");\n\tV v = th.pop();\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void take_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"take : n\");\n\tP s = th.popList(\"take : s\");\n\n Gen* g;\n\tif (n > 0) {\n\t\tif (s->isVList()) \n\t\t\tg = new Take(th, n, s);\n\t\telse\n\t\t\tg = new Takez(th, n, s);\n\t\tth.push(new List(g));\n } else if (n < 0) {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"take\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tList* s2 = new List(s->elemType, n);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(n);\n\t\tif (s->isVList()) {\n\t\t\tV* p = s2->mArray->v();\n\t\t\tV* q = s->mArray->v();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tfor (int64_t i = 0; i < offset; ++i) p[i] = 0.;\n\t\t\t\tfor (int64_t i = 0, j = offset; i < size; ++i, ++j) p[j] = q[i];\n\t\t\t} else {\n\t\t\t\tfor (int64_t i = 0, j = size - n; i < n; ++i, ++j) p[i] = q[j];\n\t\t\t}\n\t\t} else {\n\t\t\tZ* p = s2->mArray->z();\n\t\t\tZ* q = s->mArray->z();\n\t\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tmemset(p, 0, offset * elemSize);\n\t\t\t\tmemcpy(p + offset, q, size * elemSize);\n\t\t\t} else {\n\t\t\t\tmemcpy(p, q + size - n, n * elemSize);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t\t\n\t} else {\n\t\tif (s->isVList())\n\t\t\tth.push(vm._nilv);\n\t\telse \n\t\t\tth.push(vm._nilz);\n\t\treturn;\n\t\t\n\t}\n}\n\n\n\n\nstatic void skip_positive_(Thread& th, P& list, int64_t n)\n{\n\tif (n <= 0) return;\n\n\tint itemType = list->elemType;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\t\t\tif (list->isVList()) {\n\t\t\t\tfor (int64_t i = 0, j = n; i < remain; ++i, ++j) {\n\t\t\t\t\ta2->v()[i] = a->v()[j];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\t\t\t}\n\t\t\tlist = new List(a2, list->next());\n\t\t\treturn;\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm.getNil(itemType);\n\t}\n}\n\nstatic void skip_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"skip : n\");\n\tP s = th.popList(\"skip : s\");\n\n\tif (n <= 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\n\nstatic void skipT_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\">T : t\");\n\tP s = th.popList(\">T : s\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\nstruct Hops : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHops(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"Hops\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\t\t\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tint64_t hop;\n\t\t\t\tif (_hop.onei(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tskip_positive_(th, _a, hop);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct HopTs : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHopTs(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"HopTs\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tZ hop;\n\t\t\t\tif (_hop.onez(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * hop);\n\t\t\t\t\tskip_positive_(th, _a, n);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void hops_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"N>> : list\");\n\n\tth.push(new List(new Hops(th, n, s)));\n}\n\nstatic void hopTs_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"T>> : list\");\n\n\tth.push(new List(new HopTs(th, n, s)));\n}\n\n\n\n\nstatic void drop_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"drop : n\");\n\tP s = th.popList(\"drop : s\");\n\n\tif (n == 0) {\n\t\tth.push(s);\n\t} else if (n > 0) {\n\t\tskip_positive_(th, s, n);\n\t\tth.push(s);\n\t} else {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"drop\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tint64_t remain = std::max(0LL, size - n);\n\t\tif (remain <= 0) {\n\t\t\tth.push(vm.getNil(s->elemType));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tP s2 = new List(s->elemType, remain);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(remain);\n\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\tif (s->isVList()) {\n\t\t\tV* y = s->mArray->v();\n\t\t\tV* x = s2->mArray->v();\n\t\t\tfor (int64_t i = 0; i < remain; ++i) {\n\t\t\t\tx[i] = y[i];\n\t\t\t}\n\t\t} else {\n\t\t\tmemcpy(s2->mArray->z(), s->mArray->z(), remain * elemSize);\n\t\t}\n\t}\n}\n\nstatic void choff_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"choff : n\");\n\tint64_t c = th.popInt(\"choff : c\");\n\tV a = th.pop();\n\t\n\tP s2 = new List(itemTypeV, n);\n\ts2->mArray->setSize(n);\n\t\n\tif (a.isVList()) {\n\t\tif (!a.isFinite())\n\t\t\tindefiniteOp(\"choff : a\", \"\");\n\t\t\t\n\t\tP aa = ((List*)a.o())->pack(th);\n\t\tint64_t m = aa->length(th);\n\t\tint64_t mn = std::min(m,n);\n\t\tfor (int64_t i = 0; i < mn; ++i) {\n\t\t\tint64_t j = sc_imod(i+c, n);\n\t\t\ts2->mArray->put(j, aa->at(i));\n\t\t}\n\t} else {\n\t\tc = sc_imod(c, n);\n\t\ts2->mArray->put(c, a);\n\t}\n\t\t\n\tth.push(s2);\n}\n\nstatic int64_t countWhileTrue(Thread& th, List* list)\n{\n int64_t n = 0;\n while (list) {\n list->force(th);\n\n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n if (a->at(i).isTrue()) ++n;\n else return n;\n }\n list = list->nextp();\n }\n\treturn n;\n}\n\nstatic void skipWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"skipWhile : s\");\n\n if (f.isList()) {\n int64_t n = countWhileTrue(th, (List*)f.o());\n skip_positive_(th, s, n);\n\t\tth.push(s);\n } else {\n \n List* list = s();\n\n while (1) {\n list->force(th);\n if (list->isEnd()) {\n th.push(vm.getNil(s->elemType));\n return;\n }\n \n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n V v;\n {\n SaveStack ss(th);\n th.push(a->at(i));\n\t\t\t\t\tf.apply(th);\n v = th.pop();\n }\n if (v.isFalse()) {\n if (i == 0) {\n th.push(list);\n } else {\n int64_t remain = asize - i;\n Array* a2 = new Array(s->elemType, remain);\n th.push(new List(a2, list->next()));\n a2->setSize(remain);\n\t\t\t\t\t\tif (a->isV()) {\n\t\t\t\t\t\t\tfor (int64_t j = 0; j < remain; ++j) a2->v()[j] = a->v()[j+i];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmemcpy(a2->v(), a->v() + i, remain * a->elemSize());\n\t\t\t\t\t\t}\n }\n return;\n }\n }\n list = list->nextp();\n }\n th.push(list);\n }\n}\n\n\nstruct KeepWhile : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tKeepWhile(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhile\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZ : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tKeepWhileZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileVZ : Gen\n{\n\tVIn _a;\n\tZIn _b;\n\t\n\tKeepWhileVZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileVZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a;\n\t\t\tZ *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZV : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\t\n\tKeepWhileZV(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZV\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a;\n\t\t\tV *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstatic void keepWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"keepWhile : s\");\n\t\n\tif (s->isZ()) {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhileZV(th, s, f)));\n\t\t}\n\t} else {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileVZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhile(th, s, f)));\n\t\t}\n\t} \n}\n\n\nstruct Tog : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Togz : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tTogz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Togz\"; }\n \t\t\t \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill / 2;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t*out++ = *a;\n\t\t\t\t\t*out++ = *b;\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= 2*n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tog_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Tog(th, a, b)));\n}\n\nstatic void togz_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Togz(th, a, b)));\n}\n\n\n\nstruct Tog1 : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog1(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog1\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\n\nstruct Hang : Gen\n{\n\tP _a;\n\tV _b;\n\n\tHang(Thread& th, P const& a) : Gen(th, itemTypeV, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hang\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->v()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tV* out = mOut->fulfill(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Hangz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tHangz(Thread& th, P const& a) : Gen(th, itemTypeZ, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hangz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->z()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void hang_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"hang : a\");\n\t\n\tif (a->isV())\n\t\tth.push(new List(new Hang(th, a)));\n\telse\n\t\tth.push(new List(new Hangz(th, a)));\n}\n\nstatic void hangz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"hangz : a\");\n\t\n\tth.push(new List(new Hangz(th, a)));\n}\n\n\nstatic void histo_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"histo : n\");\n\tP a = th.popList(\"histo : list\");\n\n\tif (!a->isFinite()) {\n\t\tindefiniteOp(\"histo : list\", \"\");\n\t}\n\t\n\ta = a->pack(th);\n\t\n\tint64_t size = a->mArray->size();\n\t\n\tPoutList = new List(itemTypeZ, n);\n\toutList->mArray->setSize(n);\n\tZ* out = outList->mArray->z();\n\tmemset(out, 0, sizeof(Z) * n);\n\t\n\tZ n1 = n - 1;\n\tif (a->isZ()) {\n\t\tZ* in = a->mArray->z();\n\t\t\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i], 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t} else {\n\t\tV* in = a->mArray->v();\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i].asFloat(), 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t}\n\t\n\tth.push(outList);\n\t\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark MAP FILTER REDUCE\n\n\nstruct Stutter : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tStutter(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutter\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = aa_;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, aa_) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(aa_);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Stutterz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\tZ aa_;\n\t\n\tStutterz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutterz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a = aa_;\n\t\twhile (framesToFill) {\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\taa_ = a;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void filter_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.popList(\"? : a\");\n\n\tif (a.isVList()) {\n\t\tth.push(new List(new Stutter(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Stutterz(th, a, b)));\n\t}\n}\n\n\nstruct Change : Gen\n{\n\tVIn _a;\n\tV _prev;\n\t\n\tChange(Thread& th, Arg a) : Gen(th, itemTypeV, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Change\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n V a;\n for (int i = 0; framesToFill; ) {\n if (_a.one(th, a)) {\n setDone();\n break;\n }\n if (!a.Equals(th, _prev)) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Changez : Gen\n{\n\tZIn _a;\n\tZ _prev;\n\t\n\tChangez(Thread& th, Arg a) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Changez\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n Z a;\n for (int i = 0; framesToFill; ) {\n if (_a.onez(th, a)) {\n setDone();\n break;\n }\n if (a != _prev) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void change_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"change : a\");\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Change(th, a)));\n\t} else {\n\t\tth.push(new List(new Changez(th, a)));\n\t}\n}\n\nstatic void changez_(Thread& th, Prim* prim)\n{\n\tV a = th.popZList(\"change : a\");\n \n th.push(new List(new Changez(th, a)));\n}\n\nstruct Spread : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tSpread(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spread\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tV a = aa_;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Spreadz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\t\n\tSpreadz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spreadz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n \n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void spread_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Spread(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Spreadz(th, a, b)));\n\t}\n}\n\nstatic void spreadz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"spreadz : b\");\n\tV a = th.popZIn(\"spreadz : a\");\n \n th.push(new List(new Spreadz(th, a, b)));\n}\n\nstruct Expand : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tExpand(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expand\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tV a;\n\t\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Expandz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tExpandz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expandz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tZ a;\n\t\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void expand_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Expand(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Expandz(th, a, b)));\n\t}\n}\n\nstatic void expandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"expandz : b\");\n\tV a = th.popZIn(\"expandz : a\");\n \n th.push(new List(new Expandz(th, a, b)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Clump : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tClump(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clump\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeV, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV a;\n\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->add(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Clumpz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tClumpz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clumpz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeZ, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a;\n\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->addz(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void clump_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Clump(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Clumpz(th, a, b)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ShortAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tShortAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ShortAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tShortAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void shortas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new ShortAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new ShortAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"shortas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tV last;\npublic:\n\t\n\tLongAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\n\tZ last;\npublic:\n\t\n\tLongAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"longas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs0 : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tLongAs0(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tV zero(0.);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = zero;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAs0Z : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tLongAs0Z(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0Z\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas0_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs0(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAs0Z(th, a, b)));\n\t} else {\n\t\twrongType(\"longas0 : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \"Play.hpp\"\n\nstatic void play_(Thread& th, Prim* prim)\n{\n\tV v = th.popList(\"play : list\");\n\tplayWithAudioUnit(th, v);\n}\n\nstatic void record_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tV v = th.popList(\"record : list\");\n\trecordWithAudioUnit(th, v, filename);\n}\n\nstatic void stop_(Thread& th, Prim* prim)\n{\n\tstopPlaying();\n}\n\nstatic void stopDone_(Thread& th, Prim* prim)\n{\n\tstopPlayingIfDone();\n}\n\n\nstatic void interleave(int stride, int numFrames, double* in, float* out)\n{\n\tfor (int f = 0, k = 0; f < numFrames; ++f, k += stride)\n\t\tout[k] = in[f];\n}\n\nstatic void deinterleave(int numChans, int numFrames, float* in, double** out)\n{\n\tswitch (numChans) {\n\t\tcase 1 : \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, ++k) {\n\t\t\t\tout[0][f] = in[k];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 2 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=2) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3 : // e.g. W X Y \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=3) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 4 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=4) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 5 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=5) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 6 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=6) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t\tout[5][f] = in[k+5];\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f) {\n\t\t\t\tfor (int c = 0; c < numChans; ++c, ++k) {\n\t\t\t\t\tout[c][f] = in[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nstatic const size_t gSessionTimeMaxLen = 256;\nchar gSessionTime[gSessionTimeMaxLen];\n\n#include \n\nstatic void setSessionTime()\n{\n\ttime_t t;\n\ttm tt;\n\ttime(&t);\n\tlocaltime_r(&t, &tt);\n\tsnprintf(gSessionTime, gSessionTimeMaxLen, \"%04d-%02d%02d-%02d%02d%02d\",\n\t\ttt.tm_year+1900, tt.tm_mon+1, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec);\n}\n\n\nstatic void sfwrite_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.popList(\">sf : channels\");\n\t\n\tsfwrite(th, v, filename, false);\n}\n\nstatic void sfwriteopen_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.pop();\n\n\tsfwrite(th, v, filename, true);\n}\n\n\nstatic void sfread_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.popString(\"sf> : filename\");\n\t\t\n\tsfread(th, filename, 0, -1);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstatic void bench_(Thread& th, Prim* prim)\n{\n\tZIn in[kMaxSFChannels];\n\t\t\n\tint numChannels = 0;\n\t\n\tV v = th.popList(\"bench : channels\");\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin[0].set(v);\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin[i].set(va);\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tdouble t0 = elapsedTime();\n\tbool done = false;\n\tint64_t framesFilled = 0;\n\twhile (!done) {\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].bench(th, n);\n\t\t\tif (imdone) done = true;\n\t\t\tframesFilled += n;\n\t\t}\n\t}\n\tdouble t1 = elapsedTime();\n\t\n\tdouble secondsOfCPU = t1-t0;\n\tdouble secondsOfAudio = (double)framesFilled * th.rate.invSampleRate;\n\tdouble percentOfRealtime = 100. * secondsOfCPU / secondsOfAudio;\n\t\n\tpost(\"bench:\\n\");\n\tpost(\" %f seconds of audio.\\n\", secondsOfAudio);\n\tpost(\" %f seconds of CPU.\\n\", secondsOfCPU);\n\tpost(\" %f %% of real time.\\n\", percentOfRealtime);\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#include \"Spectrogram.hpp\"\n\nstd::atomic gSpectrogramFileCount = 0;\n\nstatic void sgram_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tZ dBfloor = fabs(th.popFloat(\"sgram : dBfloor\"));\n\tP list = th.popZList(\"sgram : signal\");\n\t\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"sgram : signal - indefinite number of frames\", \"\");\n\t}\n\n\tchar path[1024];\n\tif (filename.isString()) {\n\t\tconst char* sgramDir = getenv(\"SAPF_SPECTROGRAMS\");\n\t\tif (!sgramDir || strlen(sgramDir)==0) sgramDir = \"/tmp\";\n\t\tsnprintf(path, 1024, \"%s/%s-%d.jpg\", sgramDir, ((String*)filename.o())->s, (int)floor(dBfloor + .5));\n\t} else {\n\t\tint32_t count = ++gSpectrogramFileCount;\n\t\tsnprintf(path, 1024, \"/tmp/sapf-%s-%04d.jpg\", gSessionTime, count);\n\t}\n\n\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\tint64_t n = array->size();\n\tdouble* z = array->z();\n\tspectrogram((int)n, z, 3200, 11, path, -dBfloor);\n\t\n\t{\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\t\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double kaiser_alpha(double atten)\n{\n\tdouble alpha = 0.;\n\tif (atten > 50.) \n\t\talpha = .1102 * (atten - 8.7);\n\telse if (atten >= 21.)\n\t\talpha = .5842 * pow(atten - 21., .4) + .07886 * (atten - 21.);\n\treturn alpha;\n}\n\nstatic void kaiser(size_t m, double *s, double alpha)\n{\n\tif (m == 0) return;\n\tif (m == 1) {\n\t\ts[0] = 1.;\n\t\treturn;\n\t}\n\tsize_t n = m-1;\n\tdouble p = n / 2.;\n\tdouble rp = 1. / p;\n\tdouble rb = 1. / bessi0(alpha);\n\t\n\tfor (size_t i = 0; i < m; ++i) {\n\t\tdouble x = (i-p) * rp;\n\t\ts[i] = rb * bessi0(alpha * sqrt(1. - x*x));\n\t}\n}\n\nstatic void kaiser_(Thread& th, Prim* prim)\n{\n\tZ atten = fabs(th.popFloat(\"kaiser : stopband attenuation\"));\n\tint64_t n = th.popInt(\"kaiser : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tZ alpha = kaiser_alpha(atten);\n\tkaiser(n, out->mArray->z(), alpha);\n\t\n\tth.push(out);\n}\n\n\nstatic void hanning_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hann_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void hamming_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hamm_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void blackman_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_blkman_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Segment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tBothIn length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tSegment(Thread& th, Arg in, Arg hop, Arg length)\n : Gen(th, itemTypeV, mostFinite(in, hop, length)), in_(in), hop_(hop), length_(length),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Segment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zlength, zhop;\n\t\t\tif (length_.onez(th, zlength)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint length = (int)floor(sr_ * zlength + .5);\n\t\t\tP segment = new List(itemTypeZ, length);\n\t\t\tsegment->mArray->setSize(length);\n\t\t\tbool nomore = in_.fillSegment(th, length, segment->mArray->z());\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n \n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void seg_(Thread& th, Prim* prim)\n{\n\tV length = th.pop();\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n\tth.push(new List(new Segment(th, in, hop, length)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct WinSegment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tP window_;\n int length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tWinSegment(Thread& th, Arg in, Arg hop, P const& window)\n : Gen(th, itemTypeV, mostFinite(in, hop)), in_(in), hop_(hop), window_(window),\n length_((int)window_->size()),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WinSegment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zhop;\n\t\t\t\n\t\t\tP segment = new List(itemTypeZ, length_);\n\t\t\tsegment->mArray->setSize(length_);\n Z* segbuf = segment->mArray->z();\n\t\t\tbool nomore = in_.fillSegment(th, (int)length_, segbuf);\n vDSP_vmulD(segbuf, 1, window_->z(), 1, segbuf, 1, length_);\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void wseg_(Thread& th, Prim* prim)\n{\n\tP window = th.popZList(\"wseg : window\");\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n window = window->pack(th);\n \n\tth.push(new List(new WinSegment(th, in, hop, window->mArray)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void fft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"fft : imag\");\n\tP inReal = th.popZList(\"fft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"fft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"fft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"fft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"fft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\n\tfft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\n\nstatic void ifft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"ifft : imag\");\n\tP inReal = th.popZList(\"ifft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"ifft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"ifft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"ifft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"ifft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\tifft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\nstruct Add : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAdd(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Add\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tV* out = mOut->fulfill(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Addz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tAddz(Thread& th, P const& a, Z b) : Gen(th, itemTypeZ, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Addz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tZ* out = mOut->fulfillz(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void add_(Thread& th, Prim* prim)\n{\n\tV item = th.pop();\n\tP list = th.popList(\"add : list\");\n\tif (list->isZ()) {\n\t\tth.push(new List(new Addz(th, list, item.asFloat())));\n\t} else {\n\t\tth.push(new List(new Add(th, list, item)));\n\t}\n}\n\nstatic void empty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size==0);\n}\n\nstatic void nonempty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size!=0);\n}\n\nstatic void head_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tBothIn in(list);\n\tV v;\n\tif (in.one(th, v)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tth.push(v);\n}\n\nstatic void tail_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tskip_positive_(th, list, 1);\n\tth.push(list);\n}\n\nstatic void uncons_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tlist->force(th);\n\n\tBothIn in(list);\n\tV head;\n\tif (in.one(th, head)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tskip_positive_(th, list, 1);\n\t\n\tth.push(list);\n\tth.push(head);\n}\n\nclass Cons : public Gen\n{\n\tV fun;\npublic:\n\tCons(Thread& th, Arg inFun) : Gen(th, itemTypeV, false), fun(inFun) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Cons\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tSaveStack ss(th);\n\t\tfun.apply(th);\n\t\tV v = th.pop();\n\t\tif (v.isList()) {\n\t\t\tsetDone();\n\t\t\tmOut->link(th, (List*)v.o());\n\t\t} else {\n\t\t\tend();\n\t\t}\n\t}\n};\n\nstatic V cons(Thread& th, Arg head, Arg tail)\n{\n\tif (tail.isFunOrPrim()) {\n\t\tP array = new Array(itemTypeV, 1);\n\t\tarray->add(head);\n\t\treturn new List(array, new List(new Cons(th, tail)));\n\t} else if (tail.isList()) {\n\t\n\t\tP list = (List*)tail.o();\n\t\t\n\t\tlist->force(th);\n\t\t\t\n\t\tint64_t size = list->mArray->size();\n\n\t\tP array = list->mArray;\n\t\tP newArray = new Array(list->ItemType(), size+1);\n\n\t\tP newList = new List(newArray, list->next());\n\n\t\tnewArray->add(head);\n\n\t\tif (list->isZ()) {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tZ z = array->atz(i);\n\t\t\t\tnewArray->add(z);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tV v = array->at(i);\n\t\t\t\tnewArray->add(v);\n\t\t\t}\n\t\t}\n\n\t\treturn newList;\n\t} else {\n\t\twrongType(\"cons : list\", \"List or Fun\", tail);\n\t}\n}\n\nstatic void cons_(Thread& th, Prim* prim)\n{\n\tV head = th.pop();\n\tV tail = th.pop();\n\t\n\tth.push(cons(th, head, tail));\n}\n\nstatic void pack_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"pack : list\");\n\tth.push(list->pack(th));\n}\n\nstatic void packed_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"packed : list\");\n\tth.pushBool(list->isPacked());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n \n\tScan(Thread& th, Arg list, Arg fun, Arg val) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan(th, list, fun, value)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan1 : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n\tbool once_;\n \n\tScan1(Thread& th, Arg list, Arg fun) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), once_(true) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (once_) {\n\t\t\tonce_ = false;\n\t\t\tif (list_.one(th, val_)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = val_;\n\t\t\t--framesToFill;\n\t\t}\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan1(th, list, fun)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Iter : Gen\n{\n V fun_;\n V val_;\n Z index = 0.;\n\t\n\tIter(Thread& th, Arg fun, Arg val) : Gen(th, itemTypeV, true), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Iter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct NIter : Gen\n{\n V fun_;\n V val_;\n\tint64_t n_;\n Z index = 0.;\n \n\tNIter(Thread& th, Arg fun, Arg val, int64_t n) : Gen(th, itemTypeV, false), fun_(fun), val_(val), n_(n) {}\n\t \n\tvirtual const char* TypeName() const override { return \"NIter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (n_ <= 0) {\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tn_ -= n;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void iter_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new Iter(th, fun, value)));\n}\n\nstatic void itern_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"itern : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new NIter(th, fun, value, n)));\n}\n\n\n\nstatic void reduce_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\n\nstatic void reduce1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\tV value;\n\tif (in_.one(th, value)) {\n\t\tth.push(value);\n\t\treturn;\n\t}\n\t\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\nstatic void chain_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"chain : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\n\tbool pushIndex = fun.takes() == 2;\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(value);\n\t\tif (pushIndex) th.push(i);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n\tth.push(value);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Merge : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMerge(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Merge\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \nstruct MergeZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeByKey : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V key_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeByKey(Thread& th, Arg a, Arg b, Arg key) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), key_(key) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeByKey\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tV a, b;\n\t\t\t\tbool aok = aa.dot(th, key_, a);\n\t\t\t\tbool bok = bb.dot(th, key_, b);\n\t\t\t\tif (!aok || !bok) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tflag = ::Compare(th, a, b) < 0;\n\t\t\t\tif (flag) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeCmp : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmp(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmp\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\twhich = left;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\nstruct MergeCmpZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmpZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmpZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = right;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\n\nstatic void merge_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"merge : b\");\n\tV a = th.popList(\"merge : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tif (fun.isString()) {\n\t\t\tth.push(new List(new MergeByKey(th, a, b, fun)));\n\t\t} else {\n\t\t\tth.push(new List(new Merge(th, a, b, fun)));\n\t\t}\n\t} else {\n\t\tpost(\"merge : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\nstatic void mergec_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"mergec : b\");\n\tV a = th.popList(\"mergec : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeCmpZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new MergeCmp(th, a, b, fun)));\n\t} else {\n\t\tpost(\"mergec : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n//evmerge\n\nextern P s_dt;\nextern P s_out;\nP s_dur;\n\nP dtTableMap;\nP restTableMap;\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value);\n\nstatic P makeRestEvent(Z dt)\n{\n\tP
table = new Table(restTableMap);\n\ttable->put(0, V(0.));\n\ttable->put(1, V(dt));\n\ttable->put(2, V(dt));\n\treturn new Form(table);\n}\n\nstruct MergeEvents : Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tZ nextATime = 0.;\n\tZ nextBTime;\n\t\n\tMergeEvents(Thread& th, Arg a, Arg b, Z t) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), nextBTime(t)\n\t{\n\t}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeEvents\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\t{\n\t\t\t\tif (nextATime <= nextBTime) {\n\t\t\t\t\tV aa;\n\t\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\t\tif (nextATime < nextBTime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextBTime - nextATime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tV a;\n\t\t\t\t\tbool aok = aa.dot(th, s_dt, a);\n\t\t\t\t\tif (!aok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dta = a.asFloat();\n\t\t\t\t\tZ dt = std::min(dta, nextBTime - nextATime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, aa), dtTableMap, dt);\n\t\t\t\t\tnextATime += dta;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tV bb;\n\t\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\t\tif (nextBTime < nextATime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextATime - nextBTime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tV b;\n\t\t\t\t\tbool bok = bb.dot(th, s_dt, b);\n\t\t\t\t\tif (!bok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dtb = b.asFloat();\n\t\t\t\t\tZ dt = std::min(dtb, nextATime - nextBTime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, bb), dtTableMap, dt);\n\t\t\t\t\tnextBTime += dtb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstatic void evmerge_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evmerge : t\");\n\tV b = th.popVList(\"evmerge : b\");\n\tV a = th.popVList(\"evmerge : a\");\n\tth.push(new List(new MergeEvents(th, a, b, t)));\n}\n\nstatic void evrest_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evrest : t\");\n\tth.push(makeRestEvent(t));\n}\n\nstatic void evdelay_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evdelay : t\");\n\tV a = th.popVList(\"evdelay : a\");\n\tth.push(cons(th, makeRestEvent(t), a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CompareFun\n{\npublic:\n\tCompareFun() {}\n\tvirtual ~CompareFun() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) = 0;\n};\n\nclass VLess : public CompareFun\n{\npublic:\n\tVLess() {}\n\t~VLess() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) < 0; }\n};\n\nclass VGreater : public CompareFun\n{\npublic:\n\tVGreater() {}\n\t~VGreater() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) > 0; }\n};\n\nclass VCompareF : public CompareFun\n{\n\tV fun;\npublic:\n\tVCompareF(V inFun) : fun(inFun) {}\n\t~VCompareF() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\n\n\nclass ZCompareFun\n{\npublic:\n\tZCompareFun() {}\n\tvirtual ~ZCompareFun() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) = 0;\n};\n\nclass ZLess : public ZCompareFun\n{\npublic:\n\tZLess() {}\n\t~ZLess() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a < b; }\n};\n\nclass ZCompareF : public ZCompareFun\n{\n\tV fun;\npublic:\n\tZCompareF(V inFun) : fun(inFun) {}\n\t~ZCompareF() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\nclass ZGreater : public ZCompareFun\n{\npublic:\n\tZGreater() {}\n\t~ZGreater() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a > b; }\n};\n\n\nstatic void merge(Thread& th, int64_t an, V* a, int64_t bn, V* b, V* c, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, int64_t bn, Z* b, Z* c, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, V* tmp, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* tmp, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const V* in, V* out, CompareFun* compare)\n{\n\tV* tmp = new V[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const Z* in, Z* out, ZCompareFun* compare)\n{\n\tZ* tmp = new Z[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void merge(Thread& th, int64_t an, V* a, Z* az, int64_t bn, V* b, Z* bz, V* c, Z* cz, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, Z* az, int64_t bn, Z* b, Z* bz, Z* c, Z* cz, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, Z* az, V* c, Z* cz, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* az, Z* c, Z* cz, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\n\nstatic void grade(Thread& th, int64_t n, const V* in, Z* zout, CompareFun* compare)\n{\n\tV* out = new V[n];\n\tV* tmp = new V[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void grade(Thread& th, int64_t n, const Z* in, Z* zout, ZCompareFun* compare)\n{\n\tZ* out = new Z[n];\n\tZ* tmp = new Z[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void sort_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void sortf_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"sort : fun\");\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(list->ItemType(), n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void sort_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void gradef_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"grade : fun\");\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFN(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP);\n#define DEFNnoeach(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP, V(0.), true);\n\nvoid AddStreamOps();\nvoid AddStreamOps()\n{\n\tinitFFT();\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\ts_dur = getsym(\"dur\");\n\tdtTableMap = new TableMap(V(s_dt));\n\trestTableMap = new TableMap(3);\n\trestTableMap->put(0, s_out, s_out->Hash());\n\trestTableMap->put(1, s_dur, s_dur->Hash());\n\trestTableMap->put(2, s_dt, s_dt->Hash());\n\t\n\tvm.addBifHelp(\"\\n*** list conversion ***\");\n\tDEF(V, 1, 1, \"(signal --> stream) converts a signal or string to a stream.\")\n\tDEF(Z, 1, 1, \"(series --> signal) converts a stream or string to a signal.\")\t\n\tDEF(L, 1, 1, \"(anything --> stream) streams are returned as is. anything else is made into an infinite stream of itself.\")\n\tDEF(L1, 1, 1, \"(anything --> stream) streams are returned as is. anything else is wrapped in a one item list.\")\n\tDEF(unspell, 1, 1, \"(sequence --> string) converts a stream of numbers or a signal to a string.\")\n\n\tvm.addBifHelp(\"\\n*** basic list operations ***\");\n\n\tDEF(size, 1, 1, \"(seq --> num) Return the length of a sequence if it is finite. Returns inf if the sequence is of indefinite length (It may not actually be infinitely long).\")\n\tDEF(rank, 1, 1, \"(a --> n) Return the rank of an object. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(shape, 1, 1, \"(a --> [n..]) Return the shape of an object. Axes of indefinite length are represented by inf. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(finite, 1, 1, \"(seq --> bool) Returns 1 if the sequence is finite, 0 if indefinite.\")\n\n\tDEF(empty, 1, 1, \"(list --> bool) returns whether the list is empty.\")\n\tDEF(nonempty, 1, 1, \"(list --> bool) returns whether the list is nonempty.\")\n\tDEF(head, 1, 1, \"(list --> item) returns first item of list. fails if list is empty.\")\n\tDEF(tail, 1, 1, \"(list --> list) returns the rest of the list after the first item. fails if list is empty.\")\n\tDEF(add, 2, 1, \"(list item --> list) returns a new list with the item added to the end.\")\t\n\tDEF(cons, 2, 1, \"(list item --> list) returns a new list with the item added to the front.\")\t\n\tDEF(uncons, 1, 2, \"(list --> tail head) returns the tail and head of a list. fails if list is empty.\")\n\tDEF(pack, 1, 1, \"(list --> list) returns a packed version of the list.\");\n\tDEF(packed, 1, 1, \"(list --> bool) returns whether the list is packed.\");\n\n\tvm.addBifHelp(\"\\n*** list generation ***\");\n\n\tDEFnoeach(ord, 0, 1, \"(--> series) return an infinite series of integers ascending from 1.\")\n\tDEFnoeach(nat, 0, 1, \"(--> series) return an infinite series of integers ascending from 0.\")\n\tDEFnoeach(invs, 0, 1, \"(--> series) return an infinite series of reciprocals. equivalent to ord 1/\")\n\tDEFnoeach(negs, 0, 1, \"(--> series) return an infinite series of integers descending from -1.\")\n\tDEFnoeach(evens, 0, 1, \"(--> series) return an infinite series of ascending non-negative even integers.\")\n\tDEFnoeach(odds, 0, 1, \"(--> series) return an infinite series of ascending non-negative odd integers.\")\n\tDEFnoeach(ints, 0, 1, \"(--> series) return the infinite series [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primes, 0, 1, \"(--> series) returns a finite series of prime numbers up to 1000039.\")\n\tDEFAM(fib, kk, \"(a b --> series) returns a fibonacci series starting with the two numbers given.\") \n\n\tDEFnoeach(ordz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 1.\")\n\tDEFnoeach(natz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 0.\")\n\tDEFnoeach(invz, 0, 1, \"(--> signal) return an infinite signal of reciprocals. equivalent to ordz 1/\")\n\tDEFnoeach(negz, 0, 1, \"(--> signal) return an infinite signal of integers descending from -1.\")\n\tDEFnoeach(evenz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative even integers.\")\n\tDEFnoeach(oddz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative odd integers.\")\n\tDEFnoeach(intz, 0, 1, \"(--> signal) return the infinite signal [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primez, 0, 1, \"(--> signal) returns a finite signal of prime numbers up to 1000039.\")\t\n\tDEFMCX(fibz, 2, \"(a b --> signal) returns a fibonacci signal starting with the two numbers given.\")\n\n\tDEFAM(ninvs, k, \"(n --> stream) return a finite stream of n reciprocals. equivalent to n 1 1 nby 1/\")\n\tDEFMCX(ninvz, 1, \"(n --> signal) return a finite signal of n reciprocals. equivalent to n 1 1 nbyz 1/\")\n\t\n\tDEF(ever, 1, 1, \"(value --> series) return an infinite stream of value.\")\n\tDEFAM(by, kk, \"(start step --> series) return an infinite arithmetic series.\") \n\tDEFAM(nby, kkk, \"(n start step --> series) return a finite arithmetic series.\") \n\tDEFAM(grow, kk, \"(start step --> series) return an infinite geometric series.\") \n\tDEFAM(ngrow, kkk, \"(start step --> series) return a finite geometric series.\") \n\tDEFAM(to, kk, \"(a b --> series) return a finite series from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFMCX(everz, 1, \"(value --> signal) return an infinite signal of value.\")\n\tDEFMCX(byz, 2, \"(start step --> series) return an infinite arithmetic series as a signal.\") \n\tDEFMCX(nbyz, 3, \"(start step --> series) return a finite arithmetic series as a signal.\") \n\tDEFMCX(growz, 2, \"(start step --> series) return an infinite geometric series as a signal.\") \n\tDEFMCX(ngrowz, 3, \"(start step --> series) return a finite geometric series as a signal.\") \n\tDEFMCX(toz, 2, \"(a b --> series) return a finite signal from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFAM(lindiv, kkk, \"(n start end --> series) returns a series of n equal steps from start to end.\") \n\tDEFAM(expdiv, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start to end.\") \n\tDEFMCX(lindivz, 3, \"(n start end --> series) returns a signal of n equal steps from start to end.\") \n\tDEFMCX(expdivz, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start to end.\") \n\n\tDEFAM(lindiv1, kkk, \"(n start end --> series) returns a series of n equal steps from start up to but not including end.\") \n\tDEFAM(expdiv1, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start up to but not including end.\") \n\tDEFMCX(lindiv1z, 3, \"(n start end --> series) returns a signal of n equal steps from start up to but not including end.\") \n\tDEFMCX(expdiv1z, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start up to but not including end.\") \n\n\tDEFMCX(line, 3, \"(dur start end --> z) return a signal ramping linearly from start to end in dur seconds.\") // mcx\n\tDEFMCX(xline, 3, \"(dur start end --> z) return a signal ramping exponentially from start to end in dur seconds.\") // mcx\n\n\tvm.addBifHelp(\"\\n*** list reduction operations ***\");\n\tDEFAM(reduce, aak, \"(list value fun --> value) applies fun to each item in list and the current value to get a new value. returns the ending value.\")\n\tDEFAM(reduce1, ak, \"(list fun --> value) like reduce except that the initial value is the first item in the list.\")\n\n\tDEFAM(scan, aak, \"(list value fun --> list) applies fun to each item in list and the current value to get a new value, which is added to the output list.\")\n\tDEFAM(scan1, ak, \"(list fun --> list) like scan except that the initial value is the first item in the list.\")\n\tDEFAM(iter, ak, \"(value fun --> list) returns an infinite list of repeated applications of fun to value.\")\n\tDEFAM(itern, akk, \"(value fun n --> list) returns a list of n repeated applications of fun to value.\")\n \t\n\tDEFAM(chain, akk, \"(value fun n --> list) returns the result of n repeated applications of fun to value.\")\n \n\tvm.addBifHelp(\"\\n*** list ordering operations ***\");\n\tDEF(cyc, 1, 1, \"(list --> list) makes a finite list become cyclic.\")\n\tDEFAM(ncyc, ak, \"(n list --> list) concatenates n copies of a finite list.\")\n\tDEF(rcyc, 1, 1, \"(ref --> list) gets a new list from ref each time list is exhausted.\")\n\n\tvm.defautomap(\"X\", \"ak\", repeat_, \"(value n --> stream) makes a list containing n copies of value. If value is a function, then the results of applying the function with an integer count argument is used as the contents of the output list.\");\n\tvm.defmcx(\"XZ\", 2, repeatz_, \"(value n --> signal) returns a signal with value repeated n times.\");\n\tvm.defmcx(\"mum\", 1, mum_, \"(t --> signal) returns a signal of t seconds of silence.\");\n\n\tvm.def(\"$\", 2, 1, append_, \"(listA listB --> out) returns the concatenation of listA and listB.\");\n\tvm.defmcx(\"$z\", 2, append_, \"(signalA signalB --> signal) returns the concatenation of signalA and signalB.\");\n\t\n\tvm.def(\"$$\", 2, 1, appendSubs_, \"(listA listB --> out) return the concatenation of the sublists of listA and listB. equivalent to (listA @ listB @ $)\");\n\tvm.def(\"$/\", 1, 1, cat_, \"(list --> out) returns the concatenation of the sub-lists of the input list.\");\n\tDEF(flat, 1, 1, \"(list --> list) flattens a list.\")\n\tDEFAM(flatten, ak, \"(list n --> list) makes a list n levels flatter.\")\n\tvm.defautomap(\"keep\", \"ak\", N_, \"(list n --> list) returns a list of the first n items of the input list.\");\n\t\n\tDEFAM(T, zk, \"(signal t --> signal) returns a signal of the first t seconds of the input signal.\");\n\tvm.defautomap(\"T>\", \"zk\", skipT_, \"(signal t --> signal) skips the first t seconds of the input signal.\");\n\tvm.defautomap(\"N>\", \"ak\", skip_, \"(list n --> list) skips the first n items of the input list.\");\n\tvm.def(\"N>>\", 2, 1, hops_, \"(list hops --> listOfLists) returns a list of tails of the input list. equivalent to (list (hops 0 | L 0 cons +\\\\) N>).\");\n\tvm.defautomap(\"T>>\", \"za\", hopTs_, \"(signal hops --> listOfSignals) returns a list of tails of the input list. equivalent to (signal (hops 0 | L 0 cons +\\\\) T>).\");\n\tDEFAM(N, ak, \"(list n --> list) returns a list of the first n items of the input list.\") \n\tDEFAM(NZ, zk, \"(signal n --> signal) returns a signal of the first n items of the input signal. automaps over streams.\") \n\t\n\tDEFAM(skip, ak, \"(list n --> list) skips the first n items of the input list.\") \n\n\tDEFAM(take, ak, \"(list n --> list) returns a list of the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\tDEFAM(drop, ak, \"(list n --> list) skips the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\t\n\tDEFAM(choff, akk, \"(channel(s) c n --> out) takes a finite list of channels or a single signal and places it into an array of n channels beginning at offset c. Other channels are set to zero.\");\n\n\tDEF(tog, 2, 1, \"(a b --> series) return a series alternating between a and b.\")\n\tDEFMCX(togz, 2, \"(a b --> signal) return a signal alternating between a and b.\")\n\tDEF(sel, 2, 1, \"(a j --> out) select. a is a list of lists. out[i] is a[j][i]\")\n\tDEF(sell, 2, 1, \"(a j --> out) lazy select. a is a list of lists. out[i] is the next value from a[j].\")\n\n\tvm.def(\"?\", 2, 1, filter_, \"(a b --> out) the output list contains a[i] repeated b[i] times. If b is a list of booleans (1 or 0) then this functions as a filter.\");\n\tDEF(spread, 2, 1, \"(a n --> out) inserts n[i] zeroes after a[i].\")\t\n\tDEFMCX(spreadz, 2, \"(a n --> signal) inserts n[i] zeroes after a[i]. automaps over stream inputs.\")\t\n\n\tDEF(change, 1, 1, \"(a --> b) eliminates sequential duplicates in a signal or stream.\")\t\n\tDEFMCX(changez, 1, \"(a --> b) eliminates sequential duplicates in a signal. automaps over streams.\")\t\n\tDEF(expand, 2, 1, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out.\")\t\n\tDEFMCX(expandz, 2, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out. automaps over stream inputs.\")\t\n\n\tDEF(clump, 2, 1, \"(a n --> out) groups elements from list a into sub-lists of size n.\")\t\n\tDEF(hang, 1, 1, \"(a --> out) repeats the last value of a finite list indefinitely.\")\t\n\tDEFMCX(hangz, 1, \"(a --> out) repeats the last value of a finite signal indefinitely. automaps over streams.\")\t\n\tDEFAM(histo, ak, \"(a n --> out) makes a histogram of the finite stream a.\")\t\n\tvm.defautomap(\"histoz\", \"zk\", histo_, \"(a n --> out) makes a histogram of the finite signal a. automaps over streams.\");\n\n\tDEF(keepWhile, 2, 1, \"(a b --> out) return items from a while items from b are true.\")\n\tDEF(skipWhile, 2, 1, \"(a b --> out) skip items from a while items from b are true.\")\n\t\n\tDEF(flop, 1, 1, \"(a --> b) returns the transpose of the list of lists a. At least one of the dimensions must be finite.\")\t\n\tDEF(flops, 1, 1, \"(a --> b) like flop, but signals are treated as scalars and not flopped.\")\n\tDEF(flop1, 1, 1, \"(a --> b) like flop, but if list a is not a list of lists then it is wrapped in a list. compare: [[1 2 3][[4 5] 6 7]] @ flop $/ with: [[1 2 3][[4 5] 6 7]] @ flop1 $/\")\t\n\tDEF(lace, 1, 1, \"(a --> b) returns the concatenation of the transpose of the list of lists a.\")\t\n\tDEFAM(merge, aak, \"(a b fun --> c) merges two lists according to the function given. The function should work like <.\")\n\tDEFAM(mergec, aak, \"(a b fun --> c) merges two lists without duplicates according to the function given. The function should work like cmp.\")\n\t\n\tDEF(perms, 1, 1, \"(a --> b) returns a list of all permutations of the input list.\")\n\tDEFMCX(permz, 1, \"(a --> b) returns a list of all permutations of the input signal. automaps over streams.\")\n\t\n\tDEF(permswr, 1, 1, \"(a --> b) returns a list of all unique permutations of an input stream with repeated elements.\")\n\tDEFMCX(permzwr, 1, \"(a --> b) returns a returns a list of all unique permutations of an input signal with repeated elements. automaps over streams.\")\n\t\n\tDEF(shortas, 2, 1, \"(a b --> a') makes list a as short as list b.\")\n\tDEF(longas, 2, 1, \"(a b --> a') makes list a as long as list b by repeating the last item.\")\n\tDEF(longas0, 2, 1, \"(a b --> a') makes list a as long as list b by appending zeroes.\")\n\n\t// array ops\n\n\tvm.addBifHelp(\"\\n*** list ops ***\");\n\n\tDEF(bub, 1, 1, \"(a --> [a]) makes the top item on the stack into a one item list. i.e. puts a bubble around it.\")\n\tDEF(nbub, 2, 1, \"(a n --> [[..[a]..]]) embeds the top item in N one item lists.\")\n\n\tvm.def(\"2ple\", 2, 1, tupleN_<2>, \"(a b --> [a b]) make a pair from the top two stack items.\");\n\tvm.def(\"3ple\", 3, 1, tupleN_<3>, \"(a b c --> [a b c]) make a triple from the top three stack items.\");\n\tvm.def(\"4ple\", 4, 1, tupleN_<4>, \"(a b c d --> [a b c d]) make a quadriple from the top four stack items.\");\n\tvm.def(\"5ple\", 5, 1, tupleN_<5>, \"(a b c d e --> [a b c d e]) make a quintuple from the top five stack items.\");\n\tvm.def(\"6ple\", 6, 1, tupleN_<6>, \"(a b c d e f --> [a b c d e f]) make a sextuple from the top six stack items.\");\n\tvm.def(\"7ple\", 7, 1, tupleN_<7>, \"(a b c d e f g --> [a b c d e f g]) make a septuple from the top seven stack items.\");\n\tvm.def(\"8ple\", 8, 1, tupleN_<8>, \"(a b c d e f g h --> [a b c d e f g h]) make an octuple from the top eight stack items.\");\n\t\n\tvm.defautomap(\"2ples\", \"kk\", tupleN_<2>, \"(a b --> [[a0 b0][a1 b1]..[aN bN]]) make a sequence of pairs from the sequences a and b.\");\n\tvm.defautomap(\"3ples\", \"kkk\", tupleN_<3>, \"(a b c --> [[a0 b0 c0][a1 b1 c1]..[aN bN cN]]) make a sequence of triples from the sequences a, b and c.\");\n\tvm.defautomap(\"4ples\", \"kkkk\", tupleN_<4>, \"(a b c d --> seq) make a sequence of quadruples from the sequences a, b, c and d.\");\n\tvm.defautomap(\"5ples\", \"kkkkk\", tupleN_<5>, \"(a b c d e --> seq) make a sequence of quintuples from the sequences a through e.\");\n\tvm.defautomap(\"6ples\", \"kkkkkk\", tupleN_<6>, \"(a b c d e f--> seq) make a sequence of sextuples from the sequences a through f.\");\n\tvm.defautomap(\"7ples\", \"kkkkkkk\", tupleN_<7>, \"(a b c d e f g--> seq) make a sequence of septuples from the sequences a through g.\");\n\tvm.defautomap(\"8ples\", \"kkkkkkkk\", tupleN_<8>, \"(a b c d e f g h --> seq) make a sequence of octuples from the sequences a through h.\");\n\n\tDEFNnoeach(\"un2\", 1, 2, untupleN_<2>, \"([a0 a1 .. aN-1] --> a0 a1) Push two items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un3\", 1, 3, untupleN_<3>, \"([a0 a1 .. aN-1] --> a0 a1 a2) Push three items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un4\", 1, 4, untupleN_<4>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3) Push four items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un5\", 1, 5, untupleN_<5>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3 a4) Push five items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un6\", 1, 6, untupleN_<6>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a5) Push six items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un7\", 1, 7, untupleN_<7>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a6) Push seven items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un8\", 1, 8, untupleN_<8>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a7) Push eight items from a sequence onto the stack.\")\n\n\tDEF(reverse, 1, 1, \"(a --> b) reverses a finite sequence.\")\n\tDEF(mirror0, 1, 1, \"(a --> b) cyclic mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2]\")\n\tDEF(mirror1, 1, 1, \"(a --> b) odd mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2 1]\")\n\tDEF(mirror2, 1, 1, \"(a --> b) even mirror of a sequence. [1 2 3 4] --> [1 2 3 4 4 3 2 1]\")\n\tDEFAM(rot, ak, \"(seq M --> seq') rotation of a sequence by M places. M > 0 moves right.\") \n\tDEFAM(shift, ak, \"(seq M --> seq') shift of a sequence by M places. zeroes are shifted in to fill vacated positions.\") \n\tDEFAM(clipShift, ak, \"(seq M --> seq') shift of a sequence by M places. the end value is copied in to fill vacated positions.\") \n\tDEFAM(foldShift, ak, \"(seq M --> seq') shift of a sequence by M places. values from the cyclic mirrored sequence are copied in to fill vacated positions.\") \n\tDEF(muss, 1, 1, \"(a --> b) puts a finite sequence into a random order.\")\n\n\tDEF(at, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return zero.\") \n\tDEF(wrapAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the value at the end point.\") \n\tDEF(foldAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the items from the cyclic sequence.\") \n\tDEF(clipAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return items from the cyclic mirrored sequence.\") \n\tDEF(degkey, 2, 1, \"(degree scale --> converts scale degree(s) to keys, given a scale\");\n\tDEF(keydeg, 2, 1, \"(key scale --> converts key(s) to scale degree(s), given a scale\");\n\n\t\n\tDEF(sort, 1, 1, \"(in --> out) ascending order sort of the input list.\");\n\tDEFAM(sortf, ak, \"(in fun --> out) sort of the input list using a compare function.\");\n\tDEFN(\"sort>\", 1, 1, sort_gt_, \"(in --> out) descending order sort of the input list.\");\n\t\n\tDEF(grade, 1, 1, \"(in --> out) ascending order sorted indices of the input list.\");\n\tDEFAM(gradef, ak, \"(in fun --> out) sorted indices of the input list using a compare function.\");\n\tDEFN(\"grade>\", 1, 1, grade_gt_, \"(in --> out) descending order sorted indices of the input list.\");\n\n\tvm.addBifHelp(\"\\n*** event list operations ***\");\n\tDEFAM(evmerge, aak, \"(a b t --> c) merges event list 'b' with delay 't' with event list 'a' according to their delta times\")\n\tDEFAM(evdelay, ak, \"(a t --> c) delay an event list by adding a preceeding rest of duration 't'\")\n\tDEFAM(evrest, aak, \"(t --> c) returns a rest event for duration 't'.\")\n\t\n\tvm.addBifHelp(\"\\n*** dsp operations ***\");\n\t\n\tDEFMCX(kaiser, 2, \"(n stopBandAttenuation --> out) returns a signal filled with a kaiser window with the given stop band attenuation.\")\n\tDEFMCX(hanning, 1, \"(n --> out) returns a signal filled with a Hanning window.\")\n\tDEFMCX(hamming, 1, \"(n --> out) returns a signal filled with a Hamming window.\")\n\tDEFMCX(blackman, 1, \"(n --> out) returns a signal filled with a Blackman window.\")\n\tDEFMCX(fft, 2, \"(re im --> out) returns the complex FFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\tDEFMCX(ifft, 2, \"(re im --> out) returns the complex IFFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\n\tDEFAM(seg, zaa, \"(in hops durs --> out) divide input signal in to a stream of signal segments of given duration stepping by hop time.\")\n\tDEFAM(wseg, zaz, \"(in hops window --> out) divide input signal in to a stream of windowed signal segments of lengths equal to the window length, stepping by hop time.\")\n\n\tvm.addBifHelp(\"\\n*** audio I/O operations ***\");\n\tDEF(play, 1, 0, \"(channels -->) plays the audio to the hardware.\")\n\tDEF(record, 2, 0, \"(channels filename -->) plays the audio to the hardware and records it to a file.\")\n\tDEFnoeach(stop, 0, 0, \"(-->) stops any audio playing.\")\n\tvm.def(\"sf>\", 1, 0, sfread_, \"(filename -->) read channels from an audio file. not real time.\");\n\tvm.def(\">sf\", 2, 0, sfwrite_, \"(channels filename -->) writes the audio to a file.\");\n\tvm.def(\">sfo\", 2, 0, sfwriteopen_, \"(channels filename -->) writes the audio to a file and opens it in the default application.\");\n\t//vm.def(\"sf>\", 2, sfread_);\n\tDEF(bench, 1, 0, \"(channels -->) prints the amount of CPU required to compute a segment of audio. audio must be of finite duration.\")\t\n\tvm.def(\"sgram\", 3, 0, sgram_, \"(signal dBfloor filename -->) writes a spectrogram to a file and opens it.\");\n\n\tsetSessionTime();\n\n}\n\n"], ["/sapf/src/Object.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Object.hpp\"\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"MathOps.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n\nvoid post(const char* fmt, ...)\n{\n va_list vargs;\n va_start(vargs, fmt);\n vprintf(fmt, vargs);\n}\n\nvoid zprintf(std::string& out, const char* fmt, ...)\n{\n\tchar s[1024];\n\tva_list args;\n\tva_start(args, fmt);\n\tvsnprintf(s, 1024, fmt, args);\n\tout += s;\n}\n\n#pragma mark ERROR HANDLING\n\n\nThread gDummyThread;\n\n[[noreturn]] void notFound(Arg key)\n{\n\tpost(\"notFound \");\n\tkey.print(gDummyThread); // keys are either symbols or numbers neither of which will use the thread argument to print.\n\tpost(\"\\n\");\n\tthrow errNotFound;\n}\n\n[[noreturn]] void wrongType(const char* msg, const char* expected, Arg got)\n{\n\tpost(\"error: wrong type for %s . expected %s. got %s.\\n\", msg, expected, got.TypeName());\n\tthrow errWrongType;\n}\n\n[[noreturn]] void syntaxError(const char* msg)\n{\n\tpost(\"syntax error: %s\\n\", msg);\n\tthrow errSyntax;\n}\n\n[[noreturn]] void indefiniteOp(const char* msg1, const char* msg2)\n{\n\tpost(\"error: operation on indefinite object %s%s\\n\", msg1, msg2);\n\tthrow errIndefiniteOperation;\n}\n\n#pragma mark OBJECT\n\n\nObject::Object()\n\t: scratch(0), elemType(0), finite(false), flags(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nObject::~Object()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\nvoid Ref::set(Arg inV)\n{\n\tO oldval = nullptr;\n\tif (inV.isObject()) {\n\t\tO newval = inV.o();\n\t\n\t\tnewval->retain();\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = newval;\n\t\t}\n\t} else {\n\t\tZ newval = inV.f;\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = nullptr;\n\t\t\tz = newval;\n\t\t}\n\t}\n\tif (oldval)\n\t\toldval->release();\n}\n\nvoid ZRef::set(Z inZ)\n{\n\tz = inZ;\n}\n\nV Ref::deref() const\n{\n\tV out;\n\t{\n\t\tSpinLocker lock(mSpinLock);\n\t\tif (o) {\n\t\t\tout = o;\n\t\t\tif (o) o->retain();\n\t\t}\n\t\telse out = z;\n\t}\n\treturn out;\n}\n\nV ZRef::deref() const\n{\n\treturn z;\n}\n\nZ Object::derefz() const\n{\n\treturn asFloat();\n}\n\nZ ZRef::derefz() const\n{\n\treturn z;\n}\n\n\nForm::Form(P
const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nvolatile int64_t gTreeNodeSerialNumber;\n\nGForm::GForm(P const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nGForm::GForm(P const& inNext)\n\t: Object(), mNextForm(inNext)\n{ \n\tmTable = new GTable();\n}\n\nP consForm(P const& inTable, P const& inNext) { return new GForm(inTable, inNext); }\nP consForm(P
const& inTable, P const& inNext) { return new Form(inTable, inNext); }\n\nvoid Object::apply(Thread& th) {\n\tth.push(this);\n}\n\nclass PushFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nclass PushREPLFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushREPLFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushREPLFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nvoid Fun::runREPL(Thread& th)\n{\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushREPLFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::run(Thread& th)\n{\t\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.setStackBase();\n\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::apply(Thread& th) \n{ \n\tint numArgs = NumArgs();\n\n\tif (th.stackDepth() < (size_t)numArgs) {\n\t\tthrow errStackUnderflow;\n\t}\n\n\tif (NoEachOps()) {\n\t\trun(th);\n\t} else {\n\t\tif (th.stackDepth()) {\n\t\t\tbool haveEachOps = false;\n\t\t\tV* args = &th.top() - numArgs + 1;\n\n\t\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, numArgs, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\trun(th);\n\t\t\t}\n\t\t} else {\n\t\t\trun(th);\n\t\t}\n\t}\n}\n\nFun::Fun(Thread& th, FunDef* def)\n\t: mDef(def), mWorkspace(def->Workspace())\n{\n\tif (NumVars()) {\n\t\tmVars.insert(mVars.end(), th.stack.end() - NumVars(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumVars(), th.stack.end());\n\t}\n}\n\nFunDef::FunDef(Thread& th, P const& inCode, uint16_t inNumArgs, uint16_t inNumLocals, uint16_t inNumVars, P const& inHelp) \n\t: mCode(inCode), mNumArgs(inNumArgs), mNumLocals(inNumLocals), mNumVars(inNumVars), \n mWorkspace(th.mWorkspace),\n mHelp(inHelp)\n{\n}\n\nFun::~Fun()\n{\n}\n\nvoid Prim::apply(Thread& th) \n{\n\tapply_n(th, mTakes);\n}\n\nvoid Prim::apply_n(Thread& th, size_t n)\n{ \n\tif (th.stackDepth() < n)\n\t\tthrow errStackUnderflow;\n\t\n\tif (NoEachOps()) {\n\t\tprim(th, this); \n\t} else {\n\t\n\t\tif (n) {\n\t\t\tV* args = &th.top() - n + 1;\n\n\t\t\tbool haveEachOps = false;\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, (int)n, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\tprim(th, this); \n\t\t\t}\n\t\t} else {\n\t\t\tprim(th, this); \n\t\t}\n\t}\n}\n\nbool Form::get(Thread& th, Arg key, V& value) const\n{\n const Form* e = this;\n\tint64_t hash = key.Hash();\n do {\n if (e->mTable->getWithHash(th, key, hash, value)) {\n return true;\n }\n e = (Form*)e->mNextForm();\n } while (e);\n return false;\n}\n\n\nV Form::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\nbool GForm::get(Thread& th, Arg key, V& value) const\n{\n const GForm* e = this;\n do {\n if (e->mTable->get(th, key, value)) {\n return true;\n }\n e = (GForm*)e->mNextForm();\n } while (e);\n return false;\n}\n\nGForm* GForm::putImpure(Arg key, Arg value)\n{\n\tif (mTable->putImpure(key, value)) return this;\n\treturn putPure(key, value);\n}\n\nGForm* GForm::putPure(Arg inKey, Arg inValue)\n{\n\tint64_t inKeyHash = inKey.Hash();\n\treturn new GForm(mTable->putPure(inKey, inKeyHash, inValue), mNextForm);\n}\n\nV GForm::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\n\nGTable* GTable::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n auto tree = mTree.load();\n\tif (tree) {\n\t\treturn new GTable(tree->putPure(inKey, inKeyHash, inValue));\n\t} else {\n\t\tint64_t serialNo = ++gTreeNodeSerialNumber;\n\t\treturn new GTable(new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n\t}\n}\n\nTreeNode* TreeNode::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n\tif (inKeyHash == mHash && inKey.Identical(mKey)) {\n\t\treturn new TreeNode(mKey, mHash, inValue, mSerialNumber, mLeft, mRight);\n\t} \n auto left = mLeft.load();\n auto right = mRight.load();\n if (inKeyHash < mHash) {\n if (left) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left->putPure(inKey, inKeyHash, inValue), right);\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr), right);\n }\n\t} else {\n if (right) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, right->putPure(inKey, inKeyHash, inValue));\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n }\n\t}\n}\n\nstatic bool TreeNodeEquals(Thread& th, TreeNode* a, TreeNode* b)\n{\n while (1) {\n if (!a) return !b;\n if (!b) return false;\n \n if (!a->mKey.Equals(th, b->mKey)) return false;\n if (!a->mValue.Equals(th, b->mValue)) return false;\n if (a->mLeft == 0) {\n if (b->mLeft != 0) return false;\n } else {\n if (b->mLeft == 0) return false;\n if (!TreeNodeEquals(th, a->mLeft, b->mLeft)) return false;\n }\n a = a->mRight;\n b = b->mRight;\n }\n}\n\nbool GTable::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isGTable()) return false;\n\tif (this == v.o()) return true;\n\tGTable* that = (GTable*)v.o();\n return TreeNodeEquals(th, mTree.load(), that->mTree.load());\n}\n\nvoid GTable::print(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tzprintf(out, \" \");\n\t\tp->mValue.print(th, out);\n\t\tzprintf(out, \" :\");\n\t\tp->mKey.print(th, out);\n\t\tzprintf(out, \"\\n\");\n\t}\n}\n\nvoid GTable::printSomethingIWant(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tif (p->mValue.leaves() != 0 && p->mValue.leaves() != 1) {\n\t\t\tzprintf(out, \" \");\n\t\t\tp->mKey.print(th, out);\n\t\t\tzprintf(out, \" : \");\n\t\t\tp->mValue.print(th, out);\n\t\t\tzprintf(out, \"\\n\");\n\t\t}\n\t}\n}\n\nbool GTable::get(Thread& th, Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nbool GTable::getInner(Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nV GTable::mustGet(Thread& th, Arg inKey) const\n{\n\tV value;\n\tif (get(th, inKey, value)) return value;\n\t\n\tthrow errNotFound;\n}\n\nbool GTable::putImpure(Arg inKey, Arg inValue)\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tvolatile std::atomic* treeNodePtr = &mTree;\n\twhile (1) {\n\t\tTreeNode* tree = treeNodePtr->load();\n\t\tif (tree == nullptr) {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n\t\t\tTreeNode* newNode = new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr);\n\t\t\tnewNode->retain();\n TreeNode* nullNode = nullptr;\n if (treeNodePtr->compare_exchange_weak(nullNode, newNode)) {\n break;\n }\n newNode->release();\n\t\t} else {\n\t\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\t\tif (treeKeyHash == inKeyHash) {\n\t\t\t\treturn false; // cannot rebind an existing value.\n\t\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\t\ttreeNodePtr = &tree->mLeft;\n\t\t\t} else {\n\t\t\t\ttreeNodePtr = &tree->mRight;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\n\nvoid TreeNode::getAll(std::vector >& vec)\n{\n\tP node = this;\n\tdo {\n\t\tvec.push_back(node);\n auto left = node->mLeft.load();\n\t\tif (left) left->getAll(vec);\n\t\tnode = node->mRight.load();\n\t} while (node());\n}\n\nstatic bool compareTreeNodes(P const& a, P const& b)\n{\n\treturn a->mSerialNumber < b->mSerialNumber;\n}\n\nstd::vector > GTable::sorted() const\n{\n\tstd::vector > vec;\n auto tree = mTree.load();\n\tif (tree) {\n\t\ttree->getAll(vec);\n\t\tsort(vec.begin(), vec.end(), compareTreeNodes);\n\t}\n\treturn vec;\n}\n\n/////////\n\n\nV List::unaryOp(Thread& th, UnaryOp* op)\n{\n\tif (isVList())\n\t\treturn new List(new UnaryOpGen(th, op, this));\n\telse\n\t\treturn new List(new UnaryOpZGen(th, op, this));\n\t\t\n}\n\nV List::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a)\n{\n\tif (isVList())\n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nV List::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a)\n{\n\treturn op->makeVList(th, _a, this);\n}\n\nV List::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a)\n{\n\tif (isVList()) \n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nvoid V::apply(Thread& th)\n{\n\tif (o) {\n\t\to->apply(th);\n\t} else {\n\t\tth.push(*this);\n\t}\n}\n\nV V::deref()\n{\n\tif (o) {\n\t\treturn o->deref();\n\t} else {\n\t\treturn *this;\n\t}\n}\n\nV V::mustGet(Thread& th, Arg key) const\n{\n\tif (o) {\n\t\treturn o->mustGet(th, key);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nbool V::get(Thread& th, Arg key, V& value) const\n{\n\tif (o) {\n\t\treturn o->get(th, key, value);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nint V::Hash() const \n{\n\tif (o) {\n\t\treturn o->Hash();\n\t} else {\n union {\n double f;\n uint64_t i;\n } u;\n u.f = f;\n\t\treturn (int)::Hash64(u.i);\n\t}\n}\n\nV V::unaryOp(Thread& th, UnaryOp* op) const\n{\n\treturn !o ? V(op->op(f)) : o->unaryOp(th, op);\n}\n\nV V::binaryOp(Thread& th, BinaryOp* op, Arg _b) const\n{\n\treturn !o ? _b.binaryOpWithReal(th, op, f) : o->binaryOp(th, op, _b);\n}\n\nV V::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a) const\n{\n\treturn !o ? V(op->op(_a, f)) : o->binaryOpWithReal(th, op, _a);\n}\n\nV V::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeVList(th, _a, *this) : o->binaryOpWithVList(th, op, _a);\n}\n\nV V::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeZList(th, _a, *this) : o->binaryOpWithZList(th, op, _a);\n}\n\nvoid Object::printDebug(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::printShort(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"#%s\", TypeName());\n\tout += s; \n}\n\nvoid Object::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %p}\", TypeName(), this);\n\tout += s; \n}\n\nvoid Prim::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\nvoid Prim::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\n\nvoid Ref::print(Thread& th, std::string& out, int depth)\n{\n\tV v = deref();\n\tv.print(th, out, depth);\n\tzprintf(out, \" R\");\n\t\n}\n\nvoid ZRef::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%g ZR\", z);\t\n}\n\nvoid String::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%s\", (char*)s);\n}\n\nvoid String::printDebug(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"\\\"%s\\\"\", (char*)s);\n}\n\nvoid GForm::print(Thread& th, std::string& out, int depth)\n{\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n zprintf(out, \"new\\n\");\n\t} else {\n\t\tzprintf(out, \"New\\n\");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n}\n\nvoid Form::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"{...} \");\n\t\treturn;\n\t}\n\t\n\tzprintf(out, \"{\");\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n\t\tzprintf(out, \" \");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n\t\n\tzprintf(out, \"}\");\n}\n\n\nvoid EachOp::print(Thread& th, std::string& out, int inDepth)\n{\n\tv.print(th, out, inDepth);\n\tzprintf(out, \" \");\n\t\n\t// try to print as concisely as possible.\n\tif (mask == 1) {\n\t\tzprintf(out, \"@\");\n\t} else if (ONES(mask) == 1 && 1 + CTZ(mask) <= 9) {\n\t\tzprintf(out, \"@%d\", 1 + CTZ(mask));\n\t} else if (CTZ(mask) == 0) {\n\t\tint n = CTZ(~mask);\n\t\twhile (n--) \n\t\t\tzprintf(out, \"@\");\n\t} else {\n\t\tzprintf(out, \"@\");\n\t\tint32_t m = mask;\n\t\twhile (m) {\n\t\t\tzprintf(out, \"%c\", '0' + (m&1));\n\t\t\tm >>= 1;\n\t\t}\n\t}\n}\n\n\nvoid Code::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"#Code{...}\");\n\t\treturn;\n\t}\n\n\tzprintf(out, \"#Code %d{\\n\", size());\n\tOpcode* items = getOps();\n\tfor (int i = 0; i < size(); ++i) {\n\t\tzprintf(out, \"%4d %s \", i, opcode_name[items[i].op]);\n\t\titems[i].v.printShort(th, out, depth+1);\n\t\tout += \"\\n\";\n\t}\n\tzprintf(out, \"}\\n\");\n}\n\nvoid List::print(Thread& th, std::string& out, int depth)\n{\n\tif (isV()) {\n\t\tzprintf(out, \"[\");\n\t} else {\n\t\tzprintf(out, \"#[\");\n\t}\n\t\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"...]\");\n\t\treturn;\n\t}\n\t\n\tbool once = true;\n\tList* list = this;\n\t\n\tfor (int i = 0; list && i < vm.printLength;) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tfor (int j = 0; j < a->size() && i < vm.printLength; ++j, ++i) {\n\t\t\tif (!once) zprintf(out, \" \");\n\t\t\tonce = false;\n\t\t\tif (a->isV()) {\n\t\t\t\ta->v()[j].print(th, out, depth+1);\n\t\t\t} else {\n\t\t\t\n\t\t\t\tzprintf(out, \"%g\", a->z()[j]);\n\t\t\t}\n\t\t}\n\t\tif (i >= vm.printLength) {\n\t\t\tzprintf(out, \" ...]\");\n\t\t\treturn;\n\t\t}\n\t\tlist = list->nextp();\n\t}\n\tif (list && list->mNext) {\n\t\tzprintf(out, \" ...]\");\n\t} else {\n\t\tzprintf(out, \"]\");\n\t}\n}\n\nvoid V::print(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->print(th, out, depth);\n}\n\nvoid V::printShort(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printShort(th, out, depth);\n}\n\nvoid V::printDebug(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printDebug(th, out, depth);\n}\n\n\nvoid V::print(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printShort(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printDebug(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nGen::Gen(Thread& th, int inItemType, bool inFinite)\n\t: mDone(false), mOut(0), mBlockSize(inItemType == itemTypeV ? vm.VblockSize : th.rate.blockSize)\n{\n\telemType = inItemType;\n\tsetFinite(inFinite);\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t++vm.totalStreamGenerators;\n\telse\n\t\t++vm.totalSignalGenerators;\n#endif\n}\n\nGen::~Gen()\n{\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t--vm.totalStreamGenerators;\n\telse\n\t\t--vm.totalSignalGenerators;\n#endif\n}\n\nvoid Gen::end() \n{\n\tsetDone();\n\tmOut->end();\n}\n\n\nvoid Gen::produce(int shrinkBy)\n{\n\tmOut->mArray->addSize(-shrinkBy);\n\tmOut = mOut->nextp();\n}\n\nvoid List::end()\n{\n\tassert(mGen);\n\tmNext = nullptr;\n\tmGen = nullptr;\n\tmArray = vm.getNilArray(elemType);\n}\n\nV* List::fulfill(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next();\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nZ* List::fulfillz(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next;\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nvoid List::link(Thread& th, List* inList)\n{\n\tassert(mGen);\n\tif (!inList) return;\n\tinList->force(th);\n\tmNext = inList->mNext;\n\tmArray = inList->mArray;\n\tmGen = nullptr;\n}\n\nvoid List::force(Thread& th)\n{\t\n\tSpinLocker lock(mSpinLock);\n\tif (mGen) {\n\t\tP gen = mGen; // keep the gen from being destroyed out from under pull().\n\t\tif (gen->done()) {\n\t\t\tgen->end();\n\t\t} else {\n\t\t\tgen->pull(th);\n\t\t}\n\t\t// mGen should be NULL at this point because one of the following should have been called: fulfill, link, end.\n\t}\n}\n\nint64_t List::length(Thread& th)\n{\n\tif (!isFinite())\n\t\tindefiniteOp(\"size\", \"\");\n\t\n\tList* list = this;\n\t\n\tint64_t sum = 0;\n\twhile (list) {\n\t\tlist->force(th);\n\t\t\n\t\tsum += list->mArray->size();\n\t\tlist = list->nextp();\n\t}\n\t\n\treturn sum;\n}\n\nArray::~Array()\n{\n\tif (isV()) {\n\t\tdelete [] vv;\n\t} else {\n\t\tfree(p);\n\t}\n}\n\nvoid Array::alloc(int64_t inCap)\n{\n\tif (mCap >= inCap) return;\n\tmCap = inCap;\n\tif (isV()) {\n\t\tV* oldv = vv;\n\t\tvv = new V[mCap];\n\t\tfor (int64_t i = 0; i < size(); ++i) \n\t\t\tvv[i] = oldv[i];\n\t\tdelete [] oldv;\n\t} else {\n\t\tp = realloc(p, mCap * elemSize());\n\t}\n}\n\nvoid Array::add(Arg inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = inItem;\n\telse zz[mSize++] = inItem.asFloat();\n}\n\nvoid Array::addAll(Array* a)\n{\n\tif (!a->mSize)\n\t\treturn;\n\t\t\n\tint64_t newSize = mSize + a->size();\n\tif (newSize > mCap)\n\t\talloc(NEXTPOWEROFTWO(newSize));\n\t\n\tif (isV()) {\n\t\tif (a->isV()) {\n\t\t\tV* x = vv + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t} else {\n\t\t\tV* x = vv + size();\n\t\t\tZ* y = a->zz;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t}\n\t} else {\n\t\tif (a->isV()) {\n\t\t\tZ* x = zz + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i].asFloat();\n\t\t} else {\n\t\t\tmemcpy(zz + mSize, a->zz, a->mSize * sizeof(Z));\n\t\t}\n\t}\n\tmSize = newSize;\n}\n\nvoid Array::addz(Z inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = V(inItem);\n\telse zz[mSize++] = inItem;\n}\n\nvoid Array::put(int64_t inIndex, Arg inItem)\n{\n\tif (isV()) vv[inIndex] = inItem;\n\telse zz[inIndex] = inItem.asFloat();\n}\n\nvoid Array::putz(int64_t inIndex, Z inItem)\n{\n\tif (isV()) vv[inIndex] = V(inItem);\n\telse zz[inIndex] = inItem;\n}\n\nIn::In()\n\t: mList(nullptr), mOffset(0), mConstant(0.), mIsConstant(true)\n{\n}\n\nVIn::VIn()\n{\n\tset(0.);\n}\n\nVIn::VIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nZIn::ZIn()\n{\n\tset(0.);\n}\n\nZIn::ZIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nBothIn::BothIn()\n{\n\tset(0.);\n}\n\nBothIn::BothIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nvoid VIn::set(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid VIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid BothIn::set(Arg inValue)\n{\n\tif (inValue.isList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setv(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid ZIn::set(Arg inValue)\n{\n\tif (inValue.isZList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nbool VIn::operator()(Thread& th, int& ioNum, int& outStride, V*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant;\n\t\treturn false;\n\t}\n\t\n\tif (mList) {\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n int num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->v() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n }\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant;\n\tmDone = true;\n\treturn true;\n}\n\nbool ZIn::operator()(Thread& th, int& ioNum, int& outStride, Z*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant.f;\n\t\treturn false;\n\t}\n\tif (mList) {\n\t\tif (mOnce) {\n\t\t\tmOnce = false;\n\t\t}\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n\t\t\tint num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->z() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n\t}\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant.f;\n ioNum = 0;\n\tmDone = true;\n\treturn true;\n}\n\nvoid dumpList(List const* list)\n{\n\tfor (int i = 0; list; ++i, list = list->nextp()) {\n\t\tprintf(\" List %d %p mGen %p\\n\", i, list, list->mGen());\n\t\tprintf(\" List %d %p mNext %p\\n\", i, list, list->nextp());\n\t\tprintf(\" List %d %p mArray %p %d\\n\", i, list, list->mArray(), (int)(list->mArray() ? list->mArray->size() : 0));\n\t}\n}\n\nbool VIn::link(Thread& th, List* inList)\n{\n\tif (!mList) return false;\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tV* out = inList->fulfill_link(n, mList->next());\n\t\t\t\tV* in = mList->mArray->v() + mOffset;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = in[i];\n\t\t\t\t}\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nbool ZIn::link(Thread& th, List* inList)\n{\t\n\tif (!mList) return false;\n\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tZ* out = inList->fulfillz_link(n, mList->next());\n\t\t\t\tZ* in = mList->mArray->z() + mOffset;\n\t\t\t\tmemcpy(out, in, n * sizeof(Z));\n\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nvoid In::advance(int inNum)\n{\n\tif (mList) {\n\t\tmOffset += inNum;\n\t\tif (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n\t\t\tmOffset = 0;\n\t\t}\n\t}\n}\n\nbool VIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::peek(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset];\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\telse\n\t\t\t\tv = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.asFloat();\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tz = mList->mArray->v()[mOffset++].asFloat();\n\t\t\telse\n\t\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onei(Thread& th, int64_t& i)\n{\n\tZ z = 0.;\n\tbool result = onez(th, z);\n\ti = (int64_t)floor(z);\n\treturn result;\n}\n\nbool ZIn::bench(Thread& th, int& ioNum)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, Z* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, float* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nvoid ZIn::hop(Thread& th, int framesToAdvance)\n{\n\tP list = mList;\n\tint offset = mOffset;\n\twhile (list && framesToAdvance) {\n\t\tlist->force(th);\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tif (avail >= framesToAdvance) {\n\t\t\toffset += framesToAdvance;\n\t\t\tmList = list;\n\t\t\tmOffset = offset;\n\t\t\treturn;\n\t\t}\n\t\tframesToAdvance -= avail;\n\t\toffset = 0;\n\t\tlist = list->next();\n\t\tif (!list) {\n\t\t\tmList = nullptr;\n\t\t\tmOffset = 0;\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nbool ZIn::fillSegment(Thread& th, int inNum, Z* outBuffer)\n{\n\tint framesToFill = inNum;\n\tif (mIsConstant) {\n\t\tZ z = mConstant.f;\n\t\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\treturn false;\n\t}\n\n\tP list = mList;\n\tint offset = mOffset;\n\tZ* out = outBuffer;\n\twhile (list) {\n\t\tlist->force(th);\n\t\tassert(list->mArray);\n\t\t\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tint numToFill = std::min(framesToFill, avail);\n\n\t\t// copy\n\t\tZ* in = list->mArray->z() + offset;\n\t\tmemcpy(out, in, numToFill * sizeof(Z));\n\t\tout += numToFill;\n\t\tframesToFill -= numToFill;\n\t\t\n\t\tif (framesToFill == 0)\n\t\t\treturn false;\n\t\t\n\t\tlist = list->next();\n\t\toffset = 0;\n\t}\n\t\n\tZ z = mConstant.f;\n\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\n\tmDone = true;\n\treturn true;\n}\n\n\nbool ZIn::mix(Thread& th, int& ioNum, Z* outBuffer)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0; i < n; ++i)\t{\n\t\t\toutBuffer[i] += *a;\n\t\t\ta += astride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nclass Comma : public Gen\n{\n\tVIn _a;\n\tV key;\npublic:\n\tComma(Thread& th, Arg a, Arg inKey) : Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {} \n\t\n\tvirtual const char* TypeName() const override { return \"Comma\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->comma(th, key);\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\nclass Dot : public Gen\n{\n\tVIn _a;\n\tV key;\n\tV defaultValue;\npublic:\n\tDot(Thread& th, Arg a, Arg inKey, Arg inDefaultValue)\n\t\t\t\t\t: Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Dot\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tV v = defaultValue;\n\t\t\t\t\t\ta->dot(th, key, v);\n\t\t\t\t\t\tout[i] = v;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\n\nV List::comma(Thread& th, Arg key)\n{\n\treturn new List(new Comma(th, this, key));\n}\n\nbool List::dot(Thread& th, Arg key, V& ioValue)\n{\n\tioValue = new List(new Dot(th, this, key, ioValue));\n\treturn true;\n}\n\nbool List::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isList()) return false;\n\tList* that = (List*)v.o();\n\tif (!isFinite())\n\t\tindefiniteOp(\"\", \"equals : a\");\n\tif (!that->isFinite())\n\t\tindefiniteOp(\"\", \"equals : b\");\n\t\n\tif (elemType != that->elemType) return false;\n\t\n\tif (isVList()) {\n\t\tVIn _a(this);\n\t\tVIn _b(that);\n\t\t\n\t\tV *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = kDefaultVBlockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n \n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (!a->Equals(th, *b)) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t\t\n\t} else {\n\t\tZIn _a(this);\n\t\tZIn _b(that);\n\t\t\n\t\tZ *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = th.rate.blockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (*a != *b) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t}\n\n}\n\nList::List(int inItemType) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, 0))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\nList::List(int inItemType, int64_t inCap) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, inCap))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\n\n\nList::List(P const& inGen) \n\t: mNext(nullptr), mGen(inGen), mArray(0)\n{\n\telemType = inGen->elemType;\n\tsetFinite(inGen->isFinite());\n\tinGen->setOut(this);\n}\n\nList::List(P const& inArray) \n\t: mNext(nullptr), mGen(nullptr), mArray(inArray)\n{\n\telemType = inArray->elemType;\n\tsetFinite(true);\n}\n\nList::List(P const& inArray, P const& inNext) \n\t: mNext(inNext), mGen(0), mArray(inArray)\n{\n\tassert(!mNext || mArray->elemType == mNext->elemType);\n\telemType = inArray->elemType;\n\tsetFinite(!mNext || mNext->isFinite());\n}\n\nList::~List()\n{\n\t// free as much tail as possible at once in order to prevent stack overflow.\n\tP list = mNext;\n\tmNext = nullptr;\n\twhile (list) {\n\t\tif (list->getRefcount() > 1) break;\n\t\tP next = list->mNext;\n\t\tlist->mNext = nullptr;\n\t\tlist = next;\n\t}\n}\n\nint64_t List::fillz(Thread& th, int64_t n, Z* z)\n{\n\tint64_t k = 0;\n\tP list = this;\n\twhile(list && k < n) {\n\t\tlist->force(th);\n\t\t\n\t\tint64_t m = std::min((n-k), list->mArray->size());\n\t\tfor (int64_t i = 0; i < m; ++i) {\n\t\t\tz[k++] = list->mArray->_atz(i);\n\t\t}\n\t\tlist = list->mNext;\n\t}\n\treturn k;\n}\n\n\nList* List::pack(Thread& th)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packz(Thread& th)\n{\n force(th);\n\tif (isPacked() && isZ())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(itemTypeZ, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::pack(Thread& th, int limit)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\t\t\n\t\tif (cap > limit) return nullptr;\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packSome(Thread& th, int64_t& limit)\n{\n force(th);\n\tif (isPacked()) {\n\t\tlimit = std::min(limit, length(th));\n\t\treturn this;\n\t}\n\t\t\n\tP list = this;\n\tint64_t count = 0;\n\twhile(list && count < limit) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcount += list->mArray->size();\t\n\t\t\t\t\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, count);\n\t\n\tlist = this;\n\tcount = 0;\n\twhile(list && count < limit) {\n\t\ta->addAll(list->mArray());\n\t\tcount += list->mArray->size();\t\n\t\tlist = list->mNext;\n\t}\n\tlimit = std::min(limit, count);\n\t\n\treturn new List(a);\n}\n\nvoid List::forceAll(Thread& th)\n{\n\tList* list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\tlist = list->nextp();\n\t}\n}\n\nV V::msgSend(Thread& th, Arg receiver)\n{\n\tif (!o) {\n\t\treturn *this;\n\t} else {\n\t\treturn o->msgSend(th, receiver);\n\t}\n}\n\nV Prim::msgSend(Thread& th, Arg receiver)\n{\n\tSaveStack ss(th, Takes());\n\tth.push(receiver);\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\nV Fun::msgSend(Thread& th, Arg receiver)\n{\n\tth.push(receiver);\n\tSaveStack ss(th, NumArgs());\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\t\nTableMap::TableMap(size_t inSize)\n\t: mSize(inSize)\n{\n\tif (inSize == 0) {\n\t\tmMask = 0;\n\t\tmIndices = nullptr;\n\t\tmKeys = nullptr;\n\t} else {\n\t\tsize_t n = 2*NEXTPOWEROFTWO((int64_t)mSize);\n\t\tmMask = n-1;\n\t\tmIndices = new size_t[n]();\n\t\tmKeys = new V[mSize];\n\t}\n}\n\nTableMap::TableMap(Arg inKey)\n\t: mSize(1)\n{\n\tmMask = 1;\n\tmIndices = new size_t[2]();\n\tmKeys = new V[mSize];\n\t\n\tmKeys[0] = inKey;\n\tmIndices[inKey.Hash() & 1] = 1;\n}\n\n\nTableMap::~TableMap()\n{\n\tdelete [] mKeys;\n\tdelete [] mIndices;\n}\n\nbool TableMap::getIndex(Arg inKey, int64_t inKeyHash, size_t& outIndex)\n{\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\tV* keys = mKeys;\n\twhile(1) {\n\t\tsize_t index = indices[i];\n\t\tif (index == 0)\n\t\t\treturn false;\n\t\tsize_t index2 = index - 1;\n\t\tif (inKey.Identical(keys[index2])) {\n\t\t\toutIndex = index2;\n\t\t\treturn true;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nvoid TableMap::put(size_t inIndex, Arg inKey, int64_t inKeyHash)\n{\n\tmKeys[inIndex] = inKey;\n\t\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\t\n\twhile(1) {\n\t\tif (indices[i] == 0) {\n\t\t\tindices[i] = inIndex + 1;\n\t\t\treturn;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nTable::Table(P const& inMap)\n\t: mMap(inMap), mValues(new V[mMap->mSize])\n{\n}\n\nTable::~Table()\n{\n\tdelete [] mValues;\n}\n\nbool Table::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isTable()) return false;\n\tif (this == v.o()) return true;\n\tTable* that = (Table*)v.o();\n\tsize_t size = mMap->mSize;\n\tif (size != that->mMap->mSize)\n\t\treturn false;\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tV key = mMap->mKeys[i];\n\t\tV thatValue;\n\t\tif (!that->getWithHash(th, key, key.Hash(), thatValue))\n\t\t\treturn false;\n\t\tif (!mValues[i].Equals(th, thatValue))\n\t\t\treturn false;\n\t}\n return true;\n}\n\nbool Table::getWithHash(Thread& th, Arg key, int64_t hash, V& value) const\n{\n\tsize_t index;\n\tif (!mMap->getIndex(key, hash, index))\n\t\treturn false;\n\tvalue = mValues[index];\n\treturn true;\n}\n\nvoid Table::put(size_t inIndex, Arg inValue)\n{\n\tmValues[inIndex] = inValue;\n}\n\nvoid Table::print(Thread& th, std::string& out, int depth)\n{\n\tfor (size_t i = 0; i < mMap->mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmMap->mKeys[i].print(th, out, depth+1);\n\t\tzprintf(out, \" \");\n\t\tmValues[i].print(th, out, depth+1);\n\t}\n}\n\nvoid TableMap::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"{\");\n\tfor (size_t i = 0; i < mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmKeys[i].print(th, out, depth+1);\n\t}\n\tzprintf(out, \"}\");\n}\n\n\nstatic P chase_z(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\n\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\n\t\t\treturn new List(a2, list->next());\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm._nilz;\n\t}\n\t\n\treturn list;\n}\n\nstatic P chase_v(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"chase : list\", \"\");\n\t}\n\t\n\tint64_t length = list->length(th);\n\t\n\tP result = new List(itemTypeV, length);\n\tP array = result->mArray;\n\tV* out = array->v();\n\t\n\tint64_t i = 0;\n\t\n\twhile (list) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tV* in = a->v();\n\t\t\n\t\tfor (int64_t j = 0; j < asize; ++j, ++i) {\n\t\t\tout[i] = in[j].chase(th, n);\n\t\t}\n\n\t\tlist = list->next();\n\t}\n\t\n\treturn list;\n}\n\nV List::chase(Thread& th, int64_t n)\n{\n\tif (isVList()) {\n\t\treturn chase_v(th, this, n);\n\t} else {\n\t\treturn chase_z(th, this, n);\n\t}\n}\n\nP Form::chaseForm(Thread& th, int64_t n)\n{\n\tP nextForm = mNextForm() ? mNextForm->chaseForm(th, n) : nullptr;\n\treturn new Form(mTable->chaseTable(th, n), nextForm);\n}\n\nP
Table::chaseTable(Thread& th, int64_t n)\n{\n\tP
result = new Table(mMap);\n\t\n\tsize_t size = mMap->mSize;\n\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tresult->mValues[i] = mValues[i].chase(th, n);\n\t}\n\t\n\treturn result;\n}\n\n\n\nvoid Plug::setPlug(Arg inV)\n{\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid Plug::setPlug(const VIn& inVIn, int inChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inVIn;\n\t}\n}\n\nvoid Plug::getPlug(VIn& outVIn, int& outChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\toutVIn = in;\n\toutChangeCount = mChangeCount;\n}\n\n\nvoid ZPlug::setPlug(Arg inV) {\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid ZPlug::setPlug(const ZIn& inZIn, int inChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inZIn;\n\t}\n}\n\nvoid ZPlug::getPlug(ZIn& outZIn, int& outChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\toutZIn = in;\n\toutChangeCount = mChangeCount;\n}\n"], ["/sapf/src/Midi.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Midi.hpp\"\n#include \"VM.hpp\"\n#include \"UGen.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n#include \n#include \n\n\nstruct MidiChanState\n{\n\tuint8_t control[128];\n\tuint8_t polytouch[128];\n\tuint8_t keyvel[128];\n\tuint32_t numKeysDown;\n\tuint16_t bend;\n\tuint8_t touch;\n\tuint8_t program;\n\tuint8_t lastkey;\n\tuint8_t lastvel;\n};\n\nconst int kMaxMidiPorts = 16;\nMidiChanState gMidiState[kMaxMidiPorts][16];\nbool gMidiDebug = false;\nMIDIClientRef gMIDIClient = 0;\nMIDIPortRef gMIDIInPort[kMaxMidiPorts], gMIDIOutPort[kMaxMidiPorts];\nint gNumMIDIInPorts = 0, gNumMIDIOutPorts = 0;\nbool gMIDIInitialized = false;\n\nstatic bool gSysexFlag = false;\nstatic Byte gRunningStatus = 0;\nstd::vector gSysexData;\n\nstatic void sysexBegin() {\n\tgRunningStatus = 0; // clear running status\n\t//gSysexData.clear();\n\tgSysexFlag = true;\n}\n\nstatic void sysexEnd(int lastUID) {\n\tgSysexFlag = false;\n}\n\nstatic void sysexEndInvalid() {\n\tgSysexFlag = false;\n}\n\nstatic int midiProcessSystemPacket(MIDIPacket *pkt, int chan) {\n\tint index, data;\n\tswitch (chan) {\n\tcase 7: // added cp: Sysex EOX must be taken into account if first on data packet\n\tcase 0:\n\t\t{\n\t\tint last_uid = 0;\n\t\tint m = pkt->length;\n\t\tByte* p_pkt = pkt->data;\n\t\tByte pktval;\n\n\t\twhile(m--) {\n\t\t\tpktval = *p_pkt++;\n\t\t\tif(pktval & 0x80) { // status byte\n\t\t\t\tif(pktval == 0xF7) { // end packet\n\t\t\t\t\tgSysexData.push_back(pktval); // add EOX\n\t\t\t\t\tif(gSysexFlag)\n\t\t\t\t\t\tsysexEnd(last_uid); // if last_uid != 0 rebuild the VM.\n\t\t\t\t\telse\n\t\t\t\t\t\tsysexEndInvalid(); // invalid 1 byte with only EOX can happen\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if(pktval == 0xF0) { // new packet\n\t\t\t\t\tif(gSysexFlag) {// invalid new one/should not happen -- but handle in case\n\t\t\t\t\t\t// store the last uid value previous to invalid data to rebuild VM after sysexEndInvalid call\n\t\t\t\t\t\t// since it may call sysexEnd() just after it !\n\t\t\t\t\t\tsysexEndInvalid();\n\t\t\t\t\t}\n\t\t\t\t\tsysexBegin(); // new sysex in\n\t\t\t\t\t//gSysexData.push_back(pktval); // add SOX\n\t\t\t\t}\n\t\t\t\telse {// abnormal data in middle of sysex packet\n\t\t\t\t\t//gSysexData.push_back(pktval); // add it as an abort message\n\t\t\t\t\tsysexEndInvalid(); // flush invalid\n\t\t\t\t\tm = 0; // discard all packet\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(gSysexFlag) {\n\t\t\t\t//gSysexData.push_back(pktval); // add Byte\n\t\t\t} else { // garbage - handle in case - discard it\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn (pkt->length-m);\n\t\t}\n\tbreak;\n\n\tcase 1 :\n\t\tindex = pkt->data[1] >> 4;\n\t\tdata = pkt->data[1] & 0xf;\n\t\tswitch (index) { case 1: case 3: case 5: case 7: { data = data << 4; } }\n\t\treturn 2;\n\n\tcase 2 : \t//songptr\n\t\treturn 3;\n\n\tcase 3 :\t// song select\n\t\treturn 2;\n\n\tcase 8 :\t//clock\n\tcase 10:\t//start\n\tcase 11:\t//continue\n\tcase 12: \t//stop\n\tcase 15:\t//reset\n\t\tgRunningStatus = 0; // clear running status\n\t\treturn 1;\n\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn (1);\n}\n\n\n\n\nstatic void midiProcessPacket(MIDIPacket *pkt, int srcIndex)\n{\n\tif(pkt) {\n\t\tint i = 0; \n\t\twhile (i < pkt->length) {\n\t\t\tuint8_t status = pkt->data[i] & 0xF0;\n\t\t\tuint8_t chan = pkt->data[i] & 0x0F;\n\t\t\tuint8_t a, b;\n\n\t\t\tif(status & 0x80) // set the running status for voice messages\n\t\t\t\tgRunningStatus = ((status >> 4) == 0xF) ? 0 : pkt->data[i]; // keep also additional info\n\t\tL:\n\t\t\tswitch (status) {\n\t\t\tcase 0x80 : //noteOff\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note off %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = 0;\n\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0x90 : //noteOn\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note on %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tif (b) {\n\t\t\t\t\tgMidiState[srcIndex][chan].lastkey = a;\n\t\t\t\t\tgMidiState[srcIndex][chan].lastvel = b;\n\t\t\t\t\t++gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t} else {\n\t\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t}\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xA0 : //polytouch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi poly %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].polytouch[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xB0 : //control\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi control %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].control[a] = b;\n\t\t\t\tif (a == 120 || (a >= 123 && a <= 127)) {\n\t\t\t\t\t// all notes off\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].keyvel, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].numKeysDown = 0;\n\t\t\t\t} else if (a == 121) {\n\t\t\t\t\t// reset ALL controls to zero, don't follow MMA recommended practices.\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].control, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].bend = 0x4000;\n\t\t\t\t}\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xC0 : //program\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tgMidiState[srcIndex][chan].program = a;\n\t\t\t\tif (gMidiDebug) printf(\"midi program %d %d %d\\n\", srcIndex, chan+1, a);\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xD0 : //touch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tprintf(\"midi touch %d %d\\n\", chan+1, a);\n\t\t\t\tgMidiState[srcIndex][chan].touch = a;\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xE0 : //bend\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi bend %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].bend = ((b << 7) | a) - 8192;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xF0 :\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\tdefault :\t// data byte => continuing sysex message\n\t\t\t\tif(gRunningStatus && !gSysexFlag) { // modified cp: handling running status. may be we should here\n\t\t\t\t\tstatus = gRunningStatus & 0xF0; // accept running status only inside a packet beginning\n\t\t\t\t\tchan = gRunningStatus & 0x0F;\t// with a valid status byte ?\n\t\t\t\t\t--i;\n\t\t\t\t\tgoto L; // parse again with running status set\n\t\t\t\t}\n\t\t\t\tchan = 0;\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nstatic void midiReadProc(const MIDIPacketList *pktlist, void* readProcRefCon, void* srcConnRefCon)\n{\n\tMIDIPacket *pkt = (MIDIPacket*)pktlist->packet;\n\tint srcIndex = (int)(size_t) srcConnRefCon;\n\tfor (uint32_t i=0; inumPackets; ++i) {\n\t\tmidiProcessPacket(pkt, srcIndex);\n\t\tpkt = MIDIPacketNext(pkt);\n\t}\n}\n\nstatic void midiNotifyProc(const MIDINotification *message, void *refCon)\n{\n\tprintf(\"midi notification %d %d\\n\", (int)message->messageID, (int)message->messageSize);\n}\n\nstatic struct mach_timebase_info machTimebaseInfo() {\n struct mach_timebase_info info;\n mach_timebase_info(&info);\n return info;\n}\n\nstatic MIDITimeStamp midiTime(float latencySeconds)\n{\n // add the latency expressed in seconds, to the current host time base.\n static struct mach_timebase_info info = machTimebaseInfo(); // cache the timebase info.\n Float64 latencyNanos = 1000000000 * latencySeconds;\n MIDITimeStamp latencyMIDI = (latencyNanos / (Float64)info.numer) * (Float64)info.denom;\n return (MIDITimeStamp)mach_absolute_time() + latencyMIDI;\n}\n\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late);\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late)\n{\n\tMIDIPacketList mpktlist;\n\tMIDIPacketList * pktlist = &mpktlist;\n\tMIDIPacket * pk = MIDIPacketListInit(pktlist);\n\tByteCount nData = (ByteCount) length;\n\tpk->data[0] = (Byte) (hiStatus & 0xF0) | (loStatus & 0x0F);\n\tpk->data[1] = (Byte) aval;\n\tpk->data[2] = (Byte) bval;\n\tpk = MIDIPacketListAdd(pktlist, sizeof(struct MIDIPacketList) , pk, midiTime(late), nData, pk->data);\n\t/*OSStatus error =*/ MIDISend(gMIDIOutPort[port], dest, pktlist );\n}\n\n\nstatic int midiCleanUp()\n{\n\t/*\n\t* do not catch errors when disposing ports\n\t* MIDIClientDispose should normally dispose the ports attached to it\n\t* but clean up the pointers in case\n\t*/\n\tint i = 0;\n\tfor (i=0; i= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\t//pass the uid to the midiReadProc to identify the src\n\tvoid* p = (void*)(uintptr_t)inputIndex;\n\tMIDIPortConnectSource(gMIDIInPort[inputIndex], src, p);\n\n\treturn errNone;\n}\n\n\nstatic int prDisconnectMIDIIn(int uid, int inputIndex)\n{\n\tif (inputIndex < 0 || inputIndex >= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\tMIDIPortDisconnectSource(gMIDIInPort[inputIndex], src);\n\n\treturn errNone;\n}\n\n\nstatic void midiStart_(Thread& th, Prim* prim)\n{\n\tmidiInit(16, 19);\n}\n\nstatic void midiRestart_(Thread& th, Prim* prim)\n{\n\tMIDIRestart();\n}\n\nstatic void midiStop_(Thread& th, Prim* prim)\n{\n\tmidiCleanUp();\n}\n\nstatic void midiList_(Thread& th, Prim* prim)\n{\n\tprListMIDIEndpoints();\n}\n\nstatic void midiConnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiConnectInput : port\");\n\tint uid = (int)th.popInt(\"midiConnectInput : sourceUID\");\n\tprConnectMIDIIn(uid, index);\n}\n\nstatic void midiDisconnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiDisconnectInput : port\");\n\tint uid = (int)th.popInt(\"midiDisconnectInput : sourceUID\");\n\tprDisconnectMIDIIn(uid, index);\n}\n\nstatic void midiDebug_(Thread& th, Prim* prim)\n{\n gMidiDebug = th.popFloat(\"midiDebug : onoff\") != 0.;\n}\n\nconst Z kOneOver127 = 1./127.;\nconst Z kOneOver8191 = 1./8191.;\n\nstatic void mctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl1 : hi\");\n\tZ lo = th.popFloat(\"mctl1 : lo\");\n\n\tint cnum = th.popInt(\"mctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl1 : hi\");\n\tZ lo = th.popFloat(\"xmctl1 : lo\");\n\n\tint cnum = th.popInt(\"xmctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly1 : hi\");\n\tZ lo = th.popFloat(\"mpoly1 : lo\");\n\n\tint key = th.popInt(\"mpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"mpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly1 : hi\");\n\tZ lo = th.popFloat(\"xmpoly1 : lo\");\n\n\tint key = th.popInt(\"xmpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mgate1_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate1 : key\") & 127;\n\tint chan = (th.popInt(\"mgate1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mgate1 : srcIndex\") & 15;\n\n\tth.pushBool(gMidiState[srcIndex][chan].keyvel[key] > 0);\n}\n\nstatic void mtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch1 : hi\");\n\tZ lo = th.popFloat(\"mtouch1 : lo\");\n\n\tint chan = (th.popInt(\"mtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch1 : hi\");\n\tZ lo = th.popFloat(\"xmtouch1 : lo\");\n\n\tint chan = (th.popInt(\"xmtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mprog1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mprog1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].touch);\n}\n\nstatic void mlastkey1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastkey1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].lastkey);\n}\n\nstatic void mlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel1 : hi\");\n\tZ lo = th.popFloat(\"mlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"mlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel1 : hi\");\n\tZ lo = th.popFloat(\"xmlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"xmlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nstatic void mbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend1 : hi\");\n\tZ lo = th.popFloat(\"mbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo + z * (hi - lo));\n}\nstatic void xmbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend1 : hi\");\n\tZ lo = th.popFloat(\"xmbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nZ gMidiLagTime = .1;\nZ gMidiLagMul = log001 / gMidiLagTime;\n\nstruct MCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct XMLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastKey : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMLastKey(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastKey\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastkey;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MProg : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMProg(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MProg\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].program;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MGate : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n int _key;\n\t\n\tMGate(Thread& th, int srcIndex, int chan, int key)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan), _key(key)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MGate\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].keyvel[_key];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl > 0 ? 1. : 0.;\n\t\t}\n\t}\n};\n\n\nstruct ZCtl : public ZeroInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n P zref;\n\t\n\tZCtl(Thread& th, P const& inZRef)\n : ZeroInputUGen(th, false), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n zref(inZRef)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ZCtl\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n Z& ctl = zref->z;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = ctl;\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void zctl_(Thread& th, Prim* prim)\n{\n\tP zref = th.popZRef(\"mctl : zref\");\n\n\tth.push(new List(new ZCtl(th, zref)));\n}\n\n\nstatic void mctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl : hi\");\n\tZ lo = th.popFloat(\"mctl : lo\");\n\n\tint cnum = th.popInt(\"mctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void xmctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl : hi\");\n\tZ lo = th.popFloat(\"xmctl : lo\");\n\n\tint cnum = th.popInt(\"xmctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void mpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly : hi\");\n\tZ lo = th.popFloat(\"mpoly : lo\");\n\n\tint key = th.popInt(\"mpoly : key\") & 127;\n\tint chan = (th.popInt(\"mpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void xmpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly : hi\");\n\tZ lo = th.popFloat(\"xmpoly : lo\");\n\n\tint key = th.popInt(\"xmpoly : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void mtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch : hi\");\n\tZ lo = th.popFloat(\"mtouch : lo\");\n\n\tint chan = (th.popInt(\"mtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch : hi\");\n\tZ lo = th.popFloat(\"xmtouch : lo\");\n\n\tint chan = (th.popInt(\"xmtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend : hi\");\n\tZ lo = th.popFloat(\"mbend : lo\");\n\n\tint chan = (th.popInt(\"mbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MBend(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend : hi\");\n\tZ lo = th.popFloat(\"xmbend : lo\");\n\n\tint chan = (th.popInt(\"xmbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMBend(th, srcIndex, chan, lo, hi)));\n}\n\n\nstatic void mprog_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MProg(th, srcIndex, chan)));\n}\n\nstatic void mgate_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate : key\") & 127;\n\tint chan = (th.popInt(\"mgate : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MGate(th, srcIndex, chan, key)));\n}\n\n\nstatic void mlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel : hi\");\n\tZ lo = th.popFloat(\"mlastvel : lo\");\n\n\tint chan = (th.popInt(\"mlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastVel(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mlastkey_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastKey(th, srcIndex, chan)));\n}\n\nstatic void xmlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel : hi\");\n\tZ lo = th.popFloat(\"xmlastvel : lo\");\n\n\tint chan = (th.popInt(\"xmlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMLastVel(th, srcIndex, chan, lo, hi)));\n}\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMidiOps()\n{\n\tvm.addBifHelp(\"\\n*** MIDI control ***\");\n\tDEF(midiStart, 0, 0, \"(-->) start up MIDI services\");\n\tDEF(midiRestart, 0, 0, \"(-->) rescan MIDI services\");\n\tDEF(midiStop, 0, 0, \"(-->) stop MIDI services\");\n\tDEF(midiList, 0, 0, \"(-->) list MIDI endpoints\");\n\tDEF(midiConnectInput, 2, 0, \"(sourceUID index -->) connect a MIDI source\");\n\tDEF(midiDisconnectInput, 2, 0, \"(sourceUID index -->) disconnect a MIDI source\");\n\tDEF(midiDebug, 1, 0, \"(onoff -->) turn on or off midi input monitoring\");\n\t\n\tvm.addBifHelp(\"\\n*** MIDI instantaneous value ***\");\n\tDEFMCX(mctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mprog1, 2, \"(srcIndex chan --> out) value of midi channel program 0-127.\");\n\tDEFMCX(mgate1, 3, \"(srcIndex chan key --> out) value of midi key state. 1 if key is down, 0 if key is up.\");\n\tDEFMCX(mlastkey1, 2, \"(srcIndex chan --> out) value of key of most recent midi note on.\");\n\tDEFMCX(mlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(xmctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** MIDI control signal ***\");\n\tDEFMCX(mctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mlastkey, 2, \"(srcIndex chan --> out) signal of key of most recent midi note on.\");\n\tDEFMCX(mlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(mprog, 2, \"(srcIndex chan --> out) signal of midi channel program 0-127.\");\n\tDEFMCX(mgate, 3, \"(srcIndex chan key --> out) signal of midi key state. 1 if key is down, 0 if key is up.\");\n\n\tDEFMCX(xmctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** ZRef control signal ***\");\n\tDEFMCX(zctl, 1, \"(zref --> out) makes a smoothed control signal from a zref.\");\n}\n\n\n"], ["/sapf/src/CoreOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Parser.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// stack shufflers\n#pragma mark STACK OPS\n\nstatic void clear_(Thread& th, Prim* prim)\n{\n\tth.clearStack();\n}\n\nstatic void cleard_(Thread& th, Prim* prim)\n{\n\tV v = th.top();\n\tth.clearStack();\n\tth.push(v);\n}\n\nstatic void stackDepth_(Thread& th, Prim* prim)\n{\n\tth.push(th.stackDepth());\n}\n\nstatic void ba_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[0] = sp[-1];\n\tsp[-1] = b;\n}\n\nstatic void bac_(Thread& th, Prim* prim) \n{\n\t// swapd\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = a;\n\tsp[0] = c;\n}\n\nstatic void cab_(Thread& th, Prim* prim)\n{\n\t// rrot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = a;\n\tsp[0] = b;\n}\n\nstatic void bca_(Thread& th, Prim* prim)\n{\n\t// rot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = c;\n\tsp[0] = a;\n}\n\nstatic void cba_(Thread& th, Prim* prim)\n{\n\t// reverse top 3\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n}\n\nstatic void aaa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n\tth.push(v);\n}\n\nstatic void aba_(Thread& th, Prim* prim)\n{\n\t// over\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tth.push(sp[-1]);\n}\n\nstatic void bab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\n\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n}\n\nstatic void aabb_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n\tth.push(b);\t\n}\n\nstatic void abab_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(a);\t\n\tth.push(b);\t\n}\n\nstatic void nip_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[-1] = b;\n\tth.pop();\n}\n\n\nstatic void pop_(Thread& th, Prim* prim)\n{\n\tth.pop();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark INHERIT\n\nstatic bool hasItem(int64_t size, Table** a, Table* item)\n{\n\tfor (int64_t i = 0; iIdentical(item))\n\t\t\treturn true;\n\t}\n\treturn false;\n}\n\nstatic void Envir_merge2(Thread& th, int64_t asize, Table** a, int64_t bsize, Table** b, int64_t& csize, Table** c0)\n{\n\n\tTable** c = c0;\n\tTable** aend = a + asize;\n\tTable** bend = b + bsize;\n\twhile (a < aend && b < bend) {\t\n\t\tif ((*a)->Identical(*b)) {\n\t\t\t*c++ = *a++;\n\t\t\tb++;\n\t\t} else if (!hasItem(bend-b-1, b+1, *a)) {\n\t\t\t*c++ = *a++;\n\t\t} else if (!hasItem(aend-a-1, a+1, *b)) {\n\t\t\t*c++ = *b++;\n\t\t} else {\n\t\t\tthrow errInconsistentInheritance;\n\t\t}\n\t}\n\twhile (a < aend) { *c++ = *a++; }\n\twhile (b < bend) { *c++ = *b++; }\n\tcsize = c - c0;\n}\n\t\nstatic int64_t Envir_toVec(O list, int64_t maxSize, Table** vec)\n{\n\tint64_t i = 0;\n\tfor (; list && i < maxSize-1;) {\n\t\tvec[i++] = ((Form*)list)->mTable();\n\t\tlist = ((Form*)list)->mNextForm();\n\t}\n\treturn i;\n}\n\nstatic P Envir_fromVec(int64_t size, Table** a)\n{\n\tif (size == 0) return vm._ee;\n\t\n\tP list;\n\tfor (int64_t i = size-1; i >= 0; --i) {\n\t\tlist = consForm(a[i], list);\n\t}\n\treturn list;\n}\n\n\nP linearizeInheritance(Thread& th, size_t numArgs, V* args)\n{\n\tif (numArgs == 0) return vm._ee;\n\tif (numArgs == 1) {\n\t\tif (args[0].isForm()) {\n\t\t\treturn (Form*)args[0].asObj();\n\t\t} else {\n\t\t\treturn vm._ee;\n\t\t}\n\t}\n\t\n\tconst size_t maxSize = 1024;\n\tTable* t[3][maxSize];\n\t\n\tint ai = 0;\n\tint bi = 1;\n\tint ci = 2;\n\n\tint64_t asize = Envir_toVec(args[0].asObj(), maxSize, t[ai]);\n\tfor (size_t i = 1; i < numArgs; ++i) {\n\t\tint64_t bsize = Envir_toVec(args[i].asObj(), maxSize, t[bi]);\n\t\tint64_t csize;\n\t\tEnvir_merge2(th, asize, t[ai], bsize, t[bi], csize, t[ci]);\n\t\tint temp = ci;\n\t\tci = ai;\n\t\tai = temp;\n\t\tasize = csize;\n\t}\n\treturn Envir_fromVec(asize, t[ai]);\n}\n\nP asParent(Thread& th, V& v)\n{\n\tP parent;\n\tif (v.isReal()) {\n\t\tparent = nullptr;\n\t} else if (v.isForm()) {\n\t\tif (v.o() == vm._ee()) parent = nullptr;\n\t\telse parent = (Form*)v.o();\n\t} else if (v.isFunOrPrim()) {\n\t\tSaveStack save(th);\n\t\tv.apply(th);\n\t\t\n\t\tsize_t n = th.stackDepth();\n\t\tV* args = &th.top() - (n - 1);\n\n\t\tparent = linearizeInheritance(th, n, args);\n\t\n\t\tth.popn(n);\n\t} else if (v.isVList()) {\n\t\tif (!v.isFinite())\n\t\t\tindefiniteOp(\"\", \"{} : parent\");\n\t\t\t\n\t\tP const& a = ((List*)v.o())->mArray;\n\t\tsize_t n = a->size();\n\t\tparent = linearizeInheritance(th, n, a->v());\n\t} else {\n\t\twrongType(\"new : parent\", \"Form, Fun or VList\", v);\n\t\treturn NULL; // never gets here, but otherwise gcc warns about parent uninitialized.\n\t}\n\treturn parent;\n}\n\nstruct Binding\n{\n\tV key;\n\tBothIn value;\n};\n\nstruct Bind : public Gen\n{\n\tP mMap;\n\tP mParent;\n\tstd::vector _bindings;\n\t\n\tBind(Thread& th, P& parent, P const& bindings, bool inIsFinite) \n\t\t: Gen(th, itemTypeV, inIsFinite), mParent(parent)\n\t{\n\t\tint64_t m = bindings->length(th);\n\t\tfor (int64_t i = 0; i+1 < m; i += 2) {\n\t\t\tBinding b;\n\t\t\tb.key = bindings->at(i);\n\t\t\tb.value.set(bindings->at(i+1));\n\t\t\t_bindings.push_back(b);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Bind\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tint n = framesToFill;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tP e = consForm(new Table(mMap), mParent);\n\t\t\t\n\t\t\tint64_t m = _bindings.size();\n\t\t\tfor (int64_t j = 0; j < m; ++j) {\n\t\t\t\tBinding& b = _bindings[j];\n\t\t\t\tV val;\n\t\t\t\tif (b.value.one(th, val)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\te->put(j, val); // ok, single threaded mutation\n\t\t\t}\n\t\t\t\n\t\t\tout[i] = e;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark REF OPS\n\n\nstatic void ref_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tV ref = new Ref(value);\n\tth.push(ref);\n}\n\nstatic void zref_(Thread& th, Prim* prim)\n{\n\tZ z = th.popFloat(\"zref : value\");\n\tth.push(new ZRef(z));\n}\n\n\nstatic void set_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tif (ref.isRef()) {\n\t\tV value = th.pop();\n\t\t((Ref*)ref.o())->set(value);\n\t} else if (ref.isZRef()) {\n\t\tZ value = th.popFloat(\"set : value\");\n\t\t((ZRef*)ref.o())->set(value);\n\t} else if (ref.isPlug()) {\n\t\tV value = th.pop();\n\t\t((Plug*)ref.o())->setPlug(value);\n\t} else if (ref.isZPlug()) {\n\t\tV value = th.popZIn(\"set : value\");\n\t\t((ZPlug*)ref.o())->setPlug(value);\n\t} else if (ref.isVList() && ref.isFinite()) {\n\t\tV value = th.pop();\n\t\tP refList = ((List*)ref.o())->pack(th);\n\t\tP refArray = refList->mArray;\n\t\tV* refs = refArray->v();\n\t\tif (value.isVList() && value.isFinite()) {\n\t\t\tP valueList = ((List*)value.o())->pack(th);\n\t\t\tP valueArray = valueList->mArray;\n\t\t\tV* vals = valueArray->v();\n\t\t\tsize_t n = std::min(refArray->size(), valueArray->size());\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(vals[i]);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t} else {\n\t\t\tsize_t n = refArray->size();\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(value);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"set : ref\", \"Ref, ZRef, Plug or ZPlug\", ref);\n\t}\n}\n\nstatic void get_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tth.push(ref.deref());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// printing ops\n#pragma mark PRINTING\n\nstatic void pr_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().print(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void prdebug_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().printDebug(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void cr_(Thread& th, Prim* prim)\n{\n\tpost(\"\\n\");\n}\n\nstatic void tab_(Thread& th, Prim* prim)\n{\n\tpost(\"\\t\");\n}\n\nstatic void sp_(Thread& th, Prim* prim)\n{\n\tpost(\" \");\n}\n\nstatic void prstk_(Thread& th, Prim* prim)\n{\n\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n}\n\n\nstatic void printLength_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printLength);\n}\n\nstatic void printDepth_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printDepth);\n}\n\nstatic void printTotalItems_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printTotalItems);\n}\n\nstatic void setPrintLength_(Thread& th, Prim* prim)\n{\n\tvm.printLength = (int)th.popInt(\"setPrintLength : length\");\n}\n\nstatic void setPrintDepth_(Thread& th, Prim* prim)\n{\n\tvm.printDepth = (int)th.popInt(\"setPrintDepth : depth\");\n}\n\nstatic void setPrintTotalItems_(Thread& th, Prim* prim)\n{\n\tvm.printTotalItems = (int)th.popInt(\"setPrintTotalItems : numItems\");\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// string ops\n#pragma mark STRINGS\n\nstatic void str_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.print(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void debugstr_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.printDebug(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void strcat_(Thread& th, Prim* prim)\n{\n\tP sep = th.popString(\"strcat : separator\");\n\tP list = th.popVList(\"strcat : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strcat : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tif (i != 0) s += sep->s;\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\nstatic void strlines_(Thread& th, Prim* prim)\n{\n\tP list = th.popVList(\"strlines : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strlines : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t\ts += \"\\n\";\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// loops\n#pragma mark LOOPS\n\nstatic void while_(Thread& th, Prim* prim)\n{\n\tV body = th.pop();\n\tV test = th.pop();\n\twhile (1) {\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\ttest.apply(th);\n\t\t\tif (th.pop().isTrue()) break;\n\t\t}\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\tbody.apply(th);\n\t\t}\n\t}\n}\n\n\nstatic void eachDoer(Thread& th, int level, uint32_t mask, BothIn& in, V& fun)\n{\n\tint nextLevel = level - 1;\n\tif (level == 0) {\n\t\twhile (1) {\n\t\t\tSaveStack ss(th);\n\t\t\tV v;\n\t\t\tif (in.one(th, v)) \n\t\t\t\treturn;\n\n\t\t\tth.push(v);\n\t\t\tfun.apply(th);\n\t\t}\n\t} else {\n\t\tint bit = 1 << level;\n\n\t\twhile (1) {\n\t\t\tV argv;\n\t\t\tif (in.one(th, argv))\n\t\t\t\treturn;\n\n\t\t\tbool isConstant = !(argv.isList() && (mask & bit));\n\t\t\t\n\t\t\tif (isConstant) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(argv);\n\t\t\t\tfun.apply(th);\n\t\t\t} else {\n\t\t\t\tBothIn subin;\n\t\t\t\tV v = argv;\n\t\t\t\tif (mask & bit) {\n\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\t\t\t\n\t\t\t\t\tsubin.set(v);\n\t\t\t\t} else {\n\t\t\t\t\tsubin.setConstant(v);\n\t\t\t\t}\n\t\t\t\n\t\t\t\teachDoer(th, nextLevel, mask, subin, fun);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstatic void do_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tV item = th.pop();\n\t\n\tif (item.isEachOp()) {\n\t\tP p = (EachOp*)item.o();\n\t\tif (!p->v.isFinite())\n\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\n\t\tBothIn in(p->v);\n\t\tint numLevels = p->mask <= 1 ? 0 : LOG2CEIL(p->mask) - 1;\n\t\teachDoer(th, numLevels, p->mask, in, f);\n\t} else if (item.isList()) {\n\t\n\t\tP s = (List*)item.o();\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"do\", \"\");\n\n\t\tif (s->isVList()) {\n\t\t\tVIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = kDefaultVBlockSize;\n\t\t\t\tint astride;\n\t\t\t\tV *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tZIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = th.rate.blockSize;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"do : list\", \"List\", item);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark CONDITIONALS\n\nstatic void equals_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(a.Equals(th, b));\n}\n\nstatic void less_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) < 0);\n}\n\nstatic void greater_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) > 0);\n}\n\nstatic void if_(Thread& th, Prim* prim)\n{\n\tV elseCode = th.pop();\n\tV thenCode = th.pop();\n\tV test = th.pop();\n\tif (test.isTrue()) {\n\t\tthenCode.apply(th);\n\t} else {\n\t\telseCode.apply(th);\n\t}\n}\n\nstatic void dip_(Thread& th, Prim* prim)\n{\n V temp = th.pop();\n V fun = th.pop();\n fun.apply(th);\n th.push(temp);\n}\n\nstatic void not_(Thread& th, Prim* prim)\n{\n\tV p = th.pop();\n\tth.pushBool(p.isFalse());\n}\n\nstatic void protect_(Thread& th, Prim* prim)\n{\n\tV protectCode = th.pop();\n\tV tryCode = th.pop();\n\n\t\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tprotectCode.apply(th);\n\t\tthrow;\n\t}\n\n\tprotectCode.apply(th);\n}\n\nstatic void try_(Thread& th, Prim* prim)\n{\n\tV catchCode = th.pop();\n\tV tryCode = th.pop();\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tcatchCode.apply(th);\n\t\tthrow;\n\t}\n}\n\nstatic void throw_(Thread& th, Prim* prim)\n{\n\tthrow -1;\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ENVIR OPS\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.push(asParent(th, v));\n}\n\nstatic void pushWorkspace_(Thread& th, Prim* prim)\n{\n\tth.mWorkspace = consForm(new GTable(), th.mWorkspace);\n}\n\nstatic void popWorkspace_(Thread& th, Prim* prim)\n{\n if (!th.mWorkspace->mNextForm()) {\n post(\"Must not pop top level workspace!\\n\");\n return;\n }\n\tth.mWorkspace = th.mWorkspace->mNextForm;\n}\n\n\nstatic void has_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV list = th.pop();\n\t\n\tV value;\n\tbool has = list.get(th, key, value);\n\tth.pushBool(has);\n}\n\nstatic void keys_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(keys[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\nstatic void values_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(vals[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\n\nstatic void kv_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"values : e\")->mTable;\n\t\n\tP ka = new Array(itemTypeV, t->mMap->mSize);\n\tP va = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\tka->add(keys[i]);\n\t\tva->add(vals[i]);\n\t}\n\n\tth.push(new List(ka));\n\tth.push(new List(va));\n}\n\nstatic void local_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"local : e\")->mTable;\n\t\n\tth.push(new Form(t));\n}\n\nstatic void parent_(Thread& th, Prim* prim)\n{\n\tP form = th.popForm(\"values : e\");\n\t\n\tth.push(form->mNextForm ? form->mNextForm : vm._ee);\n}\n\nstatic void dot_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV e = th.pop();\n\t\t\n\tif (!key.isVList()) {\n\t\tV v;\n\t\te.dot(th, key, v);\n\t\tth.push(v);\n\t} else {\n\t\tif (!key.isFinite())\n\t\t\tindefiniteOp(\"dot : key\", \"\");\n\t\tList* ks = (List*)key.o();\n\t\tks = ks->pack(th);\n\n\t\tP ka = ks->mArray;\n\t\tint64_t size = ka->size();\n\t\tP va = new Array(itemTypeV, size);\n\t\tva->setSize(size);\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tV v;\n\t\t\te.dot(th, key, v);\n\t\t\tth.push(v);\n\t\t}\n\t\tth.push(new List(va));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark APPLY\n\nstatic void noeach_(Thread& th, Prim* prim)\n{\n\tV fun = th.top();\n\t\n\tfun.SetNoEachOps();\n}\n\nstatic void apply_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tv.apply(th);\n}\n\nstatic void applyEvent_(Thread& th, Prim* prim)\n{\n\tP fun = th.popFun(\"!e : fun\");\n\tP form = th.popForm(\"!e : form\");\n\t\n\tfor (auto const& name : fun->mDef->mArgNames) {\n\t\tV argValue;\n\t\tif (!form->dot(th, name, argValue)) {\n\t\t\tnotFound(name);\n\t\t}\n\t\tth.push(argValue);\n\t}\n\t\n\tfun->apply(th);\n}\n\nstatic void type_(Thread& th, Prim* prim)\n{\n\tth.push(getsym(th.pop().TypeName()));\n}\n\nstatic void load_(Thread& th, Prim* prim)\n{\n\tP filename = th.popString(\"load : filename\");\n\tloadFile(th, filename->s);\n}\n\nstatic void compile_(Thread& th, Prim* prim)\n{\n\tP s = th.popString(\"compile : string\");\n\tconst char* ss = s->s;\n\t\n\tP fun;\n\tif (!th.compile(ss, fun, false)) {\n\t\tth.push(0.);\n\t} else {\n\t\tth.push(fun);\n\t}\n}\n\nstatic void y_combinator_call_(Thread& th, Prim* prim)\n{\n\tth.push(prim);\n\tprim->v.apply(th);\n}\n\nstatic void Y_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tif (f.takes() < 1) {\n\t\tpost(\"Y : fun. function must take at least one argument.\\n\");\n\t\tthrow errFailed;\n\t}\n\tth.push(new Prim(y_combinator_call_, f, f.takes()-1, f.leaves(), NULL, NULL));\n}\n\n\nstatic void* gofun(void* ptr)\n{\n Thread* th = (Thread*)ptr;\n th->fun->run(*th);\n delete th;\n return NULL;\n}\n\nstatic void go_(Thread& th, Prim* prim)\n{\n P fun = th.popFun(\"go : fun\");\n \n Thread* newThread = new Thread (th, fun); \n \n pthread_t pt;\n pthread_create(&pt, NULL, gofun, newThread);\n}\n\nstatic void sleep_(Thread& th, Prim* prim)\n{\n Z t = th.popFloat(\"sleep : secs\");\n \n usleep((useconds_t)floor(1e6 * t + .5));\n}\n\n#if COLLECT_MINFO\nstatic void minfo_(Thread& th, Prim* prim)\n{\n\tpost(\"signal generators %qd\\n\", vm.totalSignalGenerators.load());\n\tpost(\"stream generators %qd\\n\", vm.totalStreamGenerators.load());\n\tpost(\"objects live %qd\\n\", vm.totalObjectsAllocated.load() - vm.totalObjectsFreed.load());\n\tpost(\"objects allocated %qd\\n\", vm.totalObjectsAllocated.load());\n\tpost(\"objects freed %qd\\n\", vm.totalObjectsFreed.load());\n\tpost(\"retains %qd\\n\", vm.totalRetains.load());\n\tpost(\"releases %qd\\n\", vm.totalReleases.load());\n}\n#endif\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark SAMPLE RATES\n\nstatic void sr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate);\n}\n\nstatic void nyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate * .5);\n}\n\nstatic void isr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invSampleRate);\n}\n\nstatic void rps_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.radiansPerSample);\n}\n\nstatic void inyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invNyquistRate);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark HELP\n\nstatic void listdump_(Thread& th, Prim* prim)\n{\t\n\tP list = th.popList(\"listdump : seq\");\n\t\n\tpost(\"[\\n\");\n\twhile (list()) {\n\t\tpost(\"list %p %p %d\\n\", list(), list->mArray(), list->mArray() ? (int)list->mArray->size() : -1);\n\t\tlist = list->next();\n\t}\n\tpost(\"]\\n\");\n}\n\nstatic void help_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\n\tconst char* mask = v.GetAutoMapMask();\n\tconst char* help = v.OneLineHelp();\n\t\n\tif (mask) {\n\t\tpost(\"@%s \", mask);\n\t}\n\tif (help) {\n\t\tpost(\"%s\\n\", help);\n\t} else {\n\t\tpost(\"no help available.\\n\");\n\t}\n\n}\n\nstatic void helpbifs_(Thread& th, Prim* prim)\n{\n post(\"\\nBUILT IN FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.bifHelp.size(); ++i) {\n\t\tstd::string& s = vm.bifHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpLine_(Thread& th, Prim* prim)\n{\n\tP str = th.popString(\"helpLine : string\");\n\tvm.addUdfHelp(str->s);\n}\n\nstatic void helpudfs_(Thread& th, Prim* prim)\n{\n post(\"\\nUSER DEFINED FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.udfHelp.size(); ++i) {\n\t\tstd::string& s = vm.udfHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpall_(Thread& th, Prim* prim)\n{\n helpbifs_(th, prim);\n helpudfs_(th, prim);\n}\n\n\nstatic void prelude_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.prelude_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.prelude_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no prelude file.\\n\");\n\t}\n}\n\nstatic void examples_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* examples_file = getenv(\"SAPF_EXAMPLES\");\n\tif (examples_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", examples_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no examples file.\\n\");\n\t}\n}\n\nstatic void readme_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* readme_file = getenv(\"SAPF_README\");\n\tif (readme_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", readme_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no readme file.\\n\");\n\t}\n}\n\nstatic void logfile_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.log_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.log_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no log file.\\n\");\n\t}\n}\n\nstatic void trace_(Thread& th, Prim* prim)\n{\n\tvm.traceon = th.pop().isTrue();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PLUGS\n\nstruct PlugOut : Gen\n{\n\tP _plug;\n\t\n\tPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeV, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"PlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tVIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\nstruct ZPlugOut : Gen\n{\n\tP _plug;\n\t\n\tZPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeZ, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"ZPlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\n\nstatic void plug_(Thread& th, Prim* prim)\n{\n\tV in = th.pop();\n\tP plug = new Plug(in);\n\tth.push(new List(new PlugOut(th, plug)));\n\tth.push(plug);\n}\n\nstatic void zplug_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tif (value.isVList() && value.isFinite()) {\n\t\tP valueList = ((List*)value.o())->pack(th);\n\t\tP valueArray = valueList->mArray;\n\t\tV* vals = valueArray->v();\n\t\tsize_t n = valueArray->size();\n\t\t\n\t\tP plugList = new List(itemTypeV, n);\n\t\tP outList = new List(itemTypeV, n);\n\t\t\n\t\tP plugArray = plugList->mArray;\n\t\tP outArray = outList->mArray;\n\t\t\n\t\tplugArray->setSize(n);\n\t\toutArray->setSize(n);\n\t\t\n\t\tV* plugItems = plugArray->v();\n\t\tV* outItems = outArray->v();\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(vals[i]);\n\t\t\tzplug_(th, prim);\n\t\t\tplugItems[i] = th.pop();\n\t\t\toutItems[i] = th.pop();\n\t\t}\n\t\t\n\t\tth.push(outList);\n\t\tth.push(plugList);\n\t} else if (value.isZIn()) {\n\t\tP plug = new ZPlug(value);\n\t\tth.push(new List(new ZPlugOut(th, plug)));\n\t\tth.push(plug);\n\t} else {\n\t\twrongType(\"zplug : ref\", \"VList or UGen input\", value);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark GLOB\n\n#include \n\nstatic void glob_(Thread& th, Prim* prim)\n{\n\tP pat = th.popString(\"glob : pattern\");\n\t\n\tglob_t g;\n\tmemset(&g, 0, sizeof(g));\n\tglob(pat->s, GLOB_MARK, nullptr, &g);\n\t\n\tP a = new Array(itemTypeV, g.gl_matchc);\n\tfor (int i = 0; i < g.gl_matchc; ++i) {\n\t\ta->add(new String(g.gl_pathv[i]));\n\t}\n\tglobfree(&g);\n\t\n\tth.push(new List(a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD CORE OPS\n\n\n#define DEFN(NAME, N, FUN, HELP) \tvm.def(NAME, N, 1, FUN, HELP);\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEF2(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddCoreOps();\nvoid AddCoreOps()\n{\n\t// stack ops\n\tvm.addBifHelp(\"\\n*** stack ops ***\");\n\tDEFnoeach(clear, 0, 0, \"(... -->) clears everything off the stack.\");\n\tDEFnoeach(cleard, 0, 1, \"(... a --> a) clears all but the top item from the stack.\")\n\tDEFnoeach(stackDepth, 0, 1, \"(--> n) returns the size of the stack.\")\n\t\n\tDEFnoeach(aa, 1, 2, \"(a --> a a) push the top item on stack again.\")\n\tDEFnoeach(aaa, 1, 3, \"(a --> a a a) push the top item on stack two more times.\")\n\tDEFnoeach(ba, 2, 2, \"(a b --> b a) swap top two items.\")\n\t\n\tDEFnoeach(bac, 3, 3, \"(a b c --> b a c) reorder items on stack.\")\n\tDEFnoeach(cba, 3, 3, \"(a b c --> c b a) reorder items on stack.\")\n\tDEFnoeach(bca, 3, 3, \"(a b c --> b c a) reorder items on stack.\")\n\tDEFnoeach(cab, 3, 3, \"(a b c --> c a b) reorder items on stack.\")\n\n\tDEFnoeach(bab, 2, 3, \"(a b --> b a b) reorder items on stack.\")\n\tDEFnoeach(aba, 2, 3, \"(a b --> a b a) reorder items on stack.\")\n\n\tDEFnoeach(aab, 2, 3, \"(a b --> a a b) reorder items on stack.\")\n\tDEFnoeach(aabb, 2, 4, \"(a b --> a a b b) reorder items on stack.\")\n\tDEFnoeach(abab, 2, 4, \"(a b --> a b a b) reorder items on stack.\")\n\n\tDEFnoeach(nip, 2, 1, \"(a b --> b) remove second item on stack.\")\n\tDEFnoeach(pop, 1, 0, \"(a -->) remove top item on stack.\")\n\t\n\t// loops\n\tvm.addBifHelp(\"\\n*** loops ***\");\n\t//DEFnoeach(while, 2, \"(A B --> ..) While applying A returns true, apply B.\")\n\tDEFnoeach(do, 2, 0, \"(list \\\\item[..] -->) applies the function to each item of a finite list. Useful for side effects like printing or file writing.\")\n\n\t// conditional ops\n\tvm.addBifHelp(\"\\n*** conditional ops ***\");\n\tDEF(equals, 2, \"(a b --> bool) returns 1 if a and b are structurally equivalent. If the data structures are cyclic then this may never terminate.\")\n\tDEF(less, 2, \"(a b --> bool) returns 1 if a is less than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF(greater, 2, \"(a b --> bool) returns 1 if a is greater than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF2(if, 3, -1, \"(A B C --> ..) if A is true then apply B else apply C.\")\n\n\tDEF(not, 1, \"(A --> bool) returns 0 if A is true and 1 if A is false.\")\n\t//DEF2(dip, 1, -1, \"(x A --> ..) pops x from stack, applies A, pushes x back on stack.\")\n\n\tDEFnoeach(try, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied.\")\n\tDEFnoeach(throw, 0, 0, \"(a -->) throw an exception.\")\n\tDEFnoeach(protect, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied and the exception is rethrown. Otherwise function B is applied and control continues as normal.\")\n\n\t// form ops\n\tvm.addBifHelp(\"\\n*** form ops ***\");\n\tDEFAM(has, kk, \"(form key --> bool) return whether a form contains the key.\")\n \n\tDEFAM(keys, k, \"(form --> keys) return an array of the keys of the form.\")\n\tDEFAM(values, k, \"(form --> values) return an array of the values of the form.\")\n\tDEFAM(kv, k, \"(form --> keys values) return two arrays of the keys and values of the form.\") /// !!!! returns two values. can't be auto mapped.\n\tDEFAM(local, k, \"(form --> local) return the head of the prototype inheritance list.\")\n\tDEFAM(parent, k, \"(form --> parent) return the tail of the prototype inheritance list.\")\n\tDEFAM(dot, ka, \"(form key --> item) return the value for the key.\")\n \n DEFnoeach(pushWorkspace, 0, 0, \"(-->) pushes a new outer scope onto the workspace. New bindings will be made in the new outer scope.\");\n DEFnoeach(popWorkspace, 0, 0, \"(-->) pops a scope from the workspace. All bindings in the outer scope will be forgotten.\");\n\t\n\tvm.addBifHelp(\"\\n*** ref ops ***\");\n\tDEFAM(get, k, \"(r --> a) return the value store in a ref.\")\n\tDEFnoeach(set, 1, 0, \"(a r -->) store the value a in the ref r.\")\n\tvm.def(\"R\", 1, 1, ref_, \"(a --> r) create a new Ref with the inital value a\");\n\tvm.def(\"ZR\", 1, 1, zref_, \"(z --> r) create a new ZRef with the inital value z. A ZRefs is a mutable reference to a real number.\");\n\tvm.def(\"P\", 1, 2, plug_, \"(a --> out in) create a new stream plug pair with the inital value a\");\n\tvm.def(\"ZP\", 1, 2, zplug_, \"(a --> out in) create a new signal plug pair with the inital value a.\");\n\t\n\t\n\t//DEF(bind, 2, \"deprecated\")\n\t\n\t// apply ops\n\tvm.addBifHelp(\"\\n*** function ops ***\");\n\tDEF(Y, 1, \"(funA --> funB) Y combinator. funB calls funA with the last argument being funB itself. Currently the only way to do recursion. \\n\\t\\te.g. \\\\x f [x 2 < \\\\[1] \\\\[ x x -- f *] if] Y = factorial 7 factorial --> 5040\")\n\tDEF(noeach, 1, \"(fun --> fun) sets a flag in the function so that it will pass through arguments with @ operators without mapping them.\")\n\tvm.def(\"!\", 1, -1, apply_, \"(... f --> ...) apply the function to its arguments, observing @ arguments as appropriate.\");\n\tvm.def(\"!e\", 2, -1, applyEvent_, \"(form fun --> ...) for each argument in the function, find the same named fields in the form and push those values as arguments to the function.\");\n\tDEF(compile, 1, \"(string --> fun) compile the string and return a function.\")\n\t\n\tvm.addBifHelp(\"\\n*** printing ops ***\");\n\tDEFnoeach(printLength, 0, 1, \"(--> length) return the number of items printed for lists.\");\n\tDEFnoeach(printDepth, 0, 1, \"(--> depth) return the number of levels of nesting printed for lists.\");\n\tDEFnoeach(setPrintLength, 1, 0, \"(length --> ) set the number of items printed for lists.\");\n\tDEFnoeach(setPrintDepth, 1, 0, \"(depth -->) set the number of levels of nesting printed for lists.\");\n\t\n\tDEFnoeach(pr, 1, 0, \"(A -->) print the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(prdebug, 1, 0, \"(A -->) print debug version of the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(cr, 0, 0, \"(-->) print a carriage return.\")\n\tDEFnoeach(sp, 0, 0, \"(-->) print a space character.\")\n\tDEFnoeach(tab, 0, 0, \"(-->) print a tab.\")\n\tDEFnoeach(prstk, 0, 0, \"(-->) print the stack.\")\n\n#if COLLECT_MINFO\n\tDEFnoeach(minfo, 0, 0, \"(-->) print memory management info.\")\n#endif\n\tDEFnoeach(listdump, 1, 0, \"(list -->) prints information about a list.\");\n\n\tvm.addBifHelp(\"\\n*** string ops ***\");\n\tDEF(str, 1, \"(x --> string) convert x to a string.\");\n\tDEF(debugstr, 1, \"(x --> string) convert x to a debug string.\");\n\tDEFAM(strcat, ak, \"(list separator --> string) convert elements of list to a string with separator string between each.\");\n\tDEF(strlines, 1, \"(list --> string) convert elements of list to a newline separated string.\");\n\tDEFAM(glob, k, \"(pattern --> paths) return a list of file path names that match.\");\n\n\tvm.addBifHelp(\"\\n*** sample rate ops ***\");\n\tDEFnoeach(sr, 0, 1, \"(--> sampleRate) returns the sample rate. samples per second. \")\n\tDEFnoeach(nyq, 0, 1, \"(--> sampleRate/2) returns the nyquist rate\")\n\tDEFnoeach(isr, 0, 1, \"(--> 1/sampleRate) returns the inverse sample rate\")\n\tDEFnoeach(inyq, 0, 1, \"(--> 2/sampleRate) returns the inverse nyquist rate.\")\n\tDEFnoeach(rps, 0, 1, \"(--> 2pi/sampleRate) returns the radians per sample\")\n\n\n\tvm.addBifHelp(\"\\n*** help ops ***\");\n\n\tDEFnoeach(help, 1, 0, \"(fun -->) prints help for a function.\");\n\tDEFnoeach(helpbifs, 0, 0, \"(-->) prints help for all built in functions.\");\n\tDEFnoeach(helpudfs, 0, 0, \"(-->) prints help for all user defined functions.\");\n\tDEFnoeach(helpall, 0, 0, \"(-->) prints help for all built in and user defined functions.\");\n DEF(helpLine, 1, \"(string -->) add a line to the user defined function help.\");\n\t\n\tvm.addBifHelp(\"\\n*** thread ops ***\");\n DEFnoeach(go, 1, 0, \"(fun -->) launches the function in a new thread.\");\n DEFnoeach(sleep, 1, 0, \"(seconds -->) sleeps the current thread for the time given.\");\n\n\tvm.addBifHelp(\"\\n*** misc ***\");\n\tDEF(type, 1, \"(a --> symbol) return a symbol naming the type of the value a.\")\n\tDEFnoeach(trace, 1, 0, \"(bool -->) turn tracing on/off in the interpreter.\")\n\n\tvm.addBifHelp(\"\\n*** text files ***\");\n\tDEFnoeach(load, 1, 0, \"(filename -->) compiles and executes a text file.\")\t\n\tDEFnoeach(prelude, 0, 0, \"(-->) opens the prelude file in the default text editor.\")\n\tDEFnoeach(examples, 0, 0, \"(-->) opens the examples file in the default text editor.\")\n\tDEFnoeach(logfile, 0, 0, \"(-->) opens the log file in the default text editor.\")\n\tDEFnoeach(readme, 0, 0, \"(-->) opens the README file in the default text editor.\")\n\n}\n\n"], ["/sapf/src/VM.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Opcode.hpp\"\n#include \"Parser.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nVM vm;\n\npthread_mutex_t gHelpMutex = PTHREAD_MUTEX_INITIALIZER;\n\nstd::atomic randSeedCounter = 77777;\n\nuint64_t timeseed()\n{\n\tstruct timeval tv;\n\tgettimeofday(&tv, 0);\n\tint32_t counter = ++randSeedCounter;\n\treturn Hash64(tv.tv_sec) + Hash64(tv.tv_usec) + Hash64(counter);\n}\n\n\nThread::Thread()\n :rate(vm.ar), stackBase(0), localBase(0),\n\tmWorkspace(new GForm()),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent)\n :rate(inParent.rate), stackBase(0), localBase(0),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent, P const& inFun)\n :rate(vm.ar), stackBase(0), localBase(0),\n fun(inFun),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::~Thread() {}\n\n//////////////////////\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV vparent = th.pop();\n\tP form = asParent(th, vparent);\n\tth.push(form);\n}\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value)\n{\t\n\tP
table = new Table(tmap);\n\tP form = new Form(table, parent);\n\ttable->put(0, value);\n\treturn form;\n}\n\nstatic void newForm_(Thread& th, Prim* prim)\n{\n\tTableMap* tmap = (TableMap*)th.pop().o();\n\tsize_t numArgs = tmap->mSize;\n\t\n\tV* args = &th.top() - numArgs + 1;\n\t\n\tP
table = new Table(tmap);\n\tV vparent = args[-1];\n\tP parent = asParent(th, vparent);\n\t\n\tP form = new Form(table, parent);\n\t\n\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\ttable->put(i, args[i]);\n\t}\n\t\n\tth.popn(numArgs+1);\n\t\n\tth.push(form);\n}\n\nstatic void newVList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilv;\n\t} else {\n\t\tseq = new List(itemTypeV, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\tth.push(seq);\t\t\n}\n\nstatic void newZList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilz;\n\t} else {\n\t\tseq = new List(itemTypeZ, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\t\n\tth.push(seq);\t\t\n}\n\n//////////////////////\n\n\nVM::VM()\n\t:\n\tprelude_file(NULL),\n\tlog_file(NULL),\n\t_ee(0),\n\t\t\n\tprintLength(20),\n\tprintDepth(8),\n\t\n\tar(kDefaultSampleRate, kDefaultZBlockSize),\n\tkr(ar, kDefaultControlBlockSize),\n\t\n\tVblockSize(kDefaultVBlockSize),\n\t\n#if COLLECT_MINFO\n\ttotalRetains(0),\n\ttotalReleases(0),\n\ttotalObjectsAllocated(0),\n\ttotalObjectsFreed(0),\n\ttotalSignalGenerators(0),\n\ttotalStreamGenerators(0)\n#endif\n{\n\tinitElapsedTime();\n\t\n\t_ee = new Form(0, NULL);\n\t\t\n\tbuiltins = new GTable();\n\t\n\t// add built in funs\n\t\t\n\t_nilz = new List(itemTypeZ);\n\t_nilv = new List(itemTypeV);\n\t\n\t_anilz = _nilz->mArray;\n\t_anilv = _nilv->mArray;\n\t\n\tnewForm = new Prim(newForm_, 0., 0, 1, NULL, NULL);\n\tinherit = new Prim(inherit_, 0., 0, 1, NULL, NULL);\n\n\tnewVList = new Prim(newVList_, 0., 0, 1, NULL, NULL);\n\tnewZList = new Prim(newZList_, 0., 0, 1, NULL, NULL);\n}\n\nVM::~VM()\n{\n}\n\n#if USE_LIBEDIT\nstatic const char* prompt(EditLine *e) \n{\n return \"sapf> \";\n}\nstatic const char* promptParen(EditLine *e) \n{\n return \"(sapf> \";\n}\nstatic const char* promptSquareBracket(EditLine *e) \n{\n return \"[sapf> \";\n}\nstatic const char* promptCurlyBracket(EditLine *e) \n{\n return \"{sapf> \";\n}\nstatic const char* promptLambda(EditLine *e) \n{\n return \"\\\\sapf> \";\n}\nstatic const char* promptString(EditLine *e) \n{\n return \"\\\"sapf> \";\n}\n#endif\n\nvoid Thread::getLine()\n{\t\n\tif (fromString) return;\n\tswitch (parsingWhat) {\n\t\tdefault: case parsingWords : el_set(el, EL_PROMPT, &prompt); break;\n\t\tcase parsingString : el_set(el, EL_PROMPT, &promptString); break;\n\t\tcase parsingParens : el_set(el, EL_PROMPT, &promptParen); break;\n\t\tcase parsingLambda : el_set(el, EL_PROMPT, &promptLambda); break;\n\t\tcase parsingArray : el_set(el, EL_PROMPT, &promptSquareBracket); break;\n\t\tcase parsingEnvir : el_set(el, EL_PROMPT, &promptCurlyBracket); break;\n\t}\n\tline = el_gets(el, &linelen);\n\tlinepos = 0;\n\tif (strncmp(line, \"quit\", 4)==0 || strncmp(line, \"..\", 2)==0) { line = NULL; throw errUserQuit; }\n\tif (line && linelen) {\n\t\thistory(myhistory, &ev, H_ENTER, line);\n\t\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\t\tif (logfilename) {\n\t\t\tFILE* logfile = fopen(logfilename, \"a\");\n\t\t\tlogTimestamp(logfile);\n\t\t\tfwrite(line, 1, strlen(line), logfile);\n\t\t\tfclose(logfile);\n\t\t}\n\t}\n}\n\nvoid Thread::logTimestamp(FILE* logfile)\n{\n\ttimeval tv;\n\tgettimeofday(&tv, NULL);\n\tif (previousTimeStamp == 0 || tv.tv_sec - previousTimeStamp > 3600) {\n\t\tpreviousTimeStamp = tv.tv_sec;\n\t\tchar date[32];\n\t\tctime_r(&tv.tv_sec, date);\n\t\tfprintf(logfile, \";;;;;;;; %s\", date);\n\t\tfflush(logfile);\n\t}\n}\n\nchar Thread::getc() { \n\tif (fromString) {\n\t\tif (line == NULL) return 0;\n\t\treturn line[linepos++];\n\t} else {\n\t\twhile (1) {\t\n\t\t\tif (line == NULL) {\n\t\t\t\tgetLine();\n\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t} else if (line[linepos] == 0) {\n\t\t\t\tif (parsingWhat == parsingWords) {\n\t\t\t\t\treturn 0;\n\t\t\t\t} else {\n\t\t\t\t\tgetLine();\n\t\t\t\t\tif (linelen == 0 || strcmp(line, \"\\n\") == 0) {\n\t\t\t\t\t\tline = NULL;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn line[linepos++];\n\t\t\t}\n\t\t}\n\t}\n\treturn 0; // never gets here, but compiler too dumb to figure this out.\n}\n\nvoid Thread::repl(FILE* infile, const char* inLogfilename)\n{\n\tThread& th = *this;\n\n\tlogfilename = inLogfilename;\n\t\n\tpreviousTimeStamp = 0;\n\n#if USE_LIBEDIT\n\tel = el_init(\"sc\", stdin, stdout, stderr);\n\tel_set(el, EL_PROMPT, &prompt);\n\tel_set(el, EL_EDITOR, \"emacs\");\n\tel_set(el, EL_BIND, \"-s\", \"\\t\", \" \", NULL);\n\n\tmyhistory = history_init();\n\tif (myhistory == 0) {\n\t\tpost(\"history could not be initialized\\n\");\n\t\treturn;\n\t}\n\n\tconst char* envHistoryFileName = getenv(\"SAPF_HISTORY\");\n\tif (envHistoryFileName) {\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s\", envHistoryFileName);\n\t} else {\n\t\tconst char* homeDir = getenv(\"HOME\");\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s/sapf-history.txt\", homeDir);\n\t}\n\thistory(myhistory, &ev, H_SETSIZE, 800);\n\thistory(myhistory, &ev, H_LOAD, historyfilename);\n\thistory(myhistory, &ev, H_SETUNIQUE, 1);\n\tel_set(el, EL_HIST, history, myhistory);\n#endif\n\t\n\tfflush(infile);\n\tbool running = true;\n\n\tpost(\"Type 'helpall' to get a list of all built-in functions.\\n\");\n\tpost(\"Type 'quit' to quit.\\n\");\n\t\n\tdo {\n\t\ttry {\n\t\t\tif (stackDepth()) {\n\t\t\t\tprintStack();\n\t\t\t\tpost(\"\\n\");\n\t\t\t}\n\t\t} catch (int err) {\n\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"\\nunknown error\\n\");\n\t\t}\n\t\t\t\t\n\t\ttry {\n\t\t\t// PARSE\n\t\t\t{\n\t\t\t\tP compiledFun;\n\t\t\t\tif (compile(NULL, compiledFun, true)) {\n\t\t\t\t// EVAL\n\t\t\t\t\tcompiledFun->runREPL(th);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (V& v) {\n post(\"error: \");\n v.print(th);\n\t\t\tpost(\"\\n\");\n\t\t} catch (int err) {\n\t\t\tif (err == errUserQuit) {\n\t\t\t\tpost(\"good bye\\n\");\n\t\t\t\trunning = false;\n\t\t\t} else if (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"error: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"not enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"unknown error\\n\");\n\t\t}\n\n\t} while (running);\n\t\n\n#if USE_LIBEDIT\n\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\thistory_end(myhistory);\n\tel_end(el);\n#endif\n}\n\n\ntemplate \nclass AutoFree\n{\n\tT* p;\npublic:\n\tAutoFree(T* _p) : p(_p) {}\n\t~AutoFree() { free(p); }\n\t\n\tT* operator()() { return p; }\n\tT* operator*() { return p; }\n\tT* operator->() { return p; }\n};\n\nvoid loadFile(Thread& th, const char* filename)\n{\n post(\"loading file '%s'\\n\", filename);\n\tFILE* f = fopen(filename, \"r\");\n\tif (!f) {\n\t\tpost(\"could not open '%s'\\n\", filename);\n\t\treturn;\n\t}\n\n\tfseek(f, 0, SEEK_END);\n\tint64_t fileSize = ftell(f);\n\tfseek(f, 0, SEEK_SET);\n\t\n\tAutoFree buf = (char*)malloc(fileSize + 1);\n\tconst char* p = buf();\n\tfread(buf(), 1, fileSize, f);\n\tbuf()[fileSize - 1] = 0;\n\t\t\n\ttry {\n\t\t{\n\t\t\tP compiledFun;\n\t\t\tif (th.compile(p, compiledFun, true)) {\n\t\t\t\tpost(\"compiled OK.\\n\");\n\t\t\t\tcompiledFun->run(th);\n\t\t\t\tpost(\"done loading file\\n\");\n\t\t\t}\n\t\t}\n } catch (V& v) {\n post(\"error: \");\n v.print(th);\n post(\"\\n\");\n\t} catch (int err) {\n\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t} else {\n\t\t\tpost(\"error: %d\\n\", err);\n\t\t}\n\t} catch (std::bad_alloc& xerr) {\n\t\tpost(\"not enough memory\\n\");\n\t} catch (...) {\n\t\tpost(\"unknown error\\n\");\n\t}\n}\n\nvoid Thread::printStack()\n{\n\tbool between = false;\n\tsize_t n = stackDepth();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &stack[stackBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid Thread::printLocals()\n{\n\tbool between = false;\n\tsize_t n = numLocals();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &local[localBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid VM::setSampleRate(double inSampleRate)\n{\n\tar = Rate(inSampleRate, ar.blockSize);\n\tkr = Rate(ar, kDefaultControlBlockSize);\n}\n\nV VM::def(Arg key, Arg value)\n{\n\tbuiltins->putImpure(key, value); \n V dummy;\n assert(builtins->getInner(key, dummy));\n\treturn value;\n}\n\nV VM::def(const char* name, Arg value)\n{\n\tdef(V(getsym(name)), value);\n\treturn value;\n}\n\nV VM::def(const char* name, int takes, int leaves, PrimFun pf, const char* help, Arg value, bool setNoEach)\n{\n\tV aPrim = new Prim(pf, value, takes, leaves, name, help);\n\tdef(name, aPrim);\n\t\n\tif (setNoEach) aPrim.SetNoEachOps();\n\t\n\tif (help)\n\t\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\t\t\n\treturn aPrim;\n}\n\nV VM::defmcx(const char* name, int numArgs, PrimFun pf, const char* help, Arg value)\n{\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = mcx(numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\nV VM::defautomap(const char* name, const char* mask, PrimFun pf, const char* help, Arg value)\n{\n\tint numArgs = (int)strlen(mask);\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = automap(mask, numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\n\n#pragma mark STACK\n\n#define POPREFTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPFUNTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\nPOPREFTYPEDEF(Ref);\nPOPTYPEDEF(ZRef);\nPOPTYPEDEF(String);\nPOPTYPEDEF(List);\nPOPFUNTYPEDEF(Fun);\nPOPTYPEDEF(Form);\n\nvoid Thread::ApplyIfFun(V& v)\n{\n if (v.isFunOrPrim()) {\n SaveStack ss(*this);\n v.apply(*this);\n v = pop();\n }\n}\n\n\nV Thread::popZInList(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn() && !p.isVList()) {\n\t\twrongType(msg, \"Real or Signal or List of Reals or Signals\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popZIn(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef() || p.isZRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn()) {\n\t\twrongType(msg, \"Real or Signal\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popValue()\n{\n\tV p = pop().deref();\n ApplyIfFun(p);\n\treturn p;\n}\n\nP Thread::popVList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isVList()) {\n\t\twrongType(msg, \"Stream\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nP Thread::popZList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isZList()) {\n\t\twrongType(msg, \"Signal\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nint64_t Thread::popInt(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Real\", v);\n\t\n\tdouble f = v.f;\n\tint64_t i;\n\tif (f >= (double)LLONG_MAX) i = LLONG_MAX;\n\telse if (f <= (double)LLONG_MIN) i = LLONG_MIN;\n\telse i = (int64_t)f;\n\treturn i;\n}\n\ndouble Thread::popFloat(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Float\", v);\n\treturn v.f;\n}\n\nvoid Thread::tuck(size_t n, Arg v)\n{\n\tstack.push_back(V(0.));\n\tV* sp = &stack.back();\n\t\n\tfor (size_t i = 0; i < n; ++i)\n\t\tsp[-i] = sp[-i-1];\n\t\n\tsp[-n] = v;\n}\n\n///////////////////////////////////////\n\nbool Thread::compile(const char* inString, P& compiledFun, bool inTopLevel)\n{\t\n\tThread& th = *this;\n\tSaveCompileScope scs(th);\n\tif (inTopLevel) {\n\t\tmCompileScope = new TopCompileScope();\n\t} else {\n\t\tmCompileScope = new InnerCompileScope(new TopCompileScope());\n\t}\n\t\n\tP code;\n\tsetParseString(inString);\n\tgetLine();\n\tbool ok = parseElems(th, code);\n\tif (!ok || !code) {\n\t\tpost(\"parse error. %d\\n\", ok);\n\t\treturn false;\n\t}\n\t\t\n\tcompiledFun = new Fun(*this, new FunDef(*this, code, 0, th.mCompileScope->numLocals(), th.mCompileScope->numVars(), NULL));\n\t\n\treturn true;\n}\n\nint TopCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = CompileScope::directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) return scope;\n\n\tfor (size_t i = 0; i < mWorkspaceVars.size(); ++i) {\n\t\tif (mWorkspaceVars[i].mName() == inName()) {\n\t\t\treturn scopeWorkspace;\n\t\t}\n\t}\n\t\n\tV value;\n\tif (th.mWorkspace->get(th, inName(), value)) {\n\t\treturn scopeWorkspace;\n\t} else if (vm.builtins->get(th, inName, value)) {\n\t\toutBuiltIn = value;\n\t\treturn scopeBuiltIn;\n\t}\n\n\treturn scopeUndefined;\n}\n\n\nint CompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tfor (size_t i = 0; i < mLocals.size(); ++i) {\n\t\tif (mLocals[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeLocal;\n\t\t}\n\t}\n\tfor (size_t i = 0; i < mVars.size(); ++i) {\n\t\tif (mVars[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeFunVar;\n\t\t}\n\t}\n\t\n\treturn scopeUndefined;\n}\n\n\nint TopCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint InnerCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) \n\t\treturn scope;\n\n\tsize_t outerIndex;\n\tscope = mNext->indirectLookup(th, inName, outerIndex, outBuiltIn);\n\tif (scope == scopeUndefined) \n\t\treturn scopeUndefined;\n\t\n\tif (scope == scopeLocal || scope == scopeFunVar) {\n\t\tVarDef def;\n\t\tdef.mName = inName;\n\t\tdef.mIndex = mVars.size();\n\t\tdef.mFromScope = scope;\n\t\tdef.mFromIndex = outerIndex;\n\t\toutIndex = mVars.size();\n\t\tmVars.push_back(def);\n\t\treturn scopeFunVar;\n\t}\n\t\n\treturn scope;\n}\n\nint TopCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope != scopeUndefined && scope != scopeBuiltIn) \n\t\treturn scope; // already defined\n\t\t\n\tWorkspaceDef def;\n\tdef.mName = inName;\n\tmWorkspaceVars.push_back(def);\n\n\treturn scopeWorkspace;\n}\n\nint CompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope == scopeFunVar) {\n\t\tpost(\"Name %s is already in use in this scope as a free variable.\\n\", inName->cstr());\n\t\tthrow errSyntax;\n\t}\n\t\n\tif (scope == scopeUndefined) {\t\t\n\t\tLocalDef def;\n\t\tdef.mName = inName;\n\t\toutIndex = def.mIndex = mLocals.size();\n\t\tmLocals.push_back(def);\n\t}\n\treturn scopeLocal;\n}\n\nint InnerCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn innerBindVar(th, inName, outIndex);\n}\n\nCompileScope* ParenCompileScope::nextNonParen() const\n{\n\tCompileScope* scope = mNext();\n\twhile (scope->isParen()) {\n\t\tscope = scope->mNext();\n\t}\n\treturn scope;\n}\n\nint ParenCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->indirectLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\nint ParenCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\n//////////////////////\n\n\n\n\n"], ["/sapf/src/UGen.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n\nstruct MulAdd : public ThreeInputUGen\n{\n\tMulAdd(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MulAdd\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = *a * *b + *c;\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_neg;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_minus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstatic void madd_(Thread& th, Prim* prim)\n{\n\tV c = th.popZIn(\"*+ : c\");\n\tV b = th.popZIn(\"*+ : b\");\n\tV a = th.popZIn(\"*+ : a\");\n\n\tif (a.isReal() && b.isReal() && c.isReal()) {\n\t\tth.push(a.f * b.f + c.f);\n\t} else {\n\t\tif (c.isReal()) {\n\t\t\tif (c.f == 0.) {\n\t\t\t\tif (a.isReal() && a.f == 1.) { th.push(b); return; }\n\t\t\t\tif (b.isReal() && b.f == 1.) { th.push(a); return; }\n\t\t\t\tif (a.isReal() && a.f == -1.) { th.push(b.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tif (b.isReal() && b.f == -1.) { th.push(a.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tth.push(a.binaryOp(th, gBinaryOpPtr_mul, b)); return;\n\t\t\t}\n\t\t}\n\t\tif (a.isReal()) {\n\t\t\tif (a.f == 0.) { th.push(c); return; }\n\t\t\tif (a.f == 1.) { th.push(b.binaryOp(th, gBinaryOpPtr_plus, c)); return; }\n\t\t\tif (a.f == -1.) { th.push(b.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tif (b.isReal()) {\n\t\t\tif (b.f == 0.) { th.push(c); return; } \n\t\t\tif (b.f == 1.) { th.push(a.binaryOp(th, gBinaryOpPtr_plus, c)); return; } \n\t\t\tif (b.f == -1.) { th.push(a.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tth.push(new List(new MulAdd(th, a, b, c)));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Fadeout : Gen\n{\n\tZIn _a;\n\tint64_t _sustainTime;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadeout(Thread& th, Arg a, Z sustainTime, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_sustainTime = (int64_t)floor(th.rate.sampleRate * sustainTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_sustainTime = std::max(1LL, _sustainTime);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadeout\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_sustainTime <= 0) {\n\t\t\tif (_fadeTime <= 0) {\n\t\t\t\tend();\n\t\t\t} else {\n\t\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t\t_fadeTime -= framesToFill;\n\t\t\t\twhile (framesToFill) {\n\t\t\t\t\tint n = framesToFill;\n\t\t\t\t\tint astride;\n\t\t\t\t\tZ *a;\n\t\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\t setDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t_amp = amp;\n\t\t\t\t\t\t_a.advance(n);\n\t\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\t\tout += n;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t produce(framesToFill);\n\t\t\t}\n\t\t} else {\n int framesToFill = (int)std::min(_sustainTime, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _sustainTime -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\n\nstruct Fadein : Gen\n{\n\tZIn _a;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadein(Thread& th, Arg a, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = .001;\n\t\t_fade = pow(1000., 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadein\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_fadeTime <= 0) {\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t} else {\n\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t_fadeTime -= framesToFill;\n\t\t\twhile (framesToFill) {\n\t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t setDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t}\n\t\t\t}\n\t\t produce(framesToFill);\n\t\t}\n\t}\n};\n\nstatic void fadeout_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadeout : fadeTime\");\n\tZ sustain = th.popFloat(\"fadeout : sustainTime\");\n\tV in = th.popZIn(\"fadeout : in\");\n\n\tth.push(new List(new Fadeout(th, in, sustain, fade)));\n}\n\nstatic void fadein_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadein : fadeTime\");\n\tV in = th.popZIn(\"fadein : in\");\n\n\tth.push(new List(new Fadein(th, in, fade)));\n}\n\nstruct Endfade : Gen\n{\n\tZIn _a;\n\tint64_t _startupTime;\n\tint64_t _holdTime;\n\tint64_t _holdTimeRemaining;\n\tint64_t _fadeTime;\n\tZ _amp, _fade, _threshold;\n\t\n\tEndfade(Thread& th, Arg a, Z startupTime, Z holdTime, Z fadeTime, Z threshold) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_startupTime = (int64_t)floor(th.rate.sampleRate * startupTime + .5);\n\t\t_holdTime = (int64_t)floor(th.rate.sampleRate * holdTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_startupTime = std::max(0LL, _startupTime);\n\t\t_holdTime = std::max(1LL, _holdTime);\n\t\t_holdTimeRemaining = _holdTime;\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_threshold = threshold;\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Endfade\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (_startupTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _startupTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_startupTime -= n;\n\t\t\t\t}\n\t\t\t} else if (_holdTimeRemaining > 0) {\n \t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint framesFilled = 0;\n\t\t\t\t\tfor (int i = 0; i < n && _holdTimeRemaining > 0; ++i) {\n\t\t\t\t\t\tZ z = *a;\n\t\t\t\t\t\tif (std::abs(z) >= _threshold) {\n\t\t\t\t\t\t\t_holdTimeRemaining = _holdTime;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t--_holdTimeRemaining;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t++framesFilled;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(framesFilled);\n\t\t\t\t\tframesToFill -= framesFilled;\n\t\t\t\t\tout += framesFilled;\n\t\t\t\t}\n\t\t\t} else if (_fadeTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _fadeTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_fadeTime -= n;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void endfade_(Thread& th, Prim* prim)\n{\n\tZ threshold = th.popFloat(\"endfade : threshold\");\n\tZ fade = th.popFloat(\"endfade : fadeTime\");\n\tZ hold = th.popFloat(\"endfade : holdTime\");\n\tZ startup = th.popFloat(\"endfade : startupTime\");\n\tV in = th.popZIn(\"endfade : in\");\n\n\tth.push(new List(new Endfade(th, in, startup, hold, fade, threshold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Imps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, invdur_;\n\tZ freqmul_;\n\tbool once;\n\n\tImps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate), once(false)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Imps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tonce = true;\n\t\t\t\t}\n\n\t\t\t\tif (once) {\n\t\t\t\t\tout[i] = val_;\n\t\t\t\t\tonce = false;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\t\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Steps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\n\tSteps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Steps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Gates : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn hold_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, hdur_;\n\tZ freqmul_;\n\n\tGates(Thread& th, Arg durs, Arg vals, Arg hold, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, hold)), durs_(durs), vals_(vals), hold_(hold), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Gates\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_) || hold_.onez(th, hdur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = phase_ < hdur_ ? val_ : 0.;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Lines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, slope_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Lines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tslope_ = (newval_ - oldval_) / dur_;\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_ + slope_ * phase_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct XLines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, ratio_, step_;\n\tZ phase_, dur_, invdur_, freq_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tXLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"XLines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t\t//oldval_ = oldval_ * pow(ratio_, phase_ * invdur_);\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = pow(ratio_, freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\toldval_ *= step_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_ * pow(ratio_, phase_ * invdur_);\n\n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\trate += rateStride;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Curves : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn curves_;\n\tZIn rate_;\n\tZ oldval_, newval_, step_;\n\tZ phase_, dur_, curve_, invdur_, freq_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tCurves(Thread& th, Arg durs, Arg vals, Arg curves, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, curves)), durs_(durs), vals_(vals), curves_(curves), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Curves\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tdur_ = std::max(dur_, 1e-4);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n //!! not correct\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n \n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n \n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Cubics : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tCubics(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Cubics\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tc0 = y1;\n\t\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n/*\nd = duration of accelerando in beats\na = duration of accelerando in seconds\n\nr0 = starting tempo in beats per second\nr1 = ending tempo in beats per second\n\nc = (r1 - r0) / d\n\nduration of accelerando in seconds\na = log(r1/r0) / c\n\ntempo for next sample\nr(0) = r0\nr(n) = r(n-1) * exp(c / sr)\n\nbeat for next sample\nb(n) = r(n)/c - r0/c\n\nb(0) = 0\nb(n) = b(n-1) + r(n)/sr \n\n*/\n\n\nstruct Tempo : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ beat_ = 0.;\n\tZ dur_ = 0.;\n\tZ lastTime_ = 0.;\n\tZ nextTime_ = 0.;\n\tZ invsr_;\n\tZ c_, r0_, r1_;\n\tbool once = true;\n\n\tTempo(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Tempo\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t// numerically it would be better to subtract off dur each time, but we need to recreate the same loss of precision over time\n\t\t\t\t// as will be experienced from an integration of tempo occuring outside of this generator. otherwise there would be a drift\n\t\t\t\t// between when tempo changes occur and the beat time as integrated from the tempo.\n\t\t\t\twhile (beat_ >= nextTime_) {\n\t\t\t\t\tdo {\n\t\t\t\t\t\tr0_ = r1_;\n\t\t\t\t\t\tif (vals_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tc_ = (r1_ - r0_) / dur_;\n\t\t\t\t\tlastTime_ = nextTime_;\n\t\t\t\t\tnextTime_ += dur_;\n\t\t\t\t}\n\n\t\t\t\tZ tempo = *rate * (r0_ + (beat_ - lastTime_) * c_);\n\t\t\t\tout[i] = tempo;\n\t\t\t\tbeat_ += tempo * invsr_;\n\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Beats : public Gen\n{\n\tZIn tempo_;\n\tZ beat_ = 0.;\n\tZ invsr_;\n\n\tBeats(Thread& th, Arg tempo) : Gen(th, itemTypeZ, tempo.isFinite()), tempo_(tempo),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Beats\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ beat = beat_;\n\t\twhile (framesToFill) {\n\t\t\tZ* tempo;\n\t\t\tint n = framesToFill;\n\t\t\tint tempoStride;\n\t\t\tif (tempo_(th, n, tempoStride, tempo)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tZ invsr = invsr_;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = beat;\n\t\t\t\tbeat += *tempo * invsr;\n\t\t\t\ttempo += tempoStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttempo_.advance(n);\n\t\t}\n\t\tbeat_ = beat;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct ADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn rate_;\n\tint stage_ = 0;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ noteOff_;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tZ beat_ = 0.;\n\tbool once = true;\n\tint sustainStage_;\n\n\tADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg rate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\trate_(rate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\t\tnoteOff_ = durs_[sustainStage_];\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"ADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (1) {\n\t\t\t\t\tif (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else if (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ < NumStages){\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tbeat_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct GatedADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn gate_;\n\tint stage_ = NumStages;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\tint sustainStage_;\n\n\tGatedADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg gate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\tgate_(gate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"GatedADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* gate;\n\t\t\tint n = framesToFill;\n\t\t\tint gateStride;\n\t\t\tif (gate_(th, n, gateStride, gate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n Z g = *gate;\n gate += gateStride;\n if (stage_ >= NumStages) {\n // waiting for trigger\n if (*gate > 0.) {\n stage_ = 0;\n } else {\n out[i] = 0.;\n --framesToFill;\n continue;\n }\n }\n\t\t\t\twhile (1) { \n if (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else if (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tgate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void imps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"imps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Imps(th, durs, vals, rate)));\n}\n\nstatic void steps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"steps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Steps(th, durs, vals, rate)));\n}\n\nstatic void gates_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"gates : rate\");\n\tV hold = th.pop();\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Gates(th, durs, vals, hold, rate)));\n}\n\nstatic void lines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Lines(th, durs, vals, rate)));\n}\n\nstatic void xlines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"xlines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new XLines(th, durs, vals, rate)));\n}\n\nstatic void cubics_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"cubics : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Cubics(th, vals, rate)));\n}\n\nstatic void curves_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"curves : rate\");\n\tV durs = th.pop();\n\tV param = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Curves(th, durs, vals, param, rate)));\n}\n\nstatic void tempo_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"tempo : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Tempo(th, vals, rate)));\n}\n\nstatic void beats_(Thread& th, Prim* prim)\n{\n\tV tempo = th.popZIn(\"beats : tempo\");\n\n\tth.push(new List(new Beats(th, tempo)));\n}\n\nstatic void adsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"adsr : tempo\");\n\tZ noteDur = th.popFloat(\"adsr : noteDur\");\n\tZ amp = th.popFloat(\"adsr : amp\");\n\n\tP list = th.popList(\"adsr : [attack decay sustain release]\");\n\tconst int kNumADSRStages = 4;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"adsr : [attack decay sustain release] list should have 4 elements.\");\n\t}\n\t\t\n\tZ relTime = env[3];\n\tZ susLvl = env[2];\n\tZ dcyTime = env[1];\n\tZ atkTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 2)));\n}\n\nstatic void dadsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dadsr : tempo\");\n\tZ noteDur = th.popFloat(\"dadsr : noteDur\");\n\tZ amp = th.popFloat(\"dadsr : amp\");\n\n\tP list = th.popList(\"dadsr : [delay attack decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 5;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack decay sustain release] list should have 5 elements.\");\n\t}\n\t\n\tZ relTime = env[4];\n\tZ susLvl = env[3];\n\tZ dcyTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 3)));\n}\n\nstatic void dahdsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dahdsr : tempo\");\n\tZ noteDur = th.popFloat(\"dahdsr : noteDur\");\n\tZ amp = th.popFloat(\"dahdsr : amp\");\n\n\tP list = th.popList(\"dahdsr : [delay attack hold decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 6;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack hold decay sustain release] list should have 6 elements.\");\n\t}\n\t\n\tZ relTime = env[5];\n\tZ susLvl = env[4];\n\tZ dcyTime = env[3];\n\tZ hldTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, hldTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., 0., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 4)));\n}\n\n\n\n\nstruct K2A : public Gen\n{\n\tint n_;\n\tint remain_;\n\tZ slopeFactor_;\n\tBothIn vals_;\n\tZ oldval_, newval_, slope_;\n\tbool once = true;\n\n\tK2A(Thread& th, int n, Arg vals) : Gen(th, itemTypeZ, vals.isFinite()), vals_(vals),\n\t\tn_(n), remain_(0), slopeFactor_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2A\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, oldval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tif (vals_.onez(th, newval_) ) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tslope_ = slopeFactor_ * (newval_ - oldval_);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = oldval_;\n\t\t\t\toldval_ += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct K2AC : public Gen\n{\n\tBothIn vals_;\n\tint n_;\n\tint remain_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ slope_;\n\tbool once = true;\n\n\tK2AC(Thread& th, int n, Arg vals)\n\t\t: Gen(th, itemTypeZ, vals.isFinite()), vals_(vals), n_(n), remain_(0),\n\t\tphase_(0), slope_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2AC\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tx = 0.;\n\t\t\t\ty0 = y1;\n\t\t\t\ty1 = y2;\n\t\t\t\ty2 = y3;\n\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tc0 = y1;\n\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\t\t\t\tx += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void k2a_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV a = th.popZIn(\"kr : signal\");\n\t\n\tth.push(new List(new K2A(th, n, a)));\n}\n\nstatic void k2ac_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"krc : n\");\n\tV a = th.popZIn(\"krc : signal\");\n\t\n\tth.push(new List(new K2AC(th, n, a)));\n}\n\nP gK2A;\nP gK2AC;\n\nstatic void kr_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"kr : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2A->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\nstatic void krc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"krc : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, (int)n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2AC->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFNoise0 : public Gen\n{\n\tZIn rate_;\n\tZ val_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise0(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise0\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\tval_ = r.drand2();\n\t\t\t\t}\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise1 : public Gen\n{\n\tZIn rate_;\n\tZ oldval_, newval_;\n\tZ slope_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise1(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\tnewval_ = oldval_ = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise1\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\tnewval_ = r.drand2();\n\t\t\t\t\tslope_ = newval_ - oldval_;\n\t\t\t\t}\n\t\t\t\tout[i] = oldval_ + slope_ * x;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise3 : public Gen\n{\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise3(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\ty1 = r.drand2();\n\t\ty2 = r.drand2();\n\t\ty3 = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise3\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\ty3 = r.drand2() * 0.8; // 0.8 because cubic interpolation can overshoot up to 1.25 if inputs are -1,1,1,-1.\n\t\t\t\t\tc0 = y1;\n\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void lfnoise0_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise0 : freq\");\n\n\tth.push(new List(new LFNoise0(th, rate)));\n}\n\nstatic void lfnoise1_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise1 : freq\");\n\n\tth.push(new List(new LFNoise1(th, rate)));\n}\n\nstatic void lfnoise3_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise3 : freq\");\n\n\tth.push(new List(new LFNoise3(th, rate)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\ntemplate \nstruct SymmetricEnv : public Gen\n{\n\tZ xinc;\n\tZ x;\n\tint64_t n_;\n\t\n\tSymmetricEnv(Thread& th, Z dur, Z scale) : Gen(th, itemTypeZ, true), x(-scale)\n\t{\n\t\tZ n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\tn_ = (int64_t)n;\n\t\txinc = 2. * scale / n;\n\t}\n\t\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tZ* out = mOut->fulfillz(n);\n\t\tstatic_cast(this)->F::calc(n, out);\n\t\tmOut = mOut->nextp();\n\t\tn_ -= n;\n\t\tif (n_ == 0) {\n\t\t\tend();\n\t\t}\n\t}\n};\n\ntemplate \nstruct TriggeredSymmetricEnv : public Gen\n{\n\tZIn trig_;\n\tBothIn dur_;\n\tBothIn amp_;\n\tZ xinc;\n\tZ x;\n\tZ scale_;\n\tZ ampval_;\n\tint64_t n_ = 0;\n\t\n\tTriggeredSymmetricEnv(Thread& th, Arg trig, Arg dur, Arg amp, Z scale)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), dur_(dur), amp_(amp), scale_(scale)\n\t{\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (n_) {\n\t\t\t\tn = (int)std::min((int64_t)n, n_);\n\t\t\t\tstatic_cast(this)->F::calc(n, ampval_, out);\n\t\t\t\tn_ -= n;\n\t\t\t\ttrig += n * trigStride;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tZ dur;\n\t\t\t\t\t\tif (dur_.onez(th, dur)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tx = -scale_;\n\t\t\t\t\t\tZ zn = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\t\t\t\t\tn_ = (int64_t)zn;\n\t\t\t\t\t\txinc = 2. * scale_ / zn;\n\t\t\t\t\t\tint n2 = (int)std::min((int64_t)(n-i), n_);\n\t\t\t\t\t\tstatic_cast(this)->F::calc(n2, ampval_, out+i);\n\t\t\t\t\t\tn_ -= n2;\n\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\ti += n2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct TriggeredSignal : public Gen\n{\n\tZIn trig_;\n\tZIn list_;\n\tBothIn amp_;\n\tV in_;\n\tZ ampval_;\n\tbool waiting_ = true;\n\tZ counter_ = 0.;\n\t\n\tTriggeredSignal(Thread& th, Arg trig, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), amp_(amp), in_(in)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"TriggeredSignal\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!waiting_) {\n\t\t\t\tZ* list;\n\t\t\t\tint listStride;\n\t\t\t\tif (list_(th, n, listStride, list)) {\n\t\t\t\t\twaiting_ = true;\n\t\t\t\t\tgoto waiting;\n\t\t\t\t}\n\t\t\t\tZ amp = ampval_;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = amp * *list;\n\t\t\t\t\tlist += listStride;\n\t\t\t\t}\n\t\t\t\tlist_.advance(n);\n\t\t\t} else {\n\t\twaiting:\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tV in = in_;\n\t\t\t\t\t\tif (in.isFunOrPrim()) {\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tth.push(counter_);\n\t\t\t\t\t\t\t\tin.apply(th);\n\t\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tin = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcounter_ += 1.;\n\t\t\t\t\t\tlist_.set(in);\n\t\t\t\t\t\tZ* list;\n\t\t\t\t\t\tint listStride;\n\t\t\t\t\t\tint n2 = n-i;\n\t\t\t\t\t\tif (list_(th, n2, listStride, list)) {\n\t\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tZ amp = ampval_;\n\t\t\t\t\t\t\tfor (int j = i; j < i+n2; ++j) {\n\t\t\t\t\t\t\t\tout[j] = amp * *list;\n\t\t\t\t\t\t\t\tlist += listStride;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\t\ti += n2;\n\t\t\t\t\t\t\tlist_.advance(n2);\n\t\t\t\t\t\t\twaiting_ = i < n;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tsig_(Thread& th, Prim* prim)\n{\n\tV amp = th.pop();\n\tV in = th.pop();\n\tV trig = th.popZIn(\"tsig : trig\");\n\n\tth.push(new List(new TriggeredSignal(th, trig, in, amp)));\n}\n\nstruct ParEnv : public SymmetricEnv\n{\n\tParEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"ParEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void parenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"parenv : dur\");\n\n\tth.push(new List(new ParEnv(th, dur)));\n}\n\nstruct TParEnv : public TriggeredSymmetricEnv\n{\n\tTParEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TParEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tparenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tparenv : amp\");\n\tV dur = th.popZIn(\"tparenv : dur\");\n\tV trig = th.popZIn(\"tparenv : trig\");\n\n\tth.push(new List(new TParEnv(th, trig, dur, amp)));\n}\n\nstruct QuadEnv : public SymmetricEnv\n{\n\tQuadEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"QuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2*x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void quadenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"quadenv : dur\");\n\n\tth.push(new List(new QuadEnv(th, dur)));\n}\n\nstruct TQuadEnv : public TriggeredSymmetricEnv\n{\n\tTQuadEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TQuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2*x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tquadenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tquadenv : amp\");\n\tV dur = th.popZIn(\"tquadenv : dur\");\n\tV trig = th.popZIn(\"tquadenv : trig\");\n\n\tth.push(new List(new TQuadEnv(th, trig, dur, amp)));\n}\n\n\nstruct OctEnv : public SymmetricEnv\n{\n\tOctEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"OctEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\t\n\t\t\tout[i] = 1. - x4*x4;\n\t\t\t\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void octenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"octenv : dur\");\n\n\tth.push(new List(new OctEnv(th, dur)));\n}\n\nstruct TOctEnv : public TriggeredSymmetricEnv\n{\n\tTOctEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TOctEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\tout[i] = amp * (1. - x4*x4);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void toctenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toctenv : amp\");\n\tV dur = th.popZIn(\"toctenv : dur\");\n\tV trig = th.popZIn(\"toctenv : trig\");\n\n\tth.push(new List(new TOctEnv(th, trig, dur, amp)));\n}\n\nstruct TriEnv : public SymmetricEnv\n{\n\tTriEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TriEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. - fabs(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trienv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trienv : dur\");\n\n\tth.push(new List(new TriEnv(th, dur)));\n}\n\nstruct TTriEnv : public TriggeredSymmetricEnv\n{\n\tTTriEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTriEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * (1. - fabs(x));\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrienv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrienv : amp\");\n\tV dur = th.popZIn(\"ttrienv : dur\");\n\tV trig = th.popZIn(\"ttrienv : trig\");\n\n\tth.push(new List(new TTriEnv(th, trig, dur, amp)));\n}\n\nstruct Tri2Env : public SymmetricEnv\n{\n\tTri2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Tri2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tri2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"tri2env : dur\");\n\n\tth.push(new List(new Tri2Env(th, dur)));\n}\n\nstruct TTri2Env : public TriggeredSymmetricEnv\n{\n\tTTri2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTri2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttri2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttri2env : amp\");\n\tV dur = th.popZIn(\"ttri2env : dur\");\n\tV trig = th.popZIn(\"ttri2env : trig\");\n\n\tth.push(new List(new TTri2Env(th, trig, dur, amp)));\n}\n\n\nstruct TrapezEnv : public SymmetricEnv\n{\n\tTrapezEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapezenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapezenv : dur\");\n\n\tth.push(new List(new TrapezEnv(th, dur)));\n}\n\n\nstruct TTrapezEnv : public TriggeredSymmetricEnv\n{\n\tTTrapezEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapezenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapezenv : amp\");\n\tV dur = th.popZIn(\"ttrapezenv : dur\");\n\tV trig = th.popZIn(\"ttrapezenv : trig\");\n\n\tth.push(new List(new TTrapezEnv(th, trig, dur, amp)));\n}\n\n\nstruct Trapez2Env : public SymmetricEnv\n{\n\tTrapez2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Trapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapez2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapez2env : dur\");\n\n\tth.push(new List(new Trapez2Env(th, dur)));\n}\n\nstruct TTrapez2Env : public TriggeredSymmetricEnv\n{\n\tTTrapez2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapez2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapez2env : amp\");\n\tV dur = th.popZIn(\"ttrapez2env : dur\");\n\tV trig = th.popZIn(\"ttrapez2env : trig\");\n\n\tth.push(new List(new TTrapez2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct CosEnv : public SymmetricEnv\n{\n\tCosEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"CosEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void cosenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"cosenv : dur\");\n\n\tth.push(new List(new CosEnv(th, dur)));\n}\n\n\nstruct TCosEnv : public TriggeredSymmetricEnv\n{\n\tTCosEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TCosEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tcosenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tcosenv : amp\");\n\tV dur = th.popZIn(\"tcosenv : dur\");\n\tV trig = th.popZIn(\"tcosenv : trig\");\n\n\tth.push(new List(new TCosEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct HanEnv : public SymmetricEnv\n{\n\tHanEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"HanEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void hanenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"hanenv : dur\");\n\n\tth.push(new List(new HanEnv(th, dur)));\n}\n\n\nstruct THanEnv : public TriggeredSymmetricEnv\n{\n\tTHanEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THanEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void thanenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"thanenv : amp\");\n\tV dur = th.popZIn(\"thanenv : dur\");\n\tV trig = th.popZIn(\"thanenv : trig\");\n\n\tth.push(new List(new THanEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct Han2Env : public SymmetricEnv\n{\n\tHan2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Han2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void han2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"han2env : dur\");\n\n\tth.push(new List(new Han2Env(th, dur)));\n}\n\n\nstruct THan2Env : public TriggeredSymmetricEnv\n{\n\tTHan2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THan2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = amp * y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void than2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"than2env : amp\");\n\tV dur = th.popZIn(\"than2env : dur\");\n\tV trig = th.popZIn(\"than2env : trig\");\n\n\tth.push(new List(new THan2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct GaussEnv : public SymmetricEnv\n{\n\tZ widthFactor;\n\tGaussEnv(Thread& th, Z dur, Z width) : SymmetricEnv(th, dur, 1.), widthFactor(-1. / (2. * width * width)) {}\n\t\n\tvirtual const char* TypeName() const override { return \"GaussEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = exp(x * x * widthFactor);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void gaussenv_(Thread& th, Prim* prim)\n{\n\tZ width = th.popFloat(\"gaussenv : width\");\n\tZ dur = th.popFloat(\"gaussenv : dur\");\n\n\tth.push(new List(new GaussEnv(th, dur, width)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Pause : public Gen\n{\n\tZIn _in;\n\tZIn _amp;\n\t\n\tPause(Thread& th, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, amp.isFinite()), _in(in), _amp(amp)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pause\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *amp;\n\t\t\tint n, ampStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_amp(th, n, ampStride, amp) ) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint framesThisTime = n;\n\t\t\twhile (framesThisTime) {\n\t\t\t\tint zerolen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp <= 0.; ++i) {\n\t\t\t\t\t*out++ = 0.;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t++zerolen;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= zerolen;\n\t\t\t\t\n\t\t\t\tint seglen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp > 0.; ++i) {\n\t\t\t\t\t++seglen;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tamp -= seglen * ampStride;\n\n\t\t\t\tint seglenRemain = seglen;\n\t\t\t\twhile (seglenRemain) {\n\t\t\t\t\tZ *in;\n\t\t\t\t\tint n2, inStride;\n\t\t\t\t\tn2 = seglenRemain;\n\t\t\t\t\tif (_in(th, n2, inStride, in) ) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0; i < n2; ++i) {\n\t\t\t\t\t\tout[i] = *amp * *in;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t}\n\t\t\t\t\tout += n2;\n\t\t\t\t\t_in.advance(n2);\n\t\t\t\t\tseglenRemain -= n2;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= seglen;\n\t\t\t\t\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\t_amp.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pause_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"pause : amp\");\n\tV in = th.popZIn(\"pause : in\");\n\n\tth.push(new List(new Pause(th, in, amp)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nP s_tempo;\nP s_dt;\nP s_out;\n\nclass OverlapAddInputSource;\nclass OverlapAddOutputChannel;\n\nclass OverlapAddBase : public Object\n{\nprotected:\n\tOverlapAddOutputChannel* mOutputs = nullptr;\n\tP mActiveSources;\n\tbool mFinished = false;\n\tbool mNoMoreSources = false;\n\tint mNumChannels;\npublic:\n OverlapAddBase(int numChannels);\n virtual ~OverlapAddBase();\n\n\tvirtual const char* TypeName() const override { return \"OverlapAddBase\"; }\n\n\tvirtual bool pull(Thread& th);\n\tvirtual void addNewSources(Thread& th, int blockSize) = 0;\n\n\tP createOutputs(Thread& th);\n void fulfillOutputs(int blockSize);\n void produceOutputs(int shrinkBy);\n int renderActiveSources(Thread& th, int blockSize, bool& anyDone);\n void removeInactiveSources();\n};\n\nclass OverlapAdd : public OverlapAddBase\n{\nprotected:\n\tVIn mSounds;\n\tBothIn mHops;\n\tZIn mRate;\n\tZ mBeatTime;\n\tZ mNextEventBeatTime;\n\tZ mEventCounter;\n\tZ mRateMul;\n\tint64_t mSampleTime;\n\tint64_t mPrevChaseTime;\n\t\n\tP mChasedSignals;\n\npublic:\n\tOverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels);\n\tvirtual ~OverlapAdd() {}\n\t\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n\t\t\n\tvirtual void addNewSources(Thread& th, int blockSize) override;\n\tvoid chaseToTime(Thread& th, int64_t inSampleTime);\n};\n\nclass OverlapAddInputSource : public Object\n{\npublic:\n\tP mNextSource;\n\tstd::vector mInputs;\n\tint mOffset;\n\tbool mSourceDone;\n\t\n\tOverlapAddInputSource(Thread& th, List* channels, int inOffset, P const& inNextSource) \n\t\t: mNextSource(inNextSource), mOffset(inOffset), mSourceDone(false)\n\t{\n\t\tif (channels->isVList()) {\n\t\t\tP packedChannels = channels->pack(th);\n\t\t\tArray* a = packedChannels->mArray();\n\t\t\t\n\t\t\t// put channels into mInputs\n\t\t\tmInputs.reserve(a->size());\n\t\t\tfor (int i = 0; i < a->size(); ++i) {\n\t\t\t\tZIn zin(a->v()[i]);\n\t\t\t\tmInputs.push_back(zin);\n\t\t\t}\n\t\t} else {\n\t\t\tZIn zin(channels);\n\t\t\tmInputs.push_back(zin);\n\t\t}\n\t}\n\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n};\n\nclass OverlapAddOutputChannel : public Gen\n{\n\tfriend class OverlapAddBase;\n\tP mOverlapAddBase;\n\tOverlapAddOutputChannel* mNextOutput;\n\t\npublic:\t\n\tOverlapAddOutputChannel(Thread& th, OverlapAddBase* inOverlapAdd)\n : Gen(th, itemTypeZ, false), mOverlapAddBase(inOverlapAdd), mNextOutput(nullptr)\n\t{\n\t}\n\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmOverlapAddBase = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"OverlapAddOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mOverlapAddBase->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nOverlapAddBase::OverlapAddBase(int numChannels)\n\t: mNumChannels(numChannels)\n{\n}\n\nOverlapAddBase::~OverlapAddBase()\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tOverlapAddOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nOverlapAdd::OverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels)\n\t: OverlapAddBase(numChannels),\n mSounds(sounds), mHops(hops), mRate(rate),\n\tmBeatTime(0.), mNextEventBeatTime(0.), mEventCounter(0.), mRateMul(th.rate.invSampleRate),\n\tmSampleTime(0), mPrevChaseTime(0),\n\tmChasedSignals(chasedSignals)\n{\n}\n\nP OverlapAddBase::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n OverlapAddOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n OverlapAddOutputChannel* c = new OverlapAddOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nvoid OverlapAdd::addNewSources(Thread& th, int blockSize)\n{\t\t\t\n\t// integrate tempo and add new sources.\n\tZ* rate;\n\tint rateStride;\n\tif (mRate(th, blockSize, rateStride, rate)) {\n\t\tmNoMoreSources = true;\n\t} else if (!mNoMoreSources) {\n\t\tZ beatTime = mBeatTime;\n\t\tZ nextEventBeatTime = mNextEventBeatTime;\n\t\tZ ratemul = mRateMul;\n\t\tfor (int i = 0; i < blockSize; ++i) {\n\t\t\twhile (beatTime >= nextEventBeatTime) {\n\t\t\t\n\t\t\t\tchaseToTime(th, mSampleTime + i);\n\t\t\t\n\t\t\t\tV newSource;\n\t\t\t\tif (mSounds.one(th, newSource)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\tif (newSource.isFun()) {\n\t\t\t\t\tSaveStack ss(th);\t\n\t\t\t\t\tth.push(mEventCounter);\n\t\t\t\t\tnewSource.apply(th);\n\t\t\t\t\tnewSource = th.pop();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tV out;\n\t\t\t\tZ deltaTime;\n\t\t\t\tif (mHops.onez(th, deltaTime)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (newSource.isForm()) {\n\t\t\t\t\tif (mChasedSignals()) {\n\t\t\t\t\t\tV parents[2];\n\t\t\t\t\t\tparents[0] = mChasedSignals;\n\t\t\t\t\t\tparents[1] = newSource;\n\t\t\t\t\t\tnewSource = linearizeInheritance(th, 2, parents);\n\t\t\t\t\t}\n\t\t\t\t\tnewSource.dot(th, s_out, out);\n\t\t\t\t\tV hop;\n\t\t\t\t\tif (newSource.dot(th, s_dt, hop) && hop.isReal()) {\n\t\t\t\t\t\tdeltaTime = hop.f;\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\t\t\t\t\tout = newSource;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// must be a finite array with fewer than mNumChannels\n\t\t\t\tif (out.isZList() || (out.isVList() && out.isFinite())) {\n\t\t\t\t\tList* s = (List*)out.o();\n\t\t\t\t\t// create an active source:\n\t\t\t\t\tP source = new OverlapAddInputSource(th, s, i, mActiveSources);\n\t\t\t\t\tmActiveSources = source;\n\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\tnextEventBeatTime += deltaTime;\n\t\t\t\tmEventCounter += 1.;\n\t\t\t}\n\t\t\tbeatTime += *rate * ratemul;\n\t\t\trate += rateStride;\n\t\t}\n\t\tmBeatTime = beatTime;\n\t\tmNextEventBeatTime = nextEventBeatTime;\n\t\tmSampleTime += blockSize;\n\t\t\n\t\tmRate.advance(blockSize);\n\n\t\tchaseToTime(th, mSampleTime);\n\t}\n}\n\nvoid OverlapAddBase::fulfillOutputs(int blockSize)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut) {\n\t\t\tZ* out = output->mOut->fulfillz(blockSize);\n\t\t\tmemset(out, 0, output->mBlockSize * sizeof(Z));\n\t\t}\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nint OverlapAddBase::renderActiveSources(Thread& th, int blockSize, bool& anyDone)\n{\n\tint maxProduced = 0;\n\tOverlapAddInputSource* source = mActiveSources();\n\twhile (source) {\n\t\tint offset = source->mOffset;\n\t\tint pullSize = blockSize - offset;\n\t\tstd::vector& sourceChannels = source->mInputs;\n\t\tbool allOutputsDone = true; // initial value for reduction on &&\n\t\tOverlapAddOutputChannel* output = mOutputs;\n\t\tfor (size_t j = 0; j < sourceChannels.size() && output; ++j, output = output->mNextOutput) {\n\t\t\tif (output->mOut) {\n\t\t\t\tZIn& zin = sourceChannels[j];\n\t\t\t\tif (zin.mIsConstant && zin.mConstant.f == 0.)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tint n = pullSize;\n\t\t\t\tZ* out = output->mOut->mArray->z() + offset;\n\t\t\t\tif (!zin.mix(th, n, out)) {\n\t\t\t\t\tallOutputsDone = false;\n\t\t\t\t}\n\t\t\t\tmaxProduced = std::max(maxProduced, n);\n\t\t\t}\n\t\t}\n\t\tsource->mOffset = 0;\n\t\tif (allOutputsDone) {\n\t\t\t// mark for removal from mActiveSources\n\t\t\tsource->mSourceDone = true;\n anyDone = true;\n\t\t}\n\t\tsource = source->mNextSource();\n\t}\n\treturn maxProduced;\n}\n\nvoid OverlapAddBase::removeInactiveSources()\n{\n\tP source = mActiveSources();\n\tP prevSource = nullptr;\n\tmActiveSources = nullptr;\n\t\n\twhile (source) {\n\t\tP nextSource = source->mNextSource;\n\t\tsource->mNextSource = nullptr;\n\t\tif (!source->mSourceDone) {\n\t\t\tif (prevSource()) prevSource->mNextSource = source;\n\t\t\telse mActiveSources = source;\n prevSource = source;\n\t\t}\n\t\tsource = nextSource;\n\t}\n}\n\nvoid OverlapAddBase::produceOutputs(int shrinkBy)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nbool OverlapAddBase::pull(Thread& th)\n{\n\tif (mFinished) {\n\t\treturn mFinished;\n }\n\t\n\tOverlapAddOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\taddNewSources(th, blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n bool anyDone = false;\n\tint maxProduced = renderActiveSources(th, blockSize, anyDone);\n\t\t\t\n\tmFinished = mNoMoreSources && mActiveSources() == nullptr;\n\tint shrinkBy = mFinished ? blockSize - maxProduced : 0;\n\t\n\tproduceOutputs(shrinkBy);\n\n\tif (anyDone)\n removeInactiveSources();\n\t\n\treturn mFinished; \n}\n\nvoid OverlapAdd::chaseToTime(Thread& th, int64_t inSampleTime)\n{\n\tint64_t n = inSampleTime - mPrevChaseTime;\n\tmPrevChaseTime = inSampleTime;\n\n\tif (mChasedSignals() && n > 0) {\n\t\tmChasedSignals = mChasedSignals->chaseForm(th, n);\n\t}\n}\n\n\nconst int64_t kMaxOverlapAddChannels = 10000;\n\nstatic void ola_(Thread& th, Prim* prim)\n{\n\tint64_t numChannels = th.popInt(\"ola : numChannels\");\n\tV rate = th.pop();\n\tV hops = th.popZInList(\"ola : hops\");\n\tV sounds = th.pop();\n\n\tif (numChannels > kMaxOverlapAddChannels) {\n\t\tpost(\"ola : too many channels\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tP chasedSignals;\n\tif (rate.isForm()) {\n\t\tchasedSignals = (Form*)rate.o();\n\t\trate = 1.;\n\t\tchasedSignals->dot(th, s_tempo, rate);\n\t}\n\n\tP ola = new OverlapAdd(th, sounds, hops, rate, chasedSignals, (int)numChannels);\n\t\n\tth.push(ola->createOutputs(th));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ITD;\n\nclass ITD_OutputChannel : public Gen\n{\n\tfriend class ITD;\n\tP mITD;\n\t\npublic:\t\n\tITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmITD = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ITD_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nstruct ITD : public Gen\n{\n\tZIn in_;\n\tZIn pan_;\n\tZ maxdelay_;\n\tZ half;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\n\tITD_OutputChannel* mLeft;\n\tITD_OutputChannel* mRight;\n\t\n\tITD(Thread& th, Arg in, Arg pan, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), pan_(pan), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\thalf = (int32_t)ceil(sr * maxdelay * .5 + .5);\n\t\tbufSize = NEXTPOWEROFTWO(2 * (int)half + 3);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~ITD() { delete mLeft; delete mRight; free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"ITD\"; }\n\t\n\tP createOutputs(Thread& th);\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, panStride;\n\t\t\tZ *in, *pan;\n\t\t\tif (in_(th, n, inStride, in) || pan_(th, n, panStride, pan)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., *pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Lout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., -*pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Rout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tRout += Routstride;\n\t\t\t\t\t}\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tpan += panStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tpan_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nITD_OutputChannel::ITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD) : Gen(th, itemTypeZ, inFinite), mITD(inITD)\n{\n}\n\nvoid ITD_OutputChannel::pull(Thread& th)\n{\n\tmITD->pull(th);\n}\n\nP ITD::createOutputs(Thread& th)\n{\n\tmLeft = new ITD_OutputChannel(th, finite, this);\n\tmRight = new ITD_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\nstatic void itd_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"itd : maxdelay\");\n\tV pan = th.popZIn(\"itd : pan\");\n\tV in = th.popZIn(\"itd : in\");\n \n\tP itd = new ITD(th, in, pan, maxdelay);\n\n\tP s = itd->createOutputs(th);\n\n\tth.push(s);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ninline Z fast_sin1(Z x)\n{\n\tx = x - floor(x + .5);\n\t\n Z y = x * (8. - 16. * fabs(x));\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\ninline Z fast_cos1(Z x)\n{\n\treturn fast_sin1(x + .25);\n}\n\ninline Z fast_pan(Z x)\n{\n\tZ y = .75 + x * (.5 - .25 * x);\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\nstruct Pan2Out;\n\nstruct Pan2 : public Object\n{\n\tZIn _in;\n\tZIn _pos;\n\t\n\tPan2Out* mLeft;\n\tPan2Out* mRight;\n\t\t\n\tPan2(Thread& th, Arg inIn, Arg inPos)\n\t\t: _in(inIn), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inIn, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Pan2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Pan2Out : public Gen\n{\n\tP mPan2;\n\t\n\tPan2Out(Thread& th, bool inFinite, P const& inPan2) : Gen(th, itemTypeZ, inFinite), mPan2(inPan2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmPan2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pan2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmPan2->pull(th);\n\t}\n\t\n};\n\nvoid Pan2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b;\n\t\tint n, aStride, bStride;\n\t\tn = framesToFill;\n\t\tif (_in(th, n, aStride, a) || _pos(th, n, bStride, b)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (bStride == 0) {\n\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * Lpan;\n\t\t\t\t*Rout = z * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * fast_pan(-x);\n\t\t\t\t*Rout = z * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_in.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Pan2::createOutputs(Thread& th)\n{\n\tmLeft = new Pan2Out(th, finite, this);\n\tmRight = new Pan2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void pan2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"pan2 : pos\");\n\tV in = th.popZIn(\"pan2 : in\");\n\n\tP pan = new Pan2(th, in, pos);\n\n\tP s = pan->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Balance2Out;\n\nstruct Balance2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tBalance2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Balance2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Balance2Out : public Gen\n{\n\tP mBalance2;\n\t\n\tBalance2Out(Thread& th, bool inFinite, P const& inBalance2) : Gen(th, itemTypeZ, inFinite), mBalance2(inBalance2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmBalance2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Balance2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmBalance2->pull(th);\n\t}\n\t\n};\n\nvoid Balance2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t*Lout = *a * Lpan;\n\t\t\t\t*Rout = *b * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t*Lout = *a * fast_pan(-x);\n\t\t\t\t*Rout = *b * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Balance2::createOutputs(Thread& th)\n{\n\tmLeft = new Balance2Out(th, finite, this);\n\tmRight = new Balance2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void bal2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"bal2 : pos\");\n\tV R = th.popZIn(\"bal2 : right\");\n\tV L = th.popZIn(\"bal2 : left\");\n\n\tP bal = new Balance2(th, L, R, pos);\n\n\tP s = bal->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Rot2Out;\n\nstruct Rot2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tRot2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Rot2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Rot2Out : public Gen\n{\n\tP mRot2;\n\t\n\tRot2Out(Thread& th, bool inFinite, P const& inRot2) : Gen(th, itemTypeZ, inFinite), mRot2(inRot2)\n\t{\n\t}\n\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmRot2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rot2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmRot2->pull(th);\n\t}\n\t\n};\n\nvoid Rot2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tif (_L.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = - R * sn;\n\t\t\t\t\t*Rout = R * cs;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else if (_R.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\t*Lout = L * cs;\n\t\t\t\t\t*Rout = L * sn;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ L = *a;\n\t\t\t\tZ R = *b;\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Rot2::createOutputs(Thread& th)\n{\n\tmLeft = new Rot2Out(th, finite, this);\n\tmRight = new Rot2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void rot2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"rot2 : pos\");\n\tV R = th.popZIn(\"rot2 : right\");\n\tV L = th.popZIn(\"rot2 : left\");\n\n\tP rot2 = new Rot2(th, L, R, pos);\n\n\tP s = rot2->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Fade2 : public Gen\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\t\n\tFade2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: Gen(th, itemTypeZ, mostFinite(inL, inR, inPos)), _L(inL), _R(inR), _pos(inPos)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fade2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *a, *b, *c;\n\t\t\tint n, aStride, bStride, cStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (cStride == 0) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\tZ Lpan = fast_pan(-x);\n\t\t\t\tZ Rpan = fast_pan(x);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a * Lpan + *b * Rpan;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t\tout[i] = *a * fast_pan(-x) + *b * fast_pan(x);\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tc += cStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_L.advance(n);\n\t\t\t_R.advance(n);\n\t\t\t_pos.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void fade2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"fade2 : pos\");\n\tV R = th.popZIn(\"fade2 : right\");\n\tV L = th.popZIn(\"fade2 : left\");\n\n\tth.push(new List(new Fade2(th, L, R, pos)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Trig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Trig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur > 0. && prev <= 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct NegTrig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tNegTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(-1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NegTrig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur >= 0. && prev < 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void tr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"tr : in\");\n\n\tth.push(new List(new Trig(th, in)));\n}\n\nstatic void ntr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"ntr : in\");\n\n\tth.push(new List(new NegTrig(th, in)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Gate : public TwoInputUGen\n{\n\tZ phase;\n\tZ freq;\n\tGate(Thread& th, Arg trig, Arg hold)\n\t\t: TwoInputUGen(th, trig, hold), phase(INFINITY), freq(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gate\"; }\n\t\n\tvoid calc(int n, Z* out, Z* trig, Z* hold, int trigStride, int holdStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ t = *trig;\n\t\t\tif (t > 0.) {\n\t\t\t\tphase = 0.;\n\t\t\t}\n\t\t\tout[i] = phase < *hold ? 1. : 0.;\n\t\t\tphase += freq;\n\t\t\ttrig += trigStride;\n\t\t\thold += holdStride;\n\t\t}\n\t}\n};\n\nstatic void gate_(Thread& th, Prim* prim)\n{\n\tV hold = th.popZIn(\"gate : hold\");\n\tV in = th.popZIn(\"gate : in\");\n\n\tth.push(new List(new Gate(th, in, hold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SampleAndHold : public Gen\n{\n\tZIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSampleAndHold(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SampleAndHold\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *tr;\n\t\t\tint n, inStride, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) val = *in;\n\t\t\t\tout[i] = val;\n\t\t\t\tin += inStride;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void sah_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"sah : trigger\");\n\tV in = th.popZIn(\"sah : in\");\n\n\tth.push(new List(new SampleAndHold(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Sequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Sequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tval = z;\n\t\t\t\t}\n\t\t\t\tout[i] = val;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void seq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"seq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new Sequencer(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct ImpulseSequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\t\n\tImpulseSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ImpulseSequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = z;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void iseq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"iseq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new ImpulseSequencer(th, in, trigger)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct PulseDivider : public Gen\n{\n\tZIn _tr;\n\tZIn _div;\n\tZ _count;\n\t\n\tPulseDivider(Thread& th, Arg tr, Arg div, Z start)\n\t\t: Gen(th, itemTypeZ, mostFinite(tr, div)), _tr(tr), _div(div), _count(start - 1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PulseDivider\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr, *div;\n\t\t\tint n, trStride, divStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr) || _div(th, n, divStride, div)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\t_count += 1.;\n\t\t\t\t\tZ idiv = floor(*div + .5);\n\t\t\t\t\tif (_count >= idiv) {\n\t\t\t\t\t\t_count -= idiv;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = _count == 0. ? *tr : 0.;\n\t\t\t\t} else out[i] = 0.;\n\t\t\t\ttr += trStride;\n\t\t\t\tdiv += divStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t\t_div.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pdiv_(Thread& th, Prim* prim)\n{\n\tZ start = th.popFloat(\"pdiv : istart\");\n\tV div = th.popZIn(\"pdiv : n\");\n\tV in = th.popZIn(\"pdiv : in\");\n\n\tth.push(new List(new PulseDivider(th, in, div, start)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Clip : public ThreeInputUGen\n{\n\t\n\tClip(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Clip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = std::clamp(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Wrap : public ThreeInputUGen\n{\n\t\n\tWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Wrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_wrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Fold : public ThreeInputUGen\n{\n\t\n\tFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_fold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\n\nstruct IWrap : public ThreeInputUGen\n{\n\t\n\tIWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IWrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_iwrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct IFold : public ThreeInputUGen\n{\n\t\n\tIFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IFold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_ifold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstatic void clip_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"clip : hi\");\n\tV lo = th.popZIn(\"clip : lo\");\n\tV in = th.popZIn(\"clip : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(std::clamp(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Clip(th, in, lo, hi)));\n\t}\n}\n\nstatic void wrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"wrap : hi\");\n\tV lo = th.popZIn(\"wrap : lo\");\n\tV in = th.popZIn(\"wrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_wrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Wrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void fold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"fold : hi\");\n\tV lo = th.popZIn(\"fold : lo\");\n\tV in = th.popZIn(\"fold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_fold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Fold(th, in, lo, hi)));\n\t}\n}\n\nstatic void iwrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"iwrap : hi\");\n\tV lo = th.popZIn(\"iwrap : lo\");\n\tV in = th.popZIn(\"iwrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_iwrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IWrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void ifold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"ifold : hi\");\n\tV lo = th.popZIn(\"ifold : lo\");\n\tV in = th.popZIn(\"ifold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_ifold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IFold(th, in, lo, hi)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \n\nstruct MouseUGenGlobalState {\n\tfloat mouseX, mouseY;\n\tbool mouseButton;\n} gMouseUGenGlobals;\n\nstatic void* gstate_update_func(void* arg)\n{\n\tMouseUGenGlobalState* gstate = &gMouseUGenGlobals;\n\n\tCGDirectDisplayID display = kCGDirectMainDisplay; // to grab the main display ID\n\tCGRect bounds = CGDisplayBounds(display);\n\tfloat rscreenWidth = 1. / bounds.size.width;\n\tfloat rscreenHeight = 1. / bounds.size.height;\n\tfor (;;) {\n\t\tHIPoint point;\n\t\tHICoordinateSpace space = 2;\n\t\tHIGetMousePosition(space, nullptr, &point);\n\n\t\tgstate->mouseX = point.x * rscreenWidth; //(float)p.h * rscreenWidth;\n\t\tgstate->mouseY = 1. - point.y * rscreenHeight; //(float)p.v * rscreenHeight;\n\t\tgstate->mouseButton = GetCurrentButtonState();\n\t\tusleep(17000);\n\t}\n\n\treturn 0;\n}\n\nZ gMouseLagTime = .1;\nZ gMouseLagMul = log001 / gMouseLagTime;\n\nstruct MouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct MouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void mousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousex : hi\");\n\tV lo = th.popZIn(\"mousex : lo\");\n\t\n\tth.push(new List(new MouseX(th, lo, hi)));\n}\n\nstatic void mousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousey : hi\");\n\tV lo = th.popZIn(\"mousey : lo\");\n\t\n\tth.push(new List(new MouseY(th, lo, hi)));\n}\n\nstatic void xmousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousex : hi\");\n\tV lo = th.popZIn(\"xmousex : lo\");\n\t\n\tth.push(new List(new ExpMouseX(th, lo, hi)));\n}\n\nstatic void xmousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousey : hi\");\n\tV lo = th.popZIn(\"xmousey : lo\");\n\t\n\tth.push(new List(new ExpMouseY(th, lo, hi)));\n}\n\nstatic void mousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousex1 : hi\");\n\tZ lo = th.popFloat(\"mousex1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseX * (hi - lo);\n\tth.push(z);\n}\n\nstatic void mousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousey1 : hi\");\n\tZ lo = th.popFloat(\"mousey1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseY * (hi - lo);\n\tth.push(z);\n}\n\nstatic void xmousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousex1 : hi\");\n\tZ lo = th.popFloat(\"xmousex1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseX);\n\tth.push(z);\n}\n\nstatic void xmousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousey1 : hi\");\n\tZ lo = th.popFloat(\"xmousey1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseY);\n\tth.push(z);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps();\nvoid AddOscilUGenOps();\nvoid AddDelayUGenOps();\n\nvoid AddUGenOps()\n{\n\ts_tempo = getsym(\"tempo\");\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\n\tpthread_t mouseListenThread;\n\tpthread_create (&mouseListenThread, nullptr, gstate_update_func, (void*)0);\n\n\tvm.addBifHelp(\"\\n*** unit generators ***\");\n\tvm.defmcx(\"*+\", 3, madd_, \"(a b c --> out) multiply add. a b * c +\");\n\n AddOscilUGenOps();\n AddFilterUGenOps();\n AddDelayUGenOps();\n\t\n\tvm.addBifHelp(\"\\n*** plugs ***\");\n\n\tvm.addBifHelp(\"\\n*** control rate subgraphs ***\");\n\tgK2A = automap(\"zk\", 2, new Prim(k2a_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tgK2AC = automap(\"zk\", 2, new Prim(k2ac_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tDEF(kr, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then linearly upsamples all returned signals by n.\")\n\tDEF(krc, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then cubically upsamples all returned signals by n.\")\n\t\n\tvm.addBifHelp(\"\\n*** control function unit generators ***\");\n\tDEFAM(imps, aaz, \"(values durs rate --> out) single sample impulses.\");\n\tDEFAM(steps, aaz, \"(values durs rate --> out) steps\");\n\tDEFAM(gates, aaaz, \"(values durs holds rate --> out) gates\");\n\tDEFAM(lines, aaz, \"(values durs rate --> out) lines\");\n\tDEFAM(xlines, aaz, \"(values durs rate --> out) exponential lines\");\n\tDEFAM(cubics, az, \"(values rate --> out) cubic splines\");\n\tDEFAM(curves, aaaz, \"(values curvatures durs rate --> out) curves.\");\n\t\n\n\tvm.addBifHelp(\"\\n*** random control unit generators ***\");\n\tDEFMCX(lfnoise0, 1, \"(freq --> out) step noise source.\");\n\tDEFMCX(lfnoise1, 1, \"(freq --> out) ramp noise source.\");\n\tDEFMCX(lfnoise3, 1, \"(freq --> out) cubic spline noise source.\");\n\t\n\tvm.addBifHelp(\"\\n*** tempo unit generators ***\");\n\tDEFAM(tempo, az, \"([bps dur bps dur ...] rate --> out) returns a signal of tempo vs time given a list of interleaved tempos (in beats per second) and durations (in beats).\");\n\tDEFAM(beats, z, \"(tempo --> beats) integrates a tempo signal to produce a signal of the time in beats.\");\n\n\tvm.addBifHelp(\"\\n*** envelope unit generators ***\");\n\tvm.addBifHelp(\"\\nFor asr, adsr, dadsr, dahdsr envelopes, the arguments are as follows:\");\n\tvm.addBifHelp(\" delay - a time in seconds. a period of time before the attack segment where the amplitude is zero.\");\n\tvm.addBifHelp(\" attack - a time in seconds to rise from zero to the level specified by the amp argument.\");\n\tvm.addBifHelp(\" hold - a time in seconds to hold at the level specified by the amp argument.\");\n\tvm.addBifHelp(\" delay - a time in seconds to fall from amp to the sustain level.\");\n\tvm.addBifHelp(\" sustain - a level from zero to one which is multiplied by the amp argument. The envelope holds at this level until released.\");\n\tvm.addBifHelp(\" release - a time in seconds to fall from the current level to zero. A release begins whenever the beat time (the integral of tempo), exceeds dur.\");\n\tvm.addBifHelp(\" amp - an amplitude that scales the peak and sustain levels of the envelope.\");\n\tvm.addBifHelp(\" dur - a time in beats to release the envelope.\");\n\tvm.addBifHelp(\" tempo - a signal giving the tempo in beats per second versus time.\");\n\tvm.addBifHelp(\"\");\n\n\tDEFAM(adsr, akkz, \"([attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dadsr, akkz, \"([delay attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dahdsr, akkz, \"([delay attack hold decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tvm.addBifHelp(\"\");\n \n\tDEFAM(endfade, zkkkk, \"(in startupTime holdTime fadeTime threshold --> out) after startupTime has elapsed, fade out the sound when peak amplitude has dropped below threshold for more than the holdTime.\");\n\tDEFAM(fadeout, zkk, \"(in sustainTime fadeTime --> out) fadeout after sustain.\");\n\tDEFAM(fadein, zk, \"(in fadeTime --> out) fade in.\");\n\tDEFAM(parenv, k, \"(dur --> out) parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(quadenv, k, \"(dur --> out) 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(octenv, k, \"(dur --> out) 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(trienv, k, \"(dur --> out) triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(tri2env, k, \"(dur --> out) triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(trapezenv, k, \"(dur --> out) trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(trapez2env, k, \"(dur --> out) trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(cosenv, k, \"(dur --> out) cosine envelope.\")\n\tDEFAM(hanenv, k, \"(dur --> out) hanning envelope.\")\n\tDEFAM(han2env, k, \"(dur --> out) hanning squared envelope.\")\n\tDEFAM(gaussenv, kk, \"(dur width --> out) gaussian envelope. exp(x^2/(-2*width^2)) for x from -1 to 1\")\n\n\tDEFAM(tsig, zza, \"(trig signal amp --> out) trigger a signal.\")\n\n\tDEFAM(tparenv, zaa, \"(trig dur amp --> out) triggered parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(tquadenv, zaa, \"(trig dur amp --> out) triggered 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(toctenv, zaa, \"(trig dur amp --> out) triggered 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(ttrienv, zaa, \"(trig dur amp --> out) triggered triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(ttri2env, zaa, \"(trig dur amp --> out) triggered triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(ttrapezenv, zaa, \"(trig dur amp --> out) triggered trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(ttrapez2env, zaa, \"(trig dur amp --> out) triggered trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(tcosenv, zaa, \"(trig dur amp --> out) triggered cosine envelope.\")\n\tDEFAM(thanenv, zaa, \"(trig dur amp --> out) triggered hanning envelope.\")\n\tDEFAM(than2env, zaa, \"(trig dur amp --> out) triggered hanning squared envelope.\")\n\t\n\tvm.addBifHelp(\"\\n*** spawn unit generators ***\");\n\tDEF(ola, 4, \"(sounds hops rate numChannels --> out) overlap add. This is the basic operator for polyphony. \")\n\n\tvm.addBifHelp(\"\\n*** pause unit generator ***\");\n\tDEFMCX(pause, 2, \"(in amp --> out) pauses the input when amp is <= 0, otherwise in is multiplied by amp.\")\n\n\tvm.addBifHelp(\"\\n*** panner unit generators ***\");\n\tDEFAM(itd, zzk, \"(in pan maxdelay --> out) interaural time delay.\");\n\tDEFMCX(pan2, 2, \"(in pos --> [left right]) stereo pan. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(rot2, 3, \"(left right pos --> [left right]) stereo rotation. pos 0 is no rotation, +/-1 is 180 degrees, -.5 is -90 degrees, +.5 is +90 degrees.\")\n\tDEFMCX(bal2, 3, \"(left right pos --> [left right]) stereo balance control. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(fade2, 3, \"(left right pos --> out) cross fade between two inputs. pos 0 is equal mix. pos -1 is all left, pos +1 is all right.\")\n\n\t\n\tvm.addBifHelp(\"\\n*** trigger unit generators ***\");\n\tDEFMCX(tr, 1, \"(in --> out) transitions from nonpositive to positive become single sample impulses.\")\n\tDEFMCX(ntr, 1, \"(in --> out) transitions from negative to nonnegative become single sample impulses.\")\n\tDEFMCX(gate, 1, \"(in hold --> out) outputs 1 for hold seconds after each trigger, else outputs zero.\")\n\tDEFMCX(sah, 2, \"(in trigger --> out) sample and hold\")\n\tDEFAM(seq, az, \"(in trigger --> out) pulls one value from the input for each trigger. output sustains at that level until the next trigger.\")\n\tDEFAM(iseq, az, \"(in trigger --> out) pulls one value from the input for each trigger. outputs that value for one sample. outputs zero when there is no trigger.\")\n\tDEFMCX(pdiv, 3, \"(in n istart --> out) pulse divider. outputs one impulse from the output for each n impulses in the input. istart is an offset. istart = 0 outputs a pulse on the first input pulse.\")\n\t\n\t\n\tvm.addBifHelp(\"\\n*** bounds unit generators ***\");\n\tDEFMCX(clip, 3, \"(in lo hi --> out) constrain the input to the bounds by clipping.\")\n\tDEFMCX(wrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping.\")\n\tDEFMCX(fold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges.\")\n\tDEFMCX(iwrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping. all inputs treated as integers.\")\n\tDEFMCX(ifold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges. all inputs treated as integers.\")\n\n\tvm.addBifHelp(\"\\n*** mouse control unit generators ***\");\n\tDEFMCX(mousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\n\n\tDEFMCX(mousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\t\n}\n"], ["/sapf/src/MultichannelExpansion.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n// multi channel mapping is a special case of auto mapping where the mask is all z's.\n\nclass MultichannelMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tVIn args[kMaxArgs];\npublic:\n\t\n\tMultichannelMapper(Thread& th, bool inFinite, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\targs[i].set(inArgs[i]);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"MultichannelMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nvoid mcx_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV& fun = prim->v;\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool hasVList = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tif (args[k].isVList()) {\n\t\t\thasVList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t}\n\t}\n\t\n\tif (hasVList) {\n\t\tList* s = new List(new MultichannelMapper(th, isFinite, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tfun.apply(th);\n\t}\n\n}\n\n\nconst char* kAaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";\nconst size_t kAaaLength = strlen(kAaa);\n\nconst char* kZzz = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\";\nconst size_t kZzzLength = strlen(kZzz);\n\nconst char* Prim::GetAutoMapMask() const\n{\n\t//return NoEachOps() || mNumArgs == 0 ? nullptr : kAaa + kAaaLength - mNumArgs;\n\treturn nullptr;\n}\n\nclass MultichannelMapPrim : public Prim\n{\npublic:\n\tMultichannelMapPrim(PrimFun _primFun, Arg _v, int n, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return kZzz + kZzzLength - mTakes; }\n\t\n};\n\nPrim* mcx(int n, Arg f, const char* name, const char* help)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = mcx_< 1>; break;\n\t\tcase 2 : pf = mcx_< 2>; break;\n\t\tcase 3 : pf = mcx_< 3>; break;\n\t\tcase 4 : pf = mcx_< 4>; break;\n\t\tcase 5 : pf = mcx_< 5>; break;\n\t\tcase 6 : pf = mcx_< 6>; break;\n\t\tcase 7 : pf = mcx_< 7>; break;\n\t\tcase 8 : pf = mcx_< 8>; break;\n\t\tcase 9 : pf = mcx_< 9>; break;\n\t\tcase 10 : pf = mcx_<10>; break;\n\t\tcase 11 : pf = mcx_<11>; break;\n\t\tcase 12 : pf = mcx_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new MultichannelMapPrim(pf, f, n, name, help);\n}\n\nclass AutoMapPrim : public Prim\n{\npublic:\n\tconst char* mask;\n\tAutoMapPrim(PrimFun _primFun, Arg _v, int n, const char* inMask, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp), mask(inMask)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return mask; }\n\t\n};\n\nclass AutoMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tBothIn args[kMaxArgs];\npublic:\n\t\n\tAutoMapper(Thread& th, bool inFinite, const char* inMask, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\tswitch (inMask[i]) {\n\t\t\t\tcase 'a' :\n\t\t\t\t\targs[i].setConstant(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'z' : // auto map over V lists, but not Z lists.\n\t\t\t\t\targs[i].setv(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", inMask[i]);\n\t\t\t\tcase 'k' :\n\t\t\t\t\targs[i].set(inArgs[i]);\n\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"AutoMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n/*\n\ta - as is. argument is not automapped.\n\tz - argument is expected to be a signal or scalar, streams are auto mapped.\n\tk - argument is expected to be a scalar, signals and streams are automapped.\n*/\n\ntemplate \nvoid automap_(Thread& th, Prim* prim)\n{\n\n\tconst char* mask = ((AutoMapPrim*)prim)->mask;\n\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool canMap = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tswitch (mask[k]) {\n\t\t\tcase 'a' :\n\t\t\t\tbreak;\n\t\t\tcase 'z' :\n\t\t\t\tif (args[k].isVList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", mask[k]);\n\t\t\t\tthrow errFailed;\n\t\t\t\tbreak;\n\t\t\tcase 'k' :\n\t\t\t\tif (args[k].isList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tif (canMap) {\n\t\tList* s = new List(new AutoMapper(th, isFinite, mask, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tprim->v.apply(th);\n\t}\n\n}\n\nPrim* automap(const char* mask, int n, Arg f, const char* inName, const char* inHelp)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = automap_< 1>; break;\n\t\tcase 2 : pf = automap_< 2>; break;\n\t\tcase 3 : pf = automap_< 3>; break;\n\t\tcase 4 : pf = automap_< 4>; break;\n\t\tcase 5 : pf = automap_< 5>; break;\n\t\tcase 6 : pf = automap_< 6>; break;\n\t\tcase 7 : pf = automap_< 7>; break;\n\t\tcase 8 : pf = automap_< 8>; break;\n\t\tcase 9 : pf = automap_< 9>; break;\n\t\tcase 10 : pf = automap_<10>; break;\n\t\tcase 11 : pf = automap_<11>; break;\n\t\tcase 12 : pf = automap_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new AutoMapPrim(pf, f, n, mask, inName, inHelp);\n}\n\n\n\n\n\nclass EachMapper : public Gen\n{\n\tconst int level;\n\tconst int numLevels;\n\tV fun;\n\tArgInfo args;\npublic:\n\t\n\tEachMapper(Thread& th, bool inFinite, int inLevel, int inNumLevels, const ArgInfo& inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), level(inLevel), numLevels(inNumLevels), args(inArgs), fun(inFun)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"EachMapper\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (level == 0) {\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, v)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tth.push(v);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tfun.apply(th);\n\t\t\t\t} catch (...) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tthrow;\n\t\t\t\t}\n\t\t\t\tout[i] = th.pop();\n\t\t\t\t\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t} else {\n\t\t\tArgInfo subargs;\n\t\t\tsubargs.numArgs = args.numArgs;\n\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\tsubargs.arg[j].mask = args.arg[j].mask;\n\t\t\t}\n\t\t\t\n\t\t\tint bit = 1 << (numLevels - level);\n\t\t\t\n\t\t\tbool mmIsFinite = true;\n\t\t\t\t\t\t\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tV argv[kMaxArgs];\n\t\t\t\tbool allConstant = true;\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, argv[j])) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (argv[j].isList() && (args.arg[j].mask & bit))\n\t\t\t\t\t\tallConstant = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (allConstant) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tth.push(argv[j]);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfun.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = th.pop();\n\t\t\t\t} else {\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tV v = argv[j];\n\t\t\t\t\t\tif (args.arg[j].mask & bit) {\n\t\t\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\t\t\tmmIsFinite = false;\n\t\t\t\t\t\t\tsubargs.arg[j].in.set(v);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tsubargs.arg[j].in.setConstant(v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\tout[i] = new List(new EachMapper(th, mmIsFinite, level - 1, numLevels, subargs, fun));\n\t\t\t\t}\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\n};\n\nList* handleEachOps(Thread& th, int numArgs, Arg fun)\n{\n\tArgInfo args;\n\tV argv[kMaxArgs];\n\t\n\targs.numArgs = numArgs;\n\tint32_t maxMask = 0;\n\n\tbool mmIsFinite = true;\n\n\tfor (int i = numArgs-1; i >= 0; --i) {\n\t\tV v = th.pop();\n\t\targv[i] = v;\n\t\tif (v.isEachOp()) {\n\t\t\t\n\t\t\tEachOp* adv = (EachOp*)v.o();\n\t\t\targs.arg[i].mask = adv->mask;\n\t\t\tmaxMask |= adv->mask;\n\t\t\tif (adv->mask & 1) {\n\t\t\t\tif (!adv->v.isFinite()) \n\t\t\t\t\tmmIsFinite = false;\n\t\t\t\targs.arg[i].in.set(adv->v);\n\t\t\t} else {\n\t\t\t\targs.arg[i].in.setConstant(adv->v);\n\t\t\t}\n\t\t} else {\n\t\t\targs.arg[i].in.setConstant(v);\n\t\t\targs.arg[i].mask = 0;\n\t\t}\n\t}\n\tif (maxMask > 1 && maxMask != NEXTPOWEROFTWO(maxMask) - 1) {\n\t\tpost(\"there are empty levels of iteration. mask: %x\\n\", maxMask);\n\t\tthrow errFailed;\n\t}\n\t\n\tint numLevels = maxMask <= 1 ? 1 : LOG2CEIL(maxMask);\n\treturn new List(new EachMapper(th, mmIsFinite, numLevels-1, numLevels, args, fun));\n}\n\n\nclass Flop : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlop(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flop\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nclass Flops : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlops(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tVIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flops\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flopz : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlopz(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flopz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeZ, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->addz(z);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopsNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopsNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopsNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isVList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid flop_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\nvoid flops_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flops : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flops : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flops : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flops : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopsNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nvoid flop1_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop1 : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tList* result = new List(itemTypeV, 1);\n\t\t\tresult->add(s);\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop1 : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop1 : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop1 : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nclass Lace : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLace(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), argPos(0)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lace\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (args[argPos].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Lacez : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLacez(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), argPos(0)\n\t{\n\t\tpost(\"Lacez\\n\");\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lacez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tZ z;\n\t\t\tif (args[argPos].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nvoid lace_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popList(\"lace : list\");\n\tif (!s->isVList())\n\t\twrongType(\"lace : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"lace : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Lacez(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Lace(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\nclass Sel : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSel(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sel\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = v;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Selz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSelz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Selz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = z;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sell : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSell(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sell\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tV v;\n\t\t\tif (args[k].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sellz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSellz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sellz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tZ z;\n\t\t\tif (args[k].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid sel_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sel : indices\");\n\n\tP s = th.popList(\"sel : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sel : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sel : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Selz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sel(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\nvoid sell_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sell : indices\");\n\n\tP s = th.popList(\"sell : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sell : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sell : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Sellz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sell(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\n\n\n\n\n\n"], ["/sapf/src/Parser.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Parser.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PARSER\n\nbool parseElem(Thread& th, P& code);\nbool parseWord(Thread& th, P& code);\nstatic void bindVar(Thread& th, P const& name, P& code);\n\nclass ParsingWhat\n{\n\tThread& th;\n\tint what;\npublic:\t\n\tParsingWhat(Thread& inThread, int newMode) : th(inThread), what(th.parsingWhat)\n\t{\n\t\tth.parsingWhat = newMode;\n\t} \n\t~ParsingWhat()\n\t{\n\t\tth.parsingWhat = what;\n\t}\n};\n\n\nstatic bool skipSpace(Thread& th)\n{\n\t//ScopeLog sl(\"skipSpace\");\n\tfor (;;) {\n\t\tint c = th.getc();\n\t\tif (c == ';') {\n\t\t\tc = th.getc();\n\t\t\twhile (c && c != '\\n') { c = th.getc(); }\n\t\t\tif (c == 0) { th.unget(1); return true; }\n\t\t}\n\t\tif (c == 0) { th.unget(1); return true; }\n\t\tbool skip = isspace(c) || iscntrl(c);\n\t\tif (!skip) { th.unget(1); break; }\n\t}\n\treturn false;\n}\n\nconst char* nonnamechars = \";()[]{}.`,:\\\"\\n\";\n\nstatic bool endOfWord(int c)\n{\n\treturn c == 0 || isspace(c) || strchr(nonnamechars, c) != nullptr;\n}\n\nstatic bool parseHexNumber(Thread& th, P& code)\n{\n\tconst char* start = th.curline();\n\tint64_t z = 0;\n\t\n\tth.getc();\n\tth.getc();\n\tint c = th.getc();\n\twhile(isxdigit(c)) {\n\t\tif (isdigit(c)) z = z*16 + c - '0';\n\t\telse z = z*16 + toupper(c) - 'A' + 10;\n\t\tc = th.getc();\n\t}\n\n\tif (!endOfWord(c)) {\n\t\t// even though it starts out like a number it continues as some other token\n\t\tth.unget(start);\n\t\treturn false;\n\t} else {\n\t\tth.unget(1);\n\t}\n\t\n\tcode->add(opPushImmediate, z);\n\t\n\treturn true;\n}\n\n\nstatic bool parseFloat(Thread& th, Z& result)\n{\t\n\t//ScopeLog sl(\"parseFloat\");\n\tconst char* start = th.curline();\n\tint c = th.getc();\n \n if (c == 'p' && th.c() == 'i') {\n th.getc();\n result = M_PI;\n return true;\n }\n \n\tif (c == '+' || c == '-') \n\t\tc = th.getc();\n\n\tint digits = 0;\n\tbool sawdot = false;\n\tfor ( ; ; ) {\n\t\tif (isdigit(c)) digits++;\n\t\telse if (c == '.') {\n\t\t\tif (sawdot) break;\n\t\t\tsawdot = true; \n\t\t}\n\t\telse break;\n\t\tc = th.getc(); \n\t}\n\tif (digits == 0) {\n\t\tth.unget(start);\n\t\treturn false;\n\t}\n\t\n\tif (c == 'e' || c == 'E') {\n\t\tc = th.getc();\n\t\tif (c == '+' || c == '-') \n\t\t\tc = th.getc();\n\t\twhile (isdigit(c)) { c = th.getc(); }\n\t}\n\n\tth.toToken(start, (int)(th.curline() - start));\n\t\n\tbool sawpi = false;\n\tbool sawmega = false;\n\tbool sawkilo = false;\n\tbool sawhecto = false;\n\tbool sawcenti = false;\n\tbool sawmilli = false;\n\tbool sawmicro = false;\n\t\n\t\n\tif (c == 'p' && th.c() == 'i') {\n\t\tsawpi = true;\n\t\tth.getc();\n\t} else if (c == 'M') {\n\t\tsawmega = true;\n\t} else if (c == 'k') {\n\t\tsawkilo = true;\n\t} else if (c == 'h') {\n\t\tsawhecto = true;\n\t} else if (c == 'c') {\n\t\tsawcenti = true;\n\t} else if (c == 'm') {\n\t\tsawmilli = true;\n\t} else if (c == 'u') {\n\t\tsawmicro = true;\n\t} else {\n\t\tth.unget(1);\n\t}\n\n\tdouble x = strtod(th.token, nullptr);\n\tif (sawpi) x *= M_PI;\n\telse if (sawmega) x *= 1e6;\n\telse if (sawkilo) x *= 1e3;\n\telse if (sawhecto) x *= 1e2;\n\telse if (sawcenti) x *= 1e-2;\n\telse if (sawmilli) x *= 1e-3;\n\telse if (sawmicro) x *= 1e-6;\n\n\tresult = x;\n\treturn true;\n}\n\nstatic bool parseNumber(Thread& th, Z& result)\n{\n\tconst char* start = th.curline();\n\n\tZ a, b;\n\tif (parseFloat(th, a)) {\n\t\tif (th.c() == '/') {\n\t\t\tth.getc();\n\t\t\tif (parseFloat(th, b) && endOfWord(th.c())) {\n\t\t\t\tresult = a/b;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (endOfWord(th.c())) {\n\t\t\tresult = a;\n\t\t\treturn true;\n\t\t}\n\t}\n\tth.unget(start);\n\treturn false;\n}\n\nstatic bool parseNumber(Thread& th, P& code)\n{\n Z x;\n if (parseNumber(th, x)) {\n \t\tcode->add(opPushImmediate, x);\n return true;\n }\n return false;\n}\n\nstatic bool parseSymbol(Thread& th, P& result);\nstatic bool parseItemList(Thread& th, P& code, int endbrace);\n\n\nstatic bool parseQuote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after quote\");\n\t\n\tV vname(name);\n\tcode->add(opPushImmediate, vname);\n\n\treturn true; \n}\n\nstatic bool parseBackquote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after backquote\");\n\n\n\tV vname(name);\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\tswitch (scope) {\n\t\tcase scopeLocal :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushLocalVar, val);\n\t\t\tbreak;\n\t\tcase scopeFunVar :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushFunVar, val);\n\t\t\tbreak;\n\t\tcase scopeBuiltIn :\n\t\t\tcode->add(opPushImmediate, val);\n\t\t\tbreak;\n\t\tcase scopeWorkspace :\n\t\t\tcode->add(opPushWorkspaceVar, vname);\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tpost(\"backquote error: \\\"%s\\\" is an undefined word\\n\", name->s);\n\t\t\tsyntaxError(\"undefined word\");\n\t}\n\n\treturn true; \n}\n\nstatic bool parseDot(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opDot, vname);\n\n\treturn true; \n}\n\nstatic bool parseComma(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opComma, vname);\n\n\treturn true; \n}\n\nstatic bool parseColon(Thread& th, P& code)\n{\n\tth.getc();\n\n P name;\n\n if (!parseSymbol(th, name)) \n syntaxError(\"expected symbol after colon\");\n \n code->keys.push_back(name);\n\n\treturn true;\n}\n\nstatic bool parseEachOp(Thread& th, P& code)\n{\n\t\n\tint64_t mask = 0;\n\tint level = 0;\n\n\tth.getc();\n\tint c = th.getc();\n\t\n\tif (c == '@') {\n\t\tmask = 1; \n\t\t++level;\n\t\tdo {\n\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '@');\n\t} else if (c >= '2' && c <= '9') {\n\t\tmask = 1LL << (c - '1');\n\t\tc = th.getc();\n\t} else if (c == '0' || c == '1') {\n\t\tdo { \n\t\t\tif (c == '1')\n\t\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '0' || c == '1');\n\t} else {\n\t\tmask = 1;\n\t}\n\tif (isdigit(c)) {\n\t\tsyntaxError(\"unexpected extra digit after @\");\n\t}\n\t\n\tth.unget(1);\n\n\tV v;\n\tv.i = mask;\n\t\n\tcode->add(opEach, v);\n\t\n\t\n\treturn true; \n}\n\n\nstatic bool parseNewForm(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingEnvir);\n\tP code2 = new Code(8);\n\tth.getc();\n\t\n\tparseItemList(th, code2, '}');\n\t\n\tif (code2->keys.size()) {\n\n\t\tP tmap = new TableMap(code2->keys.size());\n\t\t\n\t\tint i = 0;\n\t\tfor (Arg key : code2->keys) {\n tmap->put(i, key, key.Hash());\n\t\t\t++i;\n\t\t}\n\n\t\tcode2->keys.clear();\n\t\tcode2->add(opPushImmediate, V(tmap));\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\n\t\tcode->add(opNewForm, V(code2));\n\t} else {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opInherit, V(code2));\n\t}\n\t\t\t\n\treturn true;\n}\n\nstatic String* parseString(Thread& th);\n\nstatic bool parseStackEffect(Thread& th, int& outTakes, int& outLeaves)\n{\n\toutTakes = 0;\n\toutLeaves = 1;\n\tskipSpace(th);\n\tint c = th.c();\n\tif (!isdigit(c)) return true;\n\toutLeaves = 0;\n\t\n\twhile(isdigit(c)) {\n\t\toutTakes = outTakes * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\tif (c != '.') return false;\n\tc = th.getc();\n\twhile(isdigit(c)) {\n\t\toutLeaves = outLeaves * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\treturn true;\n}\n\nstatic bool parseLambda(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseLambda\");\n\tParsingWhat pw(th, parsingLambda);\n\tth.getc();\n\tstd::vector > args;\n\t\t\n\tSaveCompileScope scs(th);\n\t\n\tP cs = new InnerCompileScope(th.mCompileScope);\n\tth.mCompileScope = cs();\n\t\n\twhile (1) {\n\t\tP name;\n\t\tif (!parseSymbol(th, name)) break;\n\t\targs.push_back(name);\n\t\t\n\t\tint takes, leaves;\n\t\tif (!parseStackEffect(th, takes, leaves)) {\n\t\t\tsyntaxError(\"incorrectly formatted function argument stack effect annotation.\");\n\t\t}\n\t\t\n\t\tLocalDef def;\n\t\tdef.mName = name;\n\t\tdef.mIndex = cs->mLocals.size();\n\t\tdef.mTakes = takes;\n\t\tdef.mLeaves = leaves;\n\t\tcs->mLocals.push_back(def);\n\t}\n\t\n\tskipSpace(th);\n\t\n\tP help = parseString(th);\n\n\tskipSpace(th);\n\t\n\tint c = th.getc();\t\n\tif (c != '[') {\n post(\"got char '%c' %d\\n\", c, c);\n\t\tsyntaxError(\"expected open square bracket after argument list\");\n\t}\n\t\t\n\tP code2 = new Code(8);\t\n\tparseItemList(th, code2, ']');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\t\n\t\t\n\t// compile code to push all fun vars\n\tfor (size_t i = 0; i < cs->mVars.size(); ++i) {\n\t\tVarDef& def = cs->mVars[i];\n\t\tV vindex;\n\t\tvindex.i = def.mFromIndex;\n\t\t\n\t\tif (def.mFromScope == scopeLocal) {\n\t\t\tcode->add(opPushLocalVar, vindex);\n\t\t} else {\n\t\t\tcode->add(opPushFunVar, vindex);\n\t\t}\n\t}\n\tif (args.size() > USHRT_MAX || cs->mLocals.size() > USHRT_MAX || cs->mVars.size() > USHRT_MAX)\n\t{\n\t\tpost(\"Too many variables!\\n\");\n\t\tthrow errSyntax;\n\t}\n\n FunDef* def = new FunDef(th, code2, args.size(), cs->mLocals.size(), cs->mVars.size(), help);\n\tdef->mArgNames = args;\n\tcode->add(opPushFun, def);\n\n\treturn true;\n}\n\n#define COMPILE_PARENS 1\n\nstatic bool parseParens(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingParens);\n\tth.getc();\n\n#if COMPILE_PARENS\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ')');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\tcode->add(opParens, V(code2));\n#else\n\tparseItemList(th, code, ')');\n#endif\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseArray(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseArray\");\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewVList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilv));\n\t}\n\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseZArray(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewZList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilz));\n\t}\n\t\t\t\n\treturn true;\n}\n\nbool parseItemList(Thread& th, P& code, int endbrace)\n{\t\n\t//ScopeLog sl(\"parseItemList\");\n\t\n\twhile (1) {\n\t\tskipSpace(th);\n\t\tint c = th.c();\n\t\tif (c == endbrace) break;\n\t\tif (!parseElem(th, code)) {\n\t\t\tif (endbrace == ']') syntaxError(\"expected ']'\");\n\t\t\tif (endbrace == '}') syntaxError(\"expected '}'\");\n\t\t\tif (endbrace == ')') syntaxError(\"expected ')'\");\n\t\t}\n\t}\n\tth.getc(); // skip end brace\n\t\n\treturn true;\n}\n\n\nbool parseSymbol(Thread& th, P& result)\n{\n\t//ScopeLog sl(\"parseSymbol\");\n\tskipSpace(th);\n\tconst char* start = th.curline();\n\tint c = th.getc();\n\t\n\twhile(!endOfWord(c)) {\n\t\tc = th.getc();\n\t}\n\tth.unget(1);\n\n\tsize_t len = th.curline() - start;\n\tif (len == 0) return false;\n\n\tth.toToken(start, (int)len);\n\t\n\tresult = getsym(th.token);\n\n\treturn true;\n}\n\nstatic void bindVar(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->bindVar(th, name, index);\n\n\tV vname(name);\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tcode->add(opBindWorkspaceVar, vname);\n\t} else {\n\t\tval.i = index;\n\t\tcode->add(opBindLocal, val);\n\t}\n}\n\nstatic void bindVarFromList(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t varIndex;\n\tint scope = th.mCompileScope->bindVar(th, name, varIndex);\n\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tV vname(name);\n\t\tcode->add(opBindWorkspaceVarFromList, vname);\n\t} else {\n\t\tval.i = varIndex;\n\t\tcode->add(opBindLocalFromList, val);\n\t}\n}\n\nbool parseWord(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseWord\");\n\tP name;\n\n\tif (!parseSymbol(th, name)) return false;\n\t\t\n\tif (strcmp(name->cstr(), \"=\")==0) {\n\n\t\tskipSpace(th);\t\t\n\t\tif (th.c() == '(') {\n\t\t\tth.getc();\n\t\t\t// parse multiple assign\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ('\\n\");\n\t\t\t}\n\t\t\tfor (int64_t i = names.size()-1; i>=0; --i) {\n\t\t\t\tbindVar(th, names[i], code);\n\t\t\t}\n\t\t\tskipSpace(th);\n\t\t\tif (th.c() != ')') {\n\t\t\t\tsyntaxError(\"expected ')' after '= ('\\n\");\n\t\t\t}\n\t\t\tth.getc();\n\t\t\tcode->add(opNone, 0.);\n\t\t} else if (th.c() == '[') {\n\t\t\tth.getc();\n\t\t\t// parse assign from array\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ['\\n\");\n\t\t\t}\n\t\t\tfor (size_t i = 0; iadd(opNone, 0.);\n\t\t} else {\n\t\t\tP name2;\n\t\t\tif (!parseSymbol(th, name2)) {\n\t\t\t\tsyntaxError(\"expected a name after '='\\n\");\n\t\t\t}\n\t\t\tbindVar(th, name2, code);\n\t\t}\n\t} else {\n\t\tV val;\n\t\tsize_t index;\n\t\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\t\tV vname(name);\n\t\tswitch (scope) {\n\t\t\tcase scopeLocal :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallLocalVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeFunVar :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallFunVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeBuiltIn :\n\t\t\t\tcode->add(opCallImmediate, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeWorkspace :\n\t\t\t\tcode->add(opCallWorkspaceVar, vname);\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"\\\"%s\\\" is an undefined word\\n\", name->cstr());\n\t\t\t\tsyntaxError(\"undefined word\");\n\t\t\t\t\n\t\t}\n\n\t}\n\t\n\treturn true;\n}\n\nstatic bool parseString(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseString\");\n\tParsingWhat pw(th, parsingString);\n\t\n\tV string = parseString(th);\t\n\tcode->add(opPushImmediate, string);\n\n\treturn true;\n}\n\nstatic String* parseString(Thread& th)\n{\n\tif (th.c() != '\"') return nullptr;\n\n\tParsingWhat pw(th, parsingString);\n\tth.getc();\n\tint c = th.getc();\n\tstd::string str;\n\t\t\n\twhile (true) {\n\t\tif (c == 0) {\n\t\t\tsyntaxError(\"end of input in string\");\n\t\t} else if (c == '\\\\' && th.c() == '\\\\') {\n\t\t\tth.getc();\n\t\t\tc = th.getc();\n\t\t\tswitch (c) {\n\t\t\t\tcase 'n' : str += '\\n'; break;\n\t\t\t\tcase 'r' : str += '\\r'; break;\n\t\t\t\tcase 'f' : str += '\\f'; break;\n\t\t\t\tcase 'v' : str += '\\v'; break;\n\t\t\t\tcase 't' : str += '\\t'; break;\n\t\t\t\tdefault : str += c; break;\n\t\t\t}\n\t\t\tc = th.getc();\n\t\t} else if (c == '\"') {\n\t\t\tif (th.c() == '\"') {\n\t\t\t\tc = th.getc();\n\t\t\t\tstr += '\"';\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tstr += c;\n\t\t\tc = th.getc();\n\t\t}\n\t}\n\t\n\treturn new String(str.c_str());\n}\n\nbool parseElem(Thread& th, P& code)\n{\t\n\tskipSpace(th);\n\tint c = th.c();\n\tif (c == 0)\n\t\treturn false;\n\tif (c == ']' || c == ')' || c == '}') {\n\t\tpost(\"unexpected '%c'.\\n\", c);\n\t\tthrow errSyntax;\n\t}\n\tif (c == '@')\n\t\t return parseEachOp(th, code);\n\tif (c == '(')\n\t\t return parseParens(th, code);\n\tif (c == '[')\n\t\t return parseArray(th, code);\n\tif (c == '{')\n\t\t return parseNewForm(th, code);\n\tif (c == '\\\\')\n\t\t return parseLambda(th, code);\n\tif (c == '\"')\n\t\treturn parseString(th, code);\n\tif (c == '\\'') \n\t\treturn parseQuote(th, code);\n\tif (c == '`') \n\t\treturn parseBackquote(th, code);\n\tif (c == ',') \n\t\treturn parseComma(th, code);\n\tif (c == ':')\n\t\treturn parseColon(th, code);\n\n\tif (c == '0' && th.d() == 'x') \n\t\treturn parseHexNumber(th, code) || parseWord(th, code);\n\n\tif (isdigit(c) || c == '+' || c == '-')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n \n if (c == 'p' && th.d() == 'i')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n\n\tif (c == '.')\n\t\treturn parseNumber(th, code) || parseDot(th, code);\n\n\n\tif (c == '#') {\n\t\tint d = th.d();\n\t\tif (!d) syntaxError(\"end of input after '#'\");\n\t\tif (d == '[') {\n\t\t\treturn parseZArray(th, code);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\treturn parseWord(th, code);\n}\n\n\nbool parseElems(Thread& th, P& code)\n{\n\tcode = new Code(8);\n\twhile (1) {\n\t\tif (!parseElem(th, code)) break;\n\t}\n\t\n\tcode->add(opReturn, 0.);\n\tcode->shrinkToFit();\n\t\t\n\treturn true;\n}\n\n/////////////////////////\n\n#pragma mark PRINTI\n\n#include \n\n///////////////////////// 1 2 3 4 5 6\n/////////////////////////1234567890123456789012345678901234567890123456789012345678901234\nconst char* s64Spaces = \" \";\nconst int kNumSpaces = 64;\n\nstatic void printSpaces(std::ostream& ost, int n)\n{\n\twhile (n >= kNumSpaces) {\n\t\tost << s64Spaces;\n\t\tn -= kNumSpaces;\n\t}\n\tif (n) {\n\t\tost << (s64Spaces + kNumSpaces - n);\n\t}\n}\n\nvoid printi(std::ostream& ost, int indent, const char* fmt, ...)\n{\n\tprintSpaces(ost, indent);\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n\nvoid prints(std::ostream& ost, const char* fmt, ...)\n{\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n//////////////////////////////////\n\n"], ["/sapf/src/OscilUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n\n#include \"OscilUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"dsp.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst int kNumTables = 30; // third octave tables.\nconst int kWaveTableSize = 16384;\nconst int kWaveTableMask = kWaveTableSize - 1;\n//const int kWaveTableByteSize = kWaveTableSize * sizeof(Z);\nconst int kWaveTableTotalSize = kWaveTableSize * kNumTables;\n//const Z kPhaseInc = kTwoPi / kWaveTableSize;\nconst Z kWaveTableSizeF = kWaveTableSize;\n\n// the maximum number of harmonics is actually 1024, but 1290 is needed for extrapolation.\nconst int kMaxHarmonics = 1290;\nconst int gNumHarmonicsForTable[kNumTables+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 101, 128, 161, 203, 256, 322, 406, 512, 645, 812, 1024, 1290 };\n\nint gWaveTableSize[kNumTables];\n\nconst double kMaxHarmonicsF = kMaxHarmonics;\n\n\nZ gTableForNumHarmonics[kMaxHarmonics+1];\nZ gHertzToHarmonics[kMaxHarmonics+1];\n\nstatic void fillHarmonicsTable()\n{\t\n\tdouble maxval = kNumTables - 1.0000001;\n\t\n\tint t = 0;\n\tfor (int i = 1; i < kMaxHarmonics; ++i) {\n\t\tif (gNumHarmonicsForTable[t] < i && t < kNumTables) ++t;\n\t\t//int t1 = std::clamp(t-1, 0, kNumTables-1);\n\t\t\n\t\tdouble frac = (double)(i - gNumHarmonicsForTable[t]) / (double)(gNumHarmonicsForTable[t] - gNumHarmonicsForTable[t-1]);\n\t\tdouble ft = t - 1 + frac;\n\t\tgTableForNumHarmonics[i] = ft;\n\t}\n\t\t\n\tgTableForNumHarmonics[0] = 0.;\n\tgTableForNumHarmonics[kMaxHarmonics] = maxval;\n}\n\nstatic void zeroTable(size_t n, Z* table)\n{\n\tmemset(table, 0, n * sizeof(Z));\n}\n\nstatic void normalize(int n, Z* buf)\n{\n\tZ maxabs = 0.;\n\tfor (int i = 0; i < n; ++i) {\n\t\tmaxabs = std::max(maxabs, fabs(buf[i]));\n\t}\n\tif (maxabs > 0.) {\n\t\tZ scale = 1. / maxabs;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tbuf[i] *= scale;\n\t\t}\n\t}\n}\n\n\nstatic void fillWaveTable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* table)\n{\n\tconst size_t kWaveTableSize2 = kWaveTableSize / 2;\n\tconst Z two_pi = 2. * M_PI;\n\t\n\tZ real[kWaveTableSize2];\n\tZ imag[kWaveTableSize2];\n\tZ polar[kWaveTableSize];\n\tZ rect[kWaveTableSize];\n\t\n\tzeroTable(kWaveTableSize2, real);\n\tzeroTable(kWaveTableSize2, imag);\n\n\n\tZ w = M_PI_2 / n;\n\tfor (int i = 0; i < n; ++i) {\n\t\tZ smoothAmp = smooth == 0. ? 1. : pow(cos(w*i), smooth);\n\t\t//fillHarmonic(i+1, *amps * smoothAmp, *phases, table);\n\t\treal[i+1] = *amps * smoothAmp;\n\t\timag[i+1] = (*phases - .25) * two_pi;\n\t\tamps += ampStride;\n\t\tphases += phaseStride;\n\t}\n\t\n\tDSPDoubleSplitComplex in;\n\tin.realp = real;\n\tin.imagp = imag;\n\t\n\tvDSP_ztocD(&in, 1, (DSPDoubleComplex*)polar, 2, kWaveTableSize2);\n\tvDSP_rectD(polar, 2, rect, 2, kWaveTableSize2);\n\tvDSP_ctozD((DSPDoubleComplex*)rect, 2, &in, 1, kWaveTableSize2);\n\trifft(kWaveTableSize, real, imag, table);\n}\n\nstatic void fill3rdOctaveTables(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* tables)\n{\t\n\t// tables is assumed to be allocated to kNumTables * kWaveTableSize samples\n\tfor (int i = 0; i < kNumTables; ++i) {\n\t\tint numHarmonics = std::min(n, gNumHarmonicsForTable[i]);\n\t\tfillWaveTable(numHarmonics, amps, ampStride, phases, phaseStride, smooth, tables + i * kWaveTableSize);\n\t}\n\t\n\tnormalize(kWaveTableTotalSize, tables);\n}\n\nstatic P makeWavetable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth)\n{\n\tP list = new List(itemTypeZ, kWaveTableTotalSize);\n\tP array = list->mArray;\n\t\n\tZ* tables = array->z();\n\t\t\n\tfill3rdOctaveTables(n, amps, ampStride, phases, phaseStride, smooth, tables);\n\tarray->setSize(kWaveTableTotalSize);\n\t\n\treturn list;\n}\n\nstatic void wavefill_(Thread& th, Prim* prim)\n{\n\tZ smooth = th.popFloat(\"wavefill : smooth\");\n\tV phases = th.popZIn(\"wavefill : phases\");\n\tV amps = th.popZIn(\"wavefill : amps\");\n\t\t\n\tP ampl;\n\tP phasel;\n\tZ *phasez, *ampz;\n\tint phaseStride, ampStride; \n\tint64_t n = kMaxHarmonics;\n\tif (phases.isZList()) {\n\t\tphasel = ((List*)phases.o())->packSome(th, n);\n\t\tphasez = phasel->mArray->z();\n\t\tphaseStride = 1;\n\t} else {\n\t\tphasez = &phases.f;\n\t\tphaseStride = 0;\n\t}\n\t\n\tif (amps.isZList()) {\n\t\tampl = ((List*)amps.o())->packSome(th, n);\n\t\tampz = ampl->mArray->z();\n\t\tampStride = 1;\n\t} else {\n\t\tampz = &s.f;\n\t\tampStride = 0;\n\t}\n\t\n\tP list = makeWavetable((int)n, ampz, ampStride, phasez, phaseStride, smooth);\n\tth.push(list);\n}\n\nP gParabolicTable;\nP gTriangleTable;\nP gSquareTable;\nP gSawtoothTable;\n\nstatic void makeClassicWavetables()\n{\n\t//fprintf(stdout, \"computing wave tables\\n\");\n\tZ amps[kMaxHarmonics+1];\n\tZ phases[kMaxHarmonics+1];\n\tZ smooth = 0.;\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i;\n\t}\n\tphases[0] = .25;\n\tgParabolicTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = -1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i;\n\t}\n\n\tphases[0] = 0.;\n\tgTriangleTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t++i;\n\t}\n\tphases[0] = 0.;\n\tgSquareTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i;\n\t}\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tphases[i] = 0.;\t\t++i;\n\t\tphases[i] = .5;\t\t++i;\n\t}\n\tgSawtoothTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases+1, 1, smooth);\n\t\n\tvm.addBifHelp(\"\\n*** classic wave tables ***\");\n\tvm.def(\"parTbl\", gParabolicTable);\t\tvm.addBifHelp(\"parTbl - parabolic wave table.\");\n\tvm.def(\"triTbl\", gTriangleTable);\t\tvm.addBifHelp(\"triTbl - triangle wave table.\");\n\tvm.def(\"sqrTbl\", gSquareTable);\t\t\tvm.addBifHelp(\"sqrTbl - square wave table.\");\n\tvm.def(\"sawTbl\", gSawtoothTable);\t\tvm.addBifHelp(\"sawTbl - sawtooth wave table.\");\n\n\t//fprintf(stdout, \"done computing wave tables\\n\");\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Osc : public ZeroInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOsc(Thread& th, P const& inArray, Z ifreq, Z iphase) : ZeroInputUGen(th, false),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscPM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOscPM(Thread& th, P const& inArray, Z ifreq, Arg phasemod) : OneInputUGen(th, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* phasemod, int phasemodStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscFM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFM(Thread& th, P const& inArray, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\t\t\t\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstruct OscFMPM : public TwoInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFMPM(Thread& th, P const& inArray, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFMPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstatic void newOsc(Thread& th, Arg freq, Arg phase, P const& tables)\n{\n\tif (freq.isZList()) {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscFMPM(th, tables->mArray, freq, phase)));\n\t\t} else {\n\t\t\tth.push(new List(new OscFM(th, tables->mArray, freq, phase.asFloat())));\n\t\t}\n\t} else {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscPM(th, tables->mArray, freq.asFloat(), phase)));\n\t\t} else {\n\t\t\tth.push(new List(new Osc(th, tables->mArray, freq.asFloat(), phase.asFloat())));\n\t\t}\n\t}\n}\n\n\nstatic void osc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"osc : tables\");\n\tV phase = th.popZIn(\"osc : phase\");\n\tV freq = th.popZIn(\"osc : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"osc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tnewOsc(th, freq, phase, tables);\n}\n\nstatic void par_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"par : phase\");\n\tV freq = th.popZIn(\"par : freq\");\n\n\tnewOsc(th, freq, phase, gParabolicTable);\n}\n\nstatic void tri_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"tri : phase\");\n\tV freq = th.popZIn(\"tri : freq\");\n\n\tnewOsc(th, freq, phase, gTriangleTable);\n}\n\nstatic void saw_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"saw : phase\");\n\tV freq = th.popZIn(\"saw : freq\");\n\n\tnewOsc(th, freq, phase, gSawtoothTable);\n}\n\nstatic void square_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"square : phase\");\n\tV freq = th.popZIn(\"square : freq\");\n\n\tnewOsc(th, freq, phase, gSquareTable);\n}\n\nstruct OscPWM : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscPWM(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscPWM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\n\t\t\tZ pphase2 = pphase1 + *duty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\t\t\tout[i] = .5 * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct VarSaw : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tVarSaw(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"VarSaw\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\t\t\t\n\t\t\tZ zduty = std::clamp(*duty, .01, .99);\n\t\t\tZ pphase2 = pphase1 + zduty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\n\t\t\tZ amp = .25 / (zduty - zduty * zduty);\n\t\t\tout[i] = amp * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstatic void oscp_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"oscp : tables\");\n\tV duty = th.popZIn(\"oscp : phaseOffset\");\n\tV phase = th.popZIn(\"oscp : phase\");\n\tV freq = th.popZIn(\"oscp : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"oscp : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void pulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"pulse : phaseOffset\");\n\tV phase = th.popZIn(\"pulse : phase\");\n\tV freq = th.popZIn(\"pulse : freq\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void vsaw_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"vsaw : phaseOffset\");\n\tV phase = th.popZIn(\"vsaw : phase\");\n\tV freq = th.popZIn(\"vsaw : freq\");\n\n\tP tables = gParabolicTable;\n\n\tth.push(new List(new VarSaw(th, tables->mArray, freq, phase, duty)));\n}\n\n\n\nstruct SyncOsc : public TwoInputUGen\n{\n\tP const array;\n\tZ sinePhaseStart;\n\tZ sinePhaseReset;\n\tZ sinePhaseEnd;\n Z wavePhaseResetRatio;\n\tZ phase1;\n\tZ phase2a;\n\tZ phase2b;\n\tZ freqmul1;\n\tZ freqmul2;\n\tZ freqLimit;\n\tZ* tables;\n bool once = true;\n\t\n\tSyncOsc(Thread& th, P const& inArray, Arg freq1, Arg freq2) : TwoInputUGen(th, freq1, freq2),\n\t\tarray(inArray),\n sinePhaseStart(kSineTableSize/4),\n\t\tsinePhaseReset(kSineTableSize/2),\n\t\tsinePhaseEnd(sinePhaseStart + sinePhaseReset),\n wavePhaseResetRatio(kWaveTableSizeF / sinePhaseReset),\n\t\tphase1(sinePhaseStart), \n phase2a(0.), \n phase2b(0.),\n\t\tfreqmul1(.5 * th.rate.radiansPerSample * gInvSineTableOmega),\n\t\tfreqmul2(kWaveTableSizeF * th.rate.invSampleRate),\n\t\tfreqLimit(th.rate.freqLimit),\n\t\ttables(array->z())\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SyncOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq1, Z* freq2, int freq1Stride, int freq2Stride)\n\t{\n if (once) {\n once = false;\n phase2b = kWaveTableSizeF * (fabs(*freq2) / fabs(*freq1));\n }\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq1 = fabs(*freq1);\n\t\t\tZ ffreq2 = fabs(*freq2);\n\t\t\tfreq1 += freq1Stride;\n\t\t\tfreq2 += freq2Stride;\n\t\t\t\t\t\t\t\t\t\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq2), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase2a = floor(phase2a);\n\t\t\tint index2a = (int)iphase2a;\n\t\t\tZ fracphase2a = phase2a - iphase2a;\n\n\t\t\tZ iphase2b = floor(phase2b);\n\t\t\tint index2b = (int)iphase2b;\n\t\t\tZ fracphase2b = phase2b - iphase2b;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates an (extremely quiet) broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ sawA = oscilLUT2(tableA, tableB, index2a, mask, fracphase2a, fractable);\n\t\t\tZ sawB = oscilLUT2(tableA, tableB, index2b, mask, fracphase2b, fractable);\n\t\t\t\n\t\t\tZ window = .5 - .5 * tsinx(phase1);\n\t\t\tout[i] = sawB + window * (sawA - sawB);\n \n\t\t\tZ freq2inc = ffreq2 * freqmul2;\n\n\t\t\tphase2a += freq2inc;\n\t\t\tif (phase2a >= kWaveTableSizeF) phase2a -= kWaveTableSizeF;\n\n\t\t\tphase2b += freq2inc;\n\t\t\tif (phase2b >= kWaveTableSizeF) phase2b -= kWaveTableSizeF;\n\n\t\t\tphase1 += ffreq1 * freqmul1;\n\t\t\tif (phase1 >= sinePhaseEnd) {\n\t\t\t\tphase1 -= sinePhaseReset;\n \n // reset and swap phases\n phase2b = phase2a;\n phase2a = wavePhaseResetRatio * (phase1 - sinePhaseStart) * (ffreq2 / ffreq1); // reset to proper fractional position. \n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ssaw_(Thread& th, Prim* prim)\n{\n\tV freq2 = th.popZIn(\"ssaw : freq2\");\n\tV freq1 = th.popZIn(\"ssaw : freq1\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\nstatic void sosc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"sosc : tables\");\n\tV freq2 = th.popZIn(\"sosc : freq2\");\n\tV freq1 = th.popZIn(\"sosc : freq1\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"sosc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFSaw : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFSaw2 : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw2(Thread& th, Arg freq, Arg phasem) : TwoInputUGen(th, freq, phasem), phase(0.), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw2\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasem, int freqStride, int phasemStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ pphase = phase + 2. * *phasem - 1.;\n\t\t\tif (pphase >= 1.) do { pphase -= 2.; } while (pphase >= 1.);\n\t\t\telse if (pphase < -1.) do { pphase += 2.; } while (pphase < -1.);\n\t\t\tout[i] = pphase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFTri : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFTri(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(2. * th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFTri\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase <= 1. ? phase : 2. - phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 3.) phase -= 4.;\n\t\t\telse if (phase < -1.) phase += 4.;\n\t\t}\n\t}\n};\n\nstatic void lfsaw_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsaw : phase\");\n\tV freq = th.popZIn(\"lfsaw : freq\");\n\n\tth.push(new List(new LFSaw(th, freq, phase)));\n}\n\nstatic void lftri_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lftri : phase\");\n\tV freq = th.popZIn(\"lftri : freq\");\n\n\tth.push(new List(new LFTri(th, freq, phase)));\n}\n\nstruct LFPulse : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulse(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? 1. : 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? 1.f : 0.f;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFPulseBipolar : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulseBipolar(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulseBipolar\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? *duty : *duty - 1. ;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? *duty : *duty - 1.;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFSquare : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSquare(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSquare\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\tout[i] = phase < .5 ? 1. : -1.;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Vosim : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tVosim(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invSampleRate), freqLimit(.5*th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = (freqLimit / *freq);\n\t\t\tout[i] = sc_squared(std::sin(M_PI*std::min(maxnth, *nth)*phase)) * sc_squared(1.-phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\telse if (phase < 0.) phase += 1.;\n\t\t}\n\t}\n};\n\n\nstatic void vosim_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"vosim : n\");\n\tZ phase = th.popFloat(\"vosim : phase\");\n\tV freq = th.popZIn(\"vosim : freq\");\n\n\tth.push(new List(new Vosim(th, freq, phase, n)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SmoothSaw : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSaw(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tout[i] = phase-phase*std::pow(std::abs(phase),std::min(maxnth, *nth));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct SmoothSawPWM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSawPWM(Thread& th, Arg freq, Z iphase, Arg nth, Arg duty) : ThreeInputUGen(th, freq, nth, duty), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, Z* duty, int freqStride, int nthStride, int dutyStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tZ w = *duty;\n\t\t\tZ u = .5*phase - .5;\n\t\t\tZ wphase = (w+u)/(w*phase-u);\n\t\t\tout[i] = wphase*(1.-std::pow(std::abs(phase),std::min(maxnth, *nth)));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tduty += dutyStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\n\nstatic void smoothsawpwm_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"smoothsawpwm : duty\");\n\tV n = th.popZIn(\"smoothsawpwm : n\");\n\tZ phase = th.popFloat(\"smoothsawpwm : phase\");\n\tV freq = th.popZIn(\"smoothsawpwm : freq\");\n\n\tth.push(new List(new SmoothSawPWM(th, freq, phase, n, duty)));\n}\n\n\nstatic void smoothsaw_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"smoothsaw : n\");\n\tZ phase = th.popFloat(\"smoothsaw : phase\");\n\tV freq = th.popZIn(\"smoothsaw : freq\");\n\n\tth.push(new List(new SmoothSaw(th, freq, phase, n)));\n}\n\nstatic void lfpulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulse : duty\");\n\tZ phase = th.popFloat(\"lfpulse : phase\");\n\tV freq = th.popZIn(\"lfpulse : freq\");\n\n\tth.push(new List(new LFPulse(th, freq, phase, duty)));\n}\n\nstatic void lfpulseb_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulseb : duty\");\n\tZ phase = th.popFloat(\"lfpulseb : phase\");\n\tV freq = th.popZIn(\"lfpulseb : freq\");\n\n\tth.push(new List(new LFPulseBipolar(th, freq, phase, duty)));\n}\n\nstatic void lfsquare_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsquare : phase\");\n\tV freq = th.popZIn(\"lfsquare : freq\");\n\n\tth.push(new List(new LFSquare(th, freq, phase)));\n}\n\n\n\n\nstruct Impulse : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tImpulse(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t\tif (phase == 0.) phase = 1.; // force an initial impulse.\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Impulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\tout[i] = 1.;\n\t\t\t} else {\n\t\t\t\tout[i] = 0.;\n\t\t\t}\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstatic void impulse_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"impulse : phase\");\n\tV freq = th.popZIn(\"impulse : freq\");\n\n\tth.push(new List(new Impulse(th, freq, phase)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct SinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n#if 1\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n#else\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n#endif\n\t}\n};\n\nstruct SinOsc2 : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc2(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc2\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct TSinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tTSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"TSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\n\nstruct FSinOsc : public ZeroInputUGen\n{\n\tZ freq;\n\tZ b1, y1, y2;\n\t\n\tFSinOsc(Thread& th, Z ifreq, Z iphase) : ZeroInputUGen(th, false), \n\t\tfreq(ifreq * th.rate.radiansPerSample), \n\t\tb1(2. * cos(freq))\n\t{\n\t\tiphase = sc_wrap(iphase, 0., 1.) * kTwoPi;\n\t\ty1 = sin(iphase-freq);\n\t\ty2 = sin(iphase-2.*freq);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ zy1 = y1;\n\t\tZ zy2 = y2;\n\t\tZ zb1 = b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = zb1 * zy1 - zy2;\n\t\t\tout[i] = y0;\n\t\t\tzy2 = zy1;\n\t\t\tzy1 = y0;\n\t\t}\n\t\ty1 = zy1;\n\t\ty2 = zy2;\n\t}\n};\n\n\n\nstruct SinOscPMFB : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ y1;\n\t\n\tSinOscPMFB(Thread& th, Arg freq, Z iphase, Arg phasefb) : TwoInputUGen(th, freq, phasefb), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMFB\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasefb, int freqStride, int phasefbStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = sin(phase + *phasefb * y1);\n\t\t\tout[i] = y0;\n\t\t\ty1 = y0;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasefb += phasefbStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPM : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPM(Thread& th, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase + *phasemod * kTwoPi;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n\t}\n};\n\nstruct SinOscM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscM(Thread& th, Arg freq, Z iphase, Arg mul, Arg add) : ThreeInputUGen(th, freq, mul, add), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* mul, Z* add, int freqStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPMM : public FourInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPMM(Thread& th, Arg freq, Arg phasemod, Arg mul, Arg add)\n\t\t: FourInputUGen(th, freq, phasemod, mul, add), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* mul, Z* add, int freqStride, int phasemodStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase + *phasemod) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void tsinosc_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"tsinosc : iphase\");\n\tV freq = th.popZIn(\"tsinosc : freq\");\n\n th.push(new List(new SinOsc2(th, freq, phase)));\n}\n\nstatic void sinosc_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"sinosc : phase\");\n\tV freq = th.popZIn(\"sinosc : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPM(th, freq, phase)));\n\t} else if (freq.isZList()) {\n\t\tth.push(new List(new SinOsc(th, freq, phase.f)));\n\t} else {\n\t\tth.push(new List(new FSinOsc(th, freq.f, phase.f)));\n\t}\n}\n\nstatic void sinoscm_(Thread& th, Prim* prim)\n{\n\tV add = th.popZIn(\"sinoscm : mul\");\n\tV mul = th.popZIn(\"sinoscm : add\");\n\tV phase = th.popZIn(\"sinoscm : phase\");\n\tV freq = th.popZIn(\"sinoscm : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPMM(th, freq, phase, mul, add)));\n\t} else {\n\t\tth.push(new List(new SinOscM(th, freq, phase.f, mul, add)));\n\t}\n}\n\n\nstatic void sinoscfb_(Thread& th, Prim* prim)\n{\n\tV fb = th.popZIn(\"sinoscfb : fb\");\n\tZ iphase = th.popFloat(\"sinoscfb : phase\");\n\tV freq = th.popZIn(\"sinoscfb : freq\");\n\n\tth.push(new List(new SinOscPMFB(th, freq, iphase, fb)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Blip : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ nyq_;\n\tBlip(Thread& th, Arg freq, Z iphase, Arg numharms)\n\t\t: TwoInputUGen(th, freq, numharms), phase(sc_wrap(2. * iphase - 1., -1., 1.)), freqmul(th.rate.radiansPerSample),\n\t\tnyq_(th.rate.sampleRate * .5)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Blip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* numharms, int freqStride, int numharmsStride) \n\t{\n\t\tZ nyq = nyq_;\n\t\t\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\t\t\tZ ffreq = *freq * freqmul;\n\n\t\t\tZ maxN = floor(nyq / ffreq);\n\t\t\tZ N = *numharms;\n\t\t\t\n\t\t\tif (N > maxN) N = maxN;\n\t\t\telse if (N < 1.) N = 1.;\n\t\t\t\n\t\t\tZ Na = floor(N);\n\t\t\tZ Nb = Na + 1.;\n\t\t\t\n\t\t\tZ frac = N - Na;\n\t\t\tZ Na_scale = .5 / Na;\n\t\t\tZ Nb_scale = .5 / Nb;\n\n\t\t\tZ Na2 = 2. * Na + 1.;\n\t\t\tZ Nb2 = Na2 + 2.;\n\n\t\t\tZ d = 1. / sin(phase);\n\t\t\tZ a = Na_scale * (sin(Na2 * phase) * d - 1.);\n\t\t\tZ b = Nb_scale * (sin(Nb2 * phase) * d - 1.);\n\n\t\t\tfrac = sc_scurve0(frac); // this eliminates out a broadband tick in the spectrum.\n\n\t\t\tout[i] = a + frac * (b - a);\n\n\t\t\tphase += ffreq;\n\t\t\tfreq += freqStride;\n\t\t\tnumharms += numharmsStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < -kTwoPi) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void blip_(Thread& th, Prim* prim)\n{\n\tV numharms = th.popZIn(\"blip : numharms\");\n\tZ phase = th.popFloat(\"blip : phase\");\n\tV freq = th.popZIn(\"blip : freq\");\n\n\tth.push(new List(new Blip(th, freq, phase, numharms)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF1 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF1(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF1\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = *coef;\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scale = (a - 1.)/(an1 - 1.);\n\t\t\tout[i] = scale * (sin(p1) - a * sin(p1-p2) - an1 * (sin(p1 + N1*p2) - a * sin(p1 + N*p2)))/(1. + a2 - 2. * a * cos(p2));\nprintf(\"%d %f\\n\", i, out[i]);\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf1_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf1 : numharms\");\n\tV coef = th.popZIn(\"dsf1 : coef\");\n\tV modRatio = th.popZIn(\"dsf1 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf1 : carRatio\");\n\tV freq = th.popZIn(\"dsf1 : freq\");\n\n\tth.push(new List(new DSF1(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF3 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF3(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF3\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = std::clamp(*coef, -.9999, .9999);\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scalePeak = (a - 1.)/(2.*an1 - a - 1.);\n\t\t\tZ scale = scalePeak;\n\t\t\tZ denom = (1. + a2 - 2. * a * cos(p2));\n\t\t\tout[i] = scale * sin(p1) * (1. - a2 - 2. * an1 * (cos(N1*p2) - a * cos(N*p2)))/denom;\n\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf3_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf3 : numharms\");\n\tV coef = th.popZIn(\"dsf3 : coef\");\n\tV modRatio = th.popZIn(\"dsf3 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf3 : carRatio\");\n\tV freq = th.popZIn(\"dsf3 : freq\");\n\n\tth.push(new List(new DSF3(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct KlangOsc\n{\n\tKlangOsc(Arg f, Arg a, Z p) :\n\t\tfreq(f), amp(a), phase(p) {}\n\t\t\n\tZIn freq;\n\tZIn amp;\n\tZ phase;\n};\n\nstruct Klang : public Gen\n{\n\tstd::vector _oscs;\n\tZ _freqmul, _K;\n\tZ _nyq, _cutoff, _slope;\n\t\n\tKlang(Thread& th, V freqs, V amps, V phases)\n\t\t: Gen(th, itemTypeZ, false),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 / th.rate.sampleRate),\n\t\t\t_nyq(th.rate.sampleRate * .5),\n\t\t\t_cutoff(_nyq * .8),\n\t\t\t_slope(1. / (_nyq - _cutoff))\n\t{\n\t\tint64_t numOscs = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, freqs.length(th));\n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, amps.length(th));\n\t\t}\n\t\tif (phases.isList()) {\n\t\t\tphases = ((List*)phases.o())->pack(th);\n\t\t\tnumOscs = std::min(numOscs, phases.length(th));\n\t\t}\n\t\t\n\t\tif (numOscs == LONG_MAX) numOscs = 1;\n\t\t\n\t\tfor (int64_t i = 0; i < numOscs; ++i) {\n\t\t\tKlangOsc kf(freqs.at(i), amps.at(i), phases.atz(i));\n\t\t\t_oscs.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"Klang\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\tZ* out0 = mOut->fulfillz(mBlockSize);\n\t\tmemset(out0, 0, mBlockSize * sizeof(Z));\n\t\tint maxToFill = 0;\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ nyq = _nyq;\n\t\tZ cutoff = _cutoff;\n\t\tZ slope = _slope;\n\t\tfor (size_t osc = 0; osc < _oscs.size(); ++osc) {\n\t\t\tint framesToFill = mBlockSize;\n\t\t\tKlangOsc& ko = _oscs[osc];\n\t\t\tZ phase = ko.phase;\n\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp;\n\t\t\t\tint n, freqStride, ampStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (ko.freq(th, n, freqStride, freq) || ko.amp(th, n, ampStride, amp)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ ffreq = *freq;\n\t\t\t\t\tif (ffreq > cutoff) {\n\t\t\t\t\t\tif (ffreq < nyq) {\n\t\t\t\t\t\t\tout[i] += (cutoff - ffreq) * slope * *amp * tsin(phase);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] += *amp * tsin(phase);\n\t\t\t\t\t}\n\t\t\t\t\tphase += ffreq * freqmul;\n\t\t\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tko.freq.advance(n);\n\t\t\t\tko.amp.advance(n);\n\t\t\t}\n\t\t\tko.phase = phase;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\nstatic void klang_(Thread& th, Prim* prim)\n{\n\tV phases\t= th.popZInList(\"klang : phases\");\n\tV amps\t\t= th.popZInList(\"klang : amps\");\n\tV freqs = th.popZInList(\"klang : freqs\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (phases.isVList() && !phases.isFinite())\n\t\tindefiniteOp(\"klank : phases\", \"\");\n\n\tth.push(new List(new Klang(th, freqs, amps, phases)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddOscilUGenOps()\n{\n\tfillHarmonicsTable();\n\n\tvm.addBifHelp(\"\\n*** wavetable generation ***\");\n\tDEFAM(wavefill, aak, \"(amps phases smooth -> wavetable) generates a set 1/3 octave wavetables for table lookup oscillators. sin(i*theta + phases[i])*amps[i]*pow(cos(pi*i/n), smooth). smoothing reduces Gibb's phenomenon. zero is no smoothing\")\n\t\n\tmakeClassicWavetables();\n\n\tvm.addBifHelp(\"\\n*** oscillator unit generators ***\");\n\t\n\tDEFMCX(osc, 3, \"(freq phase wavetable --> out) band limited wave table oscillator. wavetable is a table created with wavefill.\")\n\tDEFMCX(oscp, 4, \"(freq phase phaseOffset wavetable --> out) band limited wave table oscillator pair with phase offset.\")\n\tDEFMCX(sosc, 2, \"(freq1 freq2 wavetable --> out) band limited hard sync wave table oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(par, 2, \"(freq phase --> out) band limited parabolic wave oscillator.\")\n\tDEFMCX(tri, 2, \"(freq phase --> out) band limited triangle wave oscillator.\")\n\tDEFMCX(square, 2, \"(freq phase --> out) band limited square wave oscillator.\")\n\tDEFMCX(saw, 2, \"(freq phase --> out) band limited sawtooth wave oscillator.\")\n\tDEFMCX(pulse, 3, \"(freq phase duty --> out) band limited pulse wave oscillator.\")\n\tDEFMCX(vsaw, 3, \"(freq phase duty --> out) band limited variable sawtooth oscillator.\")\n\tDEFMCX(ssaw, 2, \"(freq1 freq2 --> out) band limited hard sync sawtooth oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(blip, 3, \"(freq phase numharms --> out) band limited impulse oscillator.\")\n\tDEFMCX(dsf1, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 1\")\n\tDEFMCX(dsf3, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) two sided bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 3\")\n\t\n\tDEFMCX(lftri, 2, \"(freq phase --> out) non band limited triangle wave oscillator.\")\n\tDEFMCX(lfsaw, 2, \"(freq phase --> out) non band limited sawtooth wave oscillator.\")\n\tDEFMCX(lfpulse, 3, \"(freq phase duty --> out) non band limited unipolar pulse wave oscillator.\")\n\tDEFMCX(lfpulseb, 3, \"(freq phase duty --> out) non band limited bipolar pulse wave oscillator.\")\n\tDEFMCX(lfsquare, 2, \"(freq phase --> out) non band limited square wave oscillator.\")\n\tDEFMCX(impulse, 2, \"(freq phase --> out) non band limited single sample impulse train oscillator.\")\n\tDEFMCX(smoothsaw, 3, \"(freq phase nth --> out) smoothed sawtooth.\")\n\tDEFMCX(smoothsawpwm, 4, \"(freq phase nth duty --> out) smoothed sawtooth.\")\n\tDEFMCX(vosim, 3, \"(freq phase nth --> out) vosim sim.\")\n\tDEFMCX(sinosc, 2, \"(freq phase --> out) sine wave oscillator.\")\n\tDEFMCX(tsinosc, 2, \"(freq iphase --> out) sine wave oscillator.\")\n\tDEFMCX(sinoscfb, 3, \"(freq phase feedback --> out) sine wave oscillator with self feedback phase modulation\")\n\tDEFMCX(sinoscm, 4, \"(freq phase mul add --> out) sine wave oscillator with multiply and add.\")\n\n\tDEF(klang, 3, 1, \"(freqs amps iphases --> out) a sine oscillator bank. freqs amps and iphases are arrays.\")\n}\n\n\n\n"], ["/sapf/src/DelayUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"DelayUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass DelayN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\n\tDelayN(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n int32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n out[i] = buf[(bufPos-offset) & bufMask];\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayn_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayn : maxdelay\");\n\tV delay = th.popZIn(\"delayn : delay\");\n\tV in = th.popZIn(\"delayn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayN(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayL(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayl_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayl : maxdelay\");\n\tV delay = th.popZIn(\"delayl : delay\");\n\tV in = th.popZIn(\"delayl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayL(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayC(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayc_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayc : maxdelay\");\n\tV delay = th.popZIn(\"delayc : delay\");\n\tV in = th.popZIn(\"delayc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayC(th, in, delay, maxdelay)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass Flange : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlange(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flange() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flange\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) - zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flangep : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlangep(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flangep() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flangep\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) + zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void flange_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flange : maxdelay\");\n\tV delay = th.popZIn(\"flange : delay\");\n\tV in = th.popZIn(\"flange : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flange : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flange(th, in, delay, maxdelay)));\n}\n\nstatic void flangep_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flangep : maxdelay\");\n\tV delay = th.popZIn(\"flangep : delay\");\n\tV in = th.popZIn(\"flangep : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flangep : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flangep(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass CombN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay + 1.));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(std::abs(zdelay) * sr + .5));\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(std::abs(zdelay) * sr + .5);\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combn : decay\");\n\tZ maxdelay = th.popFloat(\"combn : maxdelay\");\n\tV delay = th.popZIn(\"combn : delay\");\n\tV in = th.popZIn(\"combn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ z = fb * (a + frac * (b - a));\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combl : decay\");\n\tZ maxdelay = th.popFloat(\"combl : maxdelay\");\n\tV delay = th.popZIn(\"combl : delay\");\n\tV in = th.popZIn(\"combl : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combc : decay\");\n\tZ maxdelay = th.popFloat(\"combc : maxdelay\");\n\tV delay = th.popZIn(\"combc : delay\");\n\tV in = th.popZIn(\"combc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass LPCombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZIn lpfreq_;\n\tZ maxdelay_;\n\tZ y1_;\n\tZ freqmul_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tLPCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay, Arg lpfreq) : Gen(th, itemTypeZ, false),\n\t\t\tin_(in), delay_(delay), decay_(decay), lpfreq_(lpfreq), maxdelay_(maxdelay), y1_(0.), freqmul_(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~LPCombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"LPCombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tZ y1 = y1_;\n\t\tZ freqmul = freqmul_;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride, lpfreqStride;\n\t\t\tZ *in, *delay, *decay, *lpfreq;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay) || lpfreq_(th, n, lpfreqStride, lpfreq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (lpfreqStride == 0) {\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n }\n\t\t\t\ty1_ = y1;\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tlpfreq_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void lpcombc_(Thread& th, Prim* prim)\n{\n\tV lpfreq = th.popZIn(\"lpcombc : lpfreq\");\n\tV decay = th.popZIn(\"lpcombc : decay\");\n\tZ maxdelay = th.popFloat(\"lpcombc : maxdelay\");\n\tV delay = th.popZIn(\"lpcombc : delay\");\n\tV in = th.popZIn(\"lpcombc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"lpcombc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new LPCombC(th, in, delay, maxdelay, decay, lpfreq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass AllpassN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(zdelay * sr + .5);\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasn : decay\");\n\tZ maxdelay = th.popFloat(\"alpasn : maxdelay\");\n\tV delay = th.popZIn(\"alpasn : delay\");\n\tV in = th.popZIn(\"alpasn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasl : decay\");\n\tZ maxdelay = th.popFloat(\"alpasl : maxdelay\");\n\tV delay = th.popZIn(\"alpasl : delay\");\n\tV in = th.popZIn(\"alpasl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasc : decay\");\n\tZ maxdelay = th.popFloat(\"alpasc : maxdelay\");\n\tV delay = th.popZIn(\"alpasc : delay\");\n\tV in = th.popZIn(\"alpasc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\nclass FDN;\n\nclass FDN_OutputChannel : public Gen\n{\n\tfriend class FDN;\n\tP mFDN;\n\t\npublic:\t\n\tFDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmFDN = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FDN_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nclass FDN : public Object\n{\n\tZIn in_;\n\tZIn wet_;\n\tZ decayLo_;\n\tZ decayMid_;\n\tZ decayHi_;\n\tZ mindelay_;\n\tZ maxdelay_;\n\tZ sr_;\n\t\n\tZ a1Lo, a1Hi;\n\tZ scaleLoLPF, scaleLoHPF, scaleHiLPF, scaleHiHPF;\n\tFDN_OutputChannel* mLeft;\n\tFDN_OutputChannel* mRight;\n\t\n\tstatic const int kNumDelays = 16;\n\t\n\tstruct FDNDelay\n\t{\n\t\tZ* buf;\n\t\tint size, mask, rpos, wpos, offset;\n\t\tZ delay, gain;\n\t\tZ fbLo, fbMid, fbHi;\n\t\tZ x1A, x1B, x1C, x1D;\n\t\tZ y1A, y1B, y1C, y1D;\n\t\t\n\t\tFDNDelay()\n\t\t{\n\t\t}\n\t\t~FDNDelay() { free(buf); }\n\t\t\n\t\tvoid set(Thread& th, const FDN& fdn, Z inDelay, int& ioSampleDelay)\n\t\t{\n\t\t\tint sampleDelay = (int)(th.rate.sampleRate * inDelay);\n\t\t\tif (sampleDelay <= ioSampleDelay) sampleDelay = ioSampleDelay + 2;\n\t\t\tsampleDelay = (int)nextPrime(sampleDelay);\n\t\t\tioSampleDelay = sampleDelay;\n\t\t\tZ actualDelay = (Z)sampleDelay * th.rate.invSampleRate;\n\t\t\tsize = NEXTPOWEROFTWO(sampleDelay);\n\t\t\tmask = size - 1;\n\t\t\tprintf(\"delay %6d %6d %6d %f\\n\", sampleDelay, size, mask, actualDelay);\n\t\t\trpos = 0;\n\t\t\twpos = sampleDelay;\n\t\t\tbuf = (Z*)calloc(size, sizeof(Z));\n\t\t\tconst Z n1 = 1. / sqrt(kNumDelays);\n\t\t\t//const Z n1 = 1. / kNumDelays;\n\t\t\tfbLo = n1 * calcDecay(actualDelay / fdn.decayLo_);\n\t\t\tfbMid = n1 * calcDecay(actualDelay / fdn.decayMid_);\n\t\t\tfbHi = n1 * calcDecay(actualDelay / fdn.decayHi_);\n\t\t\ty1A = 0.;\n\t\t\ty1B = 0.;\n\t\t\ty1C = 0.;\n\t\t\ty1D = 0.;\n\t\t\tx1A = 0.;\n\t\t\tx1B = 0.;\n\t\t\tx1C = 0.;\n\t\t\tx1D = 0.;\n\t\t}\n\t};\n\npublic:\n\n\tFDNDelay mDelay[kNumDelays];\n\t\n\tFDN(Thread& th, Arg in, Arg wet, Z mindelay, Z maxdelay, Z decayLo, Z decayMid, Z decayHi, Z seed)\n\t\t: in_(in), wet_(wet),\n\t\tdecayLo_(decayLo), decayMid_(decayMid), decayHi_(decayHi),\n\t\tmindelay_(mindelay), maxdelay_(maxdelay)\n\t{\n\t\tsr_ = th.rate.sampleRate;\n\t\tZ freqmul = th.rate.invNyquistRate * kFirstOrderCoeffScale;\n\t\ta1Lo = t_firstOrderCoeff(freqmul * 200.);\n\t\ta1Hi = t_firstOrderCoeff(freqmul * 2000.);\n\t\tscaleLoLPF = .5 * (1. - a1Lo);\n\t\tscaleLoHPF = .5 * (1. + a1Lo);\n\t\tscaleHiLPF = .5 * (1. - a1Hi);\n\t\tscaleHiHPF = .5 * (1. + a1Hi);\n\t\t\n\t\tZ delay = mindelay;\n\t\tZ ratio = maxdelay / mindelay;\n\t\tZ interval = pow(ratio, 1. / (kNumDelays - 1.));\n\t\tint prevSampleDelay = 0;\n\t\tfor (int i = 0; i < kNumDelays; ++i) {\n\t\t\tdouble expon = (random() / 2147483647. - .5) * 0.8;\n\t\t\tdouble deviation = pow(interval, expon);\n\t\t\tmDelay[i].set(th, *this, delay * deviation, prevSampleDelay);\n\t\t\tdelay *= interval;\n\t\t}\n\t\t\n\t}\n\t\n\t~FDN() { delete mLeft; delete mRight; }\n\t\n\tvirtual const char* TypeName() const override { return \"FDN\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tvoid matrix(Z x[kNumDelays])\n\t{\n\t\tZ a0 = x[ 0];\n\t\tZ a1 = x[ 1];\n\t\tZ a2 = x[ 2];\n\t\tZ a3 = x[ 3];\n\t\tZ a4 = x[ 4];\n\t\tZ a5 = x[ 5];\n\t\tZ a6 = x[ 6];\n\t\tZ a7 = x[ 7];\n\t\tZ a8 = x[ 8];\n\t\tZ a9 = x[ 9];\n\t\tZ a10 = x[10];\n\t\tZ a11 = x[11];\n\t\tZ a12 = x[12];\n\t\tZ a13 = x[13];\n\t\tZ a14 = x[14];\n\t\tZ a15 = x[15];\n\n\t\tZ b0 = a0 + a1;\n\t\tZ b1 = a0 - a1;\n\t\tZ b2 = a2 + a3;\n\t\tZ b3 = a2 - a3;\n\t\tZ b4 = a4 + a5;\n\t\tZ b5 = a4 - a5;\n\t\tZ b6 = a6 + a7;\n\t\tZ b7 = a6 - a7;\n\t\tZ b8 = a8 + a9;\n\t\tZ b9 = a8 - a9;\n\t\tZ b10 = a10 + a11;\n\t\tZ b11 = a10 - a11;\n\t\tZ b12 = a12 + a13;\n\t\tZ b13 = a12 - a13;\n\t\tZ b14 = a14 + a15;\n\t\tZ b15 = a14 - a15;\n\n\t\tZ c0 = b0 + b2;\n\t\tZ c1 = b1 + b3;\n\t\tZ c2 = b0 - b2;\n\t\tZ c3 = b1 - b3;\n\t\tZ c4 = b4 + b6;\n\t\tZ c5 = b5 + b7;\n\t\tZ c6 = b4 - b6;\n\t\tZ c7 = b5 - b7;\n\t\tZ c8 = b8 + b10;\n\t\tZ c9 = b9 + b11;\n\t\tZ c10 = b8 - b10;\n\t\tZ c11 = b9 - b11;\n\t\tZ c12 = b12 + b14;\n\t\tZ c13 = b13 + b15;\n\t\tZ c14 = b12 - b14;\n\t\tZ c15 = b13 - b15;\n\n\t\tZ d0 = c0 + c4;\n\t\tZ d1 = c1 + c5;\n\t\tZ d2 = c2 + c6;\n\t\tZ d3 = c3 + c7;\n\t\tZ d4 = c0 - c4;\n\t\tZ d5 = c1 - c5;\n\t\tZ d6 = c2 - c6;\n\t\tZ d7 = c3 - c7;\n\t\tZ d8 = c8 + c12;\n\t\tZ d9 = c9 + c13;\n\t\tZ d10 = c10 + c14;\n\t\tZ d11 = c11 + c15;\n\t\tZ d12 = c8 - c12;\n\t\tZ d13 = c9 - c13;\n\t\tZ d14 = c10 - c14;\n\t\tZ d15 = c11 - c15;\n\n\t\tx[ 0] = d0 + d8;\n\t\tx[ 1] = d1 + d9;\n\t\tx[ 2] = d2 + d10;\n\t\tx[ 3] = d3 + d11;\n\t\tx[ 4] = d4 + d12;\n\t\tx[ 5] = d5 + d13;\n\t\tx[ 6] = d6 + d14;\n\t\tx[ 7] = d7 + d15;\n\t\tx[ 8] = d0 - d8;\n\t\tx[ 9] = d1 - d9;\n\t\tx[10] = d2 - d10;\n\t\tx[11] = d3 - d11;\n\t\tx[12] = d4 - d12;\n\t\tx[13] = d5 - d13;\n\t\tx[14] = d6 - d14;\n\t\tx[15] = d7 - d15;\n\t}\n \n\tvirtual void pull(Thread& th) \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, wetStride;\n\t\t\tZ *in;\n\t\t\tZ *wet;\n\t\t\tif (in_(th, n, inStride, in) || wet_(th, n, wetStride, wet)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x[kNumDelays];\n\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\n\t\t\t\t\t\t// read from delay line\n\t\t\t\t\t\tZ x0 = d.buf[d.rpos & d.mask];\n\n\t\t\t\t\t\t// attenuate and filter the output of the delay line.\n\t\t\t\t\t\t\n\t\t\t\t\t\t// high crossover\n\t\t\t\t\t\tZ x0A = scaleHiHPF * x0;\n\t\t\t\t\t\tZ x0B = scaleHiLPF * x0 ;\n\t\t\t\t\t\tZ y0A = x0A - d.x1A + a1Hi * d.y1A;\t// hpf -> high band\n\t\t\t\t\t\tZ y0B = x0B + d.x1B + a1Hi * d.y1B;\t// lpf -> low + mid\n\t\t\t\t\t\td.y1A = y0A;\n\t\t\t\t\t\td.y1B = y0B;\n\t\t\t\t\t\td.x1A = x0A;\n\t\t\t\t\t\td.x1B = x0B;\n\t\t\t\t\t\t\n\t\t\t\t\t\t// low crossover\n\t\t\t\t\t\tZ x0C = scaleLoHPF * y0B;\n\t\t\t\t\t\tZ x0D = scaleLoLPF * y0B;\n\t\t\t\t\t\tZ y0C = x0C - d.x1C + a1Lo * d.y1C;\t// hpf -> mid band\n\t\t\t\t\t\tZ y0D = x0D + d.x1D + a1Lo * d.y1D;\t// lpf -> low band\n\t\t\t\t\t\td.y1C = y0C;\n\t\t\t\t\t\td.y1D = y0D;\n\t\t\t\t\t\td.x1C = x0C;\n\t\t\t\t\t\td.x1D = x0D;\n\t\t\t\t\t\t\n\t\t\t\t\t\tx[j] = d.fbLo * y0D + d.fbMid * y0C + d.fbHi * y0A;\n\n\t\t\t\t\t\t++d.rpos;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tmatrix(x);\n\t\t\t\t\t\n\t\t\t\t\tZ ini = *in;\n\t\t\t\t\tZ w = *wet;\n\t\t\t\t\t*Lout = ini + w * (x[1] - ini);\n\t\t\t\t\t*Rout = ini + w * (x[2] - ini);\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\n\t\t\t\t\t// write back to delay line\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j) \n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\td.buf[d.wpos & d.mask] = x[j] + ini;\n\t\t\t\t\t\t++d.wpos;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tin += inStride;\n\t\t\t\t\twet += wetStride;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nFDN_OutputChannel::FDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN)\n : Gen(th, itemTypeZ, inFinite), mFDN(inFDN)\n{\n}\n\nvoid FDN_OutputChannel::pull(Thread& th)\n{\n\tmFDN->pull(th);\n}\n\nP FDN::createOutputs(Thread& th)\n{\n\tmLeft = new FDN_OutputChannel(th, finite, this);\n\tmRight = new FDN_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void fdn_(Thread& th, Prim* prim)\n{\n\tZ seed = th.popFloat(\"fdn : seed\");\n\tZ maxdelay = th.popFloat(\"fdn : maxdelay\");\n\tZ mindelay = th.popFloat(\"fdn : mindelay\");\n\tZ decayHi = th.popFloat(\"fdn : decayHi\");\n\tZ decayMid = th.popFloat(\"fdn : decayMid\");\n\tZ decayLo = th.popFloat(\"fdn : decayLo\");\n\tV wet = th.popZIn(\"fdn : wet\");\n\tV in = th.popZIn(\"fdn : in\");\n \n\tP fdn = new FDN(th, in, wet, mindelay, maxdelay, decayLo, decayMid, decayHi, seed);\n\t\n\tP s = fdn->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddDelayUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** delay unit generators ***\");\n\tDEFAM(delayn, zzk, \"(in delay maxdelay --> out) delay line with no interpolation.\");\n\tDEFAM(delayl, zzk, \"(in delay maxdelay --> out) delay line with linear interpolation.\");\n\tDEFAM(delayc, zzk, \"(in delay maxdelay --> out) delay line with cubic interpolation.\");\n\tDEFAM(flange, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. delay can be negative. latency is maxdelay.\");\n\tDEFAM(flangep, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. adds delayed signal instead of subtracts.\");\n\t\n\tDEFAM(combn, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with no interpolation.\");\n\tDEFAM(combl, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with linear interpolation.\");\n\tDEFAM(combc, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with cubic interpolation.\");\n\tDEFAM(lpcombc, zzkzz, \"(in delay maxdelay decayTime lpfreq --> out) low pass comb delay filter with cubic interpolation.\");\n\t\n\tDEFAM(alpasn, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with no interpolation.\");\n\tDEFAM(alpasl, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with linear interpolation.\");\n\tDEFAM(alpasc, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with cubic interpolation.\");\n\t//DEFAM(fdn, zzkkkkkk, \"(in wet decayLo decayMid decayHi mindelay maxdelay rseed --> out) feedback delay network reverb.\");\n}\n\n\n"], ["/sapf/src/Opcode.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Opcode.hpp\"\n#include \"clz.hpp\"\n\nconst char* opcode_name[kNumOpcodes] = \n{\n\t\"BAD OPCODE\",\n\t\"opNone\",\n\t\"opPushImmediate\",\n\t\"opPushLocalVar\",\n\t\"opPushFunVar\",\n\t\"opPushWorkspaceVar\",\n\t\n\t\"opPushFun\",\n\n\t\"opCallImmediate\",\n\t\"opCallLocalVar\",\n\t\"opCallFunVar\",\n\t\"opCallWorkspaceVar\",\n\n\t\"opDot\",\n\t\"opComma\",\n\t\"opBindLocal\",\n\t\"opBindLocalFromList\",\n\t\"opBindWorkspaceVar\",\n\t\"opBindWorkspaceVarFromList\",\n\t\n\t\"opParens\",\n\t\"opNewVList\",\n\t\"opNewZList\",\n\t\"opNewForm\",\n\t\"opInherit\",\n\t\"opEach\",\n\t\"opReturn\"\n};\n\n\nstatic void printOpcode(Thread& th, Opcode* c)\n{\n\tV& v = c->v;\n\tpost(\"%p %s \", c, opcode_name[c->op]);\n\tswitch (c->op) {\n\t\tcase opPushImmediate :\n\t\tcase opPushWorkspaceVar :\n\t\tcase opPushFun : \n\t\tcase opCallImmediate :\n\t\tcase opCallWorkspaceVar :\n\t\tcase opDot :\n\t\tcase opComma :\n\t\tcase opInherit :\n\t\tcase opNewForm :\n\t\tcase opBindWorkspaceVar :\n\t\tcase opBindWorkspaceVarFromList :\n\t\tcase opParens :\n\t\tcase opNewVList : \n\t\tcase opNewZList : \n\t\t\tv.printShort(th);\n\t\t\tbreak;\n\t\t\t\n\t\tcase opPushLocalVar :\n\t\tcase opPushFunVar :\n\t\tcase opCallLocalVar :\n\t\tcase opCallFunVar :\n\t\tcase opBindLocal :\n\t\tcase opBindLocalFromList :\n\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\tbreak;\n\t\tcase opEach :\n\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\tbreak;\n\t\t\n\t\tcase opNone :\n\t\tcase opReturn : \n\t\t\tbreak;\n\t\t\n\t\tdefault :\n\t\t\tpost(\"BAD OPCODE\\n\");\n\t}\n\tpost(\"\\n\");\n}\n\nvoid Thread::run(Opcode* opc)\n{\n\tThread& th = *this;\n\ttry {\n\t\tfor (;;++opc) {\n\n\t\t\tV& v = opc->v;\n\n\t\t\tif (vm.traceon) {\n\t\t\t\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n\t\t\t\tprintOpcode(th, opc);\n\t\t\t}\n\n\t\t\tswitch (opc->op) {\n\t\t\t\tcase opNone :\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushImmediate :\n\t\t\t\t\tpush(v);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushLocalVar :\n\t\t\t\t\tpush(getLocal(v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFunVar :\n\t\t\t\t\tpush(fun->mVars[v.i]);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushWorkspaceVar :\n\t\t\t\t\tpush(fun->Workspace()->mustGet(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFun : {\n\t\t\t\t\t\tpush(new Fun(th, (FunDef*)v.o()));\n\t\t\t\t\t} break;\n\t\t\t\t\t\n\t\t\t\tcase opCallImmediate :\n\t\t\t\t\tv.apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallLocalVar :\n\t\t\t\t\tgetLocal(v.i).apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallFunVar :\n\t\t\t\t\tfun->mVars[v.i].apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallWorkspaceVar :\n\t\t\t\t\tfun->Workspace()->mustGet(th, v).apply(th);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase opDot : {\n\t\t\t\t\tV ioValue;\n\t\t\t\t\tif (!pop().dot(th, v, ioValue))\n\t\t\t\t\t\tnotFound(v);\n\t\t\t\t\tpush(ioValue);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase opComma :\n\t\t\t\t\tpush(pop().comma(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opBindLocal :\n\t\t\t\t\tgetLocal(v.i) = pop();\n\t\t\t\t\tbreak;\n\t\t\t\tcase opBindWorkspaceVar : {\n V value = pop();\n if (value.isList() && !value.isFinite()) {\n post(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n } else if (value.isFun()) {\n\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n } break;\n \n\t\t\t\tcase opBindLocalFromList :\n\t\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\t\t{\n\t\t\t\t\tV list = pop();\n\t\t\t\t\tBothIn in(list);\n\t\t\t\t\twhile (1) {\n\t\t\t\t\t\tif (opc->op == opNone) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tV value;\n\t\t\t\t\t\t\tif (in.one(th, value)) {\n\t\t\t\t\t\t\t\tpost(\"not enough items in list for = [..]\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (opc->op == opBindLocalFromList) {\n\t\t\t\t\t\t\t\tgetLocal(opc->v.i) = value;\n\t\t\t\t\t\t\t} else if (opc->op == opBindWorkspaceVarFromList) {\n\t\t\t\t\t\t\t\tv = opc->v;\n\t\t\t\t\t\t\t\tif (value.isList() && !value.isFinite()) {\n\t\t\t\t\t\t\t\t\tpost(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n\t\t\t\t\t\t\t\t} else if (value.isFun()) {\n\t\t\t\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++opc;\n\t\t\t\t\t}\n\t\t\t\t} break;\n\t\t\t\tcase opParens : {\n\t\t\t\t\t\tParenStack ss(th);\n\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewVList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newVList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewZList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newZList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opInherit : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tif (depth < 1) {\n\t\t\t\t\t\t\t\tresult = vm._ee;\n\t\t\t\t\t\t\t} else if (depth > 1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvm.inherit->apply_n(th, 1);\n\t\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewForm : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tTableMap* tmap = (TableMap*)th.top().o();\n\t\t\t\t\t\t\tsize_t numArgs = tmap->mSize;\n\t\t\t\t\t\t\tif (depth == numArgs+1) {\n\t\t\t\t\t\t\t\t// no inheritance, must insert zero for parent.\n\t\t\t\t\t\t\t\tth.tuck(numArgs+1, V(0.));\n\t\t\t\t\t\t\t} else if (depth < numArgs+1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"fewer arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errStackUnderflow;\n\t\t\t\t\t\t\t} else if (depth > numArgs+2) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvm.newForm->apply_n(th, numArgs+2);\n\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opEach :\n\t\t\t\t\tpush(new EachOp(pop(), (int)v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\tcase opReturn : return;\n\t\t\t\t\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t\t\t\tthrow errInternalError;\n\t\t\t}\n\t\t}\n\t} catch (...) {\n\t\tpost(\"backtrace: %s \", opcode_name[opc->op]);\n\t\topc->v.printShort(th);\n\t\tpost(\"\\n\");\n\t\tthrow;\n\t}\n}\n\nCode::~Code() { }\n\nvoid Code::shrinkToFit()\n{\n\tstd::vector(ops.begin(), ops.end()).swap(ops);\n}\n\nvoid Code::add(int _op, Arg v)\n{\n\tops.push_back(Opcode(_op, v));\n}\n\nvoid Code::add(int _op, double f)\n{\n\tadd(_op, V(f));\n}\n\nvoid Code::addAll(const P &that)\n{\n\tfor (Opcode& op : that->ops) {\n\t\tops.push_back(op);\n\t}\n}\n\nvoid Code::decompile(Thread& th, std::string& out)\n{\n\tfor (Opcode& c : ops) {\n\t\tV& v = c.v;\n\t\tswitch (c.op) {\n\t\t\tcase opPushImmediate : {\n\t\t\t\tstd::string s;\n\t\t\t\tv.printShort(th, s);\n\t\t\t\tout += s;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase opPushWorkspaceVar :\n\t\t\tcase opPushFun : \n\t\t\tcase opCallImmediate :\n\t\t\tcase opCallWorkspaceVar :\n\t\t\tcase opDot :\n\t\t\tcase opComma :\n\t\t\tcase opInherit :\n\t\t\tcase opNewForm :\n\t\t\tcase opBindWorkspaceVar :\n\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\tcase opParens :\n\t\t\tcase opNewVList : \n\t\t\tcase opNewZList : \n\t\t\t\tv.printShort(th);\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\tcase opPushLocalVar :\n\t\t\tcase opPushFunVar :\n\t\t\tcase opCallLocalVar :\n\t\t\tcase opCallFunVar :\n\t\t\tcase opBindLocal :\n\t\t\tcase opBindLocalFromList :\n\t\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\tcase opEach :\n\t\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase opNone :\n\t\t\tcase opReturn : \n\t\t\t\tbreak;\n\t\t\t\n\t\t\tdefault :\n\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t}\n\t}\n}\n\n"], ["/sapf/src/RandomOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark RANDOM STREAMS\n\n\ntemplate \nvoid swapifgt(T& a, T& b) { \n\tif (a > b) {\n\t\tT t = a;\n\t\ta = b;\n\t\tb = t;\n\t}\n}\n\n\nstruct URand : ZeroInputGen\n{\t\n RGen r;\n \n\tURand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct URandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tURandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\n\nstruct NURand : NZeroInputGen\n{\t\n RGen r;\n \n\tNURand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct NURandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNURandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct BRand : ZeroInputGen\n{\t\n RGen r;\n \n\tBRand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct BRandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tBRandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct NBRand : NZeroInputGen\n{\t\n RGen r;\n \n\tNBRand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct NBRandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNBRandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct Rand : TwoInputGen\n{\t\n RGen r;\n \n\tRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Randz : TwoInputUGen\n{\t\n RGen r;\n \n\tRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Randz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void urands_(Thread& th, Prim* prim)\n{\n\tGen* g = new URand(th);\n\tth.push(new List(g));\n}\n\nstatic void urandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new URandz(th);\n\tth.push(new List(g));\n}\n\nstatic void brands_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRand(th);\n\tth.push(new List(g));\n}\n\nstatic void brandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRandz(th);\n\tth.push(new List(g));\n}\n\nstatic void nurands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurands : n\");\n\tGen* g = new NURand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nurandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurandz : n\");\n\tGen* g = new NURandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrands : n\");\n\tGen* g = new NBRand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrandz : n\");\n\tGen* g = new NBRandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void rands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Rand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void randz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"randz : hi\");\n\tV a = th.popZIn(\"randz : lo\");\n\t\n\tGen* g = new Randz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrands : n\");\n\t\n\tGen* g = new NRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nrandz : hi\");\n\tV a = th.popZIn(\"nrandz : lo\");\n\tint64_t n = th.popInt(\"nrandz : n\");\n\t\n\tGen* g = new NRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void urand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand();\n\tth.push(z);\n}\n\nstatic void brand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand2();\n\tth.push(z);\n}\n\n\nstatic void newseed_(Thread& th, Prim* prim)\n{\n\tV v;\n\tv.i = timeseed();\n\tth.push(v);\n}\n\nstatic void setseed_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isReal()) wrongType(\"setseed : seed\", \"Float\", v);\n\tth.rgen.init(v.i);\n}\n\nstatic void rand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"rand : hi\");\n\tZ a = th.popFloat(\"rand : lo\");\n\t\n\tswapifgt(a, b);\n\tZ z = th.rgen.rand(a, b);\n\tth.push(z);\n}\n\nstruct Coin : OneInputGen\n{\t\n RGen r;\n \n\tCoin(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Coinz : OneInputUGen\n{\t\n RGen r;\n \n\tCoinz(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoin : NOneInputGen\n{\t\n RGen r;\n \n\tNCoin(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoinz : NOneInputUGen\n{\t\n RGen r;\n \n\tNCoinz(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void coin_(Thread& th, Prim* prim)\n{\n\tZ p = th.popFloat(\"coin : p\");\n\t\n\tZ z = th.rgen.coin(p);\n\tth.push(z);\n}\n\nstatic void coins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coin(th, a);\n\tth.push(new List(g));\n}\n\nstatic void coinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coinz(th, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoins : n\");\n\t\n\tGen* g = new NCoin(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoinz : n\");\n\t\n\tGen* g = new NCoinz(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstruct IRand : TwoInputGen\n{\t\n RGen r;\n \n\tIRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tIRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NIRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNIRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNIRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new IRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"irandz : hi\");\n\tV a = th.popZIn(\"irandz : lo\");\n\t\n\tGen* g = new IRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirands : n\");\n\t\n\tGen* g = new NIRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nirandz : hi\");\n\tV a = th.popZIn(\"nirandz : lo\");\n\tint64_t n = th.popInt(\"nirandz : n\");\n\t\n\tGen* g = new NIRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"irand : hi\");\n\tint64_t a = th.popInt(\"irand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tswapifgt(a, b);\n\tZ z = (Z)r.irand(a, b);\n\tth.push(z);\n}\n\n\nstruct ExcRand : TwoInputGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExcRandz : TwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\t\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExcRand : NTwoInputGen\n{\t\n RGen r;\n \tint64_t prev;\n \n\tNExcRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExcRandz : NTwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tNExcRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void eprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExcRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void eprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprandz : hi\");\n\tV a = th.popZIn(\"eprandz : lo\");\n\t\n\tGen* g = new ExcRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"neprands : n\");\n\t\n\tGen* g = new NExcRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprands : hi\");\n\tV a = th.popZIn(\"eprands : lo\");\n\tint64_t n = th.popInt(\"neprandz : n\");\n\t\n\tGen* g = new NExcRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstruct ExpRand : TwoInputGen\n{\t\n RGen r;\n \n\tExpRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExpRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tExpRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExpRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNExpRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExpRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNExpRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void xrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExpRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"xrandz : hi\");\n\tV a = th.popZIn(\"xrandz : lo\");\n\t\n\tGen* g = new ExpRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nxrands : n\");\n\t\n\tGen* g = new NExpRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nxrandz : hi\");\n\tV a = th.popZIn(\"nxrandz : lo\");\n\tint64_t n = th.popInt(\"xrandz : n\");\n\t\n\tGen* g = new NExpRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"xrand : hi\");\n\tZ a = th.popFloat(\"xrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.xrand(a, b);\n\tth.push(z);\n}\n\nstruct ILinRand : TwoInputGen\n{\t\n RGen r;\n \n\tILinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ILinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tILinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NILinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNILinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NILinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNILinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ILinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"ilinrandz : hi\");\n\tV a = th.popZIn(\"ilinrandz : lo\");\n\t\n\tGen* g = new ILinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nilinrands : n\");\n\t\n\tGen* g = new NILinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nilinrandz : hi\");\n\tV a = th.popZIn(\"nilinrandz : lo\");\n\tint64_t n = th.popInt(\"nilinrandz : n\");\n\t\n\tGen* g = new NILinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"ilinrand : hi\");\n\tint64_t a = th.popInt(\"ilinrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tint64_t x;\n\tif (b < a) { x = a; a = b; b = x; }\n\tZ z = (Z)r.ilinrand(a, b);\n\tth.push(z);\n}\n\n\n\nstruct LinRand : TwoInputGen\n{\t\n RGen r;\n \n\tLinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct LinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tLinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NLinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNLinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NLinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNLinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void linrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new LinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\t\n\tGen* g = new LinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"linrandz : n\");\n\t\n\tGen* g = new NLinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\tint64_t n = th.popInt(\"randz : n\");\n\t\n\tGen* g = new NLinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"linrand : hi\");\n\tZ a = th.popFloat(\"linrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.linrand(a, b);\n\tth.push(z);\n}\n\n\nstruct Rand2 : OneInputGen\n{\t\n RGen r;\n \n\tRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Rand2z : OneInputUGen\n{\t\n RGen r;\n \n\tRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct XorNoise1 : OneInputUGen\n{\t\n uint64_t x = 0xA40203C12F2AD936LL;\n\t\n\tXorNoise1(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise1\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct XorNoise2 : OneInputUGen\n{\t\n uint64_t s[2] = { 0xA40203C12F2AD936LL, 0x9E390BD16B74D6D3LL };\n\t\n\tXorNoise2(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise2\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint32_t raprng(uint64_t i, uint64_t seed)\n{\n// http://cessu.blogspot.com/2008/11/random-access-pseudo-random-numbers.html\n uint64_t r = (2857720171ULL * ((uint32_t) i)) ^ 0x1EF57D8A7B344E7BULL;\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n r += r >> 32;\n r = (2857720171ULL * ((uint32_t) (i ^ r))) ^ (0xD9EA571C8AF880B6ULL + seed);\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n return uint32_t(r + (r >> 32));\n}\n\n\nstruct RandomAccessNoise : OneInputUGen\n{\n uint64_t seed = 0xA40203C12F2AD936LL;\n\tuint64_t k = 0;\n\t\n\tRandomAccessNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RandomAccessNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t hash64shift(uint64_t key)\n{\n key = (~key) + (key << 21); // key = (key << 21) - key - 1;\n key = key ^ (key >> 24);\n key = (key + (key << 3)) + (key << 8); // key * 265\n key = key ^ (key >> 14);\n key = (key + (key << 2)) + (key << 4); // key * 21\n key = key ^ (key >> 28);\n key = key + (key << 31);\n return key;\n}\n\nstruct WangNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tWangNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WangNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t Hash128to64(uint64_t x, uint64_t y) {\n\tconst uint64_t kMul = 0x9ddfea08eb382d69ULL;\n\tuint64_t a = (x ^ y) * kMul;\n\ta ^= (a >> 47);\n\tuint64_t b = (y ^ a) * kMul;\n\tb ^= (b >> 47);\n\tb *= kMul;\n\treturn b;\n}\n\n\nstruct CityNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tCityNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"CityNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Violet : OneInputUGen\n{\t\n RGen r;\n\tZ prev;\n \n\tViolet(Thread& th, Arg a) : OneInputUGen(th, a), prev(0.)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Violet\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = .5 * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = a * r.drand() - a2;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ x = a * r.drand() - .5 * a;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void rand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2s : n\");\n\t\n\tGen* g = new NRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2z : n\");\n\t\n\tGen* g = new NRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstatic void white_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void wangwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"wangwhite : a\");\n\tGen* g = new WangNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void citywhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"citywhite : a\");\n\tGen* g = new CityNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rawhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"rawhite : a\");\n\tGen* g = new RandomAccessNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite : a\");\n\tGen* g = new XorNoise1(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite2_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite2 : a\");\n\tGen* g = new XorNoise2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void violet_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Violet(th, a);\n\tth.push(new List(g));\n}\n\n\nstatic void rand2_(Thread& th, Prim* prim)\n{\n\tZ a = th.popFloat(\"rand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = 2. * a * r.drand() - a;\n\tth.push(z);\n}\n\nstruct IRand2 : OneInputGen\n{\t\n RGen r;\n \n\tIRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRand2z : OneInputUGen\n{\t\n RGen r;\n \n\tIRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNIRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNIRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2s : n\");\n\t\n\tGen* g = new NIRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2z : n\");\n\t\n\tGen* g = new NIRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2_(Thread& th, Prim* prim)\n{\n\tint64_t a = th.popInt(\"irand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = floor((2. * a + 1.) * r.drand() - a);\n\tth.push(z);\n}\n\n\nstruct Pick : ZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPick(Thread& th, P const& array) : ZeroInputGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Pickz : ZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPickz(Thread& th, P const& array) : ZeroInputUGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstruct NPick : NZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPick(Thread& th, int64_t n, P const& array) : NZeroInputGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NPickz : NZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPickz(Thread& th, int64_t n, P const& array) : NZeroInputUGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstatic void picks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"picks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"picks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pick(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pickz(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npicks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npicks : list\");\n\tint64_t n = th.popInt(\"npicks : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npicks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPick(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npickz : list\");\n\tint64_t n = th.popInt(\"npickz : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPickz(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pick_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pick : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\tint64_t n = a->mArray->size();\n\tth.push(a->at(th.rgen.irand0(n)));\n}\n\nstatic int64_t weightIndex(int64_t n, Z* z, Z r)\n{\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += z[i];\n\t\tif (r < sum) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn n-1;\n}\n\nstruct WPick : ZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPick(Thread& th, P const& array, P const& weights) : ZeroInputGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct WPickz : ZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPickz(Thread& th, P const& array, P const& weights) : ZeroInputUGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstruct NWPick : NZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPick(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NWPickz : NZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPickz(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputUGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstatic P sumWeights(P& weights)\n{\n\tconst int64_t n = weights->size();\n\n\tP summedWeights = new Array(itemTypeZ, n);\n\tsummedWeights->setSize(n);\n\t\n\tZ sum = 0.;\n\tZ* z = summedWeights->z();\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += weights->atz(i);\n\t\tz[i] = sum;\n\t}\n\tZ scale = 1. / sum;\n\t\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tz[i] *= scale;\n\t}\n\t\n\treturn summedWeights;\n}\n\nstatic void wpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpicks : weights\");\n\tP a = th.popList(\"wpicks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new WPick(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void wpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpickz : weights\");\n\tP a = th.popList(\"wpickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n \n\tGen* g = new WPickz(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpicks : weights\");\n\tP a = th.popList(\"nwpicks : list\");\n\tint64_t n = th.popInt(\"nwpicks : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPick(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpickz : weights\");\n\tP a = th.popList(\"nwpickz : list\");\n\tint64_t n = th.popInt(\"nwpickz : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPickz(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wpick_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpick : weights\");\n\tP a = th.popList(\"wpick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpick : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpick : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->pack(th);\n\t\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\tconst int64_t n = aa->size();\n\tconst int64_t wn = wa->size();\n\n\tif (n != wn) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push(aa->at(i));\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push(aa->at(n-1));\n}\n\n\nstruct WRand : ZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRand(Thread& th, P const& weights) : ZeroInputGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct WRandz : ZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRandz(Thread& th, P const& weights) : ZeroInputUGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRand : NZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRand(Thread& th, int64_t n, P const& weights) : NZeroInputGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRandz : NZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRandz(Thread& th, int64_t n, P const& weights) : NZeroInputUGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\n\nstatic void wrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrands : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRand(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void wrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrandz : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRandz(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrands : weights\");\n\tint64_t n = th.popInt(\"nwrands : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRand(th, n, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrandz : weights\");\n\tint64_t n = th.popInt(\"nwrandz : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRandz(th, n, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wrand_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrand : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrand : weights must be finite\",\"\");\n\t\n\tw = w->pack(th);\n\t\n\tP wa = w->mArray;\n\tconst int64_t n = wa->size();\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push((Z)i);\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push((Z)(n-1));\n}\n\n\nstruct GrayNoise : OneInputUGen\n{\t\n RGen r;\n\tint32_t counter_;\n \n\tGrayNoise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"GrayNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 4.65661287308e-10f;\n\t\tint32_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstruct Gray64Noise : OneInputUGen\n{\t\n RGen r;\n\tint64_t counter_;\n \n\tGray64Noise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gray64Noise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 1.084202172485504434e-19;\n\t\tint64_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstatic void gray_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray : a\");\n\t\n\tth.push(new List(new GrayNoise(th, a)));\n}\n\nstatic void gray64_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray64 : a\");\n\t\n\tth.push(new List(new Gray64Noise(th, a)));\n}\n\nstruct PinkNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tout[i] = *aa * (u.f - 3.);\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct PinkNoise0 : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise0(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tdice[i] = 0;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise0\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\tconst double scale = pow(2.,-47.)/17.;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tout[i] = *aa * (scale * double(total + newrand)) - 1;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct BlueNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\tZ prev;\n\t\n\tBlueNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a), prev(0.)\n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"BlueNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tZ x = 4. * *aa * (u.f - 3.);\n\t\t\t\t\tout[i] = x - prev;\n\t\t\t\t\tprev = x;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void pink_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink : a\");\n\t\n\tth.push(new List(new PinkNoise(th, a)));\n}\n\nstatic void pink0_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink0 : a\");\n\t\n\tth.push(new List(new PinkNoise0(th, a)));\n}\n\nstatic void blue_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"blue : a\");\n\t\n\tth.push(new List(new BlueNoise(th, a)));\n}\n\n\nstruct BrownNoise : Gen\n{\n\tZIn _a;\n\tZ total_;\n\t\n\tBrownNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\ttotal_ = r.drand2();\n \n\t}\n \n\tvirtual const char* TypeName() const override { return \"BrownNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ z = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tz += r.drand16();\n\t\t\t\t\tif (z > 1.) z = 2. - z;\n\t\t\t\t\telse if (z < -1.) z = -2. - z;\n\t\t\t\t\tout[i] = *aa * z;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = z;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void brown_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"brown : a\");\n\t\n\tth.push(new List(new BrownNoise(th, a)));\n}\n\nstruct Dust : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * z / thresh : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Dust2 : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust2(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust2\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * (2. * z / thresh - 1.) : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Velvet : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tVelvet(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Velvet\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ thresh2 = .5 * thresh;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? (zfulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct TooshPlus : Gen\n{\n\tZIn _delay;\n\tZIn _amp;\n\tint64_t _counter;\n\tZ sampleRate;\n\t\n\tTooshPlus(Thread& th, Arg delay, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(delay, amp)), _delay(delay), _amp(amp), sampleRate(th.rate.sampleRate)\n\t{\n\t\t_counter = th.rgen.trand();\n\t}\n \n\tvirtual const char* TypeName() const override { return \"TooshPlus\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void toosh_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toosh : amp\");\n\tV delay = th.popZIn(\"toosh : delay\");\n \n\tth.push(new List(new Toosh(th, delay, amp)));\n}\n\nstatic void tooshp_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tooshp : amp\");\n\tV delay = th.popZIn(\"tooshp : delay\");\n \n\tth.push(new List(new TooshPlus(th, delay, amp)));\n}\n\nstruct Crackle : Gen\n{\n\tZIn _param;\n\tZ _y1, _y2;\n\t\n\tCrackle(Thread& th, Arg param) \n : Gen(th, itemTypeZ, param.isFinite()), _param(param), _y1(th.rgen.drand()), _y2(0.)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Crackle\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint paramStride;\n\t\t\tZ *param;\n\t\t\tif (_param(th, n, paramStride, param)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n Z y1 = _y1;\n Z y2 = _y2;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n Z y0 = fabs(y1 * *param - y2 - 0.05);\n y2 = y1; y1 = y0;\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\tparam += paramStride;\n\t\t\t\t}\n _y1 = y1;\n _y2 = y2;\n\t\t\t\t_param.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void crackle_(Thread& th, Prim* prim)\n{\n\tV param = th.popZIn(\"cracke : param\");\n \n\tth.push(new List(new Crackle(th, param)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD RANDOM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n\nvoid AddRandomOps();\nvoid AddRandomOps()\n{\n\tvm.addBifHelp(\"\\n*** random number generation ***\");\n\n\tDEFnoeach(newseed, 0, 1, \"(--> seed) make a new random seed.\");\n\tDEFnoeach(setseed, 1, 0, \"(seed -->) set the random seed.\");\n\n\t\n\tvm.addBifHelp(\"\\n*** single random numbers ***\");\n\tDEFAM(rand, kk, \"(a b --> r) return a uniformly distributed random real value from a to b.\")\n\tDEFAM(coin, k, \"(p --> r) return 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(rand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(irand, kk, \"(a b --> r) return a uniformly distributed random integer value from a to b.\")\n\tDEFAM(irand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(xrand, kk, \"(a b --> r) return a exponentially distributed random real value from a to b.\") \n\tDEFAM(linrand, kk, \"(a b --> r) return a linearly distributed random real value from a to b.\")\t \n\tDEFAM(ilinrand, kk, \"(a b --> r) return a linearly distributed random integer value from a to b.\") \n\tDEF(wrand, 1, 1, \"(w --> r) return a randomly chosen index from a list of probability weights. w should sum to one.\") \n\tDEF(pick, 1, 1, \"(a --> r) return a randomly chosen element from the finite list a.\") \n\tDEF(wpick, 2, 1, \"(a w --> r) return a randomly chosen element from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random streams ***\");\n\tDEFAM(rands, kk, \"(a b --> r) return a stream of uniformly distributed random real values from a to b.\")\n\tDEFAM(coins, k, \"(p --> r) return a stream of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(eprands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b, excluding the previously returned value.\")\t\n\tDEFAM(rand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(irands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b.\")\n\tDEFAM(irand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(xrands, kk, \"(a b --> r) return a stream of exponentially distributed random real values from a to b.\")\n\tDEFAM(linrands, kk, \"(a b --> r) return a stream of linearly distributed random real values from a to b.\")\n\tDEFAM(ilinrands, kk, \"(a b --> r) return a stream of linearly distributed random integer values from a to b.\")\n\tDEF(wrands, 1, 1, \"(w --> r) return a stream of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEF(picks, 1, 1, \"(a --> r) return a stream of randomly chosen elements from the finite list a.\") \n\tDEF(wpicks, 2, 1, \"(a w --> r) return a stream of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random signals ***\");\n\tDEFMCX(randz, 2, \"(a b --> r) return a signal of uniformly distributed random real values from a to b.\")\n\tDEFMCX(coinz, 1, \"(p --> r) return a signal of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(eprandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(rand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(irandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b.\")\n\tDEFMCX(irand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(xrandz, 2, \"(a b --> r) return a signal of exponentially distributed random real values from a to b.\")\n\tDEFMCX(linrandz, 2, \"(a b --> r) return a signal of linearly distributed random real values from a to b.\")\n\tDEFMCX(ilinrandz, 2, \"(a b --> r) return a signal of linearly distributed random integer values from a to b.\")\n\tDEFMCX(wrandz, 1, \"(w --> r) return a signal of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(pickz, 1, \"(a --> r) return a signal of randomly chosen elements from the finite list a.\") \n\tDEFMCX(wpickz, 2, \"(a w --> r) return a signal of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** finite random streams ***\");\n\tDEFAM(nrands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random real values from a to b.\")\n\tDEFAM(ncoins, kk, \"(n p --> r) return a stream of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(neprands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b, excluding the previously returned value.\")\n\tDEFAM(nrand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nirands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b.\")\n\tDEFAM(nirand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nxrands, kkk, \"(n a b --> r) return a stream of n exponentially distributed random real values from a to b.\")\n\tDEFAM(nlinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random real values from a to b.\")\n\tDEFAM(nilinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random integer values from a to b.\")\n\tDEFAM(nwrands, ka, \"(n w --> r) return a stream of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFAM(npicks, ka, \"(n a --> r) return a stream of n randomly chosen elements from the finite list a.\") \n\tDEFAM(nwpicks, kaa, \"(n a w --> r) return a stream of n randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** finite random signals ***\");\n\tDEFMCX(nrandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random real values from a to b.\")\n\tDEFMCX(ncoinz, 2, \"(n p --> r) return a signal of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(neprandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(nrand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nirandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b.\")\n\tDEFMCX(nirand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nxrandz, 3, \"(n a b --> r) return a signal of n exponentially distributed random real values from a to b.\")\n\tDEFMCX(nlinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random real values from a to b.\")\n\tDEFMCX(nilinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random integer values from a to b.\")\t\n\tDEFMCX(nwrandz, 2, \"(n w --> r) return a signal of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(npickz, 2, \"(n a --> r) return a signal of n randomly chosen elements from the finite signal a.\") \n\tDEFMCX(nwpickz, 3, \"(n a w --> r) return a signal of n randomly chosen elements from the finite signal a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** noise unit generators ***\");\n\tDEFMCX(violet, 1, \"(amp --> z) violet noise\")\n\tDEFMCX(blue, 1, \"(amp --> z) blue noise\")\n\tDEFMCX(xorwhite, 1, \"(amp --> z) white noise\")\n\tDEFMCX(xorwhite2, 1, \"(amp --> z) white noise\")\n\tDEFMCX(rawhite, 1, \"(amp --> z) white noise based on Cessu's random access random numbers\")\n\tDEFMCX(wangwhite, 1, \"(amp --> z) white noise based on Thomas Wang's integer hash\")\n\tDEFMCX(citywhite, 1, \"(amp --> z) white noise based on a function from CityHash\")\n\tDEFMCX(white, 1, \"(amp --> z) white noise\")\n\tDEFMCX(pink, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(pink0, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(brown, 1, \"(amp --> z) brown noise\")\n\tDEFMCX(gray, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(gray64, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(dust, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from 0 to a and whose average density is in impulses per second.\")\t\n\tDEFMCX(dust2, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from -a to +a and whose average density is in impulses per second.\")\n\tDEFMCX(velvet, 2, \"(density amp --> z) a stream of impulses whose amplitude is randomly either -a or +a and whose average density is in impulses per second.\")\n\tDEFMCX(toosh, 2, \"(delay amp --> z) flanged noise. difference of two white noise sources with a delay.\")\n\tDEFMCX(tooshp, 2, \"(delay amp--> z) flanged noise. sum of two white noise sources with a delay. no null at delay == 0. \")\n\tDEFMCX(crackle, 1, \"(param --> z) a chaotic generator.\")\t\n}\n\n\n"], ["/sapf/src/SetOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n\nstruct SetPair\n{\n\tV mValue;\n\tint mIndex;\n};\n\nclass Set : public Object\n{\n\tint mSize;\n\tint mCap;\n\tint* mIndices;\n\tSetPair* mPairs;\n\t\n\tvoid grow(Thread& th);\n\tvoid alloc(int cap);\n \n\tSet(const Set& that) {}\npublic:\n\t\n\tSet(int capacity) { alloc(capacity); }\n Set(Thread& th, P list) { alloc(32); putAll(th, list); }\n \n\tvirtual ~Set();\n\t\n\tvirtual const char* TypeName() const override { return \"Set\"; }\n \n\tvirtual bool isSet() const override { return true; }\n\tvirtual bool Equals(Thread& th, Arg v) override;\n\t\n\tint size() { return mSize; }\n\t\n\tbool has(Thread& th, V& value);\n int indexOf(Thread& th, V& value);\n\t\n\tvoid put(Thread& th, V& inValue, int inIndex);\n \n void putAll(Thread& th, P& list);\n\t\n\tvirtual V at(int64_t i) override { return mPairs[i].mValue; }\n \n P asVList(Thread& th);\n P asZList(Thread& th);\n};\n\n\nbool Set::Equals(Thread& th, Arg v) \n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isSet()) return false;\n\tif (this == v.o()) return true;\n\tSet* that = (Set*)v.o();\n\tif (mSize != that->size()) return false;\n \n\tfor (int64_t i = 0; i < mSize; ++i) {\n\t\tV& value = mPairs[i].mValue;\n\t\tV u;\n\t\tif (!that->has(th, value)) return false;\n\t}\n \n\treturn true;\n}\n\nbool Set::has(Thread& th, V& value) \n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn false;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn true;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn false;\n}\n\nint Set::indexOf(Thread& th, V& value)\n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn -1;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn pairs[index2].mIndex;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn -1;\n}\n\n\nSet::~Set()\n{\n\tdelete [] mPairs;\n\tfree(mIndices);\n}\n\nvoid Set::alloc(int cap)\n{\n\tcap = NEXTPOWEROFTWO(cap);\n\tmPairs = new SetPair[cap];\n\tmIndices = (int*)calloc(2 * cap, sizeof(int));\n\tmCap = cap;\n\tmSize = 0;\n}\n\nvoid Set::grow(Thread& th)\n{\n\tfree(mIndices);\n \n\tSetPair* oldPairs = mPairs;\n\tint oldSize = mSize;\n \n\talloc(mCap * 2);\n\t\n\tfor (int i = 0; i < oldSize; ++i) {\n\t\tSetPair& pair = oldPairs[i];\n\t\tput(th, pair.mValue, pair.mIndex);\n\t}\n\t\n\tdelete [] oldPairs;\n}\n\nvoid Set::put(Thread& th, V& inValue, int inIndex)\n{\n\tif (mSize == mCap) {\n\t\tgrow(th);\n\t}\n \n\tint hash = inValue.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n \n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\tindex2 = mSize++;\n\t\t\tindices[index] = index2+1;\n\t\t\tpairs[index2].mValue = inValue;\n\t\t\tpairs[index2].mIndex = inIndex;\n\t\t\treturn;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (inValue.Equals(th, testVal)) {\n\t\t\treturn;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\n}\n\nvoid Set::putAll(Thread& th, P& in)\n{\n // caller must ensure that in is finite.\n int64_t insize = in->length(th);\n in = in->pack(th);\n for (int i = 0; i < insize; ++i) {\n V val = in->at(i);\n put(th, val, i);\n }\n}\n\n\nP Set::asVList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeV, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nP Set::asZList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeZ, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nstatic P nub(Thread& th, P in)\n{\n P set = new Set(th, in);\n \n return set->asVList(th);\n}\n\n\nstatic P set_or(Thread& th, P a, P b)\n{\n P set = new Set(32);\n\n set->putAll(th, a);\n set->putAll(th, b);\n return a->isZ() && b->isZ() ? set->asZList(th) : set->asVList(th);\n}\n\nstatic P set_and(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_minus(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_xor(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n for (int64_t i = 0; i < setB->size(); ++i) {\n V v = setB->at(i);\n if (!setA->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic bool subset(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) return false;\n }\n\t\n\treturn true;\n}\n\nstatic bool set_equals(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n\treturn setA->Equals(th, setB);\n}\n\n/* \n \n list minus values from set.\n \n \n \n\n \n \n \n*/\n\n\nstatic void nub_(Thread& th, Prim* prim)\n{\n P a = th.popList(\"nub : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"nub : a\", \"\");\n \n th.push(nub(th, a));\n}\n\nstatic void set_or_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"|| : b\");\n if (!b->isFinite())\n indefiniteOp(\"|| : b\", \"\");\n \n P a = th.popList(\"|| : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"|| : a\", \"\");\n \n th.push(set_or(th, a, b));\n}\n\nstatic void set_and_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"&& : b\");\n if (!b->isFinite())\n indefiniteOp(\"&& : b\", \"\");\n \n P a = th.popList(\"&& : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"&& : a\", \"\");\n \n th.push(set_and(th, a, b));\n}\n\n\nstatic void set_xor_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_xor : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_xor : b\", \"\");\n \n P a = th.popList(\"set_xor : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_xor : a\", \"\");\n \n th.push(set_xor(th, a, b));\n}\n\nstatic void set_minus_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_minus : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_minus : b\", \"\");\n \n P a = th.popList(\"set_minus : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_minus : a\", \"\");\n \n th.push(set_minus(th, a, b));\n}\n\nstatic void subset_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"subset : b\");\n if (!b->isFinite())\n indefiniteOp(\"subset : b\", \"\");\n \n P a = th.popList(\"subset : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"subset : a\", \"\");\n \n th.pushBool(subset(th, a, b));\n}\n\n\nstatic void set_equals_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_equals : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_equals : b\", \"\");\n \n P a = th.popList(\"set_equals : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_equals : a\", \"\");\n \n th.push(set_equals(th, a, b));\n}\n\nstruct FindV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tFindV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->indexOf(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct FindZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tFindZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeZ, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->indexOf(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct SetHasV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tSetHasV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->has(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct SetHasZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tSetHasZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->has(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic V findBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new FindZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new FindV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->indexOf(th, a);\n\t}\n\treturn result;\n}\n\nstatic void find_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"find : list\");\n if (!b->isFinite())\n indefiniteOp(\"find : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(findBase(th, a, setB));\n}\n\nstatic V hasBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new SetHasZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new SetHasV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->has(th, a);\n\t}\n\treturn result;\n}\n\nstatic void sethas_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"Shas : list\");\n if (!b->isFinite())\n indefiniteOp(\"Shas : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(hasBase(th, a, setB));\n}\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddSetOps();\nvoid AddSetOps()\n{\n\tvm.addBifHelp(\"\\n*** set operations ***\");\n vm.def(\"S\", 1, 1, nub_, \"(list --> set) removes all duplicates from a finite list.\");\n vm.def(\"S|\", 2, 1, set_or_, \"(listA listB --> set) returns the set union of the elements of lists A and B.\");\n vm.def(\"S&\", 2, 1, set_and_, \"(listA listB --> set) returns the set intersection of the elements of lists A and B.\");\n vm.def(\"Sx\", 2, 1, set_xor_, \"(listA listB --> set) returns the set of the elements which occur in list A or B, but not both.\");\n vm.def(\"S-\", 2, 1, set_minus_, \"(listA listB --> set) returns the set of the elements of listA which do not occur in listB.\");\n vm.def(\"S=\", 2, 1, set_equals_, \"(listA listB --> set) returns 1 if the set of elements in listA is equal to the set of elements in listB.\");\n vm.def(\"subset?\", 2, 1, subset_, \"(listA listB --> set) returns 1 if the set of elements of listA is a subset of the set of elements of listB. else 0.\");\n vm.def(\"find\", 2, 1, find_, \"(item(s) list --> set) returns index of item in finite list, or -1 if not in list.\");\n vm.def(\"Shas\", 2, 1, sethas_, \"(item(s) list --> set) returns 1 if finite list contains item(s), else 0.\");\n}\n\n\n\n\n\n\n"], ["/sapf/src/MathOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathOps.hpp\"\n#include \"clz.hpp\"\n#include \n#include \"primes.hpp\"\n#include \n\n\n\nV BinaryOp::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpGen(th, this, a, b));\n}\n\nV BinaryOp::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpZGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n}\n\nvoid UnaryOp::loop(Thread& th, int n, V *a, int astride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->unaryOp(th, this);\n\t\ta += astride;\n\t} \n}\n\nvoid BinaryOp::loop(Thread& th, int n, V *a, int astride, V *b, int bstride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, *b);\n\t\ta += astride;\n\t\tb += bstride;\n\t} \n}\n\nvoid BinaryOp::loopzv(Thread& th, int n, Z *aa, int astride, V *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa;\n\t\tArg b = *bb; \n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\nvoid BinaryOp::loopvz(Thread& th, int n, V *aa, int astride, Z *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa; \n\t\tArg b = *bb;\n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\n\nvoid BinaryOp::scan(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = x = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::pairs(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, x);\n\t\tx = *a;\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::reduce(Thread& th, int n, V& z, V *a, int astride)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tx = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\n\nvoid UnaryOpZGen::pull(Thread& th) {\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ *a;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, out);\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nvoid BinaryOpZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\nvoid BinaryOpLinkZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_b.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else if (_b(th, n,bstride, b)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nstatic void DoPairwise(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new PairsOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new PairsOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoScan(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new ScanOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new ScanOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIPairwise(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IPairsOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IPairsOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoIScan(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IScanOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IScanOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z, *x;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = kDefaultVBlockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = 0., *x;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = th.rate.blockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reducez(n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z = b, *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\twhile(1) {\n\t\t\tn = kDefaultVBlockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = b.asFloat(), *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\twhile(1) {\n\t\t\tn = th.rate.blockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reducez(n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n#define UNARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.unaryOp(th, &gUnaryOp_##NAME); \\\n\t\tth.push(c); \\\n\t} \\\n\n\n#define BINARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV b = th.pop(); \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.binaryOp(th, &gBinaryOp_##NAME, b); \\\n\t\tth.push(c); \\\n\t} \\\n\tstatic void NAME##_reduce_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoReduce(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_scan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_pairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_iscan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_ipairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\n#define DEFINE_UNOP_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV(NAME, CODE, VVNAME) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *x, int astride, Z *y) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVNAME(y, x, &n); \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *x; y[i] = CODE; x += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV2(NAME, CODE, VVCODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (Z)(CODE); aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_BOOL_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_BOOL_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (CODE) ? 1. : 0.; \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n\n\n\n\n\n#define DEFINE_BINOP_FLOAT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOAT_STRING(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE); \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOATVV(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tVVCODE; \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_FLOATVV1(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tif (astride == 1 && bstride == 1) { \\\n\t\t\t\t VVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t\t} \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_INT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa, double bb) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\tint64_t b = (int64_t)bb; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; int64_t b = (int64_t)*bb; out[i] = (Z)(CODE); aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t b = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = (Z)b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; Z x = CODE; out[i] = x; a = (int64_t)x; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; a = (int64_t)(CODE); aa += astride; } \\\n\t\t\tz = (Z)a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_BOOL_FLOAT(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = (CODE) ? 1. : 0.; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE) ? 1. : 0.; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\nDEFINE_UNOP_BOOL_INT(isalnum, isalnum((int)a))\nDEFINE_UNOP_BOOL_INT(isalpha, isalpha((int)a))\nDEFINE_UNOP_BOOL_INT(isblank, isblank((int)a))\nDEFINE_UNOP_BOOL_INT(iscntrl, iscntrl((int)a))\nDEFINE_UNOP_BOOL_INT(isdigit, isdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isgraph, isgraph((int)a))\nDEFINE_UNOP_BOOL_INT(islower, islower((int)a))\nDEFINE_UNOP_BOOL_INT(isprint, isprint((int)a))\nDEFINE_UNOP_BOOL_INT(ispunct, ispunct((int)a))\nDEFINE_UNOP_BOOL_INT(isspace, isspace((int)a))\nDEFINE_UNOP_BOOL_INT(isupper, isupper((int)a))\nDEFINE_UNOP_BOOL_INT(isxdigit, isxdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isascii, isascii((int)a))\n\nDEFINE_UNOP_BOOL_FLOAT(not, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonneg, a >= 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonpos, a <= 0.)\nDEFINE_UNOP_BOOL_FLOAT(isneg, a < 0.)\nDEFINE_UNOP_BOOL_FLOAT(ispos, a > 0.)\nDEFINE_UNOP_BOOL_FLOAT(iszero, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(isint, (a - floor(a)) == 0.)\nDEFINE_UNOP_BOOL_INT(iseven, !(a & 1))\nDEFINE_UNOP_BOOL_INT(isodd, (a & 1))\nDEFINE_UNOP_BOOL_INT(isprime, isprime(a))\n\nDEFINE_UNOP_BOOL_FLOAT(isfinite, std::isfinite(a))\nDEFINE_UNOP_BOOL_FLOAT(isinf, std::isinf(a))\nDEFINE_UNOP_BOOL_FLOAT(isnormal, std::isnormal(a))\nDEFINE_UNOP_BOOL_FLOAT(isnan, std::isnan(a))\nDEFINE_UNOP_BOOL_FLOAT(signbit, std::signbit(a))\n\nstruct UnaryOp_ToZero : public UnaryOp {\n\tvirtual const char *Name() { return \"ToZero\"; }\n\tvirtual double op(double a) { return 0.; }\n\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) {\n\t\tLOOP(i,n) { out[i] = 0.; }\n\t}\n};\nUnaryOp_ToZero gUnaryOp_ToZero; \n\nDEFINE_UNOP_FLOATVV2(neg, -a, vDSP_vnegD(const_cast(aa), astride, out, 1, n))\nDEFINE_UNOP_FLOAT(sgn, sc_sgn(a))\nDEFINE_UNOP_FLOATVV(abs, fabs(a), vvfabs)\n\nDEFINE_UNOP_INT(tolower, tolower((int)a))\nDEFINE_UNOP_INT(toupper, toupper((int)a))\nDEFINE_UNOP_INT(toascii, toascii((int)a))\n\nDEFINE_UNOP_FLOATVV2(frac, a - floor(a), vvfloor(out, aa, &n); vDSP_vsubD(out, 1, aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV(floor, floor(a), vvfloor)\nDEFINE_UNOP_FLOATVV(ceil, ceil(a), vvceil)\nDEFINE_UNOP_FLOATVV(rint, rint(a), vvnint)\n\nDEFINE_UNOP_FLOAT(erf, erf(a))\nDEFINE_UNOP_FLOAT(erfc, erfc(a))\n\nDEFINE_UNOP_FLOATVV(recip, 1./a, vvrec)\nDEFINE_UNOP_FLOATVV(sqrt, sc_sqrt(a), vvsqrt)\nDEFINE_UNOP_FLOATVV(rsqrt, 1./sc_sqrt(a), vvrsqrt)\nDEFINE_UNOP_FLOAT(cbrt, cbrt(a))\nDEFINE_UNOP_FLOATVV2(ssq, copysign(a*a, a), vDSP_vssqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV2(sq, a*a, vDSP_vsqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOAT(cb, a*a*a)\nDEFINE_UNOP_FLOAT(pow4, sc_fourth(a))\nDEFINE_UNOP_FLOAT(pow5, sc_fifth(a))\nDEFINE_UNOP_FLOAT(pow6, sc_sixth(a))\nDEFINE_UNOP_FLOAT(pow7, sc_seventh(a))\nDEFINE_UNOP_FLOAT(pow8, sc_eighth(a))\nDEFINE_UNOP_FLOAT(pow9, sc_ninth(a))\n\nDEFINE_UNOP_FLOATVV(exp, exp(a), vvexp)\nDEFINE_UNOP_FLOATVV(exp2, exp2(a), vvexp2)\nDEFINE_UNOP_FLOAT(exp10, pow(10., a))\nDEFINE_UNOP_FLOATVV(expm1, expm1(a), vvexpm1)\nDEFINE_UNOP_FLOATVV(log, sc_log(a), vvlog)\nDEFINE_UNOP_FLOATVV(log2, sc_log2(a), vvlog2)\nDEFINE_UNOP_FLOATVV(log10, sc_log10(a), vvlog10)\nDEFINE_UNOP_FLOATVV(log1p, log1p(a), vvlog1p)\nDEFINE_UNOP_FLOATVV(logb, logb(a), vvlogb)\n\nDEFINE_UNOP_FLOAT(sinc, sc_sinc(a))\n\nDEFINE_UNOP_FLOATVV(sin, sin(a), vvsin)\nDEFINE_UNOP_FLOATVV(cos, cos(a), vvcos)\nDEFINE_UNOP_FLOATVV2(sin1, sin(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvsin(out, out, &n))\nDEFINE_UNOP_FLOATVV2(cos1, cos(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvcos(out, out, &n))\nDEFINE_UNOP_FLOATVV(tan, tan(a), vvtan)\nDEFINE_UNOP_FLOATVV(asin, asin(a), vvasin)\nDEFINE_UNOP_FLOATVV(acos, acos(a), vvacos)\nDEFINE_UNOP_FLOATVV(atan, atan(a), vvatan)\nDEFINE_UNOP_FLOATVV(sinh, sinh(a), vvsinh)\nDEFINE_UNOP_FLOATVV(cosh, cosh(a), vvcosh)\nDEFINE_UNOP_FLOATVV(tanh, tanh(a), vvtanh)\nDEFINE_UNOP_FLOATVV(asinh, asinh(a), vvasinh)\nDEFINE_UNOP_FLOATVV(acosh, acosh(a), vvacosh)\nDEFINE_UNOP_FLOATVV(atanh, atanh(a), vvatanh)\n\nDEFINE_UNOP_FLOAT(J0, j0(a))\nDEFINE_UNOP_FLOAT(J1, j1(a))\nDEFINE_UNOP_FLOAT(Y0, y0(a))\nDEFINE_UNOP_FLOAT(Y1, y1(a))\n\nDEFINE_UNOP_FLOAT(tgamma, tgamma(a))\nDEFINE_UNOP_FLOAT(lgamma, lgamma(a))\n\nstatic void sc_clipv(int n, const Z* in, Z* out, Z a, Z b)\n{\n\tfor (int i = 0; i < n; ++i) {\n\t\tout[i] = std::clamp(in[i], a, b);\n\t}\n}\n\nDEFINE_UNOP_FLOATVV2(inc, a+1, Z b = 1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(dec, a-1, Z b = -1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(half, a*.5, Z b = .5; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(twice, a*2., Z b = 2.; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n))\n\n\nDEFINE_UNOP_FLOATVV2(biuni, a*.5+.5, Z b = .5; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibi, a*2.-1., Z b = 2.; Z c = -1.; vDSP_vsmulD(aa, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOATVV2(biunic, std::clamp(a,-1.,1.)*.5+.5, Z b = .5; sc_clipv(n, aa, out, -1., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibic, std::clamp(a,0.,1.)*2.-1., Z b = 2.; Z c = -1.; sc_clipv(n, aa, out, 0., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOAT(cmpl, 1.-a)\n\nDEFINE_UNOP_FLOATVV2(ampdb, sc_ampdb(a), Z b = 1.; vDSP_vdbconD(const_cast(aa), astride, &b, out, 1, n, 1))\nDEFINE_UNOP_FLOAT(dbamp, sc_dbamp(a))\n\nDEFINE_UNOP_FLOAT(hzo, sc_hzoct(a))\nDEFINE_UNOP_FLOAT(ohz, sc_octhz(a))\n\nDEFINE_UNOP_FLOAT(hzst, sc_hzkey(a))\nDEFINE_UNOP_FLOAT(sthz, sc_keyhz(a))\n\nDEFINE_UNOP_FLOAT(hznn, sc_hznn(a))\nDEFINE_UNOP_FLOAT(nnhz, sc_nnhz(a))\n\nDEFINE_UNOP_FLOAT(centsratio, sc_centsratio(a))\nDEFINE_UNOP_FLOAT(ratiocents, sc_ratiocents(a))\n\nDEFINE_UNOP_FLOAT(semiratio, sc_semiratio(a))\nDEFINE_UNOP_FLOAT(ratiosemi, sc_ratiosemi(a))\n\nDEFINE_UNOP_FLOATVV2(degrad, a*kDegToRad, Z b = kDegToRad; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(raddeg, a*kRadToDeg, Z b = kRadToDeg; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(minsec, a*kMinToSecs, Z b = kMinToSecs; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(secmin, a*kSecsToMin, Z b = kSecsToMin; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(bpmsec, kMinToSecs / a, Z b = kMinToSecs; vDSP_svdivD(&b, const_cast(aa), astride, out, 1, n))\n\nDEFINE_UNOP_FLOAT(distort, sc_distort(a))\nDEFINE_UNOP_FLOAT(softclip, sc_softclip(a))\n\nDEFINE_UNOP_FLOAT(rectWin, sc_rectWindow(a))\nDEFINE_UNOP_FLOAT(triWin, sc_triWindow(a))\nDEFINE_UNOP_FLOAT(bitriWin, sc_bitriWindow(a))\nDEFINE_UNOP_FLOAT(hanWin, sc_hanWindow(a))\nDEFINE_UNOP_FLOAT(sinWin, sc_sinWindow(a))\nDEFINE_UNOP_FLOAT(ramp, sc_ramp(a))\nDEFINE_UNOP_FLOAT(scurve, sc_scurve(a))\nDEFINE_UNOP_FLOAT(sigm,\t\ta/sqrt(1.+a*a))\n\nDEFINE_UNOP_FLOAT(zapgremlins, zapgremlins(a))\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nDEFINE_BINOP_BOOL_FLOAT(lt, a < b, strcmp(a, b) < 0)\nDEFINE_BINOP_BOOL_FLOAT(le, a <= b, strcmp(a, b) <= 0)\nDEFINE_BINOP_BOOL_FLOAT(gt, a > b, strcmp(a, b) > 0)\nDEFINE_BINOP_BOOL_FLOAT(ge, a >= b, strcmp(a, b) >= 0)\nDEFINE_BINOP_BOOL_FLOAT(eq, a == b, strcmp(a, b) == 0)\nDEFINE_BINOP_BOOL_FLOAT(ne, a != b, strcmp(a, b) != 0)\nDEFINE_BINOP_FLOAT_STRING(cmp, sc_cmp(a, b), sc_sgn(strcmp(a, b)))\n\nDEFINE_BINOP_FLOATVV1(copysign, copysign(a, b), vvcopysign(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\nDEFINE_BINOP_FLOATVV1(nextafter, nextafter(a, b), vvnextafter(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\n\n// identity optimizations of basic operators.\n\n\tstruct BinaryOp_plus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus gBinaryOp_plus;\n\tBinaryOp* gBinaryOpPtr_plus = &gBinaryOp_plus;\n\tBINARY_OP_PRIM(plus)\n\n\n\tstruct BinaryOp_plus_link : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus_link gBinaryOp_plus_link;\n\tBinaryOp* gBinaryOpPtr_plus_link = &gBinaryOp_plus_link;\n\tBINARY_OP_PRIM(plus_link)\n\n\n\tstruct BinaryOp_minus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"minus\"; }\n\t\tvirtual double op(double a, double b) { return a - b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\tif (*aa != 0.) {\n\t\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, const_cast(aa), out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\tif (*bb != 0.) {\n\t\t\t\t\tZ b = -*bb;\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, &b, out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vsubD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a - b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_minus gBinaryOp_minus;\n\tBinaryOp* gBinaryOpPtr_minus = &gBinaryOp_minus;\n\tBINARY_OP_PRIM(minus)\n\n\n\n\tstruct BinaryOp_mul : public BinaryOp {\n\t\tvirtual const char *Name() { return \"mul\"; }\n\t\tvirtual double op(double a, double b) { return a * b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else if (*aa == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(bb, bstride, aa, out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += astride; }\n\t\t\t\t} else if (*bb == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(aa, astride, bb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a * b; aa += astride; bb += bstride; }\n\t\t\t\tvDSP_vmulD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a * b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_mul gBinaryOp_mul;\n\tBinaryOp* gBinaryOpPtr_mul = &gBinaryOp_mul;\n\tBINARY_OP_PRIM(mul)\n\n\n\tstruct BinaryOp_div : public BinaryOp {\n\t\tvirtual const char *Name() { return \"div\"; }\n\t\tvirtual double op(double a, double b) { return a / b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0 && *aa == 0.) {\n\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tZ rb = 1. / *bb;\n\t\t\t\t\tvDSP_vsmulD(const_cast(aa), astride, &rb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vdivD(const_cast(bb), bstride, const_cast(aa), astride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a / b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a / b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_div gBinaryOp_div;\n\tBinaryOp* gBinaryOpPtr_div = &gBinaryOp_div;\n\tBINARY_OP_PRIM(div)\n\nDEFINE_BINOP_FLOAT(mod, sc_fmod(a, b))\nDEFINE_BINOP_FLOAT(remainder, remainder(a, b))\n\nDEFINE_BINOP_INT(idiv, sc_div(a, b))\nDEFINE_BINOP_INT(imod, sc_imod(a, b))\n\nDEFINE_BINOP_FLOATVV1(pow, sc_pow(a, b), vvpow(out, bb, aa, &n))\nDEFINE_BINOP_FLOATVV1(atan2, atan2(a, b), vvatan2(out, aa, bb, &n))\n\nDEFINE_BINOP_FLOAT(Jn, jn((int)b, a))\nDEFINE_BINOP_FLOAT(Yn, yn((int)b, a))\n\nDEFINE_BINOP_FLOATVV(min, fmin(a, b), vDSP_vminD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOATVV(max, fmax(a, b), vDSP_vmaxD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(dim, fdim(a, b))\nDEFINE_BINOP_FLOAT(xor, fdim(a, b))\n\nDEFINE_BINOP_FLOAT(avg2, (a + b) * .5)\nDEFINE_BINOP_FLOAT(absdif, fabs(a - b))\nDEFINE_BINOP_FLOATVV(hypot, hypot(a, b), vDSP_vdistD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(sumsq, a*a + b*b)\nDEFINE_BINOP_FLOAT(difsq, a*a - b*b)\nDEFINE_BINOP_FLOAT(sqsum, sc_squared(a + b))\nDEFINE_BINOP_FLOAT(sqdif, sc_squared(a - b))\n\nDEFINE_BINOP_FLOAT(thresh, a < b ? 0. : a)\nDEFINE_BINOP_FLOAT(absthresh, fabs(a) < b ? 0. : a)\nDEFINE_BINOP_FLOAT(amclip, b <= 0. ? 0. : a * b)\nDEFINE_BINOP_FLOAT(scaleneg, a < 0. ? a * b : a)\n\nDEFINE_BINOP_FLOAT(ring1, a * b + a)\nDEFINE_BINOP_FLOAT(ring2, a * b + a + b)\nDEFINE_BINOP_FLOAT(ring3, a*a*b)\nDEFINE_BINOP_FLOAT(ring4, a*b*(a - b))\n\nDEFINE_BINOP_INT(gcd, sc_gcd(a, b))\nDEFINE_BINOP_INT(lcm, sc_lcm(a, b))\n\nDEFINE_BINOP_FLOAT(clip2, std::clamp(a, -b, b))\nDEFINE_BINOP_FLOAT(wrap2, sc_wrap(a, -b, b))\nDEFINE_BINOP_FLOAT(fold2, sc_fold(a, -b, b))\nDEFINE_BINOP_INT(iwrap2, sc_iwrap(a, -b, b))\nDEFINE_BINOP_INT(ifold2, sc_ifold(a, -b, b))\nDEFINE_BINOP_FLOAT(excess, a - std::clamp(a, -b, b))\n\nDEFINE_BINOP_FLOAT(clip0, std::clamp(a, 0., b))\nDEFINE_BINOP_FLOAT(wrap0, sc_wrap(a, 0., b))\nDEFINE_BINOP_FLOAT(fold0, sc_fold(a, 0., b))\n\nDEFINE_BINOP_FLOAT(round, sc_round(a, b))\nDEFINE_BINOP_FLOAT(roundUp, sc_roundUp(a, b))\nDEFINE_BINOP_FLOAT(trunc, sc_trunc(a, b))\n\n\n#define DEFN(FUNNAME, OPNAME, HELP) \tvm.def(OPNAME, 1, 1, FUNNAME##_, \"(x --> z) \" HELP);\n#define DEFNa(FUNNAME, OPNAME, HELP) \tDEFN(FUNNAME, #OPNAME, HELP)\n#define DEF(NAME, HELP) \tDEFNa(NAME, NAME, HELP); \n\n#define DEFNa2(FUNNAME, OPNAME, HELP) \t\\\n\t(vm.def(#OPNAME, 2, 1, FUNNAME##_, \"(x y --> z) \" HELP), \\\n\tvm.def(#OPNAME \"/\", 1, 1, FUNNAME##_reduce_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\\", 1, 1, FUNNAME##_scan_, nullptr), \\\n\tvm.def(#OPNAME \"^\", 1, 1, FUNNAME##_pairs_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\i\", 2, 1, FUNNAME##_iscan_, nullptr), \\\n\tvm.def(#OPNAME \"^i\", 1, 1, FUNNAME##_ipairs_, nullptr));\n\n#define DEF2(NAME, HELP) \tDEFNa2(NAME, NAME, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMathOps();\nvoid AddMathOps()\n{\t\n\tfillSineTable();\n\tfillDBAmpTable();\n\tfillDecayTable();\n fillFirstOrderCoeffTable();\n\n\tvm.addBifHelp(\"\\n*** unary math ops ***\");\n\tDEF(isalnum, \"return whether an ASCII value is alphanumeric.\")\n\tDEF(isalpha, \"return whether an ASCII value is alphabetic.\")\n\tDEF(isblank, \"return whether an ASCII value is a space or tab character.\")\n\tDEF(iscntrl, \"return whether an ASCII value is a control character.\")\n\tDEF(isdigit, \"return whether an ASCII value is a digit.\")\n\tDEF(isgraph, \"return whether an ASCII value is a graphic character.\");\n\tDEF(islower, \"return whether an ASCII value is lower case.\")\n\tDEF(isprint, \"return whether an ASCII value is a printable character.\")\n\tDEF(ispunct, \"return whether an ASCII value is a punctuation character.\")\n\tDEF(isspace, \"return whether an ASCII value is a graphic character.\")\n\tDEF(isupper, \"return whether an ASCII value is upper case.\")\n\tDEF(isxdigit, \"return whether an ASCII value is a hexadecimal digit.\")\n\tDEF(isascii, \"return whether a value is ASCII\")\n\n\tDEF(tolower, \"convert an ASCII character value to lower case.\")\n\tDEF(toupper, \"convert an ASCII character value to upper case.\")\n\tDEF(toascii, \"convert a value to ASCII by stripping the upper bits.\")\n\n\tDEFN(nonpos, \"0<=\", \"less than or equal to zero.\")\n\tDEFN(nonneg, \"0>=\", \"greater than or equal to zero.\")\n\tDEFN(isneg, \"0<\", \"less than zero.\")\n\tDEFN(ispos, \"0>\", \"greater than zero.\")\n\tDEFN(iszero, \"0=\", \"equal to zero.\")\n\tDEFN(iseven, \"even?\", \"is even.\")\n\tDEFN(isodd, \"odd?\", \"is odd.\")\n\tDEFN(isprime, \"prime?\", \"is prime.\")\n\tDEFN(isint, \"int?\", \"is integer.\")\n\t\n\tDEF(isfinite, \"is x a finite number.\")\n\tDEF(isinf, \"is x an infinity.\")\n\tDEF(isnan, \"is x not a number.\")\n\tDEF(isnormal, \"is x a normalized number (as opposed to denormals).\")\n\tDEF(signbit, \"sign bit of x.\")\n\t\t\n\tDEF(abs, \"absolute value.\")\n\tDEF(sgn, \"signum function. returns -1 when x < 0, 0 when x == 0, 1 when x > 0.\")\n\tDEFN(not, \"~\", \"logical negation. returns 1 when x == 0, else returns 0.\")\n\tDEF(neg, \"negative. -x\")\n\tDEF(sqrt, \"square root.\")\n\tDEF(cbrt, \"cube root.\")\n\tDEF(rsqrt, \"reciprocal square root.\")\n\tDEF(sq, \"square. x x *\")\n\tDEF(ssq, \"signed square. x x abs *\")\n\tDEF(cb, \"x cubed. x 3 ^\")\n\tDEFN(sq, \"^2\", \"x squared. x x *\")\n\tDEFN(cb, \"^3\", \"x cubed. x 3 ^\")\n\tDEFN(pow4, \"^4\", \"x to the fourth power. x 4 ^\")\n\tDEFN(pow5, \"^5\", \"x to the fifth power. x 5 ^\")\n\tDEFN(pow6, \"^6\", \"x to the sixth power. x 6 ^\")\n\tDEFN(pow7, \"^7\", \"x to the seventh power. x 7 ^\")\n\tDEFN(pow8, \"^8\", \"x to the eighth power. x 8 ^\")\n\tDEFN(pow9, \"^9\", \"x to the ninth power. x 9 ^\")\n\n\tDEF(recip, \"reciprocal.\")\n\tDEFN(recip, \"1/\", \"reciprocal. 1 x /\")\n\tDEF(exp, \"e to the x.\")\n\tDEF(exp2, \"2 to the x.\")\n\tDEF(exp10, \"10 to the x.\")\n\tDEFN(exp, \"e^\", \"e to the x.\")\n\tDEFN(exp2, \"2^\", \"2 to the x.\")\n\tDEFN(exp10, \"10^\", \"10 to the x.\")\n\tDEF(expm1, \"computes exp(x-1) accurately even for very small values of x.\")\n\tDEF(log, \"base e log of x.\")\n\tDEF(log2, \"base 2 log of x.\")\n\tDEF(log10, \"base 10 log of x.\")\n\tDEF(log1p, \"computes the value of log(1+x) accurately even for very small values of x.\")\n\tDEF(logb, \"x log2 floor\")\n\n\tDEF(frac, \"fractional part.\")\n\tDEF(floor, \"nearest integer <= x.\")\n\tDEF(ceil, \"nearest integer >= x.\")\n\tDEF(rint, \"nearest integer.\")\n\tDEF(erf, \"the error function.\")\n\tDEF(erfc, \"the complement of the error function.\")\n\n\tDEF(sinc, \"sinc. x sin x /\")\n\tDEF(sin, \"sine.\")\n\tDEF(cos, \"cosine.\")\n\tDEF(sin1, \"sine(x * 2pi).\")\n\tDEF(cos1, \"cosine(x * 2pi).\")\n\tDEF(tan, \"tangent.\")\n\tDEF(asin, \"arcsine.\")\n\tDEF(acos, \"arccosine.\")\n\tDEF(atan, \"arctangent.\")\n\tDEF(sinh, \"hyperbolic sine.\")\n\tDEF(cosh, \"hyperbolic cosine.\")\n\tDEF(tanh, \"hyperbolic tangent.\")\n\tDEF(asinh, \"hyperbolic arcsine.\")\n\tDEF(acosh, \"hyperbolic arccosine.\")\n\tDEF(atanh, \"hyperbolic arctangent.\")\n\t\n\tDEF(J0, \"zeroth Bessel function of the first kind evaluated at x.\")\n\tDEF(J1, \"first Bessel function of the first kind evaluated at x.\")\n\tDEF(Y0, \"zeroth Bessel function of the second kind evaluated at x.\")\n\tDEF(Y1, \"first Bessel function of the second kind evaluated at x.\")\n\n\tDEF(tgamma, \"the gamma function.\")\n\tDEF(lgamma, \"natural logarithm of the absolute value of the gamma function.\")\n\n\tDEF(inc, \"increment. x 1 +\")\n\tDEF(dec, \"decrement. x 1 -\")\n\tDEF(half, \"x .5 *\")\n\tDEF(twice, \"x 2 *\")\n\tDEFN(inc, \"++\", \"increment. x 1 +\")\n\tDEFN(dec, \"--\", \"decrement. x 1 -\")\n\tDEFN(half, \"/2\", \"half.\")\n\tDEFN(twice, \"*2\", \"twice.\")\n\tDEF(biuni, \"convert bipolar to unipolar. .5 * .5 +\")\n\tDEF(unibi, \"convert unipolar to bipolar. 2 * 1 -\")\n\tDEF(biunic, \"convert bipolar to unipolar with clipping to range. -1 1 clip .5 * .5 +\")\n\tDEF(unibic, \"convert unipolar to bipolar with clipping to range. 0 1 clip 2 * 1 -\")\n\tDEF(cmpl, \"unipolar complement. 1 x -\")\n\n\tDEF(ampdb, \"convert linear amplitude to decibels.\")\n\tDEF(dbamp, \"convert decibels to linear amplitude.\")\n\t\n\tDEF(ohz, \"convert octaves to Hertz. Octave 0.0 is middle C.\")\n\tDEF(hzo, \"convert Hertz to octaves. Octave 0.0 is middle C.\")\n\tDEF(nnhz, \"convert MIDI note numbers to Hertz. 60 is middle C.\")\n\tDEF(hznn, \"convert Hertz to MIDI note numbers. 60 is middle C.\")\n\n\tDEF(centsratio, \"convert an interval in cents to a ratio.\")\n\tDEF(ratiocents, \"convert a ratio to an interval in cents.\")\n\n\tDEF(semiratio, \"convert an interval in semitones to a ratio.\")\n\tDEF(ratiosemi, \"a ratio to an interval in semitones.\")\n\n\tDEF(minsec, \"convert from minutes to seconds. also for converting from bps to bpm\")\n\tDEF(secmin, \"convert from seconds to minutes. also for converting from bpm to bps.\")\n\tDEF(bpmsec, \"convert from beats per minute to a period in seconds(e.g. for delay times)\")\n\tDEF(degrad, \"convert from degrees to radians.\")\n\tDEF(raddeg, \"convert from radians to degrees.\")\n\n\tDEF(distort, \"sigmoid wave distortion function. x/sqrt(1 + x^2)\")\n\tDEF(softclip, \"sigmoid wave distortion function. returns x when abs(x) < .5, else returns (abs(x) - .25) / x\")\n\tDEF(sigm, \"sigmoid wave distortion function. x/sqrt(1+x*x).\")\n\n\tDEF(rectWin, \"rectangular window for x in the interval [0,1].\")\n\tDEF(triWin, \"triangular window for x in the interval [0,1].\")\n\tDEF(bitriWin, \"triangular window for x in the interval [-1,1]\")\n\tDEF(hanWin, \"hanning window for x in the interval [0,1]\")\n\tDEF(sinWin, \"sine window for x in the interval [0,1]\")\n\tDEF(ramp, \"return 0 when x <= 0, return x when 0 < x < 1, return 1 when x > 1.\")\n\tDEF(scurve, \"return 0 when x <= 0, return 3*x*x - 2*x*x*x when 0 < x < 1, return 1 when x > 1.\")\n\n\tDEF(zapgremlins, \"\")\n\n\t/////////////////////////////////////////////////////\n\n\tvm.addBifHelp(\"\\n*** binary math ops ***\");\n\tvm.addBifHelp(\"\\n All built-in binary math operators have the following variations defined:\");\n\tvm.addBifHelp(\" op/ (list --> z) reducing math operator.\");\n\tvm.addBifHelp(\" op\\\\ (list --> z) scanning math operator.\");\n\tvm.addBifHelp(\" op^ (list --> z) pairwise math operator.\");\n\tvm.addBifHelp(\" op/i (list init --> z) reducing math operator with initial value.\");\n\tvm.addBifHelp(\" op\\\\i (list init --> z) scanning math operator with initial value.\");\n\tvm.addBifHelp(\" op^i (list init --> z) pairwise math operator with initial value.\");\n\tvm.addBifHelp(\" For example, + has the following variations: +/ +\\\\ +^ +/i +\\\\i +^i\");\n\tvm.addBifHelp(\"\");\n\t\n\n\tvm.plusFun = DEFNa2(plus, +, \"addition.\")\n\tDEFNa2(plus_link, +>, \"addition. For lists, acts as if shorter list were extended with zeroes.\")\n\tDEFNa2(minus, -, \"subtraction.\")\n\tvm.mulFun = DEFNa2(mul, *, \"multiplication.\")\n\tDEFNa2(div, /, \"real division.\")\n\tDEFNa2(mod, %, \"modulo.\")\n\tDEF2(idiv, \"integer division.\")\n\tDEF2(imod, \"integer modulo.\")\n\tDEF2(remainder, \"remainder.\")\n\n\tDEFNa2(lt, <, \"less than.\")\n\tDEFNa2(le, <=, \"less than or equal.\")\n\tDEFNa2(gt, >, \"greater than.\")\n\tDEFNa2(ge, >=, \"greater than or equal.\")\n\tDEFNa2(eq, ==, \"equal.\")\n\tDEFNa2(ne, !=, \"not equal.\")\n\n\tDEF2(cmp, \"returns -1 when x < y, returns 1 when x > y, returns 0 when x == y.\")\n\n\tDEF2(copysign, \"copy the sign of y to the value of x.\")\n\tDEF2(nextafter, \"return the next machine representable number from x in direction y.\")\n\n\tDEF2(pow, \"x to the power y.\")\n\tDEFNa2(pow, ^, \"x to the power y.\")\n\tDEF2(atan2, \"arctangent of y/x.\")\n\t\n\tDEF2(Jn, \"yth Bessel function of the first kind evaluated at x.\")\n\tDEF2(Yn, \"yth Bessel function of the second kind evaluated at x.\")\n\n\tvm.minFun = DEFNa2(min, &, \"return the minimum of x and y. functions as logical AND.\")\n\tvm.maxFun = DEFNa2(max, |, \"return the maximum of x and y. functions as logical OR.\")\n\n\tDEF2(avg2, \"x y + .5 *\")\n\tDEF2(dim, \"positive difference of x and y. x y - 0 |\")\n\tDEF2(absdif, \"x y - abs\")\n\tDEF2(hypot, \"x sq y sq + sqrt\")\n\tDEF2(sumsq, \"x sq y sq +\")\n\tDEF2(difsq, \"x sq y sq -\")\n\tDEF2(sqsum, \"x y + sq\")\n\tDEF2(sqdif, \"x y - sq\")\n\n\tDEF2(thresh, \"returns 0 when x < y, else returns x.\")\n\tDEF2(absthresh, \"returns 0 when |x| < y, else returns x.\")\n\tDEF2(amclip, \"returns 0 when y <= 0, else returns x*y.\")\n\tDEF2(scaleneg, \"returns x*y when x < 0, else returns x.\")\n\n\tDEF2(ring1, \"x y * x +\")\n\tDEF2(ring2, \"x y * x + y +\")\n\tDEF2(ring3, \"x sq y *\")\n\tDEF2(ring4, \"x y * x y - *\")\n\n\tDEF2(gcd, \"greatest common divisor.\")\n\tDEF2(lcm, \"least common multiple.\")\n\n\tDEF2(clip0, \"clip x between 0 and y.\")\n\tDEF2(wrap0, \"wrap x between 0 and y.\")\n\tDEF2(fold0, \"fold x between 0 and y.\")\n\n\tDEF2(clip2, \"clip x between -y and y.\")\n\tDEF2(wrap2, \"wrap x between -y and y.\")\n\tDEF2(fold2, \"fold x between -y and y.\")\n\tDEF2(iwrap2, \"wrap integer x between -y and y.\")\n\tDEF2(ifold2, \"fold integer x between -y and y.\")\n\tDEF2(excess, \"return the excess after clipping. x x y clip2 -\")\n\n\tDEF2(round, \"round x to nearest multiple of y.\")\n\tDEF2(roundUp, \"round x to nearest multiple of y >= x.\")\n\tDEF2(trunc, \"round x to nearest multiple of y <= x\")\n\n}\n\n"], ["/sapf/src/FilterUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"FilterUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// classes for specializing feedback\n\nstruct NormalFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return x; }\n};\n\nstruct TanhApproximationFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return sc_tanh_approx(x); }\n};\n\nstruct UnityHardClipFeedback : public Gen\n{\n\tstatic inline double feedback(double x)\n\t{\n\t\tif (x <= -1.) return -1.;\n\t\tif (x >= 1.) return 1.;\n\t\treturn x;\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag : lagTime\");\n\tV in = th.popZIn(\"lag : in\");\n\n\tth.push(new List(new Lag(th, in, lagTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag2 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag2(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag2_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag2 : lagTime\");\n\tV in = th.popZIn(\"lag2 : in\");\n\n\tth.push(new List(new Lag2(th, in, lagTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag3 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag3(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag3_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag3 : lagTime\");\n\tV in = th.popZIn(\"lag3 : in\");\n\n\tth.push(new List(new Lag3(th, in, lagTime)));\n}\n\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstruct LagUD : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ b1 = y0 > y1 ? b1r : b1f;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ lagTime = y0 > y1 ? *riseTime : *fallTime;\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud : fallTime\");\n\tV riseTime = th.popZIn(\"lagud : riseTime\");\n\tV in = th.popZIn(\"lagud : in\");\n\n\tth.push(new List(new LagUD(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD2 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD2(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud2_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud2 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud2 : riseTime\");\n\tV in = th.popZIn(\"lagud2 : in\");\n\n\tth.push(new List(new LagUD2(th, in, riseTime, fallTime)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD3 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD3(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud3_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud3 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud3 : riseTime\");\n\tV in = th.popZIn(\"lagud3 : in\");\n\n\tth.push(new List(new LagUD3(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct FirstOrderLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct FirstOrderHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void lpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf1 : freq\");\n\tV in = th.popZIn(\"lpf1 : in\");\n\n\tth.push(new List(new FirstOrderLPF(th, in, freq)));\n}\n\nstatic void hpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf1 : freq\");\n\tV in = th.popZIn(\"hpf1 : in\");\n\n\tth.push(new List(new FirstOrderHPF(th, in, freq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0inv = 1. / a0;\n\t\t\t\tZ a1 = a0inv * (-2. * cs);\n\t\t\t\tZ a2 = a0inv * (1. - alpha);\n\t\t\t\tZ b1 = a0inv * (1. - cs);\n\t\t\t\tZ b0 = a0inv * (.5 * b1);\n\t\t\t\tZ b2 = a0inv * b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct LPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\t\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\nstruct HPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct HPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ntemplate \nstruct RLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RLPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRLPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\ntemplate \nstruct RHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRHPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RHPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRHPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct BPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b0 = alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * (x0 - x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstruct BSF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBSF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BSF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (x0 + x2 + a1 * (x1 - y1) - a2 * y2) * a0r;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\n\nstruct APF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tAPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"APF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2; \n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (a2 * (x0 - y2) + a1 * (x1 - y1)) * a0r + x2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct PEQ : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tPEQ(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PEQ\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alphaA = alpha * A;\n\t\t\t\tZ alphaOverA = alpha / A;\n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alphaOverA;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alphaOverA;\n\t\t\t\n\t\t\t\tZ b0 = 1. + alphaA;\n\t\t\t\tZ b2 = 1. - alphaA;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + a1 * (x1 - y1) + b2 * x2 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLowShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct HighShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHighShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HighShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 + Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 + Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 - Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ a2 = Ap1 - Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf1 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tLowShelf1(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf1\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ sqrt_g = t_dbamp(.25 * *gain);\n\t\t\t\tZ d = *freq * freqmul;\n\t\t\t\t\n\t\t\t\tZ p = 1. - d*sqrt_g;\n\t\t\t\tZ q = 1. - d/sqrt_g;\n\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = x0 + q * x1 - p * y1;\n\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct RLowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLowShelf(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = A*( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*A*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = A*( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void lpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf : freq\");\n\tV in = th.popZIn(\"lpf : in\");\n\n\tth.push(new List(new LPF(th, in, freq)));\n}\n\nstatic void lpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf2 : freq\");\n\tV in = th.popZIn(\"lpf2 : in\");\n\n\tth.push(new List(new LPF2(th, in, freq)));\n}\n\nstatic void hpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf : freq\");\n\tV in = th.popZIn(\"hpf : in\");\n\n\tth.push(new List(new HPF(th, in, freq)));\n}\n\nstatic void hpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf2 : freq\");\n\tV in = th.popZIn(\"hpf2 : in\");\n\n\tth.push(new List(new HPF2(th, in, freq)));\n}\n\n\n\nstatic void rlpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf : rq\");\n\tV freq = th.popZIn(\"rlpf : freq\");\n\tV in = th.popZIn(\"rlpf : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2 : rq\");\n\tV freq = th.popZIn(\"rlpf2 : freq\");\n\tV in = th.popZIn(\"rlpf2 : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf : rq\");\n\tV freq = th.popZIn(\"rhpf : freq\");\n\tV in = th.popZIn(\"rhpf : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2 : rq\");\n\tV freq = th.popZIn(\"rhpf2 : freq\");\n\tV in = th.popZIn(\"rhpf2 : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\nstatic void rlpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpfc : rq\");\n\tV freq = th.popZIn(\"rlpfc : freq\");\n\tV in = th.popZIn(\"rlpfc : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2c : rq\");\n\tV freq = th.popZIn(\"rlpf2c : freq\");\n\tV in = th.popZIn(\"rlpf2c : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpfc : rq\");\n\tV freq = th.popZIn(\"rhpfc : freq\");\n\tV in = th.popZIn(\"rhpfc : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2c : rq\");\n\tV freq = th.popZIn(\"rhpf2c : freq\");\n\tV in = th.popZIn(\"rhpf2c : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\n\nstatic void bpf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bpf : bw\");\n\tV freq = th.popZIn(\"bpf : freq\");\n\tV in = th.popZIn(\"bpf : in\");\n\n\tth.push(new List(new BPF(th, in, freq, bw)));\n}\n\nstatic void bsf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bsf : bw\");\n\tV freq = th.popZIn(\"bsf : freq\");\n\tV in = th.popZIn(\"bsf : in\");\n\n\tth.push(new List(new BSF(th, in, freq, bw)));\n}\n\nstatic void apf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"apf : bw\");\n\tV freq = th.popZIn(\"apf : freq\");\n\tV in = th.popZIn(\"apf : in\");\n\n\tth.push(new List(new APF(th, in, freq, bw)));\n}\n\nstatic void peq_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"peq : gain\");\n\tV bw = th.popZIn(\"peq : bw\");\n\tV freq = th.popZIn(\"peq : freq\");\n\tV in = th.popZIn(\"peq : in\");\n\n\tth.push(new List(new PEQ(th, in, freq, bw, gain)));\n}\n\nstatic void lsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf(th, in, freq, gain)));\n}\n\nstatic void hsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"hsf : gain\");\n\tV freq = th.popZIn(\"hsf : freq\");\n\tV in = th.popZIn(\"hsf : in\");\n\n\tth.push(new List(new HighShelf(th, in, freq, gain)));\n}\n\n\nstatic void lsf1_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf1(th, in, freq, gain)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Resonz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tResonz(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Resonz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. - .5 * w0 * *rq;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Ringz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _ringTime;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul, _K;\n\t\n\tRingz(Thread& th, Arg in, Arg freq, Arg ringTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, ringTime)), _in(in), _freq(freq), _ringTime(ringTime),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Ringz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *ringTime;\n\t\t\tint n, inStride, freqStride, ringTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tringTime += ringTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_ringTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Formlet : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _atkTime;\n\tZIn _dcyTime;\n\tZ _x1a, _x2a, _y1a, _y2a;\n\tZ _x1b, _x2b, _y1b, _y2b;\n\tZ _freqmul, _K;\n\t\n\tFormlet(Thread& th, Arg in, Arg freq, Arg atkTime, Arg dcyTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, atkTime, dcyTime)),\n\t\t\t_in(in), _freq(freq), _atkTime(atkTime), _dcyTime(dcyTime),\n\t\t\t_x1a(0.), _x2a(0.), _y1a(0.), _y2a(0.),\n\t\t\t_x1b(0.), _x2b(0.), _y1b(0.), _y2b(0.),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Formlet\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1a = _x1a;\n\t\tZ x2a = _x2a;\n\t\tZ y1a = _y1a;\n\t\tZ y2a = _y2a;\n\t\tZ x1b = _x1b;\n\t\tZ x2b = _x2b;\n\t\tZ y1b = _y1b;\n\t\tZ y2b = _y2b;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *atkTime, *dcyTime;\n\t\t\tint n, inStride, freqStride, atkTimeStride, dcyTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _atkTime(th, n, atkTimeStride, atkTime) || _dcyTime(th, n, dcyTimeStride, dcyTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ Ra = 1. + K / *atkTime;\n\t\t\t\tZ Rb = 1. + K / *dcyTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1a = 2. * Ra * cs;\n\t\t\t\tZ a2a = -(Ra * Ra);\n\t\t\t\tZ a1b = 2. * Rb * cs;\n\t\t\t\tZ a2b = -(Rb * Rb);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0a = *in;\n\t\t\t\tZ y0a = b0 * (x0a - x2a) + a1a * y1a + a2a * y2a;\n\t\t\t\n\t\t\t\tZ x0b = *in;\n\t\t\t\tZ y0b = b0 * (x0b - x2b) + a1b * y1b + a2b * y2b;\n\t\t\t\t\n\t\t\t\tout[i] = y0b - y0a;\n\t\t\t\ty2a = y1a;\n\t\t\t\ty1a = y0a;\n\t\t\t\tx2a = x1a;\n\t\t\t\tx1a = x0a;\n\n\t\t\t\ty2b = y1b;\n\t\t\t\ty1b = y0b;\n\t\t\t\tx2b = x1b;\n\t\t\t\tx1b = x0b;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tatkTime += atkTimeStride;\n\t\t\t\tdcyTime += dcyTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_atkTime.advance(n);\n\t\t\t_dcyTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1a = x1a;\n\t\t_x2a = x2a;\n\t\t_y1a = y1a;\n\t\t_y2a = y2a;\n\t\t\n\t\t_x1b = x1b;\n\t\t_x2b = x2b;\n\t\t_y1b = y1b;\n\t\t_y2b = y2b;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct KlankFilter\n{\n\tKlankFilter(V f, V a, V r) : \n\t\tfreq(f), amp(a), ringTime(r),\n\t\tx1(0.), x2(0.), y1(0.), y2(0.) {}\n\t\n\tZIn freq, amp, ringTime;\n\tZ x1, x2, y1, y2;\n\t\n};\n\nstruct Klank : public Gen\n{\n\tZIn _in;\n\tstd::vector _filters;\n\tZ _freqmul, _K;\n\tZ* inputBuffer;\n\t\n\tKlank(Thread& th, Arg in, V freqs, V amps, V ringTimes)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t\tinputBuffer = new Z[mBlockSize];\n\t\n\t\tint64_t numFilters = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, freqs.length(th)); \n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, amps.length(th)); \n\t\t}\n\t\tif (ringTimes.isVList()) { \n\t\t\tringTimes = ((List*)ringTimes.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, ringTimes.length(th)); \n\t\t}\n\t\t\n\t\tif (numFilters == LONG_MAX) numFilters = 1;\n\t\t\n\t\tfor (ssize_t i = 0; i < numFilters; ++i) {\n\t\t\tKlankFilter kf(freqs.at(i), amps.at(i), ringTimes.at(i));\n\t\t\t_filters.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\n\tvirtual ~Klank()\n\t{\n\t\tdelete [] inputBuffer;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Klank\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\t\n\t\t// copy input\n\t\tint numInputFrames = mBlockSize;\n\t\tif (_in.fill(th, numInputFrames, inputBuffer, 1))\n\t\t{\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tint maxToFill = 0;\n\n\t\tZ* out0 = mOut->fulfillz(numInputFrames);\n\t\tmemset(out0, 0, numInputFrames * sizeof(Z));\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ K = log001 * th.rate.invSampleRate;\n\t\t\n\t\tfor (size_t filter = 0; filter < _filters.size(); ++filter) {\n\t\t\tint framesToFill = numInputFrames;\n\t\t\tKlankFilter& kf = _filters[filter];\n\t\t\t\t\n\t\t\tZ x1 = kf.x1;\n\t\t\tZ x2 = kf.x2;\n\t\t\tZ y1 = kf.y1;\n\t\t\tZ y2 = kf.y2;\n\n\t\t\tZ* in = inputBuffer;\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp, *ringTime;\n\t\t\t\tint n, freqStride, ampStride, ringTimeStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (kf.freq(th, n, freqStride, freq) || kf.amp(th, n, ampStride, amp) || kf.ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\n\t\t\t\tif (freqStride == 0) {\n\t\t\t\t\tif (ringTimeStride == 0) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\n\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\n\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\n\t\t\t\t\t\t++in;\n\t\t\t\t\t\t++out;\n\t\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\tringTime += ringTimeStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tkf.freq.advance(n);\n\t\t\t\tkf.amp.advance(n);\n\t\t\t\tkf.ringTime.advance(n);\n\t\t\t}\n\t\t\tkf.x1 = x1;\n\t\t\tkf.x2 = x2;\n\t\t\tkf.y1 = y1;\n\t\t\tkf.y2 = y2;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\n\nstatic void resonz_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"resonz : rq\");\n\tV freq = th.popZIn(\"resonz : freq\");\n\tV in = th.popZIn(\"resonz : in\");\n\n\tth.push(new List(new Resonz(th, in, freq, rq)));\n}\n\nstatic void ringz_(Thread& th, Prim* prim)\n{\n\tV ringTime = th.popZIn(\"ringz : ringTime\");\n\tV freq = th.popZIn(\"ringz : freq\");\n\tV in = th.popZIn(\"ringz : in\");\n\n\tth.push(new List(new Ringz(th, in, freq, ringTime)));\n}\n\nstatic void formlet_(Thread& th, Prim* prim)\n{\n\tV dcyTime = th.popZIn(\"formlet : dcyTime\");\n\tV atkTime = th.popZIn(\"formlet : atkTime\");\n\tV freq = th.popZIn(\"formlet : freq\");\n\tV in = th.popZIn(\"formlet : in\");\n\n\tth.push(new List(new Formlet(th, in, freq, atkTime, dcyTime)));\n}\n\n\nstatic void klank_(Thread& th, Prim* prim)\n{\n\tV ringTimes = th.popZInList(\"klank : ringTimes\");\n\tV amps\t\t= th.popZInList(\"klank : amps\");\n\tV freqs = th.popZInList(\"klank : freqs\");\n\tV in\t\t= th.popZIn(\"klank : in\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (ringTimes.isVList() && !ringTimes.isFinite())\n\t\tindefiniteOp(\"klank : ringTimes\", \"\");\n\n\tth.push(new List(new Klank(th, in, freqs, amps, ringTimes)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakDC : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _x1, _y1;\n\t\n\tLeakDC(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_x1(0.), _y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakDC\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 - x1 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tx1 = x0;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leakdc_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leakdc : leak\");\n\tV in = th.popZIn(\"leakdc : in\");\n\n\tth.push(new List(new LeakDC(th, in, leak)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakyIntegrator : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _y1;\n\t\n\tLeakyIntegrator(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakyIntegrator\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leaky_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leaky : leak\");\n\tV in = th.popZIn(\"leaky : in\");\n\n\tth.push(new List(new LeakyIntegrator(th, in, leak)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay : public Gen\n{\n\tZIn _in;\n\tZIn _decayTime;\n\tZ _y1;\n\tZ _lagmul;\n\t\n\t\n\tDecay(Thread& th, Arg in, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, decayTime)), _in(in), _decayTime(decayTime), \n\t\t\t_y1(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *decayTime;\n\t\t\tint n, inStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (decayTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay : decayTime\");\n\tV in = th.popZIn(\"decay : in\");\n\n\tth.push(new List(new Decay(th, in, decayTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay2 : public Gen\n{\n\tZIn _in;\n\tZIn _attackTime;\n\tZIn _decayTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\t\n\t\n\tDecay2(Thread& th, Arg in, Arg attackTime, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, attackTime, decayTime)), _in(in), _attackTime(attackTime), _decayTime(decayTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *attackTime, *decayTime;\n\t\t\tint n, inStride, attackTimeStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _attackTime(th, n, attackTimeStride, attackTime) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (attackTimeStride == 0 && decayTimeStride == 0) {\n\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tattackTime += attackTimeStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_attackTime.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay2_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay2 : decayTime\");\n\tV attackTime = th.popZIn(\"decay2 : attackTime\");\n\tV in = th.popZIn(\"decay2 : in\");\n\n\tth.push(new List(new Decay2(th, in, attackTime, decayTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Phase90A : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90A(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90A\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z1;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct Phase90B : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90B(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90B\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z0;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct AmpFollow : public OneInputUGen\n{\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1a_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2a_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3a_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4a_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1a_ = 0.;\n\tZ v2a_ = 0.;\n\tZ w1a_ = 0.;\n\tZ w2a_ = 0.;\n\tZ x1a_ = 0.;\n\tZ x2a_ = 0.;\n\tZ y1a_ = 0.;\n\tZ y2a_ = 0.;\n\tZ z1a_ = 0.;\n\tZ z2a_ = 0.;\n\n\tconstexpr static Z c1b_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2b_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3b_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4b_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1b_ = 0.;\n\tZ v2b_ = 0.;\n\tZ w1b_ = 0.;\n\tZ w2b_ = 0.;\n\tZ x1b_ = 0.;\n\tZ x2b_ = 0.;\n\tZ y1b_ = 0.;\n\tZ y2b_ = 0.;\n\tZ z1b_ = 0.;\n\tZ z2b_ = 0.;\n\n\tZ b1r_;\n\tZ b1f_;\n\t\n\tZ l1a_ = 0.;\n\tZ l1b_ = 0.;\n\n\tAmpFollow(Thread& th, Arg in, Z atk, Z dcy)\n\t\t: OneInputUGen(th, in),\n\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t\tb1r_ = atk == 0. ? 0. : std::max(0., 1. + _lagmul / atk); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime)\n\t\tb1f_ = dcy == 0. ? 0. : std::max(0., 1. + _lagmul / dcy);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"AmpFollow\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1a = c1a_;\n\t\tZ c2a = c2a_;\n\t\tZ c3a = c3a_;\n\t\tZ c4a = c4a_;\n\t\t\n\t\tZ v1a = v1a_;\n\t\tZ v2a = v2a_;\n\t\tZ w1a = w1a_;\n\t\tZ w2a = w2a_;\n\t\tZ x1a = x1a_;\n\t\tZ x2a = x2a_;\n\t\tZ y1a = y1a_;\n\t\tZ y2a = y2a_;\n\t\tZ z1a = z1a_;\n\t\tZ z2a = z2a_;\n\n\t\tZ c1b = c1b_;\n\t\tZ c2b = c2b_;\n\t\tZ c3b = c3b_;\n\t\tZ c4b = c4b_;\n\t\t\n\t\tZ v1b = v1b_;\n\t\tZ v2b = v2b_;\n\t\tZ w1b = w1b_;\n\t\tZ w2b = w2b_;\n\t\tZ x1b = x1b_;\n\t\tZ x2b = x2b_;\n\t\tZ y1b = y1b_;\n\t\tZ y2b = y2b_;\n\t\tZ z1b = z1b_;\n\t\tZ z2b = z2b_;\n\t\t\n\t\tZ l1a = l1a_;\n\t\tZ l1b = l1b_;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\t{\n\t\t\t\tZ w0 = c1a * (v0 + w2a) - v2a;\n\t\t\t\tZ x0 = c2a * (w0 + x2a) - w2a;\n\t\t\t\tZ y0 = c3a * (x0 + y2a) - x2a;\n\t\t\t\tZ z0 = c4a * (y0 + z2a) - y2a;\n\t\t\t\tv2a = v1a;\n\t\t\t\tw2a = w1a;\n\t\t\t\tx2a = x1a;\n\t\t\t\ty2a = y1a;\n\t\t\t\tz2a = z1a;\n\t\t\t\tv1a = v0;\n\t\t\t\tw1a = w0;\n\t\t\t\tx1a = x0;\n\t\t\t\ty1a = y0;\n\t\t\t\tz1a = z0;\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tZ w0 = c1b * (v0 + w2b) - v2b;\n\t\t\t\tZ x0 = c2b * (w0 + x2b) - w2b;\n\t\t\t\tZ y0 = c3b * (x0 + y2b) - x2b;\n\t\t\t\tZ z0 = c4b * (y0 + z2b) - y2b;\n\t\t\t\tv2b = v1b;\n\t\t\t\tw2b = w1b;\n\t\t\t\tx2b = x1b;\n\t\t\t\ty2b = y1b;\n\t\t\t\tz2b = z1b;\n\t\t\t\tv1b = v0;\n\t\t\t\tw1b = w0;\n\t\t\t\tx1b = x0;\n\t\t\t\ty1b = y0;\n\t\t\t\tz1b = z0;\n\t\t\t}\n\t\t\t\n\t\t\tZ l0a = hypot(z1a, z1b); // vectorize this\n\n\t\t\tl1a = l0a + (l0a > l1a ? b1r_ : b1f_) * (l1a - l0a);\n\t\t\tl1b = l1a + (l1a > l1b ? b1r_ : b1f_) * (l1b - l1a);\n\t\t\tout[i] = l1b;\n\t\t}\n\t\tv1a_ = v1a;\n\t\tv2a_ = v2a;\n\t\tw1a_ = w1a;\n\t\tw2a_ = w2a;\n\t\tx1a_ = x1a;\n\t\tx2a_ = x2a;\n\t\ty1a_ = y1a;\n\t\ty2a_ = y2a;\n\t\tz1a_ = z1a;\n\t\tz2a_ = z2a;\n\n\t\tv1b_ = v1b;\n\t\tv2b_ = v2b;\n\t\tw1b_ = w1b;\n\t\tw2b_ = w2b;\n\t\tx1b_ = x1b;\n\t\tx2b_ = x2b;\n\t\ty1b_ = y1b;\n\t\ty2b_ = y2b;\n\t\tz1b_ = z1b;\n\t\tz2b_ = z2b;\n\t\t\n\t\tl1a_ = l1a;\n\t\tl1b_ = l1b;\n\t}\n};\n\nstatic void hilbert_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"hilbert : in\");\n\t\n\tth.push(new List(new Phase90A(th, in)));\n\tth.push(new List(new Phase90B(th, in)));\n}\n\nstatic void ampf_(Thread& th, Prim* prim)\n{\n\tZ dcy = th.popFloat(\"ampf : dcyTime\");\n\tZ atk = th.popFloat(\"ampf : atkTime\");\n\tV in = th.popZIn(\"ampf : in\");\n\t\n\tth.push(new List(new AmpFollow(th, in, atk, dcy)));\n}\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** filter unit generators ***\");\n\tDEFMCX(lag, 2, \"(in decayTime --> out) one pole lag filter. decayTime determines rate of convergence.\")\n\tDEFMCX(lag2, 2, \"(in decayTime --> out) cascade of two one pole lag filters. decayTime determines rate of convergence.\")\n\tDEFMCX(lag3, 2, \"(in decayTime --> out) cascade of three one pole lag filters. decayTime determines rate of convergence.\")\n\n\tDEFMCX(lagud, 3, \"(in upDecayTime, downDecayTime --> out) one pole lag filter. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud2, 3, \"(in upDecayTime, downDecayTime --> out) cascade of two one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud3, 3, \"(in upDecayTime, downDecayTime --> out) cascade of three one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\t\n\tDEFMCX(lpf1, 2, \"(in freq --> out) low pass filter. 6 dB/oct.\")\n\tDEFMCX(hpf1, 2, \"(in freq --> out) high pass filter. 6 dB/oct.\")\n\tDEFMCX(lpf, 2, \"(in freq --> out) low pass filter. 12 dB/oct.\")\n\tDEFMCX(hpf, 2, \"(in freq --> out) high pass filter. 12 dB/oct.\")\n\tDEFMCX(lpf2, 2, \"(in freq --> out) low pass filter. 24 dB/oct.\")\n\tDEFMCX(hpf2, 2, \"(in freq --> out) high pass filter. 24 dB/oct.\")\n\t\n\tDEFMCX(rlpf, 3, \"(in freq rq --> out) resonant low pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf, 3, \"(in freq rq --> out) resonant high pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2, 3, \"(in freq rq --> out) resonant low pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2, 3, \"(in freq rq --> out) resonant high pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\t\n\tDEFMCX(rlpfc, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpfc, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2c, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2c, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\n\tDEFMCX(bpf, 3, \"(in freq bw --> out) band pass filter. bw is bandwidth in octaves.\")\n\tDEFMCX(bsf, 3, \"(in freq bw --> out) band stop filter. bw is bandwidth in octaves.\")\n\tDEFMCX(apf, 3, \"(in freq bw --> out) all pass filter. bw is bandwidth in octaves.\")\n\t\n\tDEFMCX(peq, 4, \"(in freq bw gain --> out) parametric equalization filter. bw is bandwidth in octaves.\")\n\tDEFMCX(lsf, 3, \"(in freq gain --> out) low shelf filter.\")\n\tDEFMCX(hsf, 3, \"(in freq gain --> out) high shelf filter.\")\n\tDEFMCX(lsf1, 3, \"(in freq gain --> out) low shelf filter.\")\n\n\tDEFMCX(resonz, 3, \"(in freq rq --> out) resonant filter.\")\n\tDEFMCX(ringz, 3, \"(in freq ringTime --> out) resonant filter specified by a ring time in seconds.\")\n\tDEFMCX(formlet, 4, \"(in freq atkTime dcyTime --> out) a formant filter whose impulse response is a sine grain.\")\n\tDEFAM(klank, zaaa, \"(in freqs amps ringTimes --> out) a bank of ringz filters. freqs amps and ringTimes are arrays.\")\n\n\tDEFMCX(leakdc, 2, \"(in coef --> out) leaks away energy at 0 Hz.\")\n\tDEFMCX(leaky, 2, \"(in coef --> out) leaky integrator.\")\n\tDEFMCX(decay, 2, \"(in decayTime --> out) outputs an exponential decay for impulses at the input.\")\n\tDEFMCX(decay2, 3, \"(in atkTime dcyTime --> out) outputs an exponential attack and decay for impulses at the input.\")\n\n\tDEFMCX(hilbert, 1, \"(in --> outA outB) returns two signals that are 90 degrees phase shifted from each other.\")\n\tDEFMCX(ampf, 3, \"(in atkTime dcyTime --> out) amplitude follower.\")\n}\n\n\n\n"], ["/sapf/src/main.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \n#include \n#include \n#include \n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \"Manta.h\"\n\nclass MyManta : public Manta\n{\n\tvirtual void PadEvent(int row, int column, int id, int value) {\n\t\tprintf(\"pad %d %d %d %d\\n\", row, column, id, value);\n\t}\n\tvirtual void SliderEvent(int id, int value) {\n\t\tprintf(\"slider %d %d\\n\", id, value);\n\t}\n\tvirtual void ButtonEvent(int id, int value) {\n\t\tprintf(\"button %d %d\\n\", id, value);\n\t}\n\tvirtual void PadVelocityEvent(int row, int column, int id, int velocity) {\n\t\tprintf(\"pad vel %d %d %d %d\\n\", row, column, id, velocity);\n\n\t}\n\tvirtual void ButtonVelocityEvent(int id, int velocity) {\n\t\tprintf(\"button vel %d %d\\n\", id, velocity);\n\t}\n\tvirtual void FrameEvent(uint8_t *frame) {}\n\tvirtual void DebugPrint(const char *fmt, ...) {}\n};\n\nManta* manta();\nManta* manta()\n{\n\tstatic MyManta* sManta = new MyManta();\n\treturn sManta;\n}\n\n/* issue:\n\n[These comments are very old and I have not checked if they are still relevant.]\n\nTableData alloc should use new\n\nbugs:\n\nitd should have a tail time. currently the ugen stops as soon as its input, cutting off the delayed signal.\n\n+ should not stop until both inputs stop?\nother additive binops: - avg2 sumsq\n\nno, use a operator \n\n---\n\nadsrg (gate a d s r --> out) envelope generator with gate. \nadsr (dur a d s r --> out) envelope generator with duration. \nevgg - (gate levels times curves suspt --> out) envelope generator with gate. suspt is the index of the sustain level. \nevg - (dur levels times curves suspt --> out) envelope generator with duration. suspt is the index of the sustain level.\n\nblip (freq phase nharm --> out) band limited impulse oscillator.\ndsf1 (freq phase nharm lharm hmul --> out) sum of sines oscillator.\n\nformant (freq formfreq bwfreq --> out) formant oscillator\n\nsvf (in freq rq --> [lp hp bp bs]) state variable filter.\nmoogf (in freq rq --> out) moog ladder low pass filter.\n\n*/\n\nextern void AddCoreOps();\nextern void AddMathOps();\nextern void AddStreamOps();\nextern void AddLFOps();\nextern void AddUGenOps();\nextern void AddSetOps();\nextern void AddRandomOps();\nextern void AddMidiOps();\n\nconst char* gVersionString = \"0.1.21\";\n\nstatic void usage()\n{\n\tfprintf(stdout, \"sapf [-r sample-rate][-p prelude-file]\\n\");\n\tfprintf(stdout, \"\\n\");\n\tfprintf(stdout, \"sapf [-h]\\n\");\n\tfprintf(stdout, \" print this help\\n\");\n\tfprintf(stdout, \"\\n\");\t\n}\n\nint main (int argc, const char * argv[]) \n{\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"A tool for the expression of sound as pure form.\\n\");\t\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"--- version %s\\n\", gVersionString);\n\t\n\tfor (int i = 1; i < argc;) {\n\t\tint c = argv[i][0];\n\t\tif (c == '-') {\n\t\t\tc = argv[i][1];\n\t\t\tswitch (c) {\n\t\t\t\tcase 'r' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected sample rate after -r\\n\"); return 1; }\n\t\t\t\t\t\t\n\t\t\t\t\tdouble sr = atof(argv[i+1]);\n\t\t\t\t\tif (sr < 1000. || sr > 768000.) { post(\"sample rate out of range.\\n\"); return 1; }\n\t\t\t\t\tvm.setSampleRate(sr);\n\t\t\t\t\tpost(\"sample rate set to %g\\n\", vm.ar.sampleRate);\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'p' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected prelude file name after -p\\n\"); return 1; }\n\t\t\t\t\tvm.prelude_file = argv[i+1];\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'h' : {\n\t\t\t\t\tusage();\n\t\t\t\t\texit(0);\n\t\t\t\t} break;\n\t\t\t\tdefault: \n\t\t\t\t\tpost(\"unrecognized option -%c\\n\", c);\n\t\t\t}\n\t\t} else {\n\t\t\tpost(\"expected option, got \\\"%s\\\"\\n\", argv[i]);\n\t\t\t++i;\n\t\t}\n\t}\n\t\n\t\n\tvm.addBifHelp(\"Argument Automapping legend:\");\n\tvm.addBifHelp(\" a - as is. argument is not automapped.\");\n\tvm.addBifHelp(\" z - argument is expected to be a signal or scalar, streams are auto mapped.\");\n\tvm.addBifHelp(\" k - argument is expected to be a scalar, signals and streams are automapped.\");\n\tvm.addBifHelp(\"\");\n\t\n\tAddCoreOps();\n\tAddMathOps();\n\tAddStreamOps();\n AddRandomOps();\n\tAddUGenOps();\n\tAddMidiOps();\n AddSetOps();\n\t\n\t\n\tvm.log_file = getenv(\"SAPF_LOG\");\n\tif (!vm.log_file) {\n\t\tconst char* home_dir = getenv(\"HOME\");\n\t\tchar logfilename[PATH_MAX];\n\t\tsnprintf(logfilename, PATH_MAX, \"%s/sapf-log.txt\", home_dir);\n\t\tvm.log_file = strdup(logfilename);\n\t}\n\t\n\t__block Thread th;\n\n\tauto m = manta();\n\ttry {\n\t\tm->Connect();\n\t} catch(...) {\n\t}\n\tprintf(\"Manta %s connected.\\n\", m->IsConnected() ? \"is\" : \"IS NOT\");\n\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\t/*** see at bottom for better way ***/\n\t\twhile(true) {\n\t\t\ttry {\n\t\t\t\tMantaUSB::HandleEvents();\n\t\t\t\tusleep(5000);\n\t\t\t} catch(...) {\n\t\t\t\tsleep(1);\n\t\t\t}\n\t\t}\n\t});\n\t\n\tif (!vm.prelude_file) {\n\t\tvm.prelude_file = getenv(\"SAPF_PRELUDE\");\n\t}\n\tif (vm.prelude_file) {\n\t\tloadFile(th, vm.prelude_file);\n\t}\n\t\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\tth.repl(stdin, vm.log_file);\n\t\texit(0);\n\t});\n\t\n\tCFRunLoopRun();\n\t\n\treturn 0;\n}\n\n"], ["/sapf/src/Spectrogram.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Spectrogram.hpp\"\n#include \"makeImage.hpp\"\n#include \n#include \n#include \n#include \n\nstatic void makeColorTable(unsigned char* table);\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double i0(double x)\n{\n\tconst double epsilon = 1e-18;\n\tint n = 1;\n\tdouble S = 1., D = 1., T;\n\n\twhile (D > epsilon * S) {\n\t\tT = x / (2 * n++);\n\t\tD *= T * T;\n\t\tS += D;\n\t}\n\treturn S;\n}\n\nstatic void calcKaiserWindowD(size_t size, double* window, double stopBandAttenuation)\n{\n\tsize_t M = size - 1;\n\tsize_t N = M-1;\n#if VERBOSE\n\tprintf(\"FillKaiser %d %g\\n\", M, stopBandAttenuation);\n#endif\n\n\tdouble alpha = 0.;\n\tif (stopBandAttenuation <= -50.)\n\t\talpha = 0.1102 * (-stopBandAttenuation - 8.7);\n else if (stopBandAttenuation < -21.)\n\t\talpha = 0.5842 * pow(-stopBandAttenuation - 21., 0.4) + 0.07886 * (-stopBandAttenuation - 21.);\n\n\tdouble p = N / 2;\n\tdouble kk = 1.0 / i0(alpha);\n\n\tfor(unsigned int k = 0; k < M; k++ )\n\t{\n\t\tdouble x = (k-p) / p;\n\t\t\n\t\t// Kaiser window\n\t\twindow[k+1] *= kk * bessi0(alpha * sqrt(1.0 - x*x) );\n\t}\n\twindow[0] = 0.;\n\twindow[size-1] = 0.;\n#if VERBOSE\n\tprintf(\"done\\n\");\n#endif\n}\n\nconst int border = 8;\n\nvoid spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor)\n{\n\tint numRealFreqs = 1 << log2bins;\n\n\tint log2n = log2bins + 1;\n\tint n = 1 << log2n;\n\tint nOver2 = n / 2;\n\t\n\n\tdouble scale = 1./nOver2;\n\t\n\tint64_t paddedSize = size + n;\n\tdouble* paddedData = (double*)calloc(paddedSize, sizeof(double));\n\tmemcpy(paddedData + nOver2, data, size * sizeof(double));\n\n\t\n\tdouble* dBMags = (double*)calloc(numRealFreqs + 1, sizeof(double));\n\n\tdouble hopSize = size <= n ? 0 : (double)(size - n) / (double)(width - 1);\n\n\tdouble* window = (double*)calloc(n, sizeof(double));\n\tfor (int i = 0; i < n; ++i) window[i] = 1.;\n\tcalcKaiserWindowD(n, window, -180.);\n\n\tunsigned char table[1028];\n\tmakeColorTable(table);\n\n\tint heightOfAmplitudeView = 128;\n\tint heightOfFFT = numRealFreqs+1;\n\tint totalHeight = heightOfAmplitudeView+heightOfFFT+3*border;\n\tint topOfSpectrum = heightOfAmplitudeView + 2*border;\n\tint totalWidth = width+2*border;\n\tBitmap* b = createBitmap(totalWidth, totalHeight);\n\tfillRect(b, 0, 0, totalWidth, totalHeight, 160, 160, 160, 255);\n\tfillRect(b, border, border, width, heightOfAmplitudeView, 0, 0, 0, 255);\n\t\n\tFFTSetupD fftSetup = vDSP_create_fftsetupD(log2n, kFFTRadix2);\n\n\tdouble* windowedData = (double*)calloc(n, sizeof(double));\n\tdouble* interleavedData = (double*)calloc(n, sizeof(double));\n\tdouble* resultData = (double*)calloc(n, sizeof(double));\n\tDSPDoubleSplitComplex interleaved;\n\tinterleaved.realp = interleavedData;\n\tinterleaved.imagp = interleavedData + nOver2;\n\tDSPDoubleSplitComplex result;\n\tresult.realp = resultData;\n\tresult.imagp = resultData + nOver2;\n\tdouble maxmag = 0.;\n\t\n\tdouble hpos = nOver2;\n\tfor (int i = 0; i < width; ++i) {\n\t\tsize_t ihpos = (size_t)hpos;\n\t\t\n\t\t// do analysis\n\t\t// find peak\n\t\tdouble peak = 1e-20;\n\t\tfor (int w = 0; w < n; ++w) {\n\t\t\tdouble x = paddedData[w+ihpos];\n\t\t\tx = fabs(x);\n\t\t\tif (x > peak) peak = x;\n\t\t}\n\t\t\n\t\tfor (int64_t w = 0; w < n; ++w) windowedData[w] = window[w] * paddedData[w+ihpos];\n\t\t\n\t\tvDSP_ctozD((DSPDoubleComplex*)windowedData, 2, &interleaved, 1, nOver2);\n\t\t\n\t\tvDSP_fft_zropD(fftSetup, &interleaved, 1, &result, 1, log2n, kFFTDirection_Forward);\n\t\t\n\t\tdBMags[0] = result.realp[0] * scale;\n\t\tdBMags[numRealFreqs] = result.imagp[0] * scale;\n\t\tif (dBMags[0] > maxmag) maxmag = dBMags[0];\n\t\tif (dBMags[numRealFreqs] > maxmag) maxmag = dBMags[numRealFreqs];\n\t\tfor (int64_t j = 1; j < numRealFreqs-1; ++j) {\n\t\t\tdouble x = result.realp[j] * scale;\n\t\t\tdouble y = result.imagp[j] * scale;\n\t\t\tdBMags[j] = sqrt(x*x + y*y);\n\t\t\tif (dBMags[j] > maxmag) maxmag = dBMags[j];\n\t\t}\n\n\t\tdouble invmag = 1.;\n\t\tdBMags[0] = 20.*log2(dBMags[0]*invmag);\n\t\tdBMags[numRealFreqs] = 20.*log10(dBMags[numRealFreqs]*invmag);\n\t\tfor (int64_t j = 0; j <= numRealFreqs-1; ++j) {\n\t\t\tdBMags[j] = 20.*log10(dBMags[j]*invmag);\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t// set pixels\n\t\t{\n\t\t\tdouble peakdB = 20.*log10(peak);\n\t\t\tint peakColorIndex = 256. - peakdB * (256. / dBfloor);\n\t\t\tint peakIndex = heightOfAmplitudeView - peakdB * (heightOfAmplitudeView / dBfloor);\n\t\t\tif (peakIndex < 0) peakIndex = 0;\n\t\t\tif (peakIndex > heightOfAmplitudeView) peakIndex = heightOfAmplitudeView;\n\t\t\tif (peakColorIndex < 0) peakColorIndex = 0;\n\t\t\tif (peakColorIndex > 255) peakColorIndex = 255;\n\n\t\t\tunsigned char* t = table + 4*peakColorIndex;\n\t\t\tfillRect(b, i+border, border+128-peakIndex, 1, peakIndex, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\t\n\t\tfor (int j = 0; j < numRealFreqs; ++j) {\n\t\t\tint colorIndex = 256. - dBMags[j] * (256. / dBfloor); \n\t\t\tif (colorIndex < 0) colorIndex = 0;\n\t\t\tif (colorIndex > 255) colorIndex = 255;\n\t\t\t\n\t\t\tunsigned char* t = table + 4*colorIndex;\n\t\t\t\n\t\t\tsetPixel(b, i+border, numRealFreqs-j+topOfSpectrum, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\t\n\t\thpos += hopSize;\n\t}\n\n\tvDSP_destroy_fftsetupD(fftSetup);\n\t\n\twriteBitmap(b, path);\n\tfreeBitmap(b);\n\tfree(dBMags);\n\tfree(paddedData);\n\tfree(window);\n\tfree(windowedData);\n\tfree(interleavedData);\n\tfree(resultData);\n}\n\n\nstatic void makeColorTable(unsigned char* table)\n{\n\t// white >> red >> yellow >> green >> cyan >> blue >> magenta >> pink >> black\n\t// 0 -20 -40 -60 -80 -100 -120 -140 -160\n\t// 255 224 192 160 128 96 64 32 0\n\t\n\tint colors[9][4] = {\n\t\t{ 0, 0, 64, 255},\t// dk blue\n\t\t{ 0, 0, 255, 255},\t// blue\n\t\t{255, 0, 0, 255},\t// red\n\t\t{255, 255, 0, 255},\t// yellow\n\t\t{255, 255, 255, 255}\t// white\n\t};\n\t\n\tfor (int j = 0; j < 4; ++j) {\n\t\tfor (int i = 0; i < 64; ++i) {\n\t\t\tfor (int k = 0; k < 4; ++k) {\n\t\t\t\tint x = (colors[j][k] * (64 - i) + colors[j+1][k] * i) / 64;\n\t\t\t\tif (x > 255) x = 255;\n\t\t\t\ttable[j*64*4 + i*4 + k + 4] = x;\n\t\t\t}\n\t\t}\n\t}\n\t\n\ttable[0] = 0;\n\ttable[1] = 0;\n\ttable[2] = 0;\n\ttable[3] = 255;\n}\n\n"], ["/sapf/src/symbol.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"symbol.hpp\"\n#include \"VM.hpp\"\n#include \"Hash.hpp\"\n#include \n#include \n\nconst int kSymbolTableSize = 4096;\nconst int kSymbolTableMask = kSymbolTableSize - 1;\n\t\n// global atomic symbol table\nvolatile std::atomic sSymbolTable[kSymbolTableSize];\n\n\n\nstatic String* SymbolTable_lookup(String* list, const char* name, int32_t hash)\n{\n\twhile (list) {\n\t\tif (list->hash == hash && strcmp(list->s, name) == 0)\n\t\t\treturn list;\n\t\tlist = list->nextSymbol;\n\t}\n\treturn nullptr;\n}\n\nstatic String* SymbolTable_lookup(const char* name, int hash)\n{\n\treturn SymbolTable_lookup(sSymbolTable[hash & kSymbolTableMask].load(), name, hash);\n}\n\nstatic String* SymbolTable_lookup(const char* name)\n{\n\tuintptr_t hash = Hash(name);\n\treturn SymbolTable_lookup(name, (int)hash);\n}\n\nP getsym(const char* name)\n{\n\t// thread safe\n\n\tint32_t hash = Hash(name);\n int32_t binIndex = hash & kSymbolTableMask;\n\tvolatile std::atomic* bin = &sSymbolTable[binIndex];\n\twhile (1) {\n // get the head of the list.\n\t\tString* head = bin->load();\n // search the list for the symbol\n\t\tString* existingSymbol = head;\n\t\twhile (existingSymbol) {\n\t\t\tif (existingSymbol->hash == hash && strcmp(existingSymbol->s, name) == 0) {\n\t\t\t\treturn existingSymbol;\n\t\t\t}\n\t\t\texistingSymbol = existingSymbol->nextSymbol;\n\t\t}\n\t\tString* newSymbol = new String(name, hash, head);\n\t\tif (bin->compare_exchange_weak(head, newSymbol)) {\n\t\t\tnewSymbol->retain(); \n\t\t\treturn newSymbol;\n\t\t}\n delete newSymbol;\n\t}\t\n}\n"], ["/sapf/libmanta/Manta.h", "class Manta {\n public:\n Manta(void) {\n for(int i = 0; i < 53; ++i)\n {\n LastInReport[i] = 0;\n MaxSensorValues[i] = AverageMaxSensorValues[i];\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = 0xFF;\n }\n for(unsigned int i = 0; i < sizeof(CurrentOutReport); ++i)\n {\n CurrentOutReport[i] = 0;\n }\n for(unsigned int i = 0; i < sizeof(VelocityWaiting) / sizeof(VelocityWaiting[0]); ++i)\n {\n VelocityWaiting[i] = false;\n }\n}\n virtual void SetPadLED(LEDState state, int ledID) {\n int row = ledID / 8;\n int column = ledID % 8;\n\n if(ledID < 0 || ledID > 47)\n {\n throw std::invalid_argument(\"Invalid Pad Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= (1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= (1 << column);\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n break;\n case Off:\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) {\n if(row < 0 || row > 5)\n {\n throw std::invalid_argument(\"Invalid Row Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDRow(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", row, mask);\n MantaClient::DebugPrint(\"ByteReverse(0x%X) = 0x%X\", 0xA0, byteReverse(0xA0));\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= byteReverse(mask);\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n case Off:\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) {\n if(column < 0 || column > 7)\n {\n throw std::invalid_argument(\"Invalid Column Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDColumn(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", column, mask);\n switch(state)\n {\n case Amber:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[AmberIndex + i] |= (0x01 << column);\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Red:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] |= (0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Off:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) {\n switch(state)\n {\n case Amber:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Red:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Off:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case All:\n // when setting both colors we use two frames at once\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n uint8_t amberMask = mask[i];\n uint8_t redMask = mask[i+sizeof(LEDFrame)];\n // turn off any amber LEDs if there's a red LED in that position\n amberMask &= ~redMask;\n CurrentOutReport[RedIndex + i] = byteReverse(redMask);\n CurrentOutReport[AmberIndex + i] = byteReverse(amberMask);\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) {\n if(id < 0 || id > 1)\n {\n throw std::invalid_argument(\"Invalid Slider Index\");\n }\n switch(state)\n {\n case Amber:\n CurrentOutReport[SliderIndex + id] |= byteReverse(mask);\n break;\n case Red:\n /* no Red slider LEDs, do nothing */\n break;\n case Off:\n CurrentOutReport[SliderIndex + id] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetButtonLED(LEDState state, int id) {\n if(id < 0 || id > 3)\n {\n throw std::invalid_argument(\"Invalid Button Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n break;\n case Red:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n case Off:\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ResendLEDState(void) {\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearPadAndButtonLEDs(void) {\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] = 0;\n CurrentOutReport[RedIndex + i] = 0;\n }\n\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearButtonLEDs(void) {\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void Recalibrate(void) {\n if(! IsConnected())\n {\n throw MantaNotConnectedException(this);\n }\n\n /* make sure these messages get queued so that they\n * don't just cancel each other out */\n CurrentOutReport[ConfigIndex] |= 0x40;\n WriteFrame(CurrentOutReport, true);\n CurrentOutReport[ConfigIndex] &= ~0x40;\n WriteFrame(CurrentOutReport, true);\n}\n virtual void SetLEDControl(LEDControlType control, bool state) {\n uint8_t flag;\n\n switch(control)\n {\n case PadAndButton:\n flag = 0x01;\n break;\n case Slider:\n flag = 0x02;\n break;\n case Button:\n flag = 0x20;\n break;\n default:\n throw std::invalid_argument(\"Invalid Control Type\");\n }\n\n if(state)\n CurrentOutReport[ConfigIndex] |= flag;\n else\n CurrentOutReport[ConfigIndex] &= ~flag;\n if(IsConnected())\n {\n /* if we're disabling LEDControl, we want to make sure that this\n * message gets queued so that any pending LED messages get sent\n * down before we disable LEDs */\n WriteFrame(CurrentOutReport, !state);\n }\n}\n virtual void SetTurboMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x04;\n else\n CurrentOutReport[ConfigIndex] &= ~0x04;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetRawMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x08;\n else\n CurrentOutReport[ConfigIndex] &= ~0x08;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetMaxSensorValues(int *values) {\n for(int i = 0; i < 53; ++i)\n {\n MaxSensorValues[i] = values[i];\n }\n}\n private:\n virtual void FrameReceived(int8_t *frame) {\nbool hadEvent = false;\n uint8_t *uframe = (uint8_t *)frame;\n for(int i = 1; i < 53; ++i)\n {\n uframe[i] = ScaleSensorValue(frame[i] + 128, i);\n }\n /* apply the offset to the slider bytes without scaling them */\n for(int i = 53; i < 57; ++i)\n {\n uframe[i] = frame[i] + 128;\n }\n //printf(\"\\n\");\n FrameEvent(uframe);\n /* input frames have one reportID byte at the beginning */\n for(int i = 1; i < 53; ++i)\n {\n /*\n * overall pad logic:\n * if there's a velocity waiting to be calculated, send a note-on\n * if this is the first zero value, send a note-off\n * if the pad changed, send a padValue\n */\n int padIndex = i - 1;\n /* track whether this pad just went high for a single sample,\n * so we don't trigger a simultaneous note-on and note-off */\n bool singleSample = false;\n\n /* check to see if there's a previous sample waiting to have\n * the velocity algorithm run */\n if(VelocityWaiting[i])\n {\n if(uframe[i] == 0)\n {\n // we were waiting for a 2nd sample for velocity but we got zero.\n singleSample = true;\n }\n else\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n VelocityWaiting[i] = false;\n }\n\n\n if(uframe[i] != LastInReport[i])\n {\n if(padIndex < 48) {\n PadEvent(padIndex / 8, padIndex % 8, padIndex, uframe[i]);\n\t\t\t hadEvent = true;\n } else {\n ButtonEvent(padIndex - 48, uframe[i]);\n\t\t\t hadEvent = true;\n\t\t}\n\n /* check to see if this is a release */\n if(0 == uframe[i] && !singleSample)\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex, 0);\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48, 0);\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n /* check to see if this is the first nonzero sample */\n else if(0 == LastInReport[i])\n {\n VelocityWaiting[i] = true;\n }\n }\n LastInReport[i] = uframe[i];\n }\n if(uframe[53] != LastInReport[53] || uframe[54] != LastInReport[54])\n {\n\t //printf(\"slider 0 %3d %3d\\n\", (int)uframe[53], uframe[54]);\n\t int value = (uframe[53]) | ((uframe[54]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n if(uframe[55] != LastInReport[55] || uframe[56] != LastInReport[56])\n {\n\t //printf(\"slider 1 %3d %3d\\n\", (int)uframe[55], uframe[56]);\n\t int value = (uframe[55]) | ((uframe[56]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = uframe[i];\n }\n\t\n if (hadEvent) printf(\"---\\n\");\n}\n int ScaleSensorValue(int rawValue, int index) {\n float div = (float)rawValue / MaxSensorValues[index];\n return (int)((div * 210) + 0.5);\n}\n static uint8_t byteReverse(uint8_t inByte) {\n // Algorithm from Bit Twiddling Hacks\n uint8_t outByte = inByte; // first get LSB of inByte\n int s = 7; // extra shift needed at end\n\n for (inByte >>= 1; inByte; inByte >>= 1)\n {\n outByte <<= 1;\n outByte |= inByte & 1;\n s--;\n }\n outByte <<= s; // shift when inByte's highest bits are zero\n return outByte;\n}\n static int CalculateVelocity(int firstValue, int secondValue) {\n float LOG1, LOG2;\n float MAX;\n float MIN;\n float RELATIVE1, RELATIVE2;\n float LOG_RELATIVE1, LOG_RELATIVE2;\n float SUM_RAW;\n float LOG_SUM_RAW;\n float LOG_SUM_RELATIVE;\n float UP1;\n float VELOCITY = 0;\n int VELint = 0;\n\n\n // now do the velocity calculation\n LOG1 = log(1.0 + (float)LastValue);\n LOG2 = log(1.0 + (float)CurrentValue);\n\n MIN = LastValue;\n if (CurrentValue < MIN)\n {\n MIN = CurrentValue;\n }\n MAX = LastValue;\n if (CurrentValue > MAX)\n {\n MAX = CurrentValue;\n }\n RELATIVE1 = LastValue/MAX;\n RELATIVE2 = CurrentValue/MAX;\n LOG_RELATIVE1 = log(1.0 + RELATIVE1);\n LOG_RELATIVE2 = log(1.0 + RELATIVE2);\n SUM_RAW = LastValue+CurrentValue;\n LOG_SUM_RAW = log(1.0 + SUM_RAW);\n LOG_SUM_RELATIVE = log(1.0 + SUM_RAW/MAX);\n UP1 = 0;\n if (CurrentValue>LastValue) { UP1 = 1; }\n VELOCITY =\n -14.997037 +\n LastValue * 0.009361 +\n MIN * -0.014234 +\n LOG1 * 1.099763 +\n RELATIVE2 * -9.588311 +\n LOG_RELATIVE1 *-27.595303 +\n LOG_RELATIVE2 * -8.803761 +\n LOG_SUM_RELATIVE * 44.013138 +\n UP1 * 0.221622;\n //Then trim value to [0.4] range:\n if (VELOCITY < 0.)\n {\n VELOCITY = 0.;\n }\n if (VELOCITY > 4.)\n {\n VELOCITY = 4.;\n }\n //get it to 0. to 1. range\n VELOCITY = VELOCITY / 4.;\n // curve it exponentially\n VELOCITY = VELOCITY * VELOCITY;\n //get it to 0-126 range\n VELOCITY = VELOCITY * 126;\n //get it to 1-127 range\n VELOCITY = VELOCITY+ 1;\n //round to ints\n VELint = (int)VELOCITY;\n return VELint;\n}\n static const int AmberIndex = 0;\n static const int RedIndex = 10;\n static const int SliderIndex = 7;\n static const int ButtonIndex = 6;\n static const int ConfigIndex = 9;\n static const int AverageMaxSensorValues[53];\n int MaxSensorValues[53];\n uint8_t LastInReport[InPacketLen];\n uint8_t CurrentOutReport[OutPacketLen];\n bool VelocityWaiting[53];\n bool CentroidEnabled;\n bool MaximumEnabled;\n bool PadFrameEnabled;\n};"], ["/sapf/src/dsp.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"dsp.hpp\"\n#include \n#include \n#include \n\n\nFFTSetupD fftSetups[kMaxFFTLogSize+1];\n\nvoid initFFT()\n{\n\tfor (int i = kMinFFTLogSize; i <= kMaxFFTLogSize; ++i) {\n\t\tfftSetups[i] = vDSP_create_fftsetupD(i, kFFTRadix2);\n\t}\n}\n\nvoid fft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid ifft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid fft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\nvoid ifft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\n\nvoid rfft(int n, double* inReal, double* outReal, double* outImag)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\n vDSP_ctozD((DSPDoubleComplex*)inReal, 1, &in, 1, n2);\n\t\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zropD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n2);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n2);\n \n out.realp[n2] = out.imagp[0];\n out.imagp[0] = 0.;\n out.imagp[n2] = 0.;\n}\n\n\nvoid rifft(int n, double* inReal, double* inImag, double* outReal)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\t\n //in.imagp[0] = in.realp[n2];\n in.imagp[0] = 0.;\n\n\tvDSP_fft_zripD(fftSetups[log2n], &in, 1, log2n, FFT_INVERSE);\n\n vDSP_ztocD(&in, 1, (DSPDoubleComplex*)outReal, 2, n2);\n\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n); \n}\n\n\n#define USE_VFORCE 1\n\ninline void complex_expD_conj(double& re, double& im)\n{\n\tdouble rho = expf(re);\n\tre = rho * cosf(im);\n\tim = rho * sinf(im);\n}\n\n"], ["/sapf/libmanta/MantaUSB.h", "class MantaUSB {\n public:\n MantaUSB(void) {\n mantaList.push_back(this);\n MantaIndex = int(mantaList.size());\n\n DebugPrint(\"%s-%d: Manta %d initialized\", __FILE__, __LINE__, MantaIndex);\n}\n virtual ~MantaUSB(void) {\n Disconnect();\n mantaList.remove(this);\n if(mantaList.empty())\n {\n hid_exit();\n }\n}\n void WriteFrame(uint8_t *frame, bool forceQueued) {\n if(NULL == DeviceHandle)\n {\n throw(MantaNotConnectedException(this));\n }\n MantaTxQueueEntry *queuedMessage = GetQueuedTxMessage();\n if(queuedMessage && !forceQueued)\n {\n /* replace the queued packet payload with the new one */\n for(int i = 0; i < OutPacketLen; ++i)\n {\n /* the first byte of the report is the report ID (0x00) */\n queuedMessage->OutFrame[i+1] = frame[i];\n }\n DebugPrint(\"%s-%d: (WriteFrame) Queued Transfer overwritten on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n else\n {\n /* no transfer in progress, queue up a new one */\n MantaTxQueueEntry *newMessage = new MantaTxQueueEntry;\n newMessage->OutFrame[0] = 0;\n newMessage->TargetManta = this;\n /* the first byte of the report is the report ID (0x00) */\n memcpy(newMessage->OutFrame + 1, frame, OutPacketLen);\n txQueue.push_back(newMessage);\n DebugPrint(\"%s-%d: (WriteFrame) Transfer Queued on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n}\n bool IsConnected(void) {\n return DeviceHandle != NULL;\n}\n void Connect(int connectionSerial = 0) {\n#define SERIAL_STRING_SIZE 32\n wchar_t serialString[SERIAL_STRING_SIZE];\n\n if(IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Attempting to Connect to Manta %d...\",\n __FILE__, __LINE__, connectionSerial);\n if(connectionSerial)\n {\n swprintf(serialString, SERIAL_STRING_SIZE, L\"%d\", connectionSerial);\n DeviceHandle = hid_open(VendorID, ProductID, serialString);\n }\n else\n {\n DeviceHandle = hid_open(VendorID, ProductID, NULL);\n }\n if(NULL == DeviceHandle)\n throw(MantaNotFoundException());\n hid_get_serial_number_string(DeviceHandle, serialString, SERIAL_STRING_SIZE);\n SerialNumber = int(wcstol(serialString, NULL, 10));\n int rc = hid_set_nonblocking(DeviceHandle, 1);\n printf(\"hid_set_nonblocking %d\\n\", rc);\n printf(\"SerialNumber %d\\n\", SerialNumber);\n}\n void Disconnect() {\n if(! IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Manta %d Disconnecting...\", __FILE__, __LINE__, GetSerialNumber());\n hid_close(DeviceHandle);\n DeviceHandle = NULL;\n}\n int GetSerialNumber(void) {\n return SerialNumber;\n}\n int GetHardwareVersion(void) {\n return (SerialNumber < 70) ? 1 : 2;\n}\n bool MessageQueued(void) {\n return GetQueuedTxMessage() != NULL;\n}\n static void HandleEvents(void) {\n list::iterator i = mantaList.begin();\n /* read from each manta and trigger any events */\n while(mantaList.end() != i)\n {\n MantaUSB *current = *i;\n if(current->IsConnected())\n {\n int bytesRead;\n int8_t inFrame[InPacketLen];\n\n bytesRead = hid_read(current->DeviceHandle,\n reinterpret_cast(inFrame), InPacketLen);\n if(bytesRead < 0)\n {\n current->DebugPrint(\"%s-%d: Read error on Manta %d\",\n __FILE__, __LINE__, current->GetSerialNumber());\n throw(MantaCommunicationException(current));\n }\n else if(bytesRead)\n {\n current->FrameReceived(inFrame);\n }\n }\n ++i;\n }\n\n /* pop one item off the transmit queue and send down to its target */\n if(! txQueue.empty())\n {\n int bytesWritten;\n MantaTxQueueEntry *txMessage = txQueue.front();\n txQueue.pop_front();\n bytesWritten = hid_write(txMessage->TargetManta->DeviceHandle,\n txMessage->OutFrame, OutPacketLen + 1);\n txMessage->TargetManta->DebugPrint(\"%s-%d: Frame Written to Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n for(int j = 0; j < 16; j += 8)\n {\n uint8_t *frame = txMessage->OutFrame + 1;\n txMessage->TargetManta->DebugPrint(\"\\t\\t%x %x %x %x %x %x %x %x\",\n frame[j], frame[j+1], frame[j+2], frame[j+3], frame[j+4],\n frame[j+5], frame[j+6], frame[j+7]);\n }\n delete txMessage;\n if(bytesWritten < 0)\n {\n txMessage->TargetManta->DebugPrint(\"%s-%d: Write error on Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n throw(MantaCommunicationException(txMessage->TargetManta));\n }\n }\n}\n protected:\n virtual void FrameReceived(int8_t *frame) = 0;\n static const int OutPacketLen = 16;\n static const int InPacketLen = 64;\n int SerialNumber;\n int MantaIndex;\n private:\n struct MantaTxQueueEntry\n {\n MantaUSB *TargetManta;\n uint8_t OutFrame[17];\n };\n MantaTxQueueEntry *GetQueuedTxMessage();\n static const int Interface = 0;\n static const int EndpointIn = 0x81;\n static const int EndpointOut = 0x02;\n static const int Timeout = 5000;\n static const int VendorID = 0x2424;\n static const int ProductID = 0x2424;\n hid_device *DeviceHandle;\n static list mantaList;\n static list txQueue;\n};"], ["/sapf/src/MathFuns.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathFuns.hpp\"\n#include \"VM.hpp\"\n\ndouble gSineTable[kSineTableSize+1];\ndouble gDBAmpTable[kDBAmpTableSize+2];\ndouble gDecayTable[kDecayTableSize+1];\ndouble gFirstOrderCoeffTable[kFirstOrderCoeffTableSize+1];\n\n\ninline double freqToTableF(double freq)\n{\n\treturn std::clamp(3. * log2(freq * .05), 0., 28.999);\n}\n\nZ gFreqToTable[20001];\n\nstatic void initFreqToTable()\n{\n\tfor (int freq = 0; freq < 20001; ++freq) {\n\t\tgFreqToTable[freq] = freqToTableF(freq);\n\t}\n}\n\ninline double freqToTable(double freq)\n{\n\tdouble findex = std::clamp(freq, 0., 20000.);\n\tdouble iindex = floor(findex);\n\treturn lut(gFreqToTable, (int)iindex, findex - iindex);\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\nvoid fillSineTable()\n{\n\tfor (int i = 0; i < kSineTableSize; ++i) {\n\t\tgSineTable[i] = sin(gSineTableOmega * i);\n\t}\n\tgSineTable[kSineTableSize] = gSineTable[0];\n}\n\nvoid fillDBAmpTable()\n{\n\tfor (int i = 0; i < kDBAmpTableSize+2; ++i) {\n\t\tdouble dbgain = i * kInvDBAmpScale - kDBAmpOffset;\n\t\tdouble amp = pow(10., .05 * dbgain);\n\t\tgDBAmpTable[i] = amp;\n\t}\n}\n\nvoid fillDecayTable()\n{\n\tfor (int i = 0; i < kDecayTableSize+1; ++i) {\n\t\tgDecayTable[i] = exp(log001 * i * .001);\n\t}\t\n}\n\nvoid fillFirstOrderCoeffTable()\n{\n\tdouble k = M_PI * kInvFirstOrderCoeffTableSize;\n\tfor (int i = 0; i < kFirstOrderCoeffTableSize+1; ++i) {\n\t\tdouble x = k * i;\n\t\tZ b = 2. - cos(x);\n\t\tgFirstOrderCoeffTable[i] = b - sqrt(b*b - 1.);\n\t}\t\n}\n\n\n"], ["/sapf/libmanta/extern/hidapi/hidapi/hidapi.h", "/*******************************************************\n HIDAPI - Multi-Platform library for\n communication with HID devices.\n\n Alan Ott\n Signal 11 Software\n\n 8/22/2009\n\n Copyright 2009, All Rights Reserved.\n\n At the discretion of the user of this library,\n this software may be licensed under the terms of the\n GNU Public License v3, a BSD-Style license, or the\n original HIDAPI license as outlined in the LICENSE.txt,\n LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt\n files located at the root of the source distribution.\n These files may also be found in the public source\n code repository located at:\n http://github.com/signal11/hidapi .\n********************************************************/\n\n/** @file\n * @defgroup API hidapi API\n */\n\n#ifndef HIDAPI_H__\n#define HIDAPI_H__\n\n#include \n\n#ifdef _WIN32\n #define HID_API_EXPORT __declspec(dllexport)\n #define HID_API_CALL\n#else\n #define HID_API_EXPORT /**< API export macro */\n #define HID_API_CALL /**< API call macro */\n#endif\n\n#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\t\tstruct hid_device_;\n\t\ttypedef struct hid_device_ hid_device; /**< opaque hidapi structure */\n\n\t\t/** hidapi info structure */\n\t\tstruct hid_device_info {\n\t\t\t/** Platform-specific device path */\n\t\t\tchar *path;\n\t\t\t/** Device Vendor ID */\n\t\t\tunsigned short vendor_id;\n\t\t\t/** Device Product ID */\n\t\t\tunsigned short product_id;\n\t\t\t/** Serial Number */\n\t\t\twchar_t *serial_number;\n\t\t\t/** Device Release Number in binary-coded decimal,\n\t\t\t also known as Device Version Number */\n\t\t\tunsigned short release_number;\n\t\t\t/** Manufacturer String */\n\t\t\twchar_t *manufacturer_string;\n\t\t\t/** Product string */\n\t\t\twchar_t *product_string;\n\t\t\t/** Usage Page for this Device/Interface\n\t\t\t (Windows/Mac only). */\n\t\t\tunsigned short usage_page;\n\t\t\t/** Usage for this Device/Interface\n\t\t\t (Windows/Mac only).*/\n\t\t\tunsigned short usage;\n\t\t\t/** The USB interface which this logical device\n\t\t\t represents. Valid on both Linux implementations\n\t\t\t in all cases, and valid on the Windows implementation\n\t\t\t only if the device contains more than one interface. */\n\t\t\tint interface_number;\n\n\t\t\t/** Pointer to the next device */\n\t\t\tstruct hid_device_info *next;\n\t\t};\n\n\n\t\t/** @brief Initialize the HIDAPI library.\n\n\t\t\tThis function initializes the HIDAPI library. Calling it is not\n\t\t\tstrictly necessary, as it will be called automatically by\n\t\t\thid_enumerate() and any of the hid_open_*() functions if it is\n\t\t\tneeded. This function should be called at the beginning of\n\t\t\texecution however, if there is a chance of HIDAPI handles\n\t\t\tbeing opened by different threads simultaneously.\n\t\t\t\n\t\t\t@ingroup API\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_init(void);\n\n\t\t/** @brief Finalize the HIDAPI library.\n\n\t\t\tThis function frees all of the static data associated with\n\t\t\tHIDAPI. It should be called at the end of execution to avoid\n\t\t\tmemory leaks.\n\n\t\t\t@ingroup API\n\n\t\t @returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_exit(void);\n\n\t\t/** @brief Enumerate the HID Devices.\n\n\t\t\tThis function returns a linked list of all the HID devices\n\t\t\tattached to the system which match vendor_id and product_id.\n\t\t\tIf @p vendor_id and @p product_id are both set to 0, then\n\t\t\tall HID devices will be returned.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the types of device\n\t\t\t\tto open.\n\t\t\t@param product_id The Product ID (PID) of the types of\n\t\t\t\tdevice to open.\n\n\t\t @returns\n\t\t \tThis function returns a pointer to a linked list of type\n\t\t \tstruct #hid_device, containing information about the HID devices\n\t\t \tattached to the system, or NULL in the case of failure. Free\n\t\t \tthis linked list by calling hid_free_enumeration().\n\t\t*/\n\t\tstruct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);\n\n\t\t/** @brief Free an enumeration Linked List\n\n\t\t This function frees a linked list created by hid_enumerate().\n\n\t\t\t@ingroup API\n\t\t @param devs Pointer to a list of struct_device returned from\n\t\t \t hid_enumerate().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);\n\n\t\t/** @brief Open a HID device using a Vendor ID (VID), Product ID\n\t\t\t(PID) and optionally a serial number.\n\n\t\t\tIf @p serial_number is NULL, the first device with the\n\t\t\tspecified VID and PID is opened.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the device to open.\n\t\t\t@param product_id The Product ID (PID) of the device to open.\n\t\t\t@param serial_number The Serial Number of the device to open\n\t\t\t\t (Optionally NULL).\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);\n\n\t\t/** @brief Open a HID device by its path name.\n\n\t\t\tThe path name be determined by calling hid_enumerate(), or a\n\t\t\tplatform-specific path name can be used (eg: /dev/hidraw0 on\n\t\t\tLinux).\n\n\t\t\t@ingroup API\n\t\t @param path The path name of the device to open\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);\n\n\t\t/** @brief Write an Output report to a HID device.\n\n\t\t\tThe first byte of @p data[] must contain the Report ID. For\n\t\t\tdevices which only support a single report, this must be set\n\t\t\tto 0x0. The remaining bytes contain the report data. Since\n\t\t\tthe Report ID is mandatory, calls to hid_write() will always\n\t\t\tcontain one more byte than the report contains. For example,\n\t\t\tif a hid report is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_write(), the Report ID (or 0x0, for devices with a\n\t\t\tsingle report), followed by the report data (16 bytes). In\n\t\t\tthis example, the length passed in would be 17.\n\n\t\t\thid_write() will send the data on the first OUT endpoint, if\n\t\t\tone exists. If it does not, it will send the data through\n\t\t\tthe Control Endpoint (Endpoint 0).\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Read an Input report from a HID device with timeout.\n\n\t\t\tInput reports are returned\n\t\t\tto the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\t\t\t@param milliseconds timeout in milliseconds or -1 for blocking wait.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);\n\n\t\t/** @brief Read an Input report from a HID device.\n\n\t\t\tInput reports are returned\n\t\t to the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Set the device handle to be non-blocking.\n\n\t\t\tIn non-blocking mode calls to hid_read() will return\n\t\t\timmediately with a value of 0 if there is no data to be\n\t\t\tread. In blocking mode, hid_read() will wait (block) until\n\t\t\tthere is data to read before returning.\n\n\t\t\tNonblocking can be turned on and off at any time.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param nonblock enable or not the nonblocking reads\n\t\t\t - 1 to enable nonblocking\n\t\t\t - 0 to disable nonblocking.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);\n\n\t\t/** @brief Send a Feature report to the device.\n\n\t\t\tFeature reports are sent over the Control endpoint as a\n\t\t\tSet_Report transfer. The first byte of @p data[] must\n\t\t\tcontain the Report ID. For devices which only support a\n\t\t\tsingle report, this must be set to 0x0. The remaining bytes\n\t\t\tcontain the report data. Since the Report ID is mandatory,\n\t\t\tcalls to hid_send_feature_report() will always contain one\n\t\t\tmore byte than the report contains. For example, if a hid\n\t\t\treport is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_send_feature_report(): the Report ID (or 0x0, for\n\t\t\tdevices which do not use numbered reports), followed by the\n\t\t\treport data (16 bytes). In this example, the length passed\n\t\t\tin would be 17.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send, including\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Get a feature report from a HID device.\n\n\t\t\tMake sure to set the first byte of @p data[] to the Report\n\t\t\tID of the report to be read. Make sure to allow space for\n\t\t\tthis extra byte in @p data[].\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into, including\n\t\t\t\tthe Report ID. Set the first byte of @p data[] to the\n\t\t\t\tReport ID of the report to be read.\n\t\t\t@param length The number of bytes to read, including an\n\t\t\t\textra byte for the report ID. The buffer can be longer\n\t\t\t\tthan the actual report.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Close a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);\n\n\t\t/** @brief Get The Manufacturer String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Product String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Serial Number String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string from a HID device, based on its string index.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string_index The index of the string to get.\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string describing the last error which occurred.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\n\t\t\t@returns\n\t\t\t\tThis function returns a string containing the last error\n\t\t\t\twhich occurred or NULL if none has occurred.\n\t\t*/\n\t\tHID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"], ["/sapf/src/RCObj.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"RCObj.hpp\"\n#include \"VM.hpp\"\n\n\nRCObj::RCObj()\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::RCObj(RCObj const& that)\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::~RCObj()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\n\nvoid RCObj::norefs()\n{\n\trefcount = -999;\n\tdelete this; \n}\n\n\t\nvoid RCObj::negrefcount()\n{\n\tpost(\"RELEASING WITH NEGATIVE REFCOUNT %s %p %d\\n\", TypeName(), this, refcount.load());\n}\nvoid RCObj::alreadyDead()\n{\n\tpost(\"RETAINING ALREADY DEAD OBJECT %s %p\\n\", TypeName(), this);\n}\n"], ["/sapf/src/ErrorCodes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"ErrorCodes.hpp\"\n\nconst char* errString[kNumErrors] = { \n\t\"halt\", \"failed\", \"indefinite operation\", \"wrong type\", \"out of range\", \"syntax\", \"internal bug\",\n\t\"wrong state\", \"not found\", \"stack overflow\", \"stack underflow\",\n\t\"inconsistent inheritance\", \"undefined operation\", \"user quit\"\n};\n"], ["/sapf/src/primes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"primes.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n\n// Within a cycle of 30, there are only 8 numbers that are not multiples of 2, 3 or 5.\n// We pack these 8 into a one byte bit map.\n\nconst int gLowPrimes[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimeOffsets[8] = {1, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimesShift[30] = \n{\n\t-1, 0, -1, -1, -1, -1, -1, 1, -1, -1, \n\t-1, 2, -1, 3, -1, -1, -1, 4, -1, 5, \n\t-1, -1, -1, 6, -1, -1, -1, -1, -1, 7 \n};\n\t\nconst uint32_t gLowPrimesMask = 0x208a28ac;\n\n//const int kPrimeUpperLimit = kPrimesMaskSize * 30;\nuint8_t gPrimesMask[kPrimesMaskSize] = {\n\t0xdf, 0xef, 0x7e, 0xb6, 0xdb, 0x3d, 0xf9, 0xd5, 0x4f, 0x1e, 0xf3, 0xea, 0xa6, 0xed, 0x9e, 0xe6, \n\t0x0c, 0xd3, 0xd3, 0x3b, 0xdd, 0x59, 0xa5, 0x6a, 0x67, 0x92, 0xbd, 0x78, 0x1e, 0xa6, 0x56, 0x56, \n\t0xe3, 0xad, 0x2d, 0xde, 0x2a, 0x4c, 0x55, 0xd9, 0xa3, 0xf0, 0x9f, 0x03, 0x54, 0xa1, 0xf8, 0x2e, \n\t0xfd, 0x44, 0xe9, 0x66, 0xf6, 0x13, 0x3a, 0xb8, 0x4c, 0x2b, 0x3a, 0x45, 0x11, 0xbf, 0x54, 0x8c, \n\t0xc1, 0x7a, 0xb3, 0xc8, 0xbc, 0x8c, 0x4f, 0x21, 0x58, 0x71, 0x71, 0x9b, 0xc1, 0x17, 0xef, 0x54, \n\t0x96, 0x1a, 0x08, 0xe5, 0x83, 0x8c, 0x46, 0x72, 0xfb, 0xae, 0x65, 0x92, 0x8f, 0x58, 0x87, 0xd2, \n\t0x92, 0xd8, 0x81, 0x65, 0x26, 0xe3, 0xa0, 0x11, 0x38, 0xc7, 0x26, 0x3c, 0x81, 0xeb, 0x99, 0x8d, \n\t0x51, 0x88, 0x3e, 0x24, 0xf3, 0x33, 0x4d, 0x5a, 0x8b, 0x1c, 0xa7, 0x2a, 0xb4, 0x58, 0x4c, 0x4e, \n\t0x26, 0xf6, 0x19, 0x82, 0xdc, 0x83, 0xc3, 0x2c, 0xf1, 0x38, 0x02, 0xb5, 0xcd, 0xcd, 0x02, 0xb2, \n\t0x4a, 0x94, 0x0c, 0x57, 0x4c, 0x7a, 0x30, 0x43, 0x0b, 0xf1, 0xcb, 0x44, 0x6c, 0x24, 0xf8, 0x19, \n\t0x01, 0x95, 0xa8, 0x5c, 0x73, 0xea, 0x8d, 0x24, 0x96, 0x2b, 0x50, 0xa6, 0x22, 0x1e, 0xc4, 0xd1, \n\t0x48, 0x06, 0xd4, 0x3a, 0x2f, 0x74, 0x9c, 0x07, 0x6a, 0x05, 0x88, 0xbf, 0x68, 0x15, 0x2e, 0x60, \n\t0x55, 0xe3, 0xb7, 0x51, 0x98, 0x08, 0x14, 0x86, 0x5a, 0xaa, 0x45, 0x4d, 0x49, 0x70, 0x27, 0xd2, \n\t0x93, 0xd5, 0xca, 0xab, 0x02, 0x83, 0x61, 0x05, 0x24, 0xce, 0x87, 0x22, 0xc2, 0xa9, 0xad, 0x18, \n\t0x8c, 0x4d, 0x78, 0xd1, 0x89, 0x16, 0xb0, 0x57, 0xc7, 0x62, 0xa2, 0xc0, 0x34, 0x24, 0x52, 0xae, \n\t0x5a, 0x40, 0x32, 0x8d, 0x21, 0x08, 0x43, 0x34, 0xb6, 0xd2, 0xb6, 0xd9, 0x19, 0xe1, 0x60, 0x67, \n\t0x1a, 0x39, 0x60, 0xd0, 0x44, 0x7a, 0x94, 0x9a, 0x09, 0x88, 0x83, 0xa8, 0x74, 0x55, 0x10, 0x27, \n\t0xa1, 0x5d, 0x68, 0x1e, 0x23, 0xc8, 0x32, 0xe0, 0x19, 0x03, 0x44, 0x73, 0x48, 0xb1, 0x38, 0xc3, \n\t0xe6, 0x2a, 0x57, 0x61, 0x98, 0xb5, 0x1c, 0x0a, 0x68, 0xc5, 0x81, 0x8f, 0xac, 0x02, 0x29, 0x1a, \n\t0x47, 0xe3, 0x94, 0x11, 0x4e, 0x64, 0x2e, 0x14, 0xcb, 0x3d, 0xdc, 0x14, 0xc5, 0x06, 0x10, 0xe9, \n\t0x29, 0xb1, 0x82, 0xe9, 0x30, 0x47, 0xe3, 0x34, 0x19, 0xc3, 0x25, 0x0a, 0x30, 0x30, 0xb4, 0x6c, \n\t0xc1, 0xe5, 0x46, 0x44, 0xd8, 0x8e, 0x4c, 0x5d, 0x22, 0x24, 0x70, 0x78, 0x92, 0x89, 0x81, 0x82, \n\t0x56, 0x26, 0x1b, 0x86, 0xe9, 0x08, 0xa5, 0x00, 0xd3, 0xc3, 0x29, 0xb0, 0xc2, 0x4a, 0x10, 0xb2, \n\t0x59, 0x38, 0xa1, 0x1d, 0x42, 0x60, 0xc7, 0x22, 0x27, 0x8c, 0xc8, 0x44, 0x1a, 0xc6, 0x8b, 0x82, \n\t0x81, 0x1a, 0x46, 0x10, 0xa6, 0x31, 0x09, 0xf0, 0x54, 0x2f, 0x18, 0xd2, 0xd8, 0xa9, 0x15, 0x06, \n\t0x2e, 0x0c, 0xf6, 0xc0, 0x0e, 0x50, 0x91, 0xcd, 0x26, 0xc1, 0x18, 0x38, 0x65, 0x19, 0xc3, 0x56, \n\t0x93, 0x8b, 0x2a, 0x2d, 0xd6, 0x84, 0x4a, 0x61, 0x0a, 0xa5, 0x2c, 0x09, 0xe0, 0x76, 0xc4, 0x6a, \n\t0x3c, 0xd8, 0x08, 0xe8, 0x14, 0x66, 0x1b, 0xb0, 0xa4, 0x02, 0x63, 0x36, 0x10, 0x31, 0x07, 0xd5, \n\t0x92, 0x48, 0x42, 0x12, 0xc3, 0x8a, 0xa0, 0x9f, 0x2d, 0x74, 0xa4, 0x82, 0x85, 0x78, 0x5c, 0x0d, \n\t0x18, 0xb0, 0x61, 0x14, 0x1d, 0x02, 0xe8, 0x18, 0x12, 0xc1, 0x01, 0x49, 0x1c, 0x83, 0x30, 0x67, \n\t0x33, 0xa1, 0x88, 0xd8, 0x0f, 0x0c, 0xf4, 0x98, 0x88, 0x58, 0xd7, 0x66, 0x42, 0x47, 0xb1, 0x16, \n\t0xa8, 0x96, 0x08, 0x18, 0x41, 0x59, 0x15, 0xb5, 0x44, 0x2a, 0x52, 0xe1, 0xb3, 0xaa, 0xa1, 0x59, \n\t0x45, 0x62, 0x55, 0x18, 0x11, 0xa5, 0x0c, 0xa3, 0x3c, 0x67, 0x00, 0xbe, 0x54, 0xd6, 0x0a, 0x20, \n\t0x36, 0x6b, 0x82, 0x0c, 0x15, 0x08, 0x7e, 0x56, 0x91, 0x01, 0x78, 0xd0, 0x61, 0x0a, 0x84, 0xa8, \n\t0x2c, 0x01, 0x57, 0x0e, 0x56, 0xa0, 0x50, 0x0b, 0x98, 0x8c, 0x47, 0x6c, 0x20, 0x63, 0x10, 0xc4, \n\t0x09, 0xe4, 0x0c, 0x57, 0x88, 0x0b, 0x75, 0x0b, 0xc2, 0x52, 0x82, 0xc2, 0x39, 0x24, 0x02, 0x2c, \n\t0x56, 0x25, 0x7a, 0x31, 0x29, 0xd6, 0xa3, 0x20, 0xe1, 0xb1, 0x18, 0xb0, 0x0c, 0x8a, 0x32, 0xc1, \n\t0x11, 0x32, 0x09, 0xc5, 0xad, 0x30, 0x37, 0x08, 0xbc, 0x91, 0x82, 0xcf, 0x20, 0x25, 0x6b, 0x9c, \n\t0x30, 0x8f, 0x44, 0x26, 0x46, 0x6a, 0x07, 0x49, 0x8e, 0x09, 0x58, 0x10, 0x02, 0x25, 0xc5, 0xc4, \n\t0x42, 0x5a, 0x80, 0xa0, 0x80, 0x3c, 0x90, 0x28, 0x64, 0x14, 0xe1, 0x03, 0x84, 0x51, 0x0c, 0x2e, \n\t0xa3, 0x8a, 0xa4, 0x08, 0xc0, 0x47, 0x7e, 0xd3, 0x2b, 0x03, 0xcd, 0x54, 0x2a, 0x00, 0x04, 0xb3, \n\t0x92, 0x6c, 0x42, 0x29, 0x4c, 0x83, 0xc1, 0x92, 0xcc, 0x1c, 0x2d, 0x46, 0x21, 0xdb, 0x38, 0x59, \n\t0x84, 0x8c, 0x24, 0x12, 0x58, 0xbb, 0xe0, 0x06, 0x0d, 0x70, 0x30, 0xc9, 0x09, 0x28, 0x91, 0x41, \n\t0x44, 0x32, 0xf9, 0x8c, 0x30, 0x80, 0xc2, 0x72, 0xa4, 0x62, 0x0c, 0x7d, 0x81, 0x83, 0x14, 0xe1, \n\t0xaa, 0x0e, 0x15, 0x82, 0x0a, 0x78, 0x14, 0x70, 0x97, 0x08, 0x10, 0x6f, 0x2e, 0xf0, 0xb2, 0x1d, \n\t0x30, 0x49, 0x44, 0x32, 0x53, 0x62, 0x86, 0x65, 0x45, 0x84, 0x0a, 0x11, 0x4b, 0x36, 0xd9, 0x8c, \n\t0x69, 0x3a, 0x61, 0x80, 0x90, 0x7c, 0x19, 0xc0, 0x30, 0x95, 0x40, 0x8b, 0x0c, 0x05, 0x2d, 0x0e, \n\t0xc0, 0x71, 0xa1, 0xb4, 0x96, 0x85, 0x1a, 0x16, 0xc0, 0x15, 0x14, 0x51, 0x4c, 0x48, 0xb7, 0x79, \n\t0x95, 0x10, 0x89, 0x8a, 0x2e, 0x02, 0xa1, 0x1c, 0xd5, 0x90, 0x81, 0x10, 0x91, 0x08, 0x22, 0xb4, \n\t0x1e, 0xe9, 0x78, 0xc0, 0x33, 0x20, 0x5c, 0x8b, 0xc4, 0x0e, 0xe2, 0xaa, 0x23, 0x10, 0x47, 0xe3, \n\t0x28, 0x55, 0x7b, 0x19, 0xa1, 0x51, 0xa8, 0x06, 0x04, 0x90, 0x82, 0x2c, 0xd1, 0x61, 0x60, 0xa1, \n\t0x52, 0x06, 0x41, 0x44, 0x81, 0x54, 0x23, 0x88, 0x18, 0xa9, 0x04, 0x27, 0x22, 0x72, 0x48, 0xb6, \n\t0x40, 0x1c, 0x42, 0x12, 0x17, 0xca, 0x29, 0xa0, 0x5a, 0x01, 0x3c, 0xe1, 0x52, 0x84, 0x89, 0xda, \n\t0x01, 0x40, 0x06, 0xf1, 0x2c, 0x69, 0xd2, 0x48, 0x42, 0x63, 0xc1, 0x21, 0x34, 0x8a, 0xc8, 0x6c, \n\t0x21, 0x71, 0x26, 0x09, 0x88, 0x2e, 0x44, 0xd5, 0x28, 0x92, 0x1d, 0x98, 0x86, 0x12, 0xd1, 0x52, \n\t0xa3, 0xa0, 0x46, 0x20, 0x46, 0x14, 0x50, 0x83, 0xdc, 0xdd, 0x83, 0x50, 0x44, 0xa9, 0x8c, 0x4d, \n\t0x14, 0x2e, 0x54, 0x14, 0x89, 0x1b, 0x39, 0x42, 0x80, 0x14, 0x81, 0x29, 0x8f, 0x80, 0x02, 0x03, \n\t0x32, 0x96, 0x82, 0x83, 0xb0, 0x05, 0x0c, 0x14, 0x51, 0x88, 0x07, 0xf8, 0xd9, 0xec, 0x1a, 0x06, \n\t0x48, 0x31, 0x5c, 0x43, 0x86, 0x06, 0x23, 0xb3, 0x09, 0x44, 0x0c, 0xa5, 0x00, 0xf0, 0xb2, 0x80, \n\t0x01, 0xca, 0xe1, 0x42, 0xc2, 0x18, 0xb6, 0x2c, 0x9b, 0xc7, 0x2e, 0x52, 0x29, 0x2c, 0x61, 0x1a, \n\t0x8a, 0x26, 0x24, 0x8b, 0x84, 0x80, 0x5e, 0x60, 0x02, 0xc1, 0x53, 0x2a, 0x35, 0x45, 0x21, 0x52, \n\t0xd1, 0x42, 0xb8, 0xc5, 0x4a, 0x48, 0x04, 0x16, 0x70, 0x23, 0x61, 0xc1, 0x09, 0x50, 0xc4, 0x81, \n\t0x88, 0x18, 0xd9, 0x01, 0x16, 0x22, 0x28, 0x8c, 0x90, 0x84, 0xeb, 0x38, 0x24, 0x53, 0x09, 0xa9, \n\t0x41, 0x6a, 0x14, 0x82, 0x09, 0x86, 0x30, 0x9c, 0xa2, 0x38, 0x42, 0x00, 0x2b, 0x95, 0x5a, 0x02, \n\t0x4a, 0xc1, 0xa2, 0xad, 0x45, 0x04, 0x27, 0x54, 0xc0, 0x28, 0xa9, 0x05, 0x8c, 0x2e, 0x6e, 0x60, \n\t0xf3, 0x16, 0x90, 0x1b, 0x82, 0x1e, 0x00, 0x80, 0x26, 0x1c, 0x1d, 0x4a, 0x14, 0xc2, 0x1a, 0x22, \n\t0x3c, 0x85, 0xc1, 0x10, 0xb0, 0x48, 0x11, 0x00, 0x4a, 0xc5, 0x30, 0xf4, 0xaa, 0x30, 0x8c, 0xc8, \n\t0x49, 0x18, 0x07, 0xf0, 0x1c, 0xe9, 0x07, 0xcd, 0x0c, 0x22, 0x1b, 0x1c, 0xec, 0xc2, 0x45, 0x0a, \n\t0x50, 0x3a, 0x20, 0xe4, 0x0e, 0x6c, 0x20, 0x82, 0xc3, 0x91, 0xd9, 0xc8, 0x62, 0x4c, 0xd1, 0x80, \n\t0x85, 0x65, 0x09, 0x02, 0x30, 0x95, 0xf9, 0x10, 0x69, 0x02, 0xa6, 0x4a, 0x64, 0xc2, 0xb6, 0xf9, \n\t0x16, 0x20, 0x48, 0xa1, 0x73, 0x94, 0x31, 0x54, 0x61, 0x44, 0x07, 0x03, 0x82, 0x2c, 0x06, 0x00, \n\t0x38, 0x33, 0x09, 0x1c, 0xc1, 0x4b, 0xce, 0x12, 0x35, 0x41, 0xa4, 0x90, 0x99, 0x2d, 0x2a, 0xc0, \n\t0x59, 0x84, 0xd1, 0x4a, 0xa4, 0x72, 0x04, 0x22, 0x3c, 0x54, 0xc2, 0xa0, 0x0c, 0x01, 0x18, 0xac, \n\t0xac, 0x96, 0xe4, 0x04, 0x04, 0x03, 0x93, 0x05, 0x9b, 0x48, 0x44, 0x63, 0x32, 0x01, 0x31, 0x5f, \n\t0x60, 0x5c, 0x02, 0x00, 0x03, 0x80, 0xd1, 0x04, 0x2e, 0x34, 0xa9, 0x30, 0x49, 0xc4, 0xca, 0x1e, \n\t0x02, 0x4b, 0x32, 0x14, 0x05, 0x86, 0x22, 0xc5, 0xc2, 0x2a, 0x4c, 0xc8, 0x00, 0x08, 0xf3, 0x18, \n\t0x38, 0x65, 0x99, 0x82, 0x4a, 0x54, 0x63, 0xa1, 0x94, 0x8f, 0x44, 0x12, 0x93, 0xe9, 0x19, 0x28, \n\t0xca, 0xa1, 0x06, 0x12, 0x8a, 0x20, 0xa5, 0x51, 0x48, 0x18, 0x70, 0x31, 0xae, 0x90, 0x08, 0x43, \n\t0x68, 0x97, 0x32, 0xaf, 0x91, 0xc8, 0x0a, 0x2c, 0x02, 0x02, 0x8c, 0x0c, 0x51, 0xa5, 0x12, 0x00, \n\t0x1b, 0x1e, 0x81, 0x8a, 0x08, 0x28, 0x60, 0xd2, 0x86, 0x34, 0x44, 0x63, 0x76, 0x04, 0x43, 0x00, \n\t0xf1, 0x01, 0x04, 0x40, 0x36, 0xc8, 0xa1, 0x8c, 0xc3, 0xce, 0x32, 0x42, 0x09, 0x29, 0x55, 0x44, \n\t0x4e, 0x28, 0x43, 0x60, 0x1c, 0xa0, 0xda, 0x28, 0x0e, 0xa5, 0xf2, 0x05, 0x40, 0x59, 0x8c, 0x4e, \n\t0xa2, 0x60, 0x05, 0xe0, 0x05, 0xc5, 0x04, 0x62, 0x81, 0x26, 0xa8, 0x8a, 0xa4, 0x24, 0xb4, 0xd3, \n\t0x1a, 0x81, 0x42, 0xe4, 0x60, 0x34, 0x08, 0x2a, 0x39, 0xcc, 0x62, 0x08, 0x47, 0xd0, 0x00, 0x40, \n\t0x07, 0x02, 0x78, 0x20, 0xd9, 0xa2, 0x89, 0x50, 0x23, 0x32, 0x00, 0xb8, 0x80, 0x64, 0x11, 0xe9, \n\t0x74, 0x62, 0x0a, 0xaa, 0x44, 0x08, 0x8b, 0x16, 0x06, 0x18, 0x2d, 0xf1, 0x4c, 0x4f, 0x2a, 0x21, \n\t0x40, 0x15, 0xb4, 0x0c, 0x48, 0x22, 0xd1, 0xe1, 0x80, 0xd8, 0x17, 0xa7, 0x14, 0xa0, 0x82, 0x15, \n\t0x64, 0xc0, 0x89, 0x5a, 0x11, 0xbb, 0x8c, 0x78, 0x08, 0xcd, 0x04, 0x24, 0xa2, 0x9b, 0x9c, 0x10, \n\t0xcc, 0x42, 0xa3, 0x28, 0x3b, 0x58, 0x5f, 0xa6, 0x40, 0x90, 0x23, 0x04, 0x2c, 0xd2, 0xae, 0x52, \n\t0x51, 0x1a, 0xa4, 0x69, 0x80, 0xc1, 0x4a, 0xa3, 0xc8, 0x90, 0x19, 0x48, 0x42, 0x24, 0x22, 0x43, \n\t0x02, 0x45, 0xc1, 0x05, 0x00, 0x74, 0x11, 0x15, 0x94, 0x10, 0x0c, 0x38, 0x73, 0x8a, 0x25, 0x04, \n\t0x07, 0x28, 0x7e, 0x01, 0x40, 0x82, 0x41, 0x48, 0x6d, 0x16, 0x36, 0x29, 0x31, 0xe5, 0x81, 0xa4, \n\t0x1c, 0x81, 0xfa, 0x09, 0x00, 0x14, 0x2d, 0x10, 0x60, 0x40, 0x97, 0xdc, 0x88, 0x02, 0x4e, 0x17, \n\t0x98, 0x85, 0x44, 0x9c, 0xa2, 0x60, 0x91, 0x8a, 0x92, 0x68, 0x19, 0x0a, 0x40, 0x51, 0x80, 0x37, \n\t0x84, 0x15, 0x40, 0x62, 0x64, 0xb2, 0x0e, 0x91, 0x48, 0x2a, 0x00, 0x55, 0x48, 0x99, 0xb0, 0x08, \n\t0x85, 0x1a, 0x13, 0x10, 0x9b, 0x00, 0x5e, 0xc9, 0x50, 0x00, 0xe8, 0xa4, 0x00, 0x83, 0x45, 0x6c, \n\t0x40, 0x0b, 0x9d, 0xa0, 0x02, 0x2d, 0x34, 0x92, 0x01, 0x21, 0x81, 0x17, 0xa3, 0x46, 0xa0, 0x8a, \n\t0x85, 0xe8, 0x88, 0x47, 0x18, 0x96, 0x01, 0xb6, 0x41, 0x93, 0x84, 0x08, 0x02, 0x18, 0x02, 0x35, \n\t0x50, 0xe4, 0x3a, 0x81, 0x10, 0x11, 0xa1, 0xda, 0x82, 0x4c, 0x34, 0x32, 0x85, 0x00, 0x57, 0x4b, \n\t0x28, 0xa5, 0xa8, 0x38, 0x84, 0x1d, 0x0e, 0x30, 0xb3, 0x50, 0x22, 0x41, 0xc3, 0xc6, 0x06, 0xd0, \n\t0x20, 0x28, 0xa1, 0x05, 0x8a, 0x1a, 0x84, 0x22, 0x85, 0x0c, 0x46, 0x44, 0x72, 0x90, 0xc8, 0x17, \n\t0xd8, 0x41, 0x61, 0x64, 0x30, 0x39, 0x00, 0x0c, 0x97, 0xa3, 0x0e, 0xb2, 0x29, 0x02, 0x50, 0x88, \n\t0xa9, 0x5c, 0x22, 0xc1, 0x8e, 0x90, 0xc3, 0x47, 0x40, 0x31, 0x12, 0x2c, 0x38, 0x8c, 0x63, 0x64, \n\t0x86, 0xc0, 0xb3, 0x00, 0x4a, 0x2a, 0x38, 0x11, 0x91, 0x13, 0x38, 0x47, 0x49, 0x14, 0x81, 0x73, \n\t0x02, 0x2c, 0x4c, 0x8e, 0x52, 0xe5, 0xd1, 0x10, 0x10, 0x07, 0x4c, 0x06, 0x65, 0x61, 0x1a, 0x54, \n\t0x84, 0x01, 0x4a, 0xe2, 0x01, 0x2f, 0x10, 0x06, 0x09, 0x42, 0x44, 0x9a, 0x00, 0xa9, 0x52, 0x8c, \n\t0x28, 0x94, 0x61, 0x01, 0x99, 0x05, 0x20, 0x1c, 0x23, 0x78, 0xa2, 0x51, 0x18, 0x82, 0x3c, 0x41, \n\t0xd0, 0xb7, 0xc4, 0x43, 0x87, 0x44, 0xc6, 0x0a, 0x93, 0x68, 0xc1, 0x81, 0x30, 0x52, 0xb2, 0xa8, \n\t0xc1, 0x8a, 0x24, 0x1c, 0x21, 0x03, 0x33, 0x41, 0x14, 0x4a, 0x2e, 0x41, 0xe2, 0x82, 0x45, 0x01, \n\t0xac, 0x06, 0x40, 0x18, 0x20, 0x95, 0x4c, 0x67, 0x20, 0x26, 0x50, 0x94, 0x55, 0x92, 0x08, 0x1a, \n\t0x82, 0xe1, 0x8c, 0x10, 0x5b, 0x61, 0x02, 0x86, 0x72, 0x99, 0x30, 0x8d, 0x06, 0x2c, 0xb0, 0xa1, \n\t0x18, 0x28, 0x06, 0x27, 0x46, 0x20, 0x18, 0x82, 0x21, 0x9c, 0xeb, 0x18, 0xc4, 0x30, 0x81, 0x58, \n\t0xc1, 0x84, 0x06, 0x37, 0x9a, 0x24, 0x50, 0x0d, 0xa2, 0x40, 0x05, 0x29, 0x19, 0x09, 0x02, 0x84, \n\t0x52, 0x64, 0x11, 0x17, 0xec, 0xd1, 0x20, 0x78, 0x86, 0x63, 0x0e, 0xd1, 0x11, 0x2a, 0x60, 0x03, \n\t0xd1, 0x22, 0x60, 0x84, 0x06, 0x32, 0xa4, 0x68, 0x24, 0x81, 0xc7, 0xc0, 0x12, 0x42, 0x01, 0xbb, \n\t0xa8, 0x00, 0x41, 0x7c, 0x41, 0x21, 0x81, 0x91, 0x10, 0x85, 0x14, 0xa0, 0xa8, 0x2d, 0x5c, 0x15, \n\t0x47, 0x40, 0xd0, 0xfa, 0x2a, 0x84, 0x0e, 0x8f, 0x10, 0xd2, 0x80, 0x09, 0xd4, 0x49, 0x21, 0x26, \n\t0x32, 0xb0, 0x38, 0x20, 0x41, 0xa0, 0x4a, 0x11, 0x4b, 0xba, 0xac, 0x4e, 0x20, 0x34, 0x61, 0x60, \n\t0x15, 0x0d, 0x13, 0x6a, 0x70, 0x43, 0x42, 0x9c, 0x2d, 0x55, 0xe8, 0x00, 0x96, 0x98, 0x92, 0xe4, \n\t0xc8, 0x4c, 0x0c, 0xa5, 0x19, 0x81, 0x31, 0xca, 0x42, 0x02, 0x12, 0x4a, 0x30, 0x30, 0x51, 0x01, \n\t0x66, 0xa2, 0xe2, 0x16, 0x41, 0xcf, 0xa0, 0x2a, 0x84, 0x51, 0x18, 0x18, 0x41, 0xc6, 0x56, 0xa0, \n\t0x21, 0x8e, 0xe1, 0x96, 0x0b, 0x04, 0x60, 0x11, 0xb8, 0x4c, 0x93, 0x0d, 0x06, 0x04, 0x2a, 0x2a, \n\t0x4c, 0x04, 0x86, 0x2a, 0x51, 0x51, 0x31, 0x00, 0x01, 0x80, 0x76, 0x51, 0x98, 0x94, 0x2d, 0xcc, \n\t0x4a, 0x6a, 0xa4, 0x42, 0xb2, 0x69, 0x48, 0x01, 0x40, 0xb5, 0xd2, 0x32, 0x5c, 0x0e, 0x62, 0x20, \n\t0x16, 0x01, 0x37, 0xe4, 0xc1, 0xc2, 0x58, 0x24, 0x23, 0x08, 0x88, 0x02, 0x24, 0x14, 0x85, 0x98, \n\t0x06, 0xd0, 0x1d, 0xaa, 0x34, 0x80, 0x0a, 0x34, 0x61, 0x10, 0x4b, 0x48, 0x42, 0xc2, 0x02, 0x98, \n\t0x94, 0x00, 0x20, 0x57, 0xb3, 0xa1, 0x88, 0x1a, 0xce, 0x08, 0x05, 0xa0, 0xb0, 0x79, 0x4a, 0x01, \n\t0x14, 0x46, 0x03, 0x24, 0x24, 0x8d, 0x00, 0x44, 0x41, 0x41, 0x03, 0x6c, 0x8a, 0xc1, 0x02, 0xc1, \n\t0x59, 0x26, 0xd8, 0x41, 0x68, 0x56, 0x53, 0x43, 0x2a, 0x14, 0x04, 0x28, 0x0a, 0x25, 0x20, 0x8a, \n\t0x94, 0x47, 0x83, 0x1a, 0x85, 0xa0, 0x0f, 0x84, 0xd5, 0x08, 0x40, 0x70, 0x19, 0x06, 0x08, 0x51, \n\t0x80, 0x5a, 0x16, 0xa8, 0x08, 0x55, 0xd2, 0x28, 0x18, 0x41, 0x49, 0x09, 0x85, 0x02, 0x65, 0x50, \n\t0xb4, 0x80, 0x3d, 0x80, 0x81, 0x2a, 0x4a, 0x86, 0x80, 0x30, 0x01, 0x03, 0x86, 0x1c, 0x53, 0x93, \n\t0xa3, 0x61, 0x58, 0x2a, 0x54, 0x21, 0xb2, 0x97, 0xb0, 0x86, 0xab, 0x52, 0x44, 0xe9, 0x88, 0x59, \n\t0x00, 0x8b, 0x20, 0x10, 0xd2, 0x18, 0x18, 0x85, 0x08, 0x1c, 0x31, 0x50, 0x03, 0x64, 0x8c, 0x0a, \n\t0x40, 0x61, 0xc0, 0x0c, 0xa8, 0x08, 0x40, 0x32, 0x65, 0x0b, 0x9c, 0x88, 0x02, 0x42, 0x4c, 0x14, \n\t0x60, 0x34, 0x85, 0x13, 0x21, 0x50, 0x71, 0x48, 0xa1, 0xe5, 0x14, 0x6e, 0x48, 0x20, 0x32, 0x8a, \n\t0x18, 0x18, 0x45, 0x6a, 0x32, 0x20, 0x82, 0x71, 0x8b, 0xa3, 0x62, 0x16, 0x92, 0xbb, 0x01, 0x91, \n\t0x20, 0x76, 0x11, 0x21, 0x34, 0x54, 0x4c, 0x80, 0x16, 0xc6, 0x38, 0x10, 0xe4, 0x04, 0x84, 0x00, \n\t0x41, 0x01, 0x9a, 0x59, 0x48, 0x84, 0x1a, 0xa4, 0x68, 0x89, 0x51, 0x91, 0x48, 0x40, 0x46, 0xa9, \n\t0x09, 0x94, 0x04, 0x4d, 0x2a, 0x60, 0xb9, 0x18, 0x08, 0xc9, 0xc6, 0x40, 0xa4, 0x99, 0x34, 0x3c, \n\t0x11, 0x8d, 0x10, 0xe0, 0x20, 0xa4, 0x75, 0x0a, 0xe6, 0x44, 0x93, 0xb2, 0x94, 0x04, 0x81, 0xa0, \n\t0x48, 0x75, 0x2a, 0xa3, 0x48, 0x42, 0x05, 0x6e, 0x96, 0x0a, 0x08, 0x29, 0x91, 0x0c, 0x14, 0x05, \n\t0xf0, 0x22, 0x84, 0x01, 0x21, 0x04, 0xa1, 0x00, 0x3a, 0xd8, 0x15, 0x65, 0x10, 0x11, 0xc1, 0xa0, \n\t0x98, 0x8c, 0x2a, 0x16, 0xc1, 0x01, 0x88, 0xf5, 0x12, 0x42, 0x40, 0xa5, 0x01, 0x0b, 0xa0, 0xc2, \n\t0x09, 0x5c, 0xc4, 0x72, 0x00, 0x18, 0x06, 0xe4, 0x0c, 0x26, 0x5a, 0x3d, 0x80, 0x10, 0x40, 0x40, \n\t0x40, 0x11, 0x23, 0x30, 0x9c, 0x80, 0x74, 0x32, 0x82, 0x84, 0x85, 0x00, 0xaf, 0x20, 0x95, 0x20, \n\t0x8f, 0x51, 0x8e, 0xc3, 0x26, 0x84, 0x62, 0x03, 0xc1, 0x09, 0xa8, 0x34, 0x34, 0x83, 0x22, 0xcc, \n\t0x90, 0x23, 0x1a, 0x82, 0x22, 0x88, 0x48, 0x40, 0x6c, 0x32, 0xc5, 0x91, 0xa3, 0x35, 0x89, 0xa0, \n\t0x24, 0xa0, 0x58, 0x07, 0x21, 0x98, 0x0e, 0x0a, 0xf2, 0x6b, 0xb0, 0xac, 0x4a, 0x6c, 0x08, 0x92, \n\t0x29, 0x18, 0x40, 0x42, 0xc1, 0x2e, 0x04, 0x91, 0x30, 0xd1, 0x94, 0xa3, 0x42, 0x43, 0xd9, 0x20, \n\t0x59, 0x98, 0x2d, 0x20, 0x74, 0x00, 0x3d, 0x8c, 0x13, 0x0a, 0x46, 0x62, 0x00, 0x05, 0x34, 0x59, \n\t0x40, 0x26, 0x02, 0x58, 0x38, 0xad, 0x94, 0x2a, 0x18, 0x10, 0x0a, 0xa0, 0x69, 0x47, 0xe3, 0x18, \n\t0xe2, 0x70, 0x8c, 0x04, 0x54, 0x01, 0x24, 0x00, 0x8a, 0x10, 0x29, 0x06, 0xad, 0x02, 0x46, 0x28, \n\t0x0b, 0xd0, 0x50, 0xc5, 0x72, 0x50, 0xc1, 0xa9, 0x14, 0x14, 0x09, 0x60, 0xb0, 0x52, 0x12, 0x60, \n\t0x45, 0x20, 0x16, 0x06, 0xc3, 0x01, 0xa9, 0x93, 0xae, 0x04, 0x82, 0x1a, 0x0b, 0x58, 0x0e, 0x2c, \n\t0x64, 0x84, 0x30, 0x07, 0x55, 0x92, 0x09, 0x08, 0x90, 0xba, 0x91, 0x25, 0x02, 0x47, 0x66, 0x56, \n\t0x68, 0x21, 0x00, 0x9c, 0x06, 0x60, 0x20, 0x88, 0x34, 0x89, 0x9b, 0x88, 0x22, 0xc2, 0x52, 0x92, \n\t0x1d, 0x14, 0x80, 0x40, 0xd5, 0x19, 0x0b, 0xb4, 0xc4, 0xe0, 0x38, 0x45, 0x50, 0x1b, 0x44, 0x88, \n\t0x08, 0x08, 0x07, 0xe2, 0x0f, 0x24, 0x80, 0x65, 0x28, 0x72, 0x00, 0x0a, 0xe9, 0xc1, 0x08, 0x48, \n\t0xb0, 0x42, 0x0c, 0x41, 0x55, 0x26, 0x0e, 0x21, 0x1a, 0x84, 0xd1, 0x10, 0x42, 0x18, 0x07, 0xa1, \n\t0x13, 0x4c, 0xd0, 0xc0, 0x0c, 0x44, 0x2a, 0x83, 0x44, 0x01, 0x46, 0x06, 0x45, 0xf0, 0xbc, 0x04, \n\t0x8a, 0xa6, 0x0a, 0x30, 0x11, 0xb4, 0x61, 0xc3, 0x6b, 0x06, 0x07, 0x23, 0xb4, 0x6c, 0x19, 0x49, \n\t0x46, 0xa0, 0x18, 0x28, 0x60, 0x84, 0x8a, 0x12, 0xa5, 0x20, 0x04, 0x31, 0xda, 0x4c, 0x60, 0x21, \n\t0x0a, 0x17, 0x14, 0x02, 0x04, 0x32, 0x90, 0x92, 0x83, 0x89, 0x4b, 0x42, 0x68, 0x00, 0x53, 0x11, \n\t0x80, 0xd7, 0x88, 0x18, 0x72, 0xa1, 0x04, 0xb0, 0x00, 0x64, 0x08, 0x42, 0xc1, 0x2e, 0x54, 0x81, \n\t0x85, 0x68, 0xa4, 0x98, 0x92, 0x38, 0x59, 0x04, 0x44, 0x00, 0xa3, 0xa1, 0x64, 0x0f, 0x22, 0x3e, \n\t0x00, 0x90, 0x02, 0xdd, 0x1c, 0x8b, 0x1c, 0x60, 0xd0, 0x32, 0x84, 0x04, 0x03, 0x06, 0x74, 0x1a, \n\t0x31, 0x2d, 0xc9, 0x82, 0x22, 0xc3, 0x10, 0x82, 0x30, 0x8c, 0x41, 0x12, 0x12, 0x60, 0x35, 0x94, \n\t0x1f, 0x09, 0x32, 0xf1, 0xa8, 0x8c, 0x08, 0x90, 0x6b, 0x48, 0x20, 0x79, 0x3d, 0x54, 0x86, 0x04, \n\t0x4a, 0x71, 0xc8, 0x00, 0xcc, 0x02, 0xe9, 0x0c, 0x24, 0x21, 0x0a, 0x80, 0x52, 0xee, 0x00, 0xa4, \n\t0x32, 0x96, 0x1c, 0x92, 0x64, 0x20, 0x82, 0x8a, 0x88, 0xa1, 0x4b, 0x0e, 0x78, 0x35, 0x51, 0x00, \n\t0xa0, 0x49, 0x69, 0x72, 0x07, 0x23, 0x14, 0xa0, 0x45, 0x0a, 0x04, 0xd0, 0xd9, 0x82, 0xa1, 0x07, \n\t0xe5, 0x08, 0x03, 0x20, 0x3c, 0x70, 0xd4, 0x0c, 0x12, 0xc0, 0x49, 0x20, 0x08, 0xd1, 0x08, 0x62, \n\t0x63, 0x11, 0x02, 0x10, 0x98, 0x4f, 0x72, 0x20, 0x81, 0x11, 0xa8, 0x53, 0xab, 0x14, 0x02, 0x10, \n\t0x8e, 0x94, 0x86, 0x49, 0x20, 0x31, 0x02, 0x19, 0x41, 0x48, 0x62, 0x44, 0xc5, 0x80, 0x18, 0x14, \n\t0xd0, 0x83, 0x00, 0x57, 0x88, 0x25, 0xad, 0x42, 0x80, 0x3a, 0x30, 0x90, 0x15, 0xd5, 0x1a, 0xe1, \n\t0x4c, 0x24, 0x20, 0x80, 0xe1, 0x08, 0xc7, 0x14, 0x05, 0x8a, 0x11, 0xb0, 0x01, 0x28, 0x10, 0x33, \n\t0x21, 0x93, 0x04, 0xcf, 0x44, 0x22, 0xc0, 0xc9, 0x9a, 0x00, 0x4a, 0x0c, 0x2c, 0x01, 0xb1, 0x8e, \n\t0x10, 0x58, 0x21, 0x14, 0x96, 0x63, 0x34, 0x44, 0x43, 0x04, 0x44, 0xb0, 0x5b, 0x80, 0x28, 0x0c, \n\t0x00, 0x24, 0x33, 0x80, 0x0a, 0x1c, 0x0b, 0x65, 0x26, 0xe0, 0x2a, 0x1e, 0x09, 0x9d, 0xa5, 0x48, \n\t0x44, 0x13, 0x25, 0x2c, 0xc4, 0x22, 0x30, 0x00, 0x62, 0xa4, 0x48, 0x46, 0x40, 0x50, 0x27, 0x00, \n\t0xb8, 0xa4, 0x44, 0x0c, 0x26, 0x44, 0x98, 0x89, 0x81, 0x03, 0x0d, 0x1c, 0xc6, 0x58, 0x82, 0x40, \n\t0x18, 0x4b, 0x40, 0x85, 0x8b, 0x3b, 0x38, 0xc8, 0x2d, 0x64, 0x87, 0x61, 0x11, 0x58, 0x41, 0x88, \n\t0x16, 0x14, 0x89, 0x19, 0x9d, 0x10, 0xa0, 0x08, 0x22, 0x80, 0x02, 0x44, 0x86, 0x81, 0x04, 0x33, \n\t0x80, 0x10, 0x19, 0xc0, 0xc1, 0x48, 0x10, 0x80, 0x31, 0x40, 0x1f, 0x01, 0x24, 0x03, 0xe1, 0x3f, \n\t0x48, 0x4b, 0x8a, 0x10, 0x21, 0xd8, 0x06, 0x95, 0x19, 0x6b, 0x42, 0x80, 0x68, 0x16, 0x64, 0x48, \n\t0x22, 0x40, 0xd5, 0x18, 0xa9, 0x10, 0xc5, 0x0b, 0x1c, 0x74, 0x51, 0xb8, 0x25, 0x00, 0xc0, 0x62, \n\t0xa2, 0xa9, 0x10, 0xb4, 0x8a, 0x60, 0x2a, 0x77, 0xc1, 0x8e, 0x10, 0x83, 0x48, 0x76, 0x92, 0x42, \n\t0x25, 0x08, 0xc0, 0x2c, 0x1e, 0x30, 0x60, 0x21, 0x79, 0x02, 0x88, 0x30, 0x95, 0x30, 0x2a, 0x84, \n\t0x00, 0x4a, 0x4c, 0x43, 0x10, 0x17, 0x11, 0x94, 0xa2, 0x08, 0x80, 0x31, 0xb4, 0x6d, 0xc8, 0x80, \n\t0x6a, 0x40, 0x2b, 0x04, 0x70, 0x1b, 0x49, 0x78, 0xc0, 0x88, 0x04, 0x5c, 0x01, 0x25, 0x40, 0x44, \n\t0x41, 0x18, 0x05, 0x4f, 0x06, 0x0a, 0x20, 0x61, 0x37, 0xd0, 0x40, 0x05, 0x0a, 0x26, 0x48, 0xb8, \n\t0x88, 0x5b, 0x21, 0x10, 0x43, 0xda, 0x9e, 0x29, 0x81, 0xa3, 0x18, 0x00, 0x33, 0x09, 0x98, 0x93, \n\t0xcd, 0x52, 0x42, 0xa3, 0x25, 0x85, 0x1e, 0x28, 0x14, 0x35, 0x50, 0x01, 0xd0, 0xd0, 0x4a, 0x2c, \n\t0xa1, 0x22, 0xa0, 0x5d, 0x1c, 0xe2, 0x02, 0x54, 0x90, 0x02, 0x88, 0x5f, 0x28, 0x78, 0x04, 0x83, \n\t0x02, 0x40, 0x8c, 0x20, 0x0c, 0x82, 0x11, 0x04, 0x71, 0x4d, 0x26, 0x66, 0x32, 0x88, 0x8a, 0xa0, \n\t0x07, 0x8c, 0x00, 0xa3, 0x40, 0x09, 0x31, 0xc7, 0x81, 0x30, 0xd4, 0x43, 0x0a, 0x88, 0x9d, 0x49, \n\t0x4a, 0x81, 0x01, 0x8a, 0x18, 0x02, 0x67, 0x64, 0x36, 0x88, 0x18, 0x88, 0x05, 0xe8, 0x14, 0x40, \n\t0x79, 0x07, 0x49, 0x90, 0xc9, 0x2c, 0xd6, 0x02, 0x93, 0x80, 0x48, 0xa9, 0x0c, 0x67, 0x10, 0xa6, \n\t0x24, 0x51, 0x66, 0x04, 0x00, 0x5b, 0x13, 0xc8, 0xcd, 0x00, 0x62, 0x05, 0x2b, 0x32, 0x31, 0x19, \n\t0xc8, 0x20, 0x02, 0x90, 0x92, 0x21, 0x4d, 0xe0, 0x64, 0xc0, 0x43, 0x10, 0x84, 0x44, 0xa7, 0x1a, \n\t0x12, 0x18, 0x34, 0x01, 0x08, 0x07, 0x0a, 0xb4, 0xaa, 0x32, 0x1c, 0x16, 0x40, 0x06, 0xc1, 0xa8, \n\t0x1e, 0x21, 0x40, 0x41, 0x12, 0xb4, 0x13, 0x08, 0x85, 0x40, 0x0c, 0x02, 0xf0, 0x13, 0x28, 0x69, \n\t0x80, 0x45, 0x70, 0x75, 0x70, 0x80, 0x41, 0x02, 0x21, 0x00, 0x33, 0x88, 0xbc, 0x65, 0x80, 0x46, \n\t0x54, 0x82, 0x03, 0x13, 0x04, 0xc1, 0x08, 0x20, 0x50, 0x03, 0x23, 0x30, 0x1e, 0x82, 0x32, 0xa6, \n\t0xc8, 0x2a, 0x91, 0x48, 0x4c, 0x10, 0x94, 0xc1, 0x20, 0x9c, 0x03, 0x28, 0x34, 0x90, 0x70, 0xba, \n\t0xb1, 0x4a, 0xc4, 0x58, 0x44, 0xe0, 0xa8, 0xbc, 0x40, 0x05, 0x48, 0x35, 0x22, 0x10, 0x30, 0x16, \n\t0x27, 0x24, 0x20, 0x12, 0x38, 0x64, 0x07, 0x46, 0x08, 0xa3, 0xf0, 0x09, 0x14, 0x8a, 0xea, 0x20, \n\t0x07, 0xc3, 0x00, 0x85, 0x89, 0xc0, 0x22, 0xc0, 0x20, 0x8c, 0x68, 0x0a, 0x02, 0x26, 0x43, 0x48, \n\t0x8e, 0x4c, 0x03, 0xa2, 0x48, 0x75, 0xb2, 0x00, 0x61, 0x81, 0x60, 0x68, 0x40, 0x83, 0x90, 0xc5, \n\t0x50, 0x00, 0x50, 0x56, 0x02, 0xa3, 0x14, 0x44, 0x24, 0x3e, 0xa4, 0x49, 0x3a, 0x01, 0xd0, 0x0b, \n\t0x48, 0x63, 0x8a, 0xa4, 0x20, 0xd2, 0x4c, 0x1e, 0x44, 0x61, 0x11, 0x49, 0x44, 0x61, 0x36, 0x84, \n\t0x12, 0x38, 0xe8, 0x04, 0xa6, 0x50, 0x92, 0x69, 0x89, 0x35, 0x1c, 0xa1, 0x04, 0x75, 0x62, 0x2d, \n\t0xc0, 0x91, 0x82, 0x02, 0x32, 0x18, 0x05, 0x71, 0xc8, 0x66, 0x50, 0x06, 0x58, 0x3a, 0x04, 0x00, \n\t0x2c, 0x18, 0x21, 0x21, 0x07, 0x8c, 0x41, 0x42, 0x14, 0xc0, 0xb0, 0x2e, 0x08, 0x01, 0x0b, 0x10, \n\t0x03, 0x80, 0x91, 0x88, 0x02, 0xae, 0x0c, 0x14, 0x09, 0x84, 0x60, 0x5b, 0xc1, 0x40, 0x23, 0x63, \n\t0x08, 0x80, 0x10, 0x0d, 0x0e, 0x82, 0xc8, 0x00, 0xb9, 0xdd, 0x44, 0x2a, 0x30, 0x6a, 0x30, 0x69, \n\t0x10, 0x6c, 0x00, 0x93, 0x19, 0x82, 0xcc, 0x10, 0x80, 0x2c, 0x41, 0xd2, 0x85, 0x18, 0x88, 0x24, \n\t0x4e, 0xd7, 0x88, 0xa9, 0x0c, 0x86, 0xa1, 0x04, 0x43, 0x2a, 0x91, 0x60, 0x03, 0x04, 0x12, 0x50, \n\t0x50, 0x20, 0xb1, 0xcc, 0x02, 0x60, 0x87, 0xab, 0x16, 0x90, 0x10, 0xe4, 0x72, 0x51, 0x00, 0x2b, \n\t0x60, 0x4a, 0x05, 0x0a, 0x35, 0x00, 0x22, 0x40, 0x89, 0x8a, 0x48, 0x56, 0xc2, 0x0c, 0x00, 0xc2, \n\t0x2c, 0x40, 0x34, 0x3a, 0x08, 0x39, 0x9b, 0x85, 0x5a, 0x14, 0x53, 0x0d, 0x10, 0x01, 0x0f, 0x00, \n\t0x81, 0x93, 0x2e, 0x69, 0x94, 0x2e, 0x1c, 0x41, 0xc0, 0x17, 0x18, 0x91, 0x8e, 0x08, 0x44, 0x98, \n\t0xa3, 0x61, 0x02, 0x44, 0x26, 0x42, 0xe1, 0x80, 0x88, 0x16, 0x02, 0x00, 0x64, 0x0a, 0x30, 0x00, \n\t0x08, 0xe1, 0x04, 0x03, 0xd1, 0x38, 0x14, 0x19, 0x01, 0x72, 0x52, 0x51, 0x18, 0x05, 0x85, 0x4e, \n\t0x06, 0xa1, 0x30, 0x26, 0x84, 0x4e, 0x4b, 0x42, 0x71, 0x01, 0x98, 0x30, 0x44, 0x21, 0x0e, 0x70, \n\t0x62, 0x19, 0x11, 0x00, 0x2b, 0x10, 0x30, 0x22, 0x25, 0x6c, 0x14, 0xc0, 0x5e, 0xd2, 0xb8, 0x07, \n\t0x45, 0x90, 0x48, 0x50, 0xc5, 0xa3, 0x81, 0x85, 0x40, 0x22, 0x4a, 0x05, 0x9a, 0x16, 0x48, 0x8d, \n\t0x05, 0x32, 0x16, 0xe2, 0xa2, 0x21, 0x4c, 0x00, 0x06, 0x05, 0x60, 0xa2, 0xbd, 0x48, 0xcb, 0x50, \n\t0x04, 0x02, 0x8a, 0xe4, 0x08, 0xa0, 0x00, 0x41, 0x00, 0x19, 0x65, 0x05, 0x8d, 0x20, 0x00, 0x20, \n\t0x87, 0x30, 0x0d, 0x4a, 0x7a, 0xd3, 0x28, 0x07, 0x04, 0x84, 0x61, 0x14, 0xd0, 0x81, 0x88, 0xa1, \n\t0xde, 0x86, 0x22, 0x80, 0x69, 0x00, 0xa9, 0xc3, 0x00, 0x06, 0x33, 0xc8, 0x01, 0x51, 0x16, 0x08, \n\t0x20, 0x66, 0x10, 0x9e, 0xc4, 0x00, 0xc6, 0x44, 0xc6, 0x02, 0x02, 0x0d, 0xd1, 0x25, 0x74, 0xd2, \n\t0x41, 0x28, 0xe0, 0x18, 0x82, 0x04, 0x34, 0x52, 0xa5, 0x48, 0x84, 0x4a, 0x76, 0xa1, 0x0b, 0xb6, \n\t0x0c, 0x50, 0x20, 0x20, 0x04, 0x03, 0x88, 0xdc, 0x0c, 0x41, 0x0a, 0x06, 0x00, 0x31, 0x91, 0x02, \n\t0x89, 0x10, 0xe4, 0x23, 0x91, 0x10, 0x9f, 0x45, 0x6c, 0x54, 0xf9, 0x9f, 0x60, 0x0a, 0x80, 0x02, \n\t0x30, 0x71, 0x0d, 0x10, 0x42, 0x82, 0x46, 0x30, 0x12, 0x04, 0x0c, 0x12, 0x08, 0x70, 0xa1, 0x71, \n\t0xa2, 0x50, 0x00, 0xe4, 0x44, 0xd2, 0x28, 0x09, 0x0d, 0xda, 0x40, 0x40, 0x16, 0x78, 0x26, 0xa0, \n\t0x86, 0xa4, 0x08, 0x14, 0x90, 0x00, 0xd1, 0x0a, 0x00, 0x0a, 0xc3, 0x19, 0xac, 0xa5, 0x41, 0xc0, \n\t0x66, 0xb1, 0x50, 0x22, 0x28, 0x09, 0x04, 0x0a, 0xc6, 0x01, 0x96, 0x20, 0x5a, 0x4c, 0x08, 0x45, \n\t0xa2, 0x20, 0xac, 0x57, 0x0c, 0x20, 0x24, 0xa0, 0x81, 0x48, 0x50, 0x85, 0x4e, 0x14, 0x8a, 0x08, \n\t0x50, 0xd5, 0x4f, 0x46, 0xe3, 0x79, 0x0d, 0x0c, 0x88, 0x83, 0x10, 0x03, 0xa0, 0x0b, 0x85, 0x92, \n\t0x05, 0x60, 0xe2, 0x08, 0x20, 0x25, 0x15, 0x44, 0x1a, 0x45, 0x11, 0xbc, 0x80, 0x08, 0x80, 0x50, \n\t0x34, 0x22, 0x15, 0x80, 0x8b, 0x8a, 0x10, 0x41, 0x79, 0xa8, 0x64, 0x50, 0x4e, 0x04, 0xa4, 0x0a, \n\t0x18, 0xcc, 0x88, 0xa5, 0x04, 0xa2, 0x41, 0x8d, 0x40, 0x56, 0x00, 0x70, 0xa3, 0x41, 0x03, 0x30, \n\t0x88, 0x2c, 0x2c, 0x07, 0xcb, 0x92, 0xc1, 0x05, 0xae, 0x14, 0x82, 0xb8, 0x01, 0x58, 0x07, 0x09, \n\t0x10, 0xc2, 0x21, 0x2c, 0xf0, 0x18, 0x02, 0x40, 0x64, 0xa2, 0x29, 0x58, 0x41, 0x80, 0x28, 0xc4, \n\t0x88, 0x09, 0x64, 0x87, 0x82, 0x16, 0x90, 0x21, 0x09, 0x09, 0x5f, 0x06, 0x50, 0x00, 0xd0, 0x92, \n\t0xb8, 0x83, 0x81, 0x68, 0x01, 0x5a, 0x10, 0x3c, 0x05, 0x60, 0x20, 0xb0, 0x10, 0x80, 0x48, 0x88, \n\t0x2b, 0x04, 0x53, 0x38, 0xb3, 0x41, 0x92, 0x4c, 0x62, 0xa6, 0x21, 0x05, 0x2c, 0x48, 0x4d, 0x14, \n\t0x34, 0x32, 0x0b, 0x01, 0x1a, 0xa9, 0x48, 0x02, 0xca, 0x20, 0x21, 0x44, 0x47, 0x06, 0x40, 0x40, \n\t0x81, 0xd4, 0x12, 0x62, 0x14, 0x95, 0x61, 0xb1, 0x98, 0x00, 0x6b, 0x46, 0xa3, 0xb2, 0x1e, 0x10, \n\t0xd6, 0x21, 0x1c, 0x01, 0x88, 0x94, 0x25, 0x80, 0x80, 0x46, 0x61, 0xcb, 0xb3, 0x40, 0x84, 0x8b, \n\t0x50, 0x43, 0xd1, 0x34, 0x31, 0x1d, 0x04, 0x12, 0x15, 0x40, 0x30, 0x00, 0x48, 0xc2, 0x20, 0x95, \n\t0x19, 0x18, 0xf5, 0x8d, 0x84, 0x10, 0x31, 0x0a, 0xbc, 0x04, 0xd9, 0x20, 0x1c, 0x42, 0xf0, 0x01, \n\t0x68, 0x94, 0x2e, 0x0a, 0x86, 0xb0, 0x01, 0x4c, 0x40, 0x21, 0x4c, 0x91, 0x80, 0xaa, 0x34, 0x06, \n\t0xa4, 0x58, 0x01, 0x13, 0xa1, 0x50, 0x41, 0x43, 0x20, 0xc4, 0xa2, 0xa0, 0x20, 0x46, 0x04, 0x38, \n\t0x96, 0xaa, 0x82, 0x6c, 0x12, 0x0e, 0x4c, 0x21, 0x43, 0x13, 0x94, 0x1e, 0x02, 0x46, 0x66, 0x48, \n\t0x10, 0x44, 0x45, 0xe8, 0x06, 0x01, 0x10, 0x12, 0xcc, 0x0a, 0xcd, 0x08, 0x31, 0x10, 0x2f, 0xf0, \n\t0x19, 0x00, 0x70, 0x22, 0x63, 0x88, 0x0c, 0x13, 0x04, 0x48, 0xe0, 0x68, 0x86, 0xa8, 0xcf, 0x60, \n\t0x50, 0x00, 0xb2, 0x00, 0x81, 0x47, 0x22, 0x48, 0x40, 0x3b, 0x25, 0x40, 0x96, 0x45, 0x24, 0x62, \n\t0xa1, 0x08, 0x99, 0xc2, 0x44, 0x04, 0x32, 0x22, 0x01, 0x14, 0x96, 0xa5, 0x58, 0x16, 0x4b, 0x90, \n\t0x49, 0x01, 0x08, 0x32, 0x74, 0x61, 0x00, 0x6d, 0x17, 0x22, 0x12, 0x46, 0x41, 0x20, 0x79, 0x11, \n\t0x01, 0x56, 0xa6, 0x00, 0x02, 0x49, 0x46, 0x2f, 0x02, 0x07, 0x08, 0x0d, 0x45, 0x40, 0xc9, 0x68, \n\t0x07, 0x01, 0x98, 0x34, 0x00, 0x48, 0x28, 0x83, 0x00, 0x1c, 0x81, 0x41, 0xc8, 0x50, 0x20, 0x32, \n\t0x34, 0x95, 0x07, 0x45, 0x48, 0x60, 0x08, 0x0a, 0x54, 0x82, 0x24, 0x60, 0x37, 0xd0, 0xaa, 0xc5, \n\t0xd3, 0x42, 0x04, 0x32, 0xaa, 0x1a, 0x40, 0x05, 0xc1, 0x10, 0x44, 0x0a, 0x80, 0x2c, 0xd0, 0x88, \n\t0x4c, 0x31, 0x42, 0x06, 0x95, 0x07, 0xe2, 0x0c, 0x23, 0xdb, 0xa0, 0x81, 0x09, 0x64, 0x24, 0xf0, \n\t0x4a, 0x10, 0x30, 0x03, 0xc0, 0x1c, 0xc6, 0x40, 0x88, 0xa5, 0x5d, 0x45, 0x22, 0xc1, 0xc2, 0x03, \n\t0x20, 0x9a, 0x2c, 0x40, 0x76, 0x08, 0x14, 0x21, 0x8c, 0xe0, 0x26, 0xb4, 0xf2, 0x08, 0x74, 0x82, \n\t0x0d, 0x04, 0x90, 0x98, 0x2a, 0x48, 0x00, 0x09, 0x50, 0x31, 0xc2, 0x06, 0x08, 0x43, 0xe3, 0x22, \n\t0x14, 0x02, 0x89, 0x45, 0xc4, 0x23, 0x18, 0xd0, 0xb8, 0xa0, 0x89, 0x92, 0x2a, 0x58, 0x51, 0xa0, \n\t0x80, 0xed, 0x03, 0x2b, 0x20, 0x80, 0x18, 0x96, 0x8c, 0x08, 0x00, 0x02, 0x62, 0x83, 0x09, 0x61, \n\t0x01, 0x8d, 0x28, 0x04, 0x48, 0x85, 0x11, 0x58, 0x07, 0x50, 0x05, 0x08, 0x37, 0xb0, 0x96, 0x40, \n\t0x04, 0x05, 0x93, 0x01, 0x11, 0x0f, 0xa9, 0x74, 0x02, 0xb0, 0x04, 0xac, 0xd0, 0xa3, 0x00, 0x21, \n\t0xb0, 0x04, 0x68, 0x10, 0x63, 0x20, 0x60, 0x53, 0x98, 0x88, 0x11, 0x47, 0x28, 0x31, 0x20, 0x24, \n\t0x79, 0x03, 0x20, 0x66, 0x13, 0xa3, 0x36, 0xa1, 0x0f, 0x00, 0x42, 0x74, 0x50, 0x84, 0x70, 0x87, \n\t0x40, 0x28, 0x61, 0xd2, 0x06, 0x98, 0x18, 0x09, 0x44, 0x75, 0x88, 0x93, 0x81, 0x46, 0x82, 0x06, \n\t0xc4, 0x20, 0x8c, 0x44, 0x02, 0x8c, 0x62, 0x94, 0x4b, 0x80, 0x04, 0x0d, 0x49, 0x18, 0x80, 0x80, \n\t0x98, 0x29, 0xc0, 0x2a, 0x76, 0x80, 0x40, 0x15, 0xd1, 0x42, 0x2a, 0x0e, 0xd0, 0xe9, 0x81, 0x11, \n\t0x0a, 0x84, 0x58, 0x00, 0x00, 0x9f, 0x80, 0x80, 0x8e, 0x02, 0x45, 0x90, 0x10, 0x30, 0x53, 0x82, \n\t0x0e, 0x06, 0xa0, 0xb2, 0xa8, 0x90, 0x84, 0x04, 0x41, 0x99, 0x05, 0x11, 0x0f, 0xa1, 0x70, 0x82, \n\t0x29, 0x8e, 0xbc, 0x10, 0x41, 0x20, 0xe5, 0x5b, 0x32, 0x05, 0x86, 0x47, 0x02, 0x23, 0x20, 0x25, \n\t0xd0, 0x8c, 0x02, 0x30, 0x40, 0x4a, 0x32, 0x28, 0xc1, 0x40, 0x62, 0x52, 0x12, 0x19, 0xa8, 0x5a, \n\t0xc5, 0x78, 0x26, 0x4a, 0x0d, 0x65, 0x97, 0x08, 0x1c, 0x81, 0x03, 0x8c, 0xd1, 0x8c, 0x02, 0x0c, \n\t0xa4, 0xe1, 0x02, 0xc0, 0xc9, 0x2e, 0x20, 0x00, 0x32, 0x30, 0x59, 0x50, 0xa7, 0x20, 0xc1, 0x40, \n\t0x84, 0xe9, 0xd8, 0x08, 0x5a, 0x50, 0x91, 0x10, 0x50, 0x1a, 0xc8, 0x28, 0x80, 0x4a, 0x0a, 0x14, \n\t0x09, 0x86, 0x70, 0x80, 0x51, 0x13, 0xc8, 0x02, 0xc4, 0x34, 0x54, 0x60, 0x8a, 0x95, 0x80, 0x07, \n\t0x28, 0x64, 0x22, 0x8c, 0x1c, 0x8a, 0x25, 0x18, 0x03, 0xe2, 0x97, 0x90, 0x16, 0x61, 0x00, 0x26, \n\t0x08, 0x38, 0x24, 0xc1, 0xe8, 0x50, 0x82, 0x12, 0x00, 0x09, 0x90, 0x84, 0x4c, 0x80, 0x92, 0x01, \n\t0x04, 0x0a, 0x6f, 0x68, 0x34, 0x9a, 0xa8, 0x30, 0x58, 0x05, 0x12, 0x84, 0xa3, 0x02, 0x0c, 0xd1, \n\t0xa4, 0x2a, 0x10, 0x09, 0x03, 0x45, 0x15, 0x61, 0x30, 0xa7, 0x00, 0x98, 0x01, 0x44, 0x88, 0x16, \n\t0x13, 0x93, 0x28, 0x11, 0xc6, 0x44, 0x04, 0x77, 0x68, 0x18, 0x00, 0x8b, 0x03, 0x4a, 0xb3, 0x60, \n\t0x2e, 0x90, 0x85, 0x29, 0x42, 0x36, 0x38, 0x9c, 0xa0, 0x00, 0x2a, 0x40, 0x04, 0x2b, 0x14, 0x05, \n\t0x86, 0xa1, 0x4c, 0xd1, 0x0a, 0x27, 0xc0, 0x04, 0x4a, 0x60, 0x04, 0xb1, 0xa1, 0x04, 0x10, 0xe9, \n\t0x62, 0xb6, 0xb2, 0x04, 0x74, 0x48, 0x61, 0x4c, 0x01, 0x12, 0x87, 0x05, 0x91, 0xa4, 0x16, 0x30, \n\t0x09, 0xb4, 0x68, 0x54, 0x03, 0x04, 0x82, 0x02, 0x22, 0x45, 0x54, 0x88, 0x00, 0x81, 0xda, 0x8a, \n\t0xb5, 0x00, 0x42, 0x30, 0x41, 0x30, 0xb1, 0x04, 0x06, 0x0e, 0x1a, 0xa0, 0xe8, 0x09, 0x00, 0x48, \n\t0x40, 0x0e, 0x86, 0x10, 0x02, 0xe0, 0x0e, 0x07, 0x60, 0x10, 0x10, 0x29, 0x08, 0xd3, 0xec, 0x12, \n\t0x71, 0x88, 0x22, 0x8c, 0x92, 0xa4, 0x08, 0x20, 0x53, 0x0f, 0xc0, 0x81, 0x00, 0x0a, 0x87, 0x08, \n\t0x03, 0x0d, 0x08, 0x20, 0x7c, 0x40, 0x08, 0x2b, 0xa1, 0x46, 0x24, 0x60, 0x70, 0x22, 0x85, 0x11, \n\t0x81, 0xc1, 0x6a, 0x84, 0x80, 0x06, 0xa4, 0x14, 0xcb, 0x04, 0xa2, 0x02, 0xb8, 0x10, 0x05, 0x4b, \n\t0x30, 0x55, 0x28, 0x84, 0xc4, 0x00, 0x42, 0x2a, 0xc0, 0xc2, 0x18, 0x80, 0x04, 0x25, 0x4a, 0x65, \n\t0x13, 0x1d, 0x39, 0x90, 0x0c, 0x58, 0x84, 0xc3, 0x0c, 0x38, 0x83, 0xe2, 0x00, 0x21, 0x0a, 0x8c, \n\t0x38, 0x86, 0x4d, 0x74, 0xc2, 0x10, 0x04, 0x09, 0x4b, 0xa1, 0x40, 0xb4, 0x0a, 0xa2, 0x2c, 0x52, \n\t0x22, 0x10, 0xc0, 0x63, 0x08, 0xc1, 0x82, 0x82, 0x0e, 0x21, 0x28, 0x12, 0x94, 0xd8, 0x02, 0x0c, \n\t0x46, 0x09, 0x3a, 0x84, 0x11, 0xc8, 0x12, 0x30, 0x89, 0x90, 0x35, 0x48, 0xe8, 0x24, 0x55, 0x10, \n\t0xa7, 0x80, 0x03, 0x43, 0x02, 0x17, 0x09, 0x9a, 0x10, 0x8d, 0x28, 0x62, 0xe4, 0x2a, 0x11, 0x68, \n\t0x04, 0x20, 0x22, 0x10, 0x42, 0x01, 0xcc, 0x04, 0x88, 0x1e, 0xc1, 0x83, 0x28, 0x20, 0x0c, 0x24, \n\t0x14, 0x63, 0xa1, 0x90, 0x09, 0x19, 0x23, 0x28, 0x20, 0x2a, 0x38, 0x0c, 0x1d, 0x42, 0x4c, 0x90, \n\t0xc0, 0x0b, 0x41, 0x8f, 0x06, 0x14, 0x55, 0xb8, 0x92, 0x2d, 0xc8, 0x49, 0x42, 0xa0, 0x23, 0x92, \n\t0x48, 0x05, 0xc7, 0x74, 0x84, 0x80, 0x8b, 0x4d, 0x8d, 0x40, 0x38, 0x00, 0x20, 0x9c, 0xa1, 0x06, \n\t0x09, 0x32, 0x54, 0xa8, 0x85, 0x88, 0x41, 0x05, 0x44, 0xd3, 0x13, 0x04, 0x21, 0xd8, 0x8f, 0x02, \n\t0x90, 0xc1, 0x08, 0x78, 0x54, 0x26, 0x40, 0x50, 0x4a, 0x24, 0x39, 0x16, 0xa0, 0x00, 0x12, 0x41, \n\t0xb0, 0x14, 0x50, 0x82, 0x6c, 0xa3, 0x80, 0xa3, 0x71, 0x82, 0x03, 0x04, 0x04, 0xd9, 0x21, 0x09, \n\t0x5e, 0xa8, 0x08, 0x70, 0x82, 0x15, 0x68, 0x04, 0x8b, 0x52, 0x63, 0x29, 0x3a, 0x54, 0x51, 0x4b, \n\t0x62, 0x80, 0x99, 0x18, 0x34, 0x44, 0x2e, 0x30, 0x30, 0x40, 0xb2, 0x41, 0x4e, 0x44, 0x10, 0xc0, \n\t0xca, 0xa4, 0x10, 0x1a, 0x01, 0x40, 0x66, 0xf2, 0x8c, 0x01, 0x84, 0x2c, 0x18, 0x30, 0xaa, 0x11, \n\t0x05, 0xd0, 0x40, 0x52, 0xa1, 0x79, 0x83, 0xb0, 0x80, 0x2b, 0x64, 0x01, 0x80, 0x9e, 0x50, 0x18, \n\t0x01, 0x04, 0x00, 0xa2, 0x17, 0x28, 0xca, 0x24, 0x30, 0xd3, 0x22, 0xa2, 0x6d, 0x50, 0x20, 0x46, \n\t0x24, 0x80, 0x84, 0xe8, 0x0a, 0x00, 0x02, 0x01, 0x33, 0x8c, 0x74, 0x00, 0x07, 0x42, 0xd6, 0x13, \n\t0x11, 0x38, 0x0c, 0x8c, 0x18, 0x32, 0x49, 0x29, 0x61, 0x82, 0x8a, 0x20, 0x50, 0x41, 0x08, 0xac, \n\t0xc1, 0x41, 0x30, 0x25, 0x58, 0x8a, 0xb0, 0x42, 0x24, 0x5c, 0x02, 0x5a, 0x00, 0xc5, 0x12, 0x82, \n\t0x1c, 0x20, 0x42, 0x07, 0xad, 0x04, 0x21, 0x64, 0x52, 0x00, 0x9f, 0x48, 0x48, 0x09, 0x24, 0x31, \n\t0xa2, 0xa9, 0x14, 0x58, 0xe1, 0x72, 0x15, 0x58, 0x26, 0x89, 0x0d, 0x0e, 0x04, 0x00, 0x00, 0x26, \n\t0x84, 0x85, 0xa0, 0x26, 0x03, 0x00, 0x32, 0xb9, 0x00, 0xa2, 0x50, 0x05, 0x80, 0x11, 0x10, 0x0e, \n\t0x85, 0x00, 0x62, 0x61, 0x85, 0x74, 0x99, 0x8a, 0x00, 0x31, 0x4a, 0x01, 0x90, 0x09, 0x0c, 0x26, \n\t0xd0, 0x90, 0x07, 0xc1, 0x50, 0x41, 0x26, 0xb6, 0xd9, 0x3c, 0x19, 0x83, 0x09, 0x08, 0x71, 0x10, \n\t0x2a, 0x68, 0x88, 0x25, 0x00, 0xb2, 0xb0, 0x00, 0xc4, 0x82, 0xc1, 0x48, 0x07, 0x92, 0x16, 0x0c, \n\t0x01, 0xe4, 0x22, 0x02, 0x03, 0x88, 0x0c, 0x81, 0x24, 0x4e, 0x24, 0x48, 0x20, 0x75, 0x41, 0xa2, \n\t0x28, 0x80, 0x90, 0x12, 0x59, 0x15, 0x47, 0x52, 0x80, 0x00, 0xb1, 0x15, 0x09, 0xc0, 0x18, 0x81, \n\t0x18, 0x21, 0x44, 0x58, 0x80, 0x28, 0xc2, 0x00, 0xb6, 0xac, 0x58, 0x00, 0x50, 0x24, 0x32, 0x81, \n\t0x18, 0x15, 0x6a, 0x64, 0x84, 0xc9, 0x21, 0xd0, 0x01, 0x4e, 0x16, 0x31, 0xe8, 0x2e, 0xc1, 0x98, \n\t0x81, 0x04, 0x03, 0x30, 0xa4, 0x8c, 0xc0, 0x0f, 0x02, 0xe1, 0x08, 0x13, 0x49, 0x00, 0xe0, 0x40, \n\t0x52, 0xd2, 0x08, 0x09, 0x8c, 0x02, 0x44, 0x60, 0x89, 0xb3, 0x29, 0x93, 0x89, 0x1c, 0x24, 0x9a, \n\t0x04, 0x71, 0x18, 0x08, 0x30, 0x91, 0xc2, 0x2a, 0x51, 0x40, 0xa6, 0x02, 0x04, 0x19, 0x18, 0xc1, \n\t0xc8, 0x41, 0x12, 0x06, 0xc0, 0x05, 0x18, 0x47, 0x6c, 0x24, 0x91, 0x21, 0x08, 0x90, 0x4d, 0x6d, \n\t0x10, 0x24, 0xe0, 0x01, 0x0d, 0x92, 0x8b, 0x16, 0xc0, 0x20, 0xa1, 0x40, 0x00, 0x80, 0x24, 0xd4, \n\t0x72, 0x00, 0x88, 0x80, 0xc1, 0x20, 0x43, 0x28, 0x3a, 0x58, 0x42, 0xc5, 0x24, 0x54, 0x69, 0xa6, \n\t0x81, 0x06, 0xac, 0x2a, 0x24, 0x13, 0x12, 0x8c, 0x8a, 0x03, 0x0c, 0x80, 0x32, 0x86, 0xc5, 0x44, \n\t0xa8, 0x00, 0x30, 0x13, 0x19, 0xc8, 0x43, 0x80, 0x1e, 0x10, 0x08, 0x0b, 0x44, 0x5b, 0xc4, 0x10, \n\t0x60, 0x09, 0x25, 0x24, 0xd4, 0x45, 0x24, 0x02, 0xc0, 0x1f, 0x89, 0x14, 0x61, 0x18, 0x30, 0x48, \n\t0x25, 0xac, 0x91, 0xa4, 0x04, 0x51, 0x13, 0xa8, 0x39, 0x14, 0x48, 0x04, 0x20, 0x23, 0x1e, 0x48, \n\t0x0a, 0x83, 0x08, 0x86, 0x20, 0x35, 0x00, 0x09, 0x01, 0x48, 0x90, 0x01, 0xb6, 0xe0, 0x08, 0x08, \n\t0x44, 0x41, 0x61, 0x02, 0x50, 0x1c, 0x29, 0x62, 0x03, 0xd0, 0xaa, 0x00, 0x59, 0xad, 0x30, 0x15, \n\t0x40, 0x0a, 0xfc, 0x81, 0x80, 0x20, 0x63, 0x10, 0x1a, 0x01, 0x15, 0x41, 0x40, 0x47, 0x08, 0x21, \n\t0x00, 0x96, 0x28, 0x22, 0x92, 0x88, 0x8e, 0x80, 0x0b, 0xe8, 0x22, 0x10, 0x11, 0x00, 0x04, 0x07, \n\t0xee, 0x46, 0xb2, 0x48, 0x88, 0x01, 0x8c, 0x42, 0x7c, 0x07, 0xa0, 0x84, 0xd0, 0x82, 0xce, 0x06, \n\t0x97, 0x3a, 0xa0, 0x18, 0x43, 0x81, 0x34, 0x80, 0xa3, 0x01, 0x44, 0xca, 0x2e, 0x44, 0x01, 0x51, \n\t0x00, 0x18, 0x5d, 0x41, 0x0a, 0x84, 0x90, 0x34, 0x24, 0x00, 0xcc, 0x26, 0x03, 0x08, 0x11, 0xc8, \n\t0x0a, 0xc6, 0x20, 0x42, 0x01, 0x18, 0x11, 0xca, 0x46, 0x40, 0x51, 0x00, 0x21, 0x88, 0x0b, 0x25, \n\t0x58, 0x21, 0x80, 0x91, 0x09, 0x18, 0xc2, 0x54, 0x24, 0x41, 0x00, 0xc4, 0xd0, 0x09, 0x0a, 0x10, \n\t0xb9, 0x80, 0xb8, 0x18, 0x21, 0x24, 0x86, 0x30, 0xac, 0x40, 0xd0, 0x63, 0x64, 0xa0, 0x10, 0x10, \n\t0x69, 0x41, 0x41, 0x42, 0x11, 0xaa, 0x16, 0x8d, 0x40, 0x8c, 0x2a, 0x50, 0x8b, 0x80, 0xe1, 0x58, \n\t0x03, 0x46, 0x24, 0x52, 0x84, 0x45, 0x04, 0xa2, 0x52, 0xe6, 0x98, 0x28, 0x10, 0xcf, 0x69, 0x08, \n\t0x14, 0x48, 0x2a, 0x30, 0x83, 0xc0, 0x50, 0x83, 0x20, 0x07, 0xa4, 0x1b, 0x64, 0x52, 0x43, 0x23, \n\t0x14, 0x18, 0x01, 0xc2, 0x78, 0x30, 0x09, 0x04, 0xbc, 0x40, 0x40, 0x4c, 0xc1, 0x90, 0x04, 0x40, \n\t0x0c, 0xa2, 0x70, 0x05, 0xa2, 0x29, 0x09, 0x90, 0xc6, 0x2c, 0xd2, 0x08, 0x0e, 0x68, 0x19, 0xc4, \n\t0x26, 0xd0, 0x12, 0x00, 0x24, 0x87, 0xa0, 0x18, 0x10, 0x9a, 0x85, 0x78, 0x88, 0x60, 0x52, 0x45, \n\t0x43, 0x20, 0xdd, 0x01, 0x20, 0x32, 0x44, 0xc9, 0x9a, 0xc8, 0x4a, 0x83, 0x06, 0x25, 0x10, 0x83, \n\t0xe0, 0x56, 0x00, 0x08, 0x60, 0x2b, 0x8c, 0x28, 0x94, 0x00, 0x26, 0xd0, 0xb1, 0x80, 0x58, 0x9c, \n\t0x00, 0x32, 0x00, 0x80, 0x01, 0x48, 0x07, 0xe4, 0x44, 0x20, 0x22, 0xa6, 0x99, 0x8a, 0x0c, 0x78, \n\t0x90, 0x22, 0x15, 0x94, 0x4a, 0x80, 0x46, 0x32, 0x30, 0x37, 0x05, 0xd1, 0x22, 0x10, 0x04, 0x71, \n\t0xa4, 0x84, 0x13, 0x82, 0x50, 0x44, 0x32, 0x07, 0x50, 0x80, 0x89, 0x18, 0xe3, 0x28, 0x08, 0x91, \n\t0x5c, 0x20, 0x24, 0x24, 0x42, 0x93, 0x89, 0x80, 0x49, 0x20, 0xb4, 0x41, 0x20, 0x01, 0x00, 0x84, \n\t0x00, 0x13, 0x29, 0x8a, 0x04, 0x4c, 0x41, 0x4a, 0xc4, 0x60, 0x08, 0x08, 0x04, 0x8d, 0x48, 0xa6, \n\t0x18, 0x38, 0x0c, 0x84, 0xca, 0x08, 0xa3, 0xb0, 0x8c, 0x0c, 0x0e, 0x4f, 0x34, 0xc0, 0xc0, 0x21, \n\t0x55, 0x53, 0x04, 0x60, 0x76, 0x9a, 0x28, 0x39, 0x81, 0x83, 0x3a, 0x95, 0x43, 0xb4, 0x21, 0x05, \n\t0x82, 0x0c, 0x54, 0xb0, 0xb3, 0x80, 0x02, 0x62, 0x5c, 0x04, 0x2a, 0x2e, 0x08, 0x00, 0x65, 0x06, \n\t0x50, 0x80, 0x8b, 0x90, 0x08, 0x61, 0x12, 0x60, 0x20, 0x0f, 0x50, 0x0b, 0xc1, 0x08, 0x20, 0x41, \n\t0x10, 0x30, 0x01, 0x60, 0x0c, 0x16, 0x89, 0x01, 0x78, 0x9a, 0x68, 0x22, 0x04, 0x31, 0x30, 0x4c, \n\t0x12, 0x85, 0x18, 0x42, 0xb1, 0x81, 0x14, 0x8a, 0x05, 0x58, 0x82, 0x83, 0x34, 0x09, 0x83, 0x07, \n\t0x6e, 0x63, 0x00, 0x1d, 0x00, 0x18, 0xc4, 0x3a, 0xc1, 0x98, 0x3a, 0x2d, 0x41, 0x02, 0x64, 0x15, \n\t0xa8, 0x26, 0x08, 0x0b, 0x68, 0x48, 0x24, 0x03, 0x16, 0x94, 0x4c, 0x86, 0x46, 0x65, 0x82, 0x8a, \n\t0xc8, 0x4d, 0x48, 0x34, 0x71, 0x30, 0x2a, 0x20, 0xd4, 0x8b, 0x00, 0xf0, 0x8a, 0x9e, 0xa4, 0x43, \n\t0x48, 0x1c, 0x02, 0x10, 0x84, 0x01, 0xc5, 0x63, 0x34, 0x16, 0x13, 0x25, 0xc1, 0x10, 0x48, 0x54, \n\t0xc1, 0xc3, 0x00, 0xd0, 0x10, 0x22, 0x04, 0x84, 0xc1, 0x38, 0x01, 0x02, 0x09, 0x02, 0xa0, 0x00, \n\t0x8c, 0x24, 0x0c, 0x03, 0x08, 0x11, 0xc8, 0x2d, 0x48, 0x58, 0x0e, 0x00, 0x04, 0xb2, 0x84, 0x30, \n\t0x80, 0x49, 0x62, 0x00, 0xb8, 0x20, 0x30, 0x08, 0xa7, 0x74, 0x32, 0x08, 0x02, 0x8c, 0xc9, 0x46, \n\t0x12, 0x91, 0x31, 0x33, 0xa0, 0xc7, 0x85, 0x32, 0x24, 0x68, 0x84, 0x90, 0xc0, 0x09, 0x30, 0x50, \n\t0x49, 0x8e, 0xa8, 0x90, 0x84, 0x6a, 0x92, 0x39, 0x14, 0x0d, 0x10, 0xa8, 0x48, 0x21, 0x13, 0x2a, \n\t0x74, 0x98, 0x84, 0x40, 0x96, 0x82, 0x81, 0x00, 0x11, 0x44, 0x00, 0x62, 0xa8, 0xb3, 0x28, 0xd9, \n\t0x02, 0x30, 0xc5, 0xf2, 0x19, 0x80, 0x57, 0x04, 0x02, 0x41, 0x73, 0x00, 0x0c, 0x90, 0x28, 0x00, \n\t0x07, 0x32, 0xa8, 0x2c, 0x58, 0x64, 0x42, 0x03, 0x43, 0x18, 0xb4, 0x04, 0x85, 0x2c, 0x21, 0x19, \n\t0x21, 0x80, 0x02, 0x43, 0x32, 0x54, 0xc0, 0x16, 0x30, 0x8e, 0x21, 0x4a, 0x55, 0x08, 0x02, 0xc0, \n\t0x8b, 0x20, 0x4c, 0x80, 0x32, 0x38, 0x14, 0xd4, 0xa3, 0x40, 0x63, 0xd3, 0x00, 0x49, 0x10, 0xe4, \n\t0x18, 0xe0, 0x01, 0x81, 0x04, 0x52, 0x81, 0x6e, 0x33, 0x28, 0x04, 0x05, 0xce, 0x46, 0x72, 0x82, \n\t0xc2, 0x8d, 0x60, 0x58, 0x0a, 0x36, 0x51, 0x6a, 0x26, 0x04, 0xda, 0x80, 0x0e, 0x06, 0xb1, 0x2a, \n\t0x89, 0x15, 0x08, 0x30, 0x83, 0x10, 0xa1, 0x01, 0x00, 0x84, 0x1c, 0xa1, 0x70, 0xa4, 0x34, 0x4a, \n\t0x4e, 0x28, 0x00, 0xa1, 0x2b, 0x10, 0x90, 0x00, 0x28, 0xc2, 0x70, 0x05, 0xf9, 0x41, 0x67, 0x74, \n\t0x02, 0x18, 0x08, 0xb0, 0xd4, 0x8a, 0x4a, 0xc1, 0x03, 0x0a, 0x91, 0x08, 0x02, 0x3c, 0x25, 0x22, \n\t0x05, 0x44, 0x50, 0x40, 0x08, 0x55, 0x32, 0x07, 0x49, 0x02, 0x27, 0x00, 0x00, 0x02, 0x9a, 0xa4, \n\t0x02, 0x80, 0x44, 0x65, 0x4b, 0xa4, 0x20, 0x13, 0x8b, 0x48, 0x81, 0x0a, 0x88, 0xc0, 0x44, 0x08, \n\t0x56, 0xa7, 0x40, 0x22, 0x05, 0x4e, 0x2e, 0x04, 0xd1, 0x19, 0x88, 0x34, 0x0c, 0x03, 0x00, 0xa2, \n\t0x21, 0x22, 0xa8, 0x1c, 0x01, 0x06, 0x72, 0x91, 0x15, 0x39, 0xd8, 0x8c, 0x2a, 0x22, 0xc8, 0x38, \n\t0x48, 0x05, 0x47, 0x48, 0x12, 0x30, 0x0a, 0x2c, 0x16, 0x89, 0x30, 0xd3, 0x02, 0x06, 0x09, 0x18, \n\t0x24, 0x22, 0x04, 0x02, 0x28, 0x45, 0x46, 0x25, 0x32, 0xc6, 0x00, 0x00, 0x01, 0xc2, 0x0a, 0x78, \n\t0x51, 0xa8, 0x32, 0xa0, 0x03, 0xe8, 0x58, 0xc6, 0x0a, 0x84, 0x65, 0x01, 0x80, 0x10, 0xd4, 0x12, \n\t0xa1, 0x60, 0x0e, 0x89, 0x00, 0x96, 0x01, 0x31, 0x80, 0x09, 0x00, 0x08, 0xf4, 0x0b, 0xb3, 0x1c, \n\t0x8d, 0x20, 0x14, 0x90, 0xe3, 0x12, 0x30, 0x48, 0x0d, 0x1e, 0x04, 0x60, 0x21, 0x88, 0x82, 0x8a, \n\t0x5a, 0x00, 0x4b, 0x89, 0x44, 0x0e, 0xe0, 0x64, 0x01, 0x72, 0x1c, 0x58, 0x11, 0x04, 0x0c, 0x30, \n\t0xa0, 0x1a, 0x1d, 0x9d, 0x03, 0x12, 0x02, 0xd0, 0x12, 0x25, 0x43, 0x2a, 0x3a, 0x50, 0x21, 0x35, \n\t0x69, 0x44, 0x43, 0x08, 0xc0, 0x4a, 0x2c, 0x01, 0x18, 0x41, 0x04, 0x12, 0xd2, 0x0b, 0x48, 0xc7, \n\t0x40, 0x0a, 0xa4, 0x18, 0x9e, 0x80, 0x88, 0x40, 0x18, 0x55, 0xe1, 0x0c, 0x94, 0x5d, 0x01, 0x70, \n\t0x83, 0x48, 0x12, 0x90, 0x59, 0x29, 0x24, 0x22, 0x0a, 0x20, 0x38, 0x80, 0x08, 0x08, 0x03, 0x08, \n\t0x09, 0x64, 0x10, 0x43, 0x20, 0x85, 0x00, 0x2a, 0x1d, 0xda, 0x20, 0x06, 0xe0, 0x22, 0x3c, 0x24, \n\t0x43, 0x40, 0x26, 0xc0, 0x78, 0x94, 0x08, 0x17, 0x0e, 0x58, 0x20, 0x29, 0x07, 0xa4, 0xcc, 0x80, \n\t0x54, 0x42, 0xa2, 0x18, 0x91, 0x01, 0xc4, 0x00, 0x80, 0x10, 0x23, 0x7c, 0x05, 0x87, 0x02, 0xc0, \n\t0x58, 0xaa, 0x01, 0x1e, 0x0b, 0x68, 0x41, 0x03, 0x83, 0xa0, 0x57, 0x01, 0x10, 0x34, 0x19, 0x14, \n\t0x80, 0x02, 0xa0, 0x28, 0x82, 0x61, 0x2c, 0x61, 0x42, 0x40, 0x0e, 0xa3, 0x92, 0x84, 0x81, 0x10, \n\t0x43, 0x2c, 0x94, 0x02, 0x04, 0xcc, 0x48, 0x60, 0x2a, 0x51, 0x92, 0x01, 0x18, 0x49, 0xe6, 0x38, \n\t0x81, 0xa3, 0x2d, 0x60, 0x44, 0x20, 0x10, 0x21, 0x71, 0xb0, 0x04, 0x07, 0xaa, 0x0c, 0xc4, 0x2a, \n\t0x18, 0x14, 0x00, 0x8e, 0x54, 0xf2, 0x01, 0x18, 0x19, 0x48, 0x23, 0x22, 0xc0, 0x18, 0x0c, 0x35, \n\t0x06, 0x49, 0x32, 0x10, 0x63, 0x32, 0xac, 0x44, 0x60, 0x08, 0xe1, 0x48, 0x96, 0x88, 0x84, 0x08, \n\t0x24, 0x00, 0xfb, 0x25, 0x80, 0x81, 0xce, 0x16, 0x02, 0xb9, 0x00, 0xc1, 0x00, 0x0c, 0x44, 0x06, \n\t0x10, 0x83, 0x40, 0x51, 0xc2, 0x60, 0x23, 0x1a, 0xb8, 0x41, 0x80, 0x42, 0x0c, 0x11, 0xe2, 0x12, \n\t0xa4, 0x0d, 0x8a, 0x2e, 0x41, 0x98, 0x20, 0x0d, 0x14, 0xe0, 0x6a, 0x41, 0x10, 0x10, 0xc1, 0x54, \n\t0x05, 0x16, 0x42, 0x18, 0x28, 0x55, 0x0d, 0x03, 0x0a, 0x43, 0x40, 0x00, 0xe0, 0x96, 0x80, 0x10, \n\t0xa1, 0x48, 0x01, 0xa4, 0x12, 0x40, 0x34, 0xe5, 0x30, 0x00, 0x39, 0x06, 0x23, 0x08, 0x94, 0x21, \n\t0x19, 0xc8, 0x41, 0x06, 0x14, 0x82, 0x82, 0x80, 0x4c, 0x90, 0x41, 0x3c, 0x03, 0x12, 0xa6, 0xc4, \n\t0x40, 0x4b, 0x24, 0x44, 0x32, 0x97, 0x7c, 0x02, 0x64, 0x66, 0x52, 0x29, 0x06, 0x85, 0x1c, 0xa2, \n\t0x34, 0x00, 0x18, 0x21, 0x09, 0x90, 0x21, 0x62, 0x06, 0xcb, 0x00, 0x01, 0x45, 0xa0, 0x20, 0x12, \n\t0x41, 0x33, 0x94, 0x08, 0x62, 0x1e, 0x82, 0x50, 0x84, 0xb0, 0x10, 0x8d, 0x50, 0x23, 0x8b, 0x14, \n\t0x00, 0x10, 0x04, 0x48, 0x70, 0x8b, 0x80, 0x88, 0x8f, 0x4d, 0x5c, 0xb0, 0xa1, 0x01, 0x00, 0x84, \n\t0xa8, 0x04, 0x12, 0xf9, 0x00, 0x08, 0x00, 0x8f, 0x30, 0x41, 0x62, 0x90, 0x05, 0x8a, 0xa3, 0x6a, \n\t0x90, 0x02, 0x14, 0x58, 0x4d, 0x00, 0x40, 0x04, 0x80, 0xa5, 0xc1, 0x17, 0x02, 0x76, 0x04, 0x83, \n\t0x07, 0x50, 0x98, 0x49, 0x04, 0x22, 0x90, 0x88, 0x01, 0x5d, 0x04, 0x30, 0x11, 0x58, 0x11, 0x68, \n\t0x80, 0x4c, 0x28, 0x51, 0x61, 0x15, 0x11, 0x4d, 0x42, 0x02, 0x92, 0x22, 0x02, 0x34, 0x5e, 0x49, \n\t0x5a, 0xa2, 0xe2, 0x80, 0x98, 0x0a, 0x0f, 0x40, 0x04, 0x60, 0x08, 0x50, 0x12, 0x60, 0x40, 0x90, \n\t0x1b, 0x8d, 0xd4, 0x86, 0x0e, 0x40, 0x40, 0x70, 0x2b, 0x99, 0xc9, 0x65, 0x00, 0x87, 0x88, 0x2e, \n\t0x10, 0xd3, 0x84, 0x42, 0x01, 0x58, 0x98, 0x05, 0x80, 0x00, 0x20, 0x60, 0xd8, 0x03, 0x80, 0x92, \n\t0xcb, 0x0c, 0x40, 0x98, 0x06, 0x29, 0x40, 0x23, 0x20, 0x36, 0x90, 0x91, 0x50, 0x83, 0x0d, 0x16, \n\t0x24, 0x48, 0xaa, 0x95, 0x0f, 0xc7, 0x60, 0xa0, 0x48, 0x2d, 0xa0, 0x41, 0x28, 0x30, 0x45, 0x82, \n\t0x02, 0x40, 0x55, 0x0e, 0x2e, 0x90, 0x52, 0x20, 0xa5, 0x03, 0x20, 0x5a, 0x41, 0x71, 0xa1, 0x18, \n\t0x90, 0x8e, 0x40, 0xf1, 0xe0, 0xad, 0x40, 0x90, 0x21, 0x06, 0x52, 0x32, 0xa4, 0x20, 0x90, 0x02, \n\t0x0a, 0x90, 0x11, 0x0e, 0x0c, 0x1c, 0xa4, 0x40, 0x21, 0x40, 0x90, 0xa8, 0x4c, 0x8b, 0x3a, 0x20, \n\t0x53, 0x3a, 0x45, 0x01, 0xa5, 0x14, 0x82, 0xc8, 0xb8, 0x11, 0x8c, 0xa2, 0x10, 0x33, 0x08, 0x86, \n\t0xe4, 0x11, 0x07, 0x02, 0xb2, 0x28, 0x1b, 0x24, 0x43, 0x04, 0x66, 0x66, 0x62, 0x8e, 0x60, 0x53, \n\t0x8a, 0x70, 0x90, 0x01, 0x1d, 0x11, 0x14, 0x27, 0x58, 0x10, 0x80, 0x21, 0x89, 0x04, 0xe0, 0x24, \n\t0x44, 0xc0, 0x99, 0x98, 0x00, 0xcf, 0x08, 0x03, 0x10, 0xa0, 0x5d, 0x18, 0x20, 0x0c, 0xd2, 0xb8, \n\t0x15, 0x44, 0xc3, 0xa8, 0x60, 0x40, 0x50, 0x91, 0xc0, 0x03, 0x88, 0x4c, 0x82, 0x60, 0x0e, 0x0d, \n\t0x19, 0x03, 0x26, 0x15, 0x80, 0xba, 0x01, 0xce, 0xa0, 0x10, 0xa0, 0x10, 0x84, 0x50, 0x05, 0x43, \n\t0x38, 0x62, 0x00, 0x19, 0x00, 0x88, 0x08, 0x64, 0x52, 0x23, 0x14, 0x00, 0xc6, 0x0a, 0x50, 0x84, \n\t0x0b, 0x01, 0x00, 0x10, 0x05, 0x52, 0x71, 0xd1, 0x0a, 0x80, 0x94, 0xe0, 0x08, 0x22, 0x83, 0xac, \n\t0x40, 0xc9, 0x2a, 0x4a, 0x34, 0xa2, 0xa2, 0x41, 0x13, 0x80, 0x14, 0x05, 0xc8, 0x18, 0xa0, 0x4c, \n\t0xa6, 0x00, 0x40, 0x13, 0x01, 0x24, 0x54, 0x22, 0x14, 0xa1, 0x78, 0x98, 0x38, 0x4d, 0x29, 0x06, \n\t0x60, 0x43, 0x22, 0x2c, 0x8a, 0x40, 0x22, 0x00, 0x49, 0x25, 0xc0, 0xd4, 0x8c, 0x32, 0x85, 0x81, \n\t0x18, 0x24, 0x5b, 0x04, 0x68, 0x61, 0x39, 0x16, 0x61, 0x42, 0x41, 0x60, 0x10, 0x0a, 0x00, 0x44, \n\t0x12, 0x40, 0x4c, 0x61, 0x03, 0xa0, 0xc4, 0x90, 0x22, 0x2c, 0xe4, 0x10, 0x98, 0x45, 0x1a, 0x05, \n\t0x48, 0x02, 0x02, 0x28, 0x74, 0x40, 0x42, 0x06, 0x06, 0x4a, 0x0b, 0xa8, 0x94, 0x28, 0x0c, 0x40, \n\t0x02, 0x05, 0xd9, 0x8a, 0xc2, 0x00, 0x43, 0x60, 0x20, 0xb0, 0x10, 0x2c, 0x06, 0x05, 0x01, 0x89, \n\t0x08, 0x8c, 0x03, 0x12, 0x74, 0x21, 0x88, 0x44, 0x87, 0x47, 0x20, 0x25, 0x82, 0x35, 0x10, 0x0a, \n\t0x0d, 0x0a, 0x22, 0x01, 0x07, 0xd0, 0x80, 0xe3, 0x44, 0x04, 0xf0, 0x38, 0x3d, 0x92, 0xa5, 0x50, \n\t0xa0, 0x30, 0x80, 0x39, 0x80, 0x40, 0x14, 0x17, 0xd2, 0x02, 0x45, 0xc0, 0xa0, 0x00, 0x34, 0x18, \n\t0xa0, 0x41, 0x04, 0x82, 0x1e, 0x16, 0x2b, 0x04, 0x41, 0x8a, 0x80, 0x02, 0x00, 0x50, 0x25, 0x71, \n\t0xd2, 0x21, 0x60, 0x87, 0x81, 0x24, 0x39, 0x15, 0x06, 0x74, 0x22, 0x41, 0xa2, 0xe8, 0x42, 0x02, \n\t0x08, 0xc3, 0x71, 0x31, 0xc5, 0x44, 0x8b, 0x48, 0x20, 0x02, 0x0a, 0x04, 0x46, 0x0d, 0x40, 0x95, \n\t0x30, 0x18, 0x19, 0x44, 0x6a, 0x02, 0x92, 0xaa, 0x30, 0xf0, 0x10, 0x87, 0x1e, 0xb2, 0xa8, 0x06, \n\t0x25, 0x14, 0xcf, 0x74, 0xe0, 0x01, 0x0a, 0x00, 0x08, 0xc7, 0x22, 0x10, 0x08, 0x20, 0x15, 0x0a, \n\t0x67, 0x64, 0x05, 0x82, 0x01, 0x8c, 0xca, 0xa8, 0x40, 0x00, 0x58, 0xa3, 0x04, 0x12, 0x69, 0x06, \n\t0x84, 0xb9, 0x9e, 0x2c, 0x40, 0x00, 0x04, 0xa2, 0x5b, 0x01, 0x80, 0x0c, 0xae, 0x2a, 0x05, 0x41, \n\t0x13, 0x00, 0xc0, 0x0d, 0x50, 0x95, 0x22, 0xb0, 0x10, 0x43, 0x0c, 0x38, 0x03, 0xfa, 0x12, 0x08, \n\t0x52, 0x86, 0x40, 0x84, 0x00, 0x1d, 0xb0, 0xc6, 0x8c, 0x0a, 0x70, 0x92, 0x0d, 0x38, 0x00, 0x82, \n\t0x60, 0xd4, 0x32, 0xa3, 0x88, 0x10, 0x04, 0x28, 0x51, 0x18, 0x10, 0x29, 0x98, 0x20, 0x50, 0x04, \n\t0xc0, 0x2e, 0x88, 0x51, 0x0a, 0x28, 0x55, 0x32, 0xb1, 0x90, 0x0d, 0x62, 0x60, 0x04, 0x00, 0xb6, \n\t0xdc, 0x58, 0xc9, 0x34, 0x14, 0x41, 0xa8, 0xc1, 0x44, 0x82, 0x38, 0x90, 0x00, 0x19, 0x90, 0x11, \n\t0x01, 0x3a, 0x04, 0xc0, 0x2f, 0x00, 0x88, 0x21, 0x28, 0x20, 0x51, 0x93, 0x01, 0x89, 0x61, 0x14, \n\t0x26, 0x29, 0x15, 0xe4, 0x12, 0x64, 0x00, 0xc1, 0x28, 0x0b, 0x45, 0x02, 0xa8, 0x44, 0x63, 0x80, \n\t0x8a, 0x94, 0x8a, 0x04, 0x42, 0x04, 0x28, 0x95, 0x25, 0x86, 0x42, 0x40, 0x02, 0xb3, 0xa0, 0xc8, \n\t0x1e, 0x00, 0x1e, 0x51, 0xb0, 0x02, 0x7c, 0x4c, 0x00, 0x06, 0x86, 0xe8, 0x38, 0x80, 0x0c, 0xad, \n\t0x02, 0xc4, 0x02, 0x89, 0xb1, 0x81, 0xa4, 0x20, 0x21, 0x20, 0x2d, 0xd1, 0x54, 0x02, 0x08, 0x62, \n\t0x68, 0x81, 0xa8, 0x11, 0x05, 0x42, 0x50, 0x10, 0x92, 0x91, 0x50, 0x4c, 0x18, 0x04, 0x71, 0x04, \n\t0x24, 0xd5, 0x2a, 0x14, 0x00, 0x89, 0xaa, 0x78, 0x08, 0x04, 0x5c, 0x50, 0x00, 0x04, 0x11, 0x08, \n\t0x64, 0x0c, 0xd1, 0x92, 0x91, 0x0c, 0x13, 0x61, 0x00, 0x40, 0xd3, 0x22, 0xc1, 0x8e, 0x86, 0x1c, \n\t0x34, 0xd9, 0x31, 0x4c, 0xc1, 0xa2, 0x08, 0x80, 0x02, 0x82, 0x60, 0x08, 0x00, 0x06, 0x62, 0x48, \n\t0x20, 0x11, 0x4a, 0x26, 0x00, 0x71, 0x49, 0x14, 0x84, 0x07, 0xc7, 0x40, 0xa0, 0x43, 0xa7, 0x80, \n\t0x8f, 0x20, 0x56, 0x35, 0x12, 0x10, 0x50, 0x1c, 0x43, 0x38, 0x20, 0xab, 0x1c, 0xcd, 0xc0, 0xc1, \n\t0x08, 0x12, 0x00, 0x09, 0xd8, 0x18, 0xa5, 0x58, 0x72, 0x43, 0x20, 0x41, 0x41, 0xe8, 0x48, 0xa0, \n\t0x90, 0xa2, 0x70, 0xc1, 0x45, 0x36, 0x00, 0x69, 0x93, 0xec, 0x87, 0x28, 0x36, 0x00, 0x0a, 0xb0, \n\t0x8c, 0x41, 0x02, 0x62, 0x26, 0x53, 0x2a, 0x80, 0x48, 0x2b, 0x42, 0xc5, 0x91, 0x99, 0x78, 0x00, \n\t0x61, 0x26, 0x14, 0x20, 0x1d, 0x10, 0x01, 0x4a, 0x48, 0xa0, 0x08, 0x2f, 0x90, 0x8a, 0x4c, 0x04, \n\t0xe0, 0xa1, 0x82, 0x31, 0x45, 0x22, 0x30, 0x04, 0x20, 0x10, 0x08, 0x81, 0xe3, 0x50, 0xb1, 0x22, \n\t0xa0, 0x4c, 0x8c, 0x49, 0x60, 0x66, 0xa1, 0x0e, 0x09, 0x11, 0xa4, 0x00, 0x80, 0xa0, 0x9c, 0x21, \n\t0x43, 0x61, 0x18, 0x03, 0x58, 0x80, 0xc1, 0xc5, 0x22, 0x08, 0x31, 0x12, 0x80, 0x00, 0x18, 0x08, \n\t0x1a, 0x85, 0xc3, 0x34, 0x90, 0x48, 0x20, 0x06, 0x13, 0x49, 0x28, 0xa1, 0x01, 0x0d, 0x02, 0x65, \n\t0x50, 0x15, 0x95, 0x10, 0x0c, 0x02, 0x04, 0x80, 0x09, 0x18, 0x8c, 0x49, 0x04, 0x25, 0x91, 0x18, \n\t0x38, 0x1b, 0x01, 0x72, 0x02, 0x90, 0x20, 0x80, 0x03, 0xa4, 0x06, 0xc1, 0x78, 0x08, 0x98, 0x10, \n\t0x00, 0x10, 0x85, 0x01, 0x8f, 0x81, 0x48, 0x82, 0x08, 0xc2, 0x08, 0xa5, 0x14, 0x5f, 0x83, 0x20, \n\t0x55, 0x70, 0x0d, 0x41, 0x00, 0x04, 0x5e, 0x20, 0xb1, 0x03, 0xb1, 0x88, 0xc0, 0x48, 0x40, 0xcb, \n\t0x20, 0xe5, 0x41, 0xc6, 0x40, 0x12, 0x91, 0xb3, 0x78, 0x40, 0x23, 0x24, 0x03, 0x20, 0x87, 0x04, \n\t0x0d, 0x88, 0x30, 0x90, 0x20, 0x10, 0x80, 0x03, 0x68, 0x68, 0xc6, 0x10, 0x15, 0x01, 0xcc, 0x20, \n\t0x08, 0x06, 0x78, 0x0c, 0x20, 0x94, 0x85, 0x02, 0x91, 0x10, 0x06, 0xc8, 0x12, 0x86, 0x48, 0x02, \n\t0xb0, 0x04, 0x04, 0x1a, 0xe8, 0x00, 0x96, 0x82, 0x20, 0x35, 0x98, 0x82, 0x48, 0x80, 0x10, 0x29, \n\t0x84, 0xcb, 0x22, 0x6c, 0x50, 0x00, 0xb0, 0x9d, 0x02, 0x02, 0x4c, 0x24, 0x48, 0x8e, 0x01, 0x50, \n\t0xcf, 0x40, 0x42, 0x10, 0x1b, 0x29, 0x09, 0x29, 0x24, 0x00, 0x10, 0x82, 0x00, 0x42, 0x05, 0x22, \n\t0x01, 0xc8, 0x15, 0x98, 0x18, 0x05, 0x04, 0x34, 0x0a, 0x85, 0x80, 0x1e, 0xa6, 0x34, 0x80, 0xe9, \n\t0x00, 0x75, 0x05, 0xcb, 0x12, 0x03, 0x51, 0x25, 0x6c, 0x10, 0x8a, 0x44, 0x87, 0xa0, 0x11, 0x08, \n\t0x01, 0xa2, 0x42, 0xc5, 0x38, 0x22, 0x24, 0x81, 0xc6, 0x70, 0x82, 0xe1, 0x10, 0x04, 0x1a, 0x88, \n\t0x14, 0x20, 0x12, 0x26, 0x04, 0x5c, 0x49, 0x12, 0x60, 0x12, 0x38, 0xd0, 0x05, 0x81, 0x20, 0x67, \n\t0x92, 0x12, 0x49, 0x01, 0xa1, 0x0c, 0x43, 0x60, 0x18, 0xc4, 0xc3, 0x08, 0x60, 0x52, 0x82, 0x16, \n\t0xbc, 0x88, 0x64, 0x24, 0x61, 0xd0, 0x00, 0x70, 0x19, 0x20, 0x74, 0x24, 0x00, 0x19, 0xc0, 0xc4, \n\t0x02, 0x04, 0xb1, 0x42, 0x85, 0x10, 0x94, 0x6a, 0x28, 0x10, 0x21, 0xa9, 0xcc, 0x08, 0xc8, 0x02, \n\t0x42, 0x92, 0xb5, 0x08, 0x12, 0x81, 0x0a, 0x82, 0xe0, 0x05, 0x49, 0x5b, 0x0c, 0x0c, 0x24, 0xc9, \n\t0x20, 0x1c, 0x8a, 0x83, 0x0e, 0x60, 0x99, 0x06, 0x91, 0x00, 0x4d, 0x56, 0x10, 0x5b, 0x98, 0x25, \n\t0xc9, 0x89, 0x00, 0xb0, 0x48, 0xa1, 0x10, 0x0d, 0x06, 0x42, 0xc6, 0x80, 0x20, 0x10, 0xc3, 0x28, \n\t0x74, 0x62, 0xa1, 0x09, 0x01, 0x44, 0xe6, 0x22, 0x26, 0x88, 0x11, 0xa8, 0xd2, 0x00, 0x58, 0x02, \n\t0x19, 0x00, 0xa1, 0x04, 0x01, 0x18, 0xa5, 0x91, 0x16, 0xd0, 0xd0, 0x60, 0x00, 0x05, 0x08, 0x02, \n\t0x0d, 0x1d, 0xe4, 0x02, 0xd6, 0x08, 0x3a, 0x48, 0x19, 0x0c, 0x3c, 0x00, 0x20, 0xa3, 0xa0, 0x54, \n\t0x21, 0x14, 0x41, 0x88, 0x28, 0x49, 0x00, 0x86, 0x24, 0x33, 0x82, 0x30, 0x58, 0x01, 0x4f, 0x28, \n\t0x93, 0x69, 0x29, 0x54, 0x45, 0x82, 0x50, 0xc3, 0x8a, 0x38, 0x30, 0x46, 0x45, 0x2a, 0x14, 0x08, \n\t0x8e, 0x99, 0x06, 0x60, 0x02, 0x10, 0xe8, 0x00, 0x19, 0x82, 0x21, 0x5c, 0x20, 0x00, 0xa7, 0x24, \n\t0x86, 0x00, 0x28, 0x36, 0x02, 0x1c, 0xc4, 0x0b, 0x0c, 0x0e, 0xb4, 0x08, 0x0d, 0x64, 0xd4, 0xc4, \n\t0x00, 0x81, 0x09, 0xb1, 0x01, 0x41, 0x2e, 0x14, 0x20, 0x08, 0x82, 0x0d, 0x51, 0xca, 0x0a, 0x07, \n\t0x23, 0xb0, 0x28, 0x05, 0x09, 0x20, 0x60, 0x90, 0x99, 0x90, 0x82, 0x0e, 0x0e, 0xc1, 0x70, 0x24, \n\t0x60, 0xcb, 0xc3, 0x00, 0xa0, 0xea, 0x17, 0x24, 0x14, 0x04, 0x70, 0x22, 0x00, 0x01, 0x48, 0xc1, \n\t0xa4, 0x20, 0x24, 0x70, 0x28, 0x8d, 0xc4, 0x44, 0x00, 0xa1, 0x51, 0x20, 0x7d, 0x88, 0x01, 0x1c, \n\t0xa3, 0xa0, 0x85, 0x8c, 0x50, 0xa8, 0x44, 0x60, 0x02, 0x3c, 0x44, 0x55, 0xa3, 0x30, 0x06, 0xb3, \n\t0x0c, 0x44, 0x12, 0xac, 0x0a, 0x14, 0x21, 0x03, 0x15, 0x59, 0x20, 0x58, 0xa0, 0x9a, 0x94, 0x11, \n\t0x08, 0x63, 0x62, 0xe0, 0x42, 0x23, 0xb5, 0xce, 0x00, 0x00, 0x15, 0x10, 0x82, 0xa0, 0x1a, 0x4e, \n\t0x00, 0x23, 0x63, 0x18, 0x10, 0x94, 0x04, 0x52, 0x82, 0xbb, 0x08, 0x70, 0xc6, 0x41, 0x68, 0x02, \n\t0x90, 0x14, 0x08, 0x93, 0x88, 0x10, 0x51, 0x78, 0x05, 0x44, 0x18, 0x8e, 0x50, 0xd6, 0x43, 0x84, \n\t0x08, 0x8a, 0x80, 0x00, 0xc0, 0x22, 0x14, 0x40, 0x04, 0xc0, 0x48, 0x05, 0xa0, 0x01, 0x08, 0x40, \n\t0x80, 0x40, 0x40, 0xcb, 0x94, 0x0d, 0xd2, 0x8a, 0x46, 0x86, 0x80, 0x80, 0xb9, 0x48, 0x40, 0x74, \n\t0x95, 0x10, 0xa8, 0x34, 0x8f, 0x0d, 0x0e, 0x16, 0x08, 0x2a, 0x50, 0x90, 0x0b, 0x5a, 0xc5, 0x6a, \n\t0x14, 0x80, 0x8d, 0x48, 0x02, 0x03, 0x02, 0x81, 0x21, 0x4c, 0x86, 0x5a, 0x82, 0x83, 0x09, 0x99, \n\t0x02, 0x20, 0x04, 0x60, 0x6b, 0x89, 0x48, 0x08, 0x6a, 0x68, 0x84, 0x40, 0xa5, 0xc4, 0x0a, 0x81, \n\t0x40, 0x21, 0x28, 0x16, 0x04, 0x02, 0x61, 0x16, 0x94, 0x00, 0x3a, 0x80, 0xd6, 0x2c, 0x22, 0x64, \n\t0x48, 0x80, 0x08, 0xc1, 0x40, 0x38, 0x00, 0x80, 0x18, 0x08, 0x10, 0xc1, 0x34, 0x03, 0xda, 0x82, \n\t0x44, 0x03, 0x4b, 0x0a, 0x74, 0x38, 0x85, 0x41, 0x42, 0xc5, 0x32, 0x65, 0x40, 0x26, 0xb4, 0x90, \n\t0x21, 0x6a, 0x94, 0x0b, 0x09, 0x20, 0x14, 0x21, 0x72, 0x80, 0x82, 0x25, 0x20, 0x80, 0x2a, 0x0a, \n\t0x12, 0x81, 0x81, 0x10, 0x02, 0x08, 0x18, 0x62, 0x80, 0x88, 0x55, 0x58, 0x09, 0x0e, 0xe2, 0x22, \n\t0x31, 0x61, 0x53, 0x62, 0x68, 0x54, 0x12, 0x9b, 0xc0, 0x9d, 0x82, 0x2e, 0x00, 0x88, 0x20, 0x45, \n\t0xc0, 0x40, 0x72, 0x62, 0x0b, 0x04, 0x31, 0x18, 0xe6, 0x22, 0x60, 0x48, 0x1a, 0x40, 0x80, 0xa7, \n\t0x12, 0x72, 0x10, 0x9d, 0x80, 0x8d, 0x82, 0x08, 0x66, 0xc2, 0xb4, 0x24, 0x00, 0x20, 0x54, 0x90, \n\t0x28, 0x0c, 0x08, 0x81, 0xe9, 0x10, 0x04, 0xb3, 0x28, 0x60, 0x05, 0x22, 0x0c, 0x10, 0x81, 0x09, \n\t0x01, 0x98, 0x0c, 0x24, 0x12, 0x41, 0x02, 0x88, 0xc2, 0x42, 0x04, 0x95, 0x80, 0xa1, 0x48, 0x1b, \n\t0x85, 0x0c, 0x85, 0x03, 0x9a, 0x88, 0x8e, 0x20, 0x04, 0x04, 0x91, 0x10, 0x31, 0x1e, 0x01, 0x40, \n\t0x03, 0x10, 0xbe, 0x48, 0x04, 0x0a, 0x74, 0x60, 0x01, 0x03, 0xf4, 0x46, 0x46, 0x10, 0x41, 0x09, \n\t0x8a, 0xb0, 0x43, 0x88, 0x58, 0xd1, 0x20, 0x26, 0x94, 0xc4, 0x04, 0x5e, 0x83, 0x18, 0x1b, 0x59, \n\t0x88, 0xc2, 0x10, 0x02, 0x11, 0x30, 0xa0, 0x56, 0xa5, 0x08, 0x00, 0x20, 0x0c, 0xf4, 0x0a, 0xad, \n\t0x00, 0x14, 0x20, 0x21, 0x80, 0x13, 0x25, 0x2c, 0x80, 0x12, 0x13, 0x50, 0x88, 0x67, 0x12, 0x15, \n\t0x4a, 0x04, 0x0d, 0xc9, 0x06, 0x02, 0x10, 0xd8, 0x10, 0xcc, 0x0b, 0x02, 0x24, 0x04, 0x02, 0xa4, \n\t0x75, 0x04, 0x28, 0x00, 0xa2, 0x40, 0x90, 0x3c, 0x44, 0xc3, 0x00, 0xe2, 0x61, 0x83, 0x20, 0x06, \n\t0x03, 0x58, 0x50, 0x09, 0x31, 0x80, 0xce, 0x08, 0x04, 0xa5, 0x98, 0x1c, 0x89, 0x95, 0x04, 0x02, \n\t0x30, 0x00, 0x28, 0x05, 0x05, 0xc1, 0x52, 0xa0, 0x10, 0x2e, 0x19, 0x80, 0x28, 0x50, 0x56, 0x21, \n\t0x0f, 0x08, 0x52, 0x21, 0x46, 0x26, 0x08, 0x02, 0x14, 0x10, 0x80, 0x5c, 0x10, 0x82, 0xa1, 0xc0, \n\t0xd5, 0x0e, 0x50, 0x10, 0x43, 0x05, 0x48, 0x95, 0x21, 0x26, 0x41, 0xa0, 0x20, 0x2d, 0x4c, 0x42, \n\t0x02, 0xc3, 0x03, 0x99, 0xc8, 0x03, 0x0c, 0x22, 0x40, 0x50, 0x26, 0x90, 0x02, 0x81, 0x08, 0x42, \n\t0x2b, 0xa5, 0x00, 0x46, 0x65, 0x22, 0x72, 0x4a, 0x08, 0x80, 0x98, 0xc5, 0x0a, 0x80, 0xc9, 0x19, \n\t0x54, 0x94, 0x05, 0x16, 0x02, 0xc0, 0x82, 0x01, 0x88, 0xc3, 0x38, 0xa1, 0x51, 0x1d, 0x08, 0x8a, \n\t0xc1, 0x44, 0x45, 0x3a, 0xb0, 0x00, 0x05, 0xc0, 0x28, 0x41, 0xe9, 0x04, 0x09, 0x50, 0x08, 0x02, \n\t0x30, 0x28, 0x86, 0x21, 0x8b, 0x00, 0x02, 0xe4, 0xaa, 0x0e, 0xb1, 0x00, 0xe5, 0x20, 0xa1, 0x11, \n\t0x1b, 0x11, 0x80, 0x0c, 0x2a, 0xd5, 0x40, 0x02, 0x35, 0x1d, 0x40, 0x38, 0x00, 0x61, 0x1a, 0x24, \n\t0x49, 0x0c, 0x1c, 0x27, 0xd0, 0x01, 0x00, 0xc0, 0xa3, 0x12, 0x14, 0x2a, 0x15, 0x4d, 0x01, 0x01, \n\t0x06, 0xc2, 0x38, 0x2e, 0xec, 0x94, 0xc2, 0x50, 0x00, 0x21, 0x24, 0x1d, 0x40, 0xac, 0x04, 0x15, \n\t0x30, 0xb0, 0x01, 0x81, 0x00, 0x62, 0x40, 0x43, 0x3f, 0x25, 0x80, 0x02, 0x06, 0x31, 0x18, 0xb4, \n\t0x54, 0x1a, 0xcb, 0x10, 0x22, 0x00, 0x02, 0x6c, 0x10, 0x6a, 0x72, 0x20, 0x83, 0x13, 0x44, 0x88, \n\t0xcd, 0x2c, 0xa1, 0x19, 0x0f, 0x95, 0x54, 0x8d, 0x3a, 0x37, 0xc0, 0xb3, 0x08, 0x55, 0x61, 0x50, \n\t0xd2, 0x8b, 0x84, 0x01, 0x48, 0xc0, 0x28, 0x04, 0x48, 0x08, 0xa1, 0x06, 0x42, 0x46, 0x03, 0x40, \n\t0x00, 0x40, 0x80, 0x20, 0x50, 0xb3, 0x13, 0x08, 0x50, 0x50, 0x04, 0x08, 0x64, 0x32, 0x2f, 0x7c, \n\t0x0c, 0x41, 0x62, 0x13, 0xe0, 0x38, 0xa8, 0xd1, 0x20, 0x10, 0x05, 0xf2, 0xa4, 0x15, 0x03, 0x01, \n\t0x52, 0x05, 0x7a, 0xa8, 0x05, 0x09, 0xc0, 0x62, 0xc4, 0x10, 0x0a, 0x45, 0x08, 0x69, 0x24, 0x61, \n\t0x01, 0x00, 0x81, 0x16, 0x88, 0x0a, 0x14, 0x81, 0x83, 0x0c, 0x02, 0x4d, 0x1a, 0x84, 0xaa, 0x81, \n\t0x91, 0xc6, 0x0a, 0x24, 0x10, 0x51, 0x0d, 0x88, 0x90, 0x4e, 0x5a, 0x21, 0xc1, 0xa2, 0xa4, 0x90, \n\t0x0c, 0x34, 0x44, 0x21, 0x80, 0x48, 0x43, 0x0b, 0x48, 0x43, 0x92, 0x90, 0x30, 0xc0, 0x06, 0x14, \n\t0x45, 0xb9, 0x00, 0x08, 0x1b, 0x88, 0x20, 0x44, 0xa9, 0x11, 0x60, 0x0c, 0x8a, 0x30, 0x03, 0x48, \n\t0x28, 0x88, 0x11, 0x86, 0x64, 0x23, 0x8a, 0x22, 0x30, 0xc1, 0xa1, 0x28, 0x40, 0x00, 0x05, 0xe4, \n\t0x0d, 0x86, 0x3a, 0x22, 0x62, 0xaf, 0x8c, 0x56, 0x60, 0x10, 0x10, 0xb8, 0x18, 0x41, 0x04, 0x24, \n\t0x48, 0x30, 0x82, 0x15, 0x70, 0x00, 0x88, 0x42, 0x53, 0x20, 0xad, 0x81, 0x98, 0x4b, 0x50, 0x86, \n\t0x02, 0x0b, 0x40, 0x88, 0x2d, 0x4c, 0xa0, 0x02, 0x00, 0x08, 0x42, 0x40, 0x16, 0x84, 0x00, 0x99, \n\t0x4c, 0x00, 0xa2, 0x22, 0x40, 0x52, 0x14, 0x10, 0x84, 0xa9, 0x0c, 0x26, 0x92, 0x08, 0x24, 0x49, \n\t0x8e, 0x42, 0x93, 0x49, 0x8a, 0x54, 0x04, 0x88, 0x06, 0x40, 0x08, 0x1d, 0x21, 0x90, 0x00, 0x60, \n\t0x21, 0x02, 0x94, 0x98, 0x89, 0x04, 0x1a, 0x94, 0x5b, 0x87, 0x20, 0x44, 0x47, 0x48, 0x90, 0x2a, \n\t0x18, 0x80, 0xd1, 0x43, 0x14, 0x02, 0x29, 0xa0, 0x8c, 0x10, 0xe1, 0x60, 0xf0, 0x81, 0x09, 0xc5, \n\t0xc0, 0x2d, 0x08, 0x95, 0x82, 0xa4, 0x04, 0x4a, 0x40, 0x12, 0x00, 0x11, 0xaf, 0xc1, 0x94, 0x26, \n\t0x3e, 0x60, 0x41, 0x10, 0x41, 0x87, 0xa0, 0x16, 0x42, 0x60, 0x9a, 0x8c, 0x04, 0xe0, 0x14, 0x62, \n\t0x12, 0x18, 0xf4, 0xc0, 0x02, 0x0c, 0x10, 0x21, 0x98, 0x01, 0xde, 0x82, 0x08, 0xb3, 0x60, 0x11, \n\t0x18, 0x01, 0x49, 0x32, 0x00, 0xd0, 0x0a, 0x58, 0x91, 0x29, 0x26, 0x04, 0x48, 0x00, 0x35, 0x00, \n\t0xc8, 0x08, 0x31, 0x32, 0x0e, 0x70, 0x0a, 0x46, 0x00, 0x17, 0x70, 0x88, 0x90, 0xc0, 0x8b, 0x00, \n\t0x04, 0x28, 0x22, 0x45, 0x11, 0x64, 0x38, 0x10, 0xb1, 0x1a, 0xa4, 0x00, 0x24, 0x4a, 0x50, 0x08, \n\t0x82, 0xa0, 0x0f, 0xc0, 0x0e, 0x85, 0x9b, 0x04, 0x31, 0x11, 0x4c, 0x02, 0xf4, 0xc2, 0x90, 0xc5, \n\t0x03, 0x02, 0x04, 0xc3, 0x10, 0x08, 0xa0, 0x57, 0xc0, 0x42, 0x05, 0x80, 0x00, 0x94, 0x42, 0x00, \n\t0x52, 0x45, 0x81, 0x01, 0x09, 0x1d, 0x4b, 0x2a, 0xa6, 0xa0, 0x30, 0x04, 0x95, 0x00, 0x0a, 0x52, \n\t0x08, 0x28, 0x24, 0x12, 0x65, 0x14, 0x24, 0x70, 0xa4, 0x00, 0x98, 0xe2, 0x68, 0x10, 0x0a, 0x33, \n\t0x41, 0x80, 0x01, 0x44, 0x90, 0x0a, 0x36, 0xc1, 0x5b, 0x22, 0x40, 0x71, 0x23, 0xa4, 0x01, 0x14, \n\t0x8a, 0x64, 0x62, 0xab, 0x9a, 0x10, 0x48, 0xc8, 0x04, 0x10, 0xc1, 0x82, 0x11, 0xca, 0xc1, 0x14, \n\t0x96, 0x58, 0x04, 0xe0, 0x01, 0x00, 0x20, 0xa6, 0x8b, 0x81, 0x1c, 0xcf, 0x08, 0x30, 0x12, 0x53, \n\t0x1b, 0xb8, 0x12, 0x0a, 0x5c, 0x22, 0x61, 0x25, 0xc0, 0x84, 0x0f, 0x42, 0x12, 0x00, 0xa4, 0x09, \n\t0x94, 0x0e, 0x20, 0xd0, 0x71, 0x22, 0x04, 0x0b, 0x00, 0x60, 0xa3, 0x10, 0x00, 0x75, 0x5b, 0x00, \n\t0x70, 0x90, 0x50, 0x86, 0x24, 0x1e, 0x80, 0x18, 0x35, 0x02, 0x81, 0x38, 0xc7, 0x60, 0x4c, 0x06, \n\t0x00, 0x92, 0x08, 0x00, 0x20, 0x50, 0x01, 0x42, 0x30, 0x25, 0x44, 0x6c, 0x34, 0x34, 0x20, 0x12, \n\t0x04, 0xc1, 0xc1, 0x1a, 0x83, 0x09, 0x20, 0x90, 0x86, 0x40, 0x08, 0x35, 0x48, 0x94, 0xe1, 0x09, \n\t0x05, 0x5e, 0x34, 0x08, 0x01, 0x91, 0x12, 0xca, 0x10, 0xd2, 0x30, 0x23, 0x45, 0x0e, 0x48, 0x34, \n\t0x24, 0xc3, 0xbf, 0x50, 0xd8, 0x2c, 0x02, 0x31, 0x12, 0x90, 0x20, 0x42, 0x21, 0x24, 0xc5, 0x21, \n\t0x85, 0x24, 0x14, 0x04, 0x3c, 0x11, 0x08, 0x10, 0x00, 0x09, 0x6b, 0x10, 0xc6, 0xb8, 0x80, 0x8c, \n\t0x0d, 0x0b, 0x32, 0x85, 0x5a, 0x01, 0x98, 0x01, 0x01, 0x00, 0x62, 0x70, 0xa6, 0xc0, 0x4c, 0x40, \n\t0x20, 0x40, 0x81, 0x00, 0x28, 0x80, 0x04, 0x08, 0x30, 0x19, 0x15, 0xb8, 0xda, 0x28, 0x5c, 0x80, \n\t0xe1, 0x08, 0x41, 0x52, 0x45, 0x4c, 0x23, 0x09, 0x81, 0x08, 0x00, 0x02, 0x40, 0x63, 0x00, 0x32, \n\t0xd0, 0x12, 0xa6, 0x2a, 0x81, 0x38, 0xa3, 0x15, 0x54, 0x03, 0x58, 0x00, 0x22, 0x00, 0x0d, 0x90, \n\t0x82, 0x10, 0x21, 0x80, 0x25, 0x01, 0x11, 0xc0, 0x44, 0x81, 0x5b, 0x02, 0xc4, 0x00, 0x02, 0x42, \n\t0x60, 0x91, 0x20, 0x10, 0x80, 0xe5, 0x10, 0x13, 0x48, 0x1a, 0xa0, 0xc1, 0x48, 0x0a, 0x14, 0x29, \n\t0xb0, 0x24, 0x0b, 0x00, 0x70, 0xe1, 0x02, 0x0c, 0x51, 0x40, 0xca, 0x0c, 0x02, 0x8a, 0x11, 0xa8, \n\t0x87, 0xad, 0x18, 0xe0, 0xb1, 0x85, 0x65, 0x08, 0x6c, 0x48, 0xa3, 0xc0, 0x24, 0x11, 0x8a, 0xc8, \n\t0x22, 0x04, 0x88, 0x98, 0x18, 0x50, 0x22, 0x00, 0x56, 0x61, 0x21, 0x00, 0xde, 0x84, 0x02, 0x10, \n\t0x53, 0x22, 0xdd, 0x13, 0x08, 0x2a, 0x06, 0xc1, 0xa4, 0xc8, 0x00, 0x00, 0x12, 0xa6, 0xc8, 0xa0, \n\t0x1c, 0x8c, 0x22, 0x2e, 0x02, 0x18, 0x1f, 0xf0, 0x03, 0x07, 0x02, 0x03, 0x09, 0x33, 0xa4, 0x10, \n\t0x08, 0x60, 0xd1, 0x0a, 0x0e, 0x90, 0x5c, 0x40, 0x70, 0xa4, 0x02, 0x18, 0xd1, 0x00, 0xa3, 0x1e, \n\t0x80, 0x70, 0x02, 0xc5, 0x84, 0xe2, 0x00, 0x20, 0x30, 0x91, 0x05, 0x43, 0x81, 0x04, 0x62, 0x98, \n\t0x92, 0x41, 0x00, 0x64, 0x02, 0x13, 0xa2, 0x0d, 0x40, 0x13, 0x0c, 0x40, 0x25, 0x42, 0xa4, 0x40, \n\t0x19, 0x09, 0x10, 0xa1, 0x6b, 0x10, 0x25, 0x19, 0x04, 0x06, 0xd4, 0xc8, 0x13, 0x28, 0x42, 0x23, \n\t0x26, 0x22, 0x20, 0x09, 0xe0, 0x08, 0x04, 0x00, 0xd5, 0xc2, 0x30, 0x38, 0x54, 0x01, 0x2e, 0x00, \n\t0xa1, 0x14, 0x80, 0x08, 0xc5, 0x4a, 0x10, 0x40, 0x00, 0x60, 0xc6, 0x24, 0x06, 0xd1, 0x20, 0x0a, \n\t0x09, 0x06, 0x0c, 0x28, 0x00, 0x11, 0xa8, 0xc9, 0xc8, 0x02, 0x08, 0x86, 0xb2, 0x21, 0x19, 0x87, \n\t0x62, 0x3c, 0x56, 0x40, 0x0b, 0x24, 0x94, 0xa0, 0x28, 0x44, 0x00, 0x80, 0xb4, 0x08, 0x08, 0x04, \n\t0x47, 0xeb, 0x24, 0xa0, 0x50, 0x64, 0x70, 0xa0, 0x13, 0xb8, 0xc0, 0x01, 0x29, 0x08, 0x90, 0x21, \n\t0x92, 0x54, 0xc1, 0x08, 0x0a, 0x02, 0xe3, 0x21, 0x00, 0x18, 0x44, 0x06, 0x05, 0x00, 0x08, 0x68, \n\t0x10, 0xa4, 0x12, 0x20, 0x5b, 0x3d, 0x2c, 0xd0, 0x45, 0x08, 0x13, 0x03, 0x89, 0x90, 0x82, 0x40, \n\t0x44, 0xd1, 0xe1, 0x22, 0x00, 0xca, 0x02, 0x00, 0x06, 0xb8, 0xb8, 0x00, 0x8f, 0x07, 0x10, 0xc4, \n\t0x58, 0xa8, 0x65, 0x0e, 0x86, 0x4e, 0x00, 0x80, 0x25, 0x81, 0x1d, 0x60, 0x20, 0x63, 0x42, 0x08, \n\t0x25, 0x04, 0x40, 0x56, 0x20, 0x10, 0x80, 0x14, 0x0b, 0x21, 0x32, 0xc3, 0x48, 0x00, 0x24, 0xdb, \n\t0x84, 0x40, 0x91, 0x02, 0x82, 0x98, 0x41, 0x09, 0x64, 0x06, 0x41, 0x86, 0x41, 0xc5, 0x08, 0x2a, \n\t0x00, 0xb8, 0x11, 0x4d, 0x12, 0x41, 0x18, 0xe2, 0x60, 0xa0, 0x11, 0x04, 0x0a, 0x08, 0x80, 0xe0, \n\t0x14, 0x05, 0x91, 0x8f, 0x48, 0x30, 0x82, 0x31, 0x54, 0x01, 0x02, 0x50, 0x00, 0x28, 0x33, 0x68, \n\t0x90, 0x0a, 0x12, 0x24, 0x43, 0x20, 0x04, 0x03, 0x63, 0x70, 0x61, 0x31, 0x10, 0x3c, 0x44, 0x23, \n\t0x30, 0x40, 0x0a, 0x08, 0x8d, 0x45, 0x29, 0x14, 0x10, 0x40, 0x06, 0xc5, 0x40, 0x85, 0x4a, 0x52, \n\t0x08, 0x88, 0xa0, 0x90, 0x09, 0x0e, 0xe4, 0x02, 0x82, 0x71, 0x19, 0x02, 0x42, 0x26, 0x08, 0x3d, \n\t0x01, 0x90, 0x6c, 0x40, 0x31, 0x4b, 0x81, 0xe9, 0x86, 0xa2, 0x0c, 0x94, 0x62, 0x80, 0x41, 0x1b, \n\t0x42, 0x22, 0xc3, 0x00, 0x18, 0x29, 0x0e, 0x24, 0x1e, 0x02, 0x88, 0x8c, 0x0c, 0xc1, 0x28, 0x62, \n\t0x71, 0x01, 0x01, 0x70, 0x85, 0xc2, 0x62, 0x41, 0x01, 0x2e, 0x60, 0x08, 0x0d, 0x12, 0x56, 0xca, \n\t0x80, 0xbc, 0x00, 0x08, 0x00, 0x44, 0x08, 0x8e, 0x41, 0x03, 0xc4, 0x32, 0x22, 0x00, 0x80, 0x94, \n\t0x88, 0x40, 0x50, 0x00, 0xd9, 0x9b, 0x20, 0x42, 0x04, 0x44, 0x90, 0x22, 0x05, 0x5c, 0x43, 0xc4, \n\t0x14, 0xa1, 0xab, 0xae, 0x60, 0x88, 0x83, 0x60, 0x03, 0x02, 0x02, 0x10, 0xd9, 0x4a, 0x06, 0xb7, \n\t0x20, 0x05, 0x68, 0x1c, 0xa0, 0x0e, 0x55, 0x38, 0x38, 0xe0, 0x49, 0x86, 0x10, 0x41, 0x92, 0x20, \n\t0x21, 0x12, 0x83, 0x40, 0x62, 0xa9, 0x38, 0x25, 0x10, 0xcc, 0x40, 0x54, 0xc0, 0x20, 0x0c, 0x84, \n\t0x4a, 0x0c, 0xe3, 0x30, 0x26, 0x55, 0xc6, 0x01, 0x22, 0x44, 0x09, 0x82, 0xa8, 0x54, 0x25, 0x0a, \n\t0x31, 0x62, 0x1e, 0xd8, 0x84, 0x01, 0x6e, 0x82, 0x40, 0x2d, 0x19, 0x00, 0xa0, 0x54, 0x10, 0x11, \n\t0xa0, 0xcc, 0x02, 0x6f, 0x24, 0xf4, 0x02, 0x09, 0x09, 0x59, 0xc5, 0x40, 0x00, 0x30, 0xac, 0x45, \n\t0x08, 0xa1, 0x56, 0x00, 0x52, 0x02, 0x81, 0xc4, 0x24, 0x40, 0x01, 0xa9, 0x32, 0x8c, 0x80, 0x6a, \n\t0x00, 0x81, 0xb1, 0x92, 0x90, 0x15, 0xca, 0x44, 0x63, 0x41, 0x32, 0x00, 0x48, 0x81, 0x1c, 0xa2, \n\t0x08, 0x81, 0x34, 0x1a, 0xcb, 0x28, 0x74, 0x00, 0xa1, 0x0c, 0x90, 0x4c, 0x24, 0xc2, 0x31, 0x01, \n\t0xc8, 0xdb, 0x04, 0x30, 0x14, 0xb1, 0x08, 0x04, 0x05, 0xc4, 0x0a, 0xd0, 0x20, 0x2e, 0x21, 0x0e, \n\t0x41, 0x20, 0x00, 0x50, 0x89, 0x0c, 0x89, 0x20, 0x20, 0x40, 0x12, 0x05, 0x44, 0x93, 0x66, 0x00, \n\t0xc0, 0x80, 0x08, 0xcc, 0x5b, 0x20, 0x08, 0x44, 0x12, 0x82, 0xb5, 0x13, 0x61, 0x12, 0x84, 0x41, \n\t0x04, 0x49, 0x00, 0x09, 0x64, 0x82, 0x03, 0x22, 0xf8, 0x04, 0xa0, 0x2e, 0x83, 0x60, 0x31, 0x15, \n\t0x52, 0x08, 0x08, 0xa5, 0x63, 0x1c, 0x80, 0x06, 0x09, 0x18, 0xa6, 0x49, 0x8c, 0x21, 0x8b, 0xc0, \n\t0x02, 0x16, 0x50, 0x14, 0xa0, 0x11, 0x09, 0x1c, 0x82, 0x80, 0x03, 0x90, 0x80, 0xc3, 0x00, 0x07, \n\t0x33, 0x80, 0x14, 0xc0, 0x0b, 0x48, 0x41, 0x08, 0x8e, 0x10, 0xc8, 0x62, 0x24, 0x07, 0xd0, 0x16, \n\t0x01, 0x42, 0x08, 0x18, 0x75, 0x03, 0x25, 0xe1, 0x01, 0xc3, 0x04, 0x86, 0x20, 0x92, 0x54, 0x01, \n\t0x80, 0x44, 0x42, 0xd8, 0x0a, 0x10, 0x80, 0x6c, 0x28, 0x23, 0x41, 0x22, 0x50, 0x08, 0x00, 0x38, \n\t0x37, 0xc0, 0x00, 0x28, 0x1e, 0x0c, 0x3a, 0x00, 0x19, 0x03, 0x30, 0x11, 0x00, 0x54, 0x04, 0xc2, \n\t0x19, 0xcc, 0x14, 0x01, 0x04, 0xf0, 0x63, 0x8d, 0x2c, 0x0c, 0x69, 0x44, 0x56, 0x02, 0x21, 0x80, \n\t0x12, 0x4c, 0x2c, 0x71, 0x08, 0x38, 0x2c, 0x52, 0xc2, 0x20, 0x80, 0x51, 0x90, 0x80, 0x0f, 0xa6, \n\t0x28, 0x14, 0x00, 0x83, 0x70, 0x4e, 0x00, 0x26, 0x24, 0x8a, 0x16, 0x4d, 0x41, 0xa3, 0x00, 0x00, \n\t0x03, 0x12, 0x68, 0xc7, 0xca, 0x30, 0xa4, 0x20, 0x97, 0x41, 0x0a, 0x80, 0x60, 0xe0, 0x22, 0x8d, \n\t0xa4, 0x5f, 0x04, 0x60, 0x02, 0x9a, 0x82, 0x89, 0xc0, 0x6a, 0x1e, 0x20, 0xa0, 0x34, 0x80, 0x43, \n\t0x44, 0x02, 0x43, 0xc2, 0x20, 0x75, 0x18, 0x05, 0x40, 0x66, 0x10, 0x35, 0x50, 0x02, 0x81, 0x40, \n\t0x52, 0x18, 0x28, 0x0c, 0x92, 0x42, 0x2a, 0x02, 0x80, 0x29, 0x08, 0x96, 0x04, 0x08, 0x20, 0x99, \n\t0x30, 0x91, 0x15, 0x09, 0x36, 0xa6, 0xe0, 0x18, 0x09, 0x14, 0x0f, 0x60, 0x81, 0x40, 0x21, 0x14, \n\t0xcc, 0x02, 0x22, 0x13, 0x08, 0x1c, 0x51, 0x92, 0xc0, 0x08, 0x62, 0x69, 0x8c, 0x04, 0x07, 0x61, \n\t0x48, 0x44, 0xa8, 0x88, 0xc1, 0x03, 0x01, 0x56, 0x00, 0x99, 0x0c, 0x75, 0x02, 0xa8, 0x4a, 0x31, \n\t0xd0, 0x21, 0x99, 0x10, 0x07, 0x44, 0x25, 0x42, 0x33, 0x40, 0x80, 0xa4, 0x22, 0x02, 0xba, 0x00, \n\t0x5c, 0x4c, 0x81, 0x24, 0xc3, 0xc0, 0x09, 0x20, 0x0a, 0xae, 0x06, 0x44, 0x41, 0x95, 0x0d, 0xdc, \n\t0x02, 0x26, 0x02, 0x42, 0x0c, 0xf0, 0x19, 0x43, 0x00, 0x10, 0x18, 0x12, 0xc4, 0xc5, 0x61, 0x22, \n\t0xb5, 0x69, 0x32, 0x10, 0x98, 0x44, 0x52, 0x40, 0x08, 0xb0, 0x24, 0x81, 0x44, 0x74, 0x45, 0xd0, \n\t0x01, 0x89, 0x4b, 0x41, 0x2c, 0x36, 0x20, 0x20, 0x04, 0x96, 0x26, 0x18, 0x72, 0xa2, 0x08, 0x45, \n\t0x82, 0xa0, 0x40, 0x63, 0x03, 0x26, 0xd1, 0x89, 0xaa, 0x24, 0x14, 0x92, 0x15, 0x20, 0xc0, 0x27, \n\t0x70, 0x52, 0x00, 0xb4, 0x21, 0x40, 0x86, 0x16, 0x50, 0x89, 0x91, 0x59, 0x0c, 0x2b, 0x6c, 0x20, \n\t0xe0, 0x30, 0x70, 0x4c, 0xa2, 0x00, 0x32, 0x11, 0x21, 0x54, 0x40, 0x29, 0x0c, 0x84, 0x11, 0xb2, \n\t0xd0, 0x08, 0x84, 0x02, 0x01, 0x69, 0x15, 0x20, 0x99, 0x09, 0x00, 0x12, 0x53, 0x18, 0x21, 0x40, \n\t0x28, 0x6a, 0x94, 0x02, 0x20, 0xed, 0x85, 0x46, 0x4a, 0xc2, 0x30, 0x80, 0x00, 0x8a, 0x43, 0x34, \n\t0x11, 0x21, 0x30, 0x49, 0x83, 0x20, 0x6e, 0x06, 0x20, 0x05, 0x30, 0x41, 0x65, 0x30, 0xd3, 0x98, \n\t0x81, 0x80, 0x41, 0x88, 0x3a, 0x05, 0x80, 0xa2, 0x01, 0xd0, 0x62, 0x60, 0x00, 0x69, 0xa2, 0xcc, \n\t0x51, 0x8e, 0x20, 0x80, 0x10, 0x92, 0x0d, 0x02, 0xa0, 0x14, 0x85, 0x21, 0x29, 0xf0, 0x10, 0x08, \n\t0x5a, 0x41, 0x23, 0x00, 0x14, 0xc8, 0x41, 0x00, 0xc0, 0xa1, 0x0f, 0x28, 0x0c, 0x0e, 0x30, 0x90, \n\t0x90, 0x35, 0x08, 0x07, 0x80, 0x16, 0x80, 0x82, 0x8e, 0x10, 0x80, 0x60, 0x58, 0x14, 0x10, 0x04, \n\t0x41, 0x8a, 0xc6, 0x44, 0x85, 0xa0, 0x8b, 0x04, 0xc0, 0xa1, 0x04, 0x01, 0x8b, 0xb6, 0x61, 0x54, \n\t0x2a, 0x10, 0x70, 0x30, 0x16, 0x89, 0x12, 0x48, 0x4a, 0xa5, 0x81, 0x82, 0x61, 0x01, 0x65, 0x70, \n\t0xa7, 0x43, 0x89, 0x09, 0x40, 0x48, 0x34, 0xb1, 0x21, 0x04, 0xb4, 0xc8, 0x80, 0x00, 0x85, 0x6a, \n\t0x12, 0x18, 0x0e, 0x04, 0x12, 0x46, 0x50, 0x9d, 0x28, 0x8e, 0x0e, 0x0a, 0x20, 0xd1, 0x05, 0x61, \n\t0x03, 0x2a, 0x08, 0x50, 0x98, 0x29, 0xfc, 0x84, 0x88, 0x00, 0x03, 0x80, 0x08, 0x8c, 0x00, 0x00, \n\t0x26, 0x22, 0x0a, 0xb0, 0x1c, 0x99, 0x43, 0x70, 0x54, 0x03, 0x06, 0x28, 0x00, 0x04, 0x78, 0x41, \n\t0x88, 0x07, 0xc8, 0x57, 0x80, 0x24, 0x00, 0x0a, 0x88, 0xc8, 0x01, 0x46, 0x22, 0x36, 0x1b, 0x00, \n\t0xb4, 0x49, 0xe8, 0x2c, 0x23, 0x38, 0x8d, 0xa0, 0x10, 0x8b, 0x10, 0x31, 0x82, 0xb0, 0xb8, 0x8c, \n\t0x25, 0x50, 0x44, 0x62, 0x10, 0x50, 0x1d, 0xc8, 0x34, 0x00, 0x03, 0x08, 0x28, 0x54, 0x09, 0x4e, \n\t0xc2, 0x11, 0xa5, 0x00, 0x04, 0x2c, 0x08, 0xa0, 0x81, 0x39, 0x11, 0x82, 0x04, 0x08, 0x36, 0x88, \n\t0x32, 0x40, 0x87, 0x05, 0x04, 0x81, 0x10, 0x28, 0x2c, 0x45, 0x08, 0x12, 0x35, 0x48, 0x32, 0xb9, \n\t0x46, 0x02, 0x50, 0x21, 0x01, 0x8c, 0x88, 0x08, 0x03, 0x56, 0xb2, 0x50, 0x1b, 0xd4, 0x00, 0xa9, \n\t0x0c, 0x00, 0x58, 0x24, 0x00, 0x97, 0xc2, 0x30, 0x56, 0x03, 0x0a, 0xac, 0x10, 0x60, 0x72, 0x03, \n\t0x31, 0x8c, 0x91, 0xc0, 0x60, 0x2e, 0x20, 0x80, 0x00, 0xd0, 0x10, 0x46, 0x4c, 0xe1, 0x8a, 0x85, \n\t0x10, 0x0e, 0x8c, 0x38, 0x92, 0x12, 0x08, 0x40, 0x42, 0x46, 0x08, 0x21, 0x10, 0x2b, 0x09, 0x1a, \n\t0xa5, 0x50, 0x94, 0xb8, 0x30, 0x24, 0x08, 0x06, 0x20, 0x65, 0x7a, 0xb0, 0x68, 0x00, 0x09, 0x1c, \n\t0x81, 0x88, 0x06, 0x21, 0x0c, 0xc4, 0x32, 0x51, 0x52, 0xb0, 0x81, 0x88, 0x84, 0x18, 0x90, 0x61, \n\t0x9d, 0x01, 0x49, 0xc2, 0x02, 0x00, 0xc0, 0x14, 0x14, 0x9f, 0x60, 0x00, 0x74, 0x00, 0x0b, 0x01, \n\t0x90, 0x84, 0x28, 0x22, 0x09, 0x10, 0x41, 0x43, 0x44, 0x06, 0x70, 0xe0, 0x25, 0x04, 0x1e, 0x24, \n\t0x04, 0x92, 0x50, 0x88, 0x99, 0x40, 0x27, 0x42, 0x82, 0xaa, 0x83, 0x5c, 0xc2, 0x40, 0x24, 0x40, \n\t0x11, 0x2a, 0xc5, 0x11, 0xa2, 0x4e, 0x04, 0x10, 0x01, 0xc4, 0x84, 0x88, 0x02, 0xc5, 0x22, 0x28, \n\t0x50, 0x10, 0xab, 0x00, 0x11, 0x81, 0x82, 0x8c, 0x88, 0x4a, 0x3c, 0x02, 0x50, 0x0e, 0x34, 0x01, \n\t0x88, 0x50, 0x15, 0x29, 0x16, 0x2c, 0x5b, 0x00, 0x08, 0x91, 0x03, 0x04, 0x48, 0x8e, 0x64, 0x16, \n\t0x26, 0x5a, 0x21, 0x0d, 0x50, 0x81, 0x44, 0x21, 0x08, 0x03, 0x0c, 0x94, 0xe0, 0x18, 0x90, 0x22, \n\t0x92, 0x84, 0x40, 0xc9, 0x64, 0xa0, 0x18, 0x04, 0x70, 0x49, 0x82, 0x18, 0x02, 0x19, 0x80, 0x80, \n\t0x85, 0x20, 0x6c, 0x41, 0x0b, 0x21, 0x9d, 0x4e, 0x00, 0x12, 0x40, 0x09, 0x8a, 0x10, 0x08, 0x64, \n\t0x74, 0x44, 0xd3, 0x08, 0x69, 0xc6, 0x08, 0x02, 0x76, 0x68, 0x38, 0x50, 0x91, 0x85, 0x00, 0xd1, \n\t0x42, 0xa5, 0x20, 0x15, 0x04, 0x08, 0x20, 0x79, 0x00, 0x71, 0x45, 0xe2, 0x34, 0x10, 0x11, 0x18, \n\t0x30, 0x94, 0x0e, 0x40, 0x30, 0x2a, 0x25, 0x15, 0x04, 0x25, 0x44, 0x10, 0xc2, 0x0f, 0x9d, 0x80, \n\t0x62, 0x20, 0x52, 0x00, 0x00, 0x20, 0xc6, 0x47, 0x5a, 0x14, 0xb9, 0x9a, 0x8c, 0x83, 0x28, 0x4e, \n\t0x21, 0x19, 0x02, 0x44, 0xd8, 0x81, 0x00, 0xa0, 0x18, 0x12, 0x51, 0x19, 0x09, 0x20, 0x13, 0x88, \n\t0x10, 0x20, 0xc0, 0x40, 0x20, 0x06, 0x19, 0x33, 0x45, 0x02, 0x89, 0x52, 0x20, 0x42, 0x05, 0x88, \n\t0x40, 0x08, 0x10, 0x04, 0x92, 0x10, 0x28, 0x19, 0xe3, 0x2c, 0x10, 0x82, 0x25, 0x20, 0x97, 0x41, \n\t0x10, 0x02, 0x88, 0x00, 0x11, 0x96, 0xce, 0x40, 0x37, 0x80, 0x08, 0x05, 0x02, 0x43, 0x02, 0x31, \n\t0x20, 0x9b, 0x20, 0x0e, 0x06, 0x20, 0x84, 0x78, 0x85, 0xc8, 0x06, 0x8a, 0x08, 0x10, 0x72, 0x25, \n\t0xa0, 0x90, 0xea, 0x3e, 0x82, 0x20, 0x12, 0x71, 0x18, 0x40, 0x04, 0x24, 0x89, 0x0a, 0x60, 0x4b, \n\t0xcd, 0x12, 0x00, 0x40, 0x98, 0x11, 0x15, 0x41, 0x22, 0x52, 0x2a, 0x23, 0x14, 0x81, 0x28, 0x1c, \n\t0x40, 0x23, 0x89, 0x00, 0x11, 0x6e, 0x48, 0x00, 0xb2, 0x1d, 0x14, 0x44, 0x80, 0x56, 0xc1, 0x11, \n\t0x8c, 0x20, 0x9e, 0xac, 0x40, 0x81, 0x31, 0x11, 0x14, 0x8a, 0xc0, 0x02, 0xd0, 0x28, 0x03, 0x08, \n\t0x06, 0x64, 0x44, 0xc3, 0xa1, 0x80, 0x20, 0x84, 0x80, 0x10, 0x45, 0x03, 0x10, 0xc9, 0xc2, 0x20, \n\t0x4a, 0x83, 0x78, 0x1a, 0xc0, 0x0d, 0x49, 0x00, 0x24, 0x90, 0x99, 0xe1, 0x05, 0xa6, 0x14, 0x82, \n\t0x10, 0x80, 0x91, 0xd9, 0x01, 0x00, 0x47, 0x68, 0x09, 0x10, 0x86, 0x08, 0x08, 0x14, 0x40, 0x9f, \n\t0x70, 0xd5, 0x6b, 0x0c, 0x14, 0x4a, 0x01, 0xd0, 0x40, 0x60, 0x02, 0x40, 0x10, 0x22, 0xa5, 0x08, \n\t0x4d, 0x20, 0xe0, 0x00, 0x97, 0x41, 0x4a, 0x8a, 0x06, 0xf1, 0x10, 0x35, 0x14, 0x82, 0x20, 0x68, \n\t0x00, 0x09, 0x34, 0x60, 0x01, 0x86, 0x00, 0x20, 0x40, 0x04, 0xcd, 0x02, 0x43, 0x06, 0x87, 0x03, \n\t0x9a, 0xa8, 0x14, 0xae, 0x62, 0x44, 0x0b, 0x88, 0x34, 0x42, 0x42, 0x20, 0x42, 0x60, 0x81, 0x14, \n\t0xc3, 0x83, 0x10, 0x53, 0x80, 0x11, 0x28, 0x95, 0x64, 0x3c, 0xe6, 0x8b, 0x00, 0x81, 0xd8, 0x81, \n\t0x14, 0xa2, 0x33, 0x20, 0x85, 0x44, 0x40, 0x00, 0x21, 0x1a, 0x09, 0x68, 0x0c, 0x40, 0x40, 0xf5, \n\t0x81, 0x80, 0x0d, 0x5b, 0x26, 0x2a, 0x03, 0x32, 0x22, 0x21, 0x00, 0x05, 0x0a, 0x80, 0xe0, 0x28, \n\t0x8c, 0x86, 0x24, 0x04, 0x01, 0x92, 0x91, 0x2c, 0x44, 0x81, 0x40, 0x26, 0x60, 0xb4, 0x7c, 0x15, \n\t0x49, 0x50, 0x02, 0x80, 0x08, 0x85, 0x86, 0xab, 0x10, 0x42, 0x40, 0x82, 0x94, 0x5d, 0x0f, 0x02, \n\t0x10, 0x6a, 0x19, 0x90, 0x0a, 0x05, 0x20, 0x24, 0xaa, 0x00, 0xd1, 0x04, 0x28, 0x74, 0x22, 0x80, \n\t0x11, 0x60, 0x81, 0xa9, 0x44, 0x00, 0x9b, 0x06, 0x04, 0x00, 0x49, 0x54, 0xe2, 0xf3, 0x09, 0x00, \n\t0xcb, 0xa2, 0x40, 0xa2, 0x08, 0x10, 0x18, 0x90, 0x22, 0x28, 0x50, 0xa9, 0x27, 0x04, 0xd8, 0xae, \n\t0x18, 0x41, 0xe0, 0x00, 0x70, 0x06, 0x82, 0x20, 0xc1, 0x90, 0x02, 0x09, 0x00, 0x06, 0x06, 0xc4, \n\t0xdb, 0x00, 0x08, 0x81, 0x0c, 0x0a, 0x26, 0x50, 0x82, 0xa4, 0x17, 0xc6, 0x28, 0x40, 0x21, 0x27, \n\t0x00, 0x43, 0x2d, 0x44, 0xd7, 0x31, 0x02, 0x09, 0x83, 0x00, 0x2a, 0xb0, 0x70, 0x05, 0x9c, 0x41, \n\t0x47, 0x12, 0xa2, 0x50, 0x22, 0x44, 0x90, 0x00, 0x48, 0x03, 0x11, 0x8e, 0xc9, 0x50, 0x21, 0x66, \n\t0x10, 0xa8, 0x81, 0x04, 0x11, 0xc1, 0x62, 0x91, 0x49, 0x00, 0x44, 0x91, 0x22, 0x0e, 0x24, 0x8a, \n\t0x36, 0xe1, 0x0d, 0x61, 0x6c, 0x44, 0x28, 0xa0, 0x94, 0x18, 0x04, 0x04, 0x81, 0x19, 0x01, 0x38, \n\t0x47, 0x42, 0x30, 0xa4, 0x41, 0x04, 0x05, 0x9a, 0x84, 0x50, 0x32, 0x29, 0x0c, 0x10, 0x08, 0x08, \n\t0x66, 0x21, 0x20, 0x85, 0xc8, 0x8c, 0x04, 0x06, 0x12, 0x40, 0x35, 0x19, 0x96, 0x04, 0x12, 0x52, \n\t0xd2, 0x08, 0xb0, 0x14, 0xa7, 0x40, 0x00, 0x53, 0x1f, 0x08, 0x03, 0xe1, 0x28, 0x81, 0x00, 0x3e, \n\t0x01, 0xdb, 0x42, 0x5c, 0x05, 0x61, 0xad, 0x00, 0xc0, 0x0c, 0x14, 0x20, 0x18, 0x93, 0x0c, 0x52, \n\t0x89, 0x24, 0xe0, 0x82, 0x0e, 0x04, 0x40, 0x6d, 0x32, 0xb6, 0x4a, 0xaa, 0x91, 0x00, 0x41, 0x04, \n\t0x00, 0x01, 0x12, 0x65, 0x8c, 0x00, 0x12, 0x51, 0x88, 0xbb, 0xa4, 0x0c, 0x21, 0x48, 0xa1, 0x10, \n\t0x0e, 0x48, 0x8a, 0x24, 0x54, 0x02, 0x61, 0x38, 0x31, 0x00, 0x88, 0x00, 0x42, 0xc9, 0x0e, 0x0c, \n\t0x82, 0x40, 0x0c, 0x22, 0x51, 0x04, 0x90, 0x00, 0x6c, 0x22, 0x24, 0x88, 0x9c, 0x04, 0x04, 0x42, \n\t0x40, 0x01, 0x23, 0x01, 0x88, 0x05, 0x20, 0x0a, 0x70, 0xa2, 0xa6, 0x00, 0x11, 0x68, 0x38, 0x24, \n\t0xa0, 0x30, 0xa1, 0x41, 0x4d, 0x20, 0xf0, 0x90, 0x00, 0x15, 0x40, 0xc0, 0x02, 0xe4, 0x59, 0x2c, \n\t0xe0, 0xd7, 0x08, 0x3a, 0x90, 0x8b, 0xaa, 0x20, 0x08, 0x08, 0x00, 0xd2, 0x02, 0x04, 0xe1, 0xc0, \n\t0x00, 0x38, 0x04, 0xe9, 0x08, 0xb8, 0x47, 0x86, 0x40, 0x00, 0x32, 0x23, 0x99, 0x00, 0x05, 0x0c, \n\t0x57, 0x10, 0x30, 0x55, 0x59, 0x8a, 0x48, 0x84, 0x90, 0x33, 0x3c, 0x04, 0xc1, 0x6a, 0x12, 0xc1, \n\t0x00, 0x85, 0x5a, 0x06, 0x30, 0x44, 0x98, 0x34, 0x19, 0x18, 0x22, 0x32, 0x24, 0x70, 0x24, 0xa0, \n\t0x0c, 0x23, 0x44, 0x51, 0x00, 0x29, 0x51, 0x43, 0x00, 0x10, 0x21, 0x10, 0x21, 0x00, 0x14, 0x42, \n\t0x62, 0x84, 0x01, 0x00, 0x38, 0x1b, 0x68, 0x10, 0x73, 0x52, 0x02, 0x00, 0x11, 0x21, 0x06, 0x90, \n\t0x01, 0x05, 0x60, 0x04, 0x62, 0x00, 0x00, 0x80, 0xa0, 0x41, 0x1e, 0xcc, 0x00, 0x03, 0xf0, 0xb8, \n\t0x4c, 0x08, 0x20, 0x0c, 0x01, 0x20, 0x08, 0x7c, 0x06, 0x24, 0x40, 0x93, 0x4b, 0x80, 0x45, 0xc7, \n\t0x84, 0x46, 0x25, 0x11, 0x00, 0xd0, 0x89, 0x02, 0x18, 0xc2, 0xf0, 0x02, 0x08, 0x1c, 0xac, 0x42, \n\t0xd4, 0x48, 0x10, 0xac, 0xc4, 0x02, 0x1a, 0x11, 0x49, 0x19, 0x00, 0xcd, 0xc0, 0x5a, 0x47, 0xa2, \n\t0xa9, 0x08, 0x00, 0x01, 0x24, 0x21, 0x60, 0x10, 0x40, 0x52, 0xec, 0x00, 0x04, 0x00, 0x19, 0x50, \n\t0x11, 0x8d, 0x1a, 0x30, 0x9a, 0x03, 0x80, 0x80, 0xc7, 0x20, 0x03, 0x90, 0x03, 0x98, 0x88, 0x2f, \n\t0x0e, 0x34, 0x08, 0x15, 0x68, 0xd5, 0x26, 0x24, 0x80, 0x50, 0x81, 0x04, 0x57, 0xa0, 0x60, 0x01, \n\t0x31, 0x15, 0xb4, 0x92, 0x00, 0x06, 0xe0, 0x40, 0x30, 0x01, 0x59, 0x48, 0x04, 0x86, 0x49, 0x99, \n\t0xc0, 0x08, 0x4b, 0x26, 0x81, 0x48, 0x0e, 0x44, 0x14, 0x43, 0x22, 0x26, 0x82, 0x2e, 0x00, 0x81, \n\t0x40, 0x68, 0xa1, 0x51, 0x84, 0x58, 0x86, 0xc0, 0x20, 0xa2, 0x92, 0x28, 0x44, 0x84, 0x03, 0x5c, \n\t0x50, 0x90, 0x02, 0x6c, 0x04, 0xaf, 0x70, 0x16, 0x32, 0x06, 0x91, 0x81, 0xa8, 0x00, 0xb0, 0x28, \n\t0x23, 0x30, 0x01, 0x40, 0x60, 0x81, 0x08, 0xa9, 0x41, 0x10, 0x0a, 0x2a, 0x74, 0x29, 0x97, 0xa0, \n\t0x52, 0x8a, 0x1c, 0x40, 0xa2, 0x38, 0x9c, 0x10, 0x07, 0x02, 0xc0, 0x02, 0x01, 0x50, 0x4e, 0x0b, \n\t0x00, 0x06, 0x21, 0xad, 0x24, 0x53, 0x44, 0x4a, 0x96, 0x8b, 0x20, 0x10, 0x9c, 0x40, 0x24, 0xa3, \n\t0x89, 0x19, 0x70, 0x01, 0x22, 0x14, 0x10, 0x98, 0x00, 0x21, 0x95, 0x09, 0x4a, 0x91, 0x49, 0x22, \n\t0xc5, 0x04, 0x27, 0x60, 0x65, 0xe2, 0x20, 0x80, 0x02, 0x00, 0x24, 0x22, 0xaa, 0x96, 0x64, 0x84, \n\t0x02, 0x4e, 0xc0, 0x0a, 0x18, 0xe0, 0x80, 0x04, 0x58, 0x04, 0x51, 0x25, 0x81, 0x98, 0x40, 0x0e, \n\t0x20, 0x90, 0x0a, 0xc8, 0x0d, 0x08, 0x42, 0x21, 0x81, 0x12, 0x00, 0xca, 0x00, 0x36, 0x82, 0x58, \n\t0x20, 0x15, 0x01, 0xca, 0x48, 0x21, 0x41, 0x01, 0xb0, 0x00, 0x20, 0x06, 0x80, 0x18, 0x04, 0x00, \n\t0x92, 0x09, 0x28, 0x24, 0x01, 0x0c, 0x74, 0x05, 0x42, 0x18, 0x90, 0x61, 0x2b, 0x09, 0x16, 0x45, \n\t0x44, 0xa2, 0xc0, 0x1a, 0x14, 0x01, 0x00, 0x00, 0x40, 0x22, 0x9d, 0x45, 0x4b, 0x84, 0x12, 0x05, \n\t0xea, 0x04, 0xcc, 0x0a, 0x08, 0x20, 0x40, 0x09, 0x02, 0x6c, 0x83, 0x80, 0x00, 0x00, 0x30, 0x90, \n\t0x99, 0x00, 0x4d, 0x30, 0x41, 0x9a, 0x03, 0x65, 0xc5, 0x29, 0x38, 0x10, 0x50, 0x24, 0x61, 0x80, \n\t0x44, 0x02, 0xd2, 0xc0, 0x80, 0x20, 0x02, 0x20, 0x02, 0x54, 0x63, 0x10, 0xb0, 0x15, 0x85, 0x48, \n\t0xa2, 0x03, 0x10, 0x95, 0xd0, 0x00, 0x08, 0xc1, 0xe3, 0x0c, 0x40, 0x16, 0x66, 0x40, 0x45, 0x11, \n\t0x89, 0x00, 0x00, 0x8e, 0x42, 0x93, 0xb0, 0x28, 0x69, 0xd0, 0xe2, 0x22, 0x07, 0x11, 0x0c, 0x2c, \n\t0x98, 0x80, 0x48, 0x04, 0x10, 0x14, 0xdd, 0x8e, 0x01, 0x08, 0x07, 0xe2, 0x8e, 0x08, 0x00, 0x6a, \n\t0x30, 0x11, 0x40, 0x03, 0x40, 0x85, 0x26, 0x08, 0x06, 0x18, 0x0a, 0x40, 0x82, 0x01, 0x28, 0x50, \n\t0x29, 0xa3, 0xa0, 0xc3, 0x68, 0x54, 0xa2, 0x98, 0x88, 0x20, 0x00, 0x2e, 0x46, 0x26, 0xa0, 0x00, \n\t0x1c, 0x41, 0x04, 0x14, 0x02, 0x42, 0x80, 0x89, 0x1e, 0xa9, 0x44, 0xc5, 0x92, 0xb0, 0x80, 0xca, \n\t0xa0, 0x08, 0x76, 0xb0, 0xa8, 0x40, 0xcf, 0x83, 0x2a, 0xc0, 0x58, 0x3e, 0x0c, 0x04, 0x84, 0x0e, \n\t0x51, 0xc0, 0x13, 0x81, 0x59, 0xe8, 0x40, 0x42, 0x19, 0x0a, 0x38, 0x40, 0xc6, 0x22, 0x40, 0x11, \n\t0x80, 0x41, 0x01, 0x66, 0x2e, 0xa1, 0x08, 0x31, 0x50, 0x0a, 0x89, 0x00, 0x07, 0x40, 0x13, 0x00, \n\t0x41, 0x28, 0x02, 0xc0, 0x0b, 0x85, 0x11, 0xd8, 0x28, 0x2e, 0x82, 0xa2, 0x24, 0xb0, 0x50, 0x67, \n\t0x56, 0x80, 0x03, 0x8f, 0x28, 0x00, 0x05, 0x24, 0x81, 0xc0, 0x12, 0x4c, 0x82, 0x04, 0x0a, 0x16, \n\t0xb0, 0x8a, 0x51, 0x00, 0x80, 0x14, 0x41, 0x53, 0x0e, 0x29, 0x4a, 0x08, 0x14, 0x14, 0x22, 0xa5, \n\t0x24, 0x46, 0x41, 0x02, 0x01, 0x40, 0x84, 0x64, 0x04, 0xc4, 0x04, 0x92, 0x99, 0x08, 0xa8, 0x89, \n\t0x2a, 0x10, 0x40, 0x21, 0x14, 0xa0, 0x18, 0xc8, 0x48, 0xa4, 0x49, 0xa1, 0x00, 0x47, 0x41, 0x28, \n\t0x86, 0x88, 0x0e, 0x80, 0x48, 0xa1, 0x64, 0x12, 0x72, 0x28, 0x40, 0x53, 0x48, 0x52, 0xb2, 0x02, \n\t0x00, 0xd8, 0x90, 0x48, 0x20, 0x36, 0xc2, 0x25, 0x80, 0x09, 0x25, 0x2c, 0x12, 0x88, 0x98, 0x69, \n\t0x1c, 0x04, 0x12, 0x14, 0xe2, 0x90, 0x68, 0x06, 0x88, 0x38, 0x00, 0x23, 0x01, 0x90, 0x15, 0xa0, \n\t0x1e, 0x04, 0x31, 0xa6, 0x71, 0x40, 0x0a, 0x50, 0xd4, 0x41, 0x08, 0x08, 0x0a, 0x04, 0x2c, 0x15, \n\t0x00, 0x8a, 0x40, 0x10, 0x8a, 0x70, 0xb0, 0x81, 0x22, 0x14, 0x0b, 0x25, 0x12, 0x15, 0x0a, 0x00, \n\t0x30, 0x81, 0xcc, 0x08, 0x30, 0x61, 0x18, 0xdc, 0xc4, 0x60, 0x14, 0x83, 0x78, 0xa1, 0x00, 0x82, \n\t0x83, 0x08, 0x52, 0xb0, 0x06, 0x0c, 0x02, 0x29, 0x00, 0x14, 0x2a, 0x90, 0x0d, 0x11, 0x64, 0x42, \n\t0x02, 0x40, 0x21, 0x80, 0x45, 0x06, 0x08, 0x04, 0x4b, 0x04, 0x30, 0x50, 0x40, 0x26, 0x64, 0xe2, \n\t0x04, 0xc5, 0x0c, 0xc8, 0x30, 0xc6, 0x02, 0x0b, 0x18, 0x4f, 0x80, 0x28, 0x84, 0x20, 0x29, 0x85, \n\t0x8e, 0x0b, 0x58, 0x24, 0x80, 0x01, 0x14, 0x55, 0x04, 0x02, 0xc1, 0xb0, 0x80, 0xc0, 0x80, 0x8b, \n\t0x42, 0x82, 0x59, 0x34, 0x4c, 0xc0, 0xc0, 0x12, 0x53, 0x39, 0x20, 0x84, 0x0a, 0xc5, 0x18, 0x91, \n\t0x20, 0xa3, 0x50, 0x48, 0x43, 0x4a, 0x10, 0x3a, 0xb2, 0x11, 0x89, 0x42, 0x18, 0x10, 0xe0, 0x93, \n\t0x40, 0x02, 0xa6, 0x64, 0x04, 0x08, 0x87, 0x18, 0xc3, 0x00, 0x16, 0x07, 0x20, 0x2a, 0x04, 0x09, \n\t0x44, 0x22, 0xa2, 0x83, 0xb0, 0x29, 0xc1, 0x40, 0x20, 0xa3, 0x01, 0x07, 0x81, 0x5c, 0x42, 0x00, \n\t0x45, 0x21, 0x83, 0xac, 0x13, 0x25, 0x0e, 0x80, 0x80, 0x01, 0x49, 0x14, 0x8b, 0x10, 0x16, 0x62, \n\t0x10, 0x14, 0x82, 0x07, 0x48, 0xb0, 0xe9, 0x09, 0x80, 0x9a, 0x88, 0x70, 0xe0, 0xc0, 0x0d, 0x8d, \n\t0x03, 0x84, 0x04, 0xd1, 0x20, 0x82, 0x25, 0x07, 0x62, 0x68, 0x11, 0x10, 0x20, 0x20, 0x01, 0x06, \n\t0x14, 0x40, 0x72, 0x12, 0x11, 0xd4, 0x20, 0x10, 0x65, 0x72, 0x10, 0xc8, 0x04, 0x8a, 0x04, 0x04, \n\t0x0a, 0x98, 0x08, 0xc8, 0x20, 0x04, 0x12, 0x48, 0x85, 0x70, 0x10, 0xc3, 0x08, 0x25, 0x80, 0x18, \n\t0x00, 0x1c, 0x40, 0x1e, 0x20, 0x00, 0x13, 0xa1, 0x43, 0xe0, 0x1e, 0x04, 0xc3, 0x18, 0xc4, 0x00, \n\t0x69, 0x44, 0x00, 0x20, 0xaf, 0xa0, 0x04, 0x0a, 0x00, 0x01, 0x43, 0x3c, 0x11, 0x10, 0x66, 0x48, \n\t0x82, 0x20, 0x0f, 0x1c, 0x0c, 0x44, 0x38, 0x13, 0xa8, 0x14, 0x24, 0x8f, 0x80, 0x06, 0x60, 0x72, \n\t0x00, 0x90, 0x84, 0x01, 0x12, 0x61, 0x50, 0x2e, 0xbc, 0x04, 0x24, 0x64, 0x90, 0x48, 0x28, 0x49, \n\t0x83, 0xa0, 0x10, 0x54, 0x19, 0x1b, 0xa5, 0x01, 0x08, 0x52, 0xf6, 0x00, 0x07, 0xac, 0x09, 0x40, \n\t0x24, 0x42, 0xd8, 0x8a, 0xd1, 0x99, 0x88, 0x6e, 0x90, 0x08, 0x04, 0x00, 0x50, 0x0c, 0x18, 0x73, \n\t0x09, 0x85, 0x24, 0x84, 0x6a, 0x00, 0xc0, 0x83, 0xa1, 0x85, 0x5a, 0x40, 0x42, 0x64, 0x82, 0x30, \n\t0x31, 0x48, 0x05, 0x14, 0xd1, 0x7a, 0x00, 0x0d, 0x10, 0x20, 0x42, 0x20, 0xc0, 0x26, 0x84, 0x0c, \n\t0xc3, 0x1c, 0x20, 0x51, 0x10, 0xa9, 0x19, 0x21, 0x14, 0x22, 0x41, 0xa8, 0x90, 0x0d, 0xe9, 0x10, \n\t0x64, 0x29, 0xbd, 0x31, 0xc4, 0x46, 0x28, 0x40, 0x0a, 0x9a, 0x88, 0xc4, 0x20, 0x28, 0x21, 0xc2, \n\t0x80, 0x40, 0x86, 0x03, 0x38, 0x96, 0x83, 0x08, 0x39, 0xd0, 0x0c, 0x1a, 0x81, 0x78, 0x2a, 0x51, \n\t0x06, 0xc7, 0x00, 0x13, 0x91, 0x05, 0x01, 0x59, 0x4c, 0x00, 0xc1, 0x02, 0x86, 0x15, 0x5f, 0x84, \n\t0x22, 0x56, 0x62, 0xa3, 0x84, 0x10, 0x00, 0x7a, 0x01, 0xa1, 0x11, 0x91, 0x92, 0xa0, 0x48, 0x20, \n\t0x28, 0x98, 0x10, 0x45, 0xa4, 0x04, 0x81, 0x02, 0x3a, 0x88, 0x01, 0x08, 0x24, 0xc3, 0x20, 0x34, \n\t0x84, 0x5c, 0x40, 0x20, 0xf6, 0x22, 0x10, 0xbc, 0x02, 0x21, 0x02, 0x44, 0x38, 0x0b, 0x98, 0x82, \n\t0x60, 0x2e, 0x96, 0x88, 0x05, 0x44, 0x45, 0xca, 0x0c, 0x00, 0x0a, 0x82, 0xe9, 0x00, 0x61, 0x58, \n\t0x00, 0x11, 0x15, 0x10, 0x13, 0x21, 0x26, 0x02, 0x08, 0x80, 0x41, 0x96, 0x04, 0x28, 0x01, 0x81, \n\t0x0d, 0x21, 0x99, 0x00, 0x42, 0x71, 0x82, 0xa2, 0xc0, 0x45, 0x60, 0x38, 0x40, 0xd2, 0x80, 0x80, \n\t0x58, 0x43, 0x06, 0xe1, 0x13, 0x22, 0xe8, 0x08, 0x00, 0x00, 0x40, 0x00, 0x1d, 0x20, 0x5b, 0x44, \n\t0x42, 0x12, 0x4b, 0x28, 0x10, 0x0c, 0x0c, 0x54, 0xc2, 0xc0, 0x0e, 0x10, 0xc7, 0x00, 0x70, 0xa0, \n\t0x60, 0x30, 0x3c, 0x82, 0x03, 0x48, 0x40, 0x12, 0x2c, 0x7c, 0x80, 0x86, 0x20, 0x02, 0x12, 0x21, \n\t0x49, 0x01, 0xe9, 0x68, 0x12, 0xb8, 0x28, 0x04, 0xd0, 0x82, 0x54, 0x42, 0x89, 0x9b, 0x40, 0x52, \n\t0x84, 0x1e, 0x21, 0xe0, 0x22, 0x85, 0x15, 0x80, 0x4c, 0x84, 0x81, 0x04, 0xc0, 0x09, 0x0a, 0x42, \n\t0x46, 0x81, 0x22, 0x40, 0x89, 0x26, 0x16, 0x94, 0x49, 0x11, 0x94, 0x41, 0x0f, 0x00, 0x40, 0xa0, \n\t0x2d, 0x28, 0x40, 0x2d, 0x18, 0x11, 0x1b, 0x19, 0x18, 0x92, 0x81, 0x26, 0x26, 0x0b, 0x00, 0x0c, \n\t0x91, 0x0c, 0x46, 0xe0, 0x20, 0x0c, 0x31, 0x8a, 0x08, 0x14, 0x90, 0x12, 0x3a, 0x11, 0x53, 0x25, \n\t0x00, 0x85, 0x22, 0x11, 0x05, 0x40, 0x80, 0x20, 0x96, 0x40, 0x83, 0x41, 0x8d, 0x28, 0x00, 0x40, \n\t0xe2, 0x04, 0x08, 0xc6, 0x08, 0x10, 0xa2, 0x98, 0x12, 0x29, 0x00, 0x29, 0x24, 0x54, 0x80, 0x82, \n\t0x25, 0x03, 0x45, 0x16, 0x00, 0x18, 0x90, 0x30, 0x11, 0x0a, 0x30, 0x84, 0x21, 0x06, 0x08, 0x0c, \n\t0x60, 0x22, 0x14, 0xc2, 0x82, 0x38, 0x54, 0xc0, 0x6a, 0x84, 0x11, 0x3c, 0x00, 0x10, 0x8c, 0x48, \n\t0x82, 0x8a, 0x8d, 0x65, 0x88, 0x40, 0x00, 0x42, 0x33, 0x25, 0x5c, 0x09, 0x01, 0x00, 0x03, 0x20, \n\t0x3f, 0x50, 0x0a, 0xe6, 0x04, 0x40, 0x38, 0x00, 0x0d, 0xd0, 0x8e, 0x50, 0x40, 0x61, 0x04, 0x20, \n\t0x4c, 0x83, 0x24, 0x26, 0x28, 0x06, 0xc0, 0x00, 0x88, 0x04, 0x72, 0x12, 0x19, 0x81, 0x84, 0x43, \n\t0x26, 0x10, 0x18, 0x90, 0x21, 0x93, 0x04, 0x08, 0xa3, 0x89, 0x27, 0x04, 0x84, 0x68, 0x00, 0x93, \n\t0x43, 0x81, 0x71, 0x84, 0x0c, 0x10, 0xb4, 0xe0, 0x21, 0xc1, 0x52, 0x2e, 0x02, 0x10, 0x00, 0x00, \n\t0xc1, 0x08, 0x00, 0x68, 0x80, 0xd2, 0x01, 0x00, 0x00, 0xa5, 0x0e, 0x85, 0x32, 0x8c, 0x01, 0x40, \n\t0x82, 0x20, 0x95, 0x8b, 0x92, 0x40, 0x1c, 0x08, 0x54, 0x30, 0x40, 0x36, 0x34, 0x09, 0x82, 0x06, \n\t0x84, 0xf2, 0xac, 0x84, 0x18, 0x21, 0x32, 0xd0, 0x41, 0x11, 0xb0, 0x82, 0x43, 0x12, 0x50, 0x08, \n\t0x0a, 0x80, 0x0b, 0x02, 0x50, 0x06, 0x60, 0xa6, 0x04, 0x51, 0x08, 0x02, 0x84, 0x1b, 0x91, 0x79, \n\t0x01, 0x8c, 0x44, 0x30, 0xa2, 0x00, 0x20, 0x16, 0x82, 0x48, 0x10, 0x00, 0x21, 0x09, 0x08, 0x22, \n\t0x08, 0x20, 0x62, 0x30, 0x99, 0x89, 0x4a, 0x26, 0x07, 0xb2, 0x0a, 0x01, 0x02, 0xc4, 0x2c, 0x03, \n\t0xd0, 0x22, 0xc4, 0x94, 0x80, 0x5a, 0x14, 0xc0, 0x15, 0x49, 0x86, 0x28, 0x0a, 0xa2, 0x43, 0x24, \n\t0x24, 0x14, 0x01, 0x16, 0x60, 0xd0, 0x2b, 0x45, 0x09, 0x04, 0x16, 0xa1, 0x48, 0x1e, 0xa4, 0x14, \n\t0xc0, 0x48, 0x00, 0x42, 0x8b, 0x90, 0xcd, 0x40, 0x68, 0xc2, 0x02, 0x91, 0x00, 0x4c, 0xc8, 0x24, \n\t0x12, 0x4b, 0x28, 0x21, 0x04, 0x48, 0x12, 0x10, 0x82, 0x87, 0x01, 0x9a, 0xa1, 0x14, 0x60, 0x41, \n\t0x8b, 0xd0, 0x08, 0xa8, 0x22, 0x20, 0x02, 0x8c, 0x69, 0x88, 0x06, 0x58, 0x05, 0xa3, 0x27, 0x48, \n\t0x15, 0xaa, 0x20, 0x40, 0x50, 0x30, 0x2c, 0x0c, 0x08, 0x6c, 0x82, 0x21, 0x8a, 0x29, 0x58, 0x0d, \n\t0x40, 0x91, 0xd3, 0x00, 0x05, 0x02, 0x2e, 0x24, 0x11, 0x11, 0xb5, 0xc0, 0x94, 0x08, 0x02, 0x60, \n\t0x20, 0x08, 0x88, 0x0f, 0x25, 0x46, 0xc4, 0x42, 0x12, 0x18, 0x41, 0x2d, 0x10, 0x04, 0x12, 0x25, \n\t0x20, 0xc1, 0xe0, 0x44, 0x30, 0xd0, 0x2a, 0x1c, 0x06, 0x62, 0x38, 0x73, 0x81, 0xa0, 0x4c, 0x01, \n\t0x08, 0x60, 0x16, 0x02, 0x95, 0x3c, 0x51, 0xa1, 0x58, 0x12, 0x71, 0x2d, 0x60, 0x98, 0x08, 0x68, \n\t0x00, 0x12, 0x01, 0x50, 0x54, 0x00, 0x02, 0x87, 0xa9, 0x32, 0x19, 0x00, 0x82, 0x00, 0x41, 0x02, \n\t0xa1, 0x00, 0x0d, 0xe0, 0x10, 0x82, 0x50, 0x88, 0x75, 0x8c, 0x8c, 0x42, 0x16, 0x48, 0x19, 0x28, \n\t0x00, 0x08, 0x00, 0x94, 0x08, 0x11, 0x00, 0x1b, 0x83, 0x12, 0x20, 0x08, 0x2c, 0x2c, 0xc2, 0x60, \n\t0x10, 0x82, 0xb8, 0x02, 0x09, 0x04, 0x04, 0x38, 0x61, 0x51, 0x36, 0x04, 0x82, 0xe0, 0x06, 0xa1, \n\t0x0a, 0x8c, 0x11, 0xc3, 0x42, 0x0c, 0x17, 0x42, 0x84, 0x28, 0x03, 0x86, 0x4c, 0x70, 0x3b, 0x15, \n\t0xf8, 0xc8, 0x40, 0x10, 0xe1, 0xc8, 0xa0, 0x14, 0x41, 0x24, 0x64, 0x92, 0x41, 0x2b, 0x31, 0x09, \n\t0x41, 0x0c, 0x80, 0x40, 0x80, 0x85, 0x10, 0x82, 0x22, 0x52, 0xc8, 0x12, 0x38, 0x46, 0x65, 0x16, \n\t0x26, 0x20, 0x98, 0x61, 0x00, 0x29, 0x04, 0x94, 0xab, 0x28, 0x09, 0x00, 0x23, 0x02, 0xf0, 0x02, \n\t0x84, 0xe0, 0x0a, 0x05, 0x40, 0x20, 0xf0, 0x3b, 0x8c, 0x18, 0x4f, 0x44, 0xc0, 0x08, 0x2c, 0x20, \n\t0x42, 0x20, 0x00, 0x01, 0x02, 0xa9, 0x41, 0x03, 0x00, 0x52, 0x20, 0x72, 0x02, 0x80, 0xc2, 0x0a, \n\t0x64, 0x47, 0x92, 0x04, 0x49, 0x14, 0x03, 0x74, 0x80, 0x10, 0x83, 0x8c, 0x09, 0x29, 0x0e, 0x50, \n\t0x29, 0x04, 0x81, 0x1f, 0x49, 0x08, 0x85, 0xc0, 0x8c, 0x00, 0xd5, 0x41, 0x32, 0x46, 0xe1, 0x82, \n\t0x20, 0x90, 0xa6, 0x22, 0x80, 0xa8, 0x08, 0xf5, 0x43, 0x05, 0x18, 0x22, 0x41, 0x04, 0xc0, 0x00, \n\t0x0e, 0x1c, 0x12, 0xa0, 0x84, 0x44, 0xd9, 0x2c, 0x2a, 0xc7, 0x20, 0x2b, 0x04, 0x1b, 0x00, 0x3e, \n\t0x10, 0x00, 0x14, 0xc5, 0x05, 0x84, 0x04, 0x55, 0x22, 0x04, 0x08, 0xd1, 0xa8, 0x5a, 0x41, 0x12, \n\t0x9e, 0xf4, 0x08, 0x04, 0x50, 0x05, 0x48, 0x90, 0x0d, 0x07, 0x40, 0x08, 0x74, 0x28, 0x80, 0x81, \n\t0x16, 0x08, 0x0a, 0x80, 0x08, 0x0c, 0x04, 0xc9, 0x41, 0x7a, 0x65, 0x43, 0x82, 0x21, 0x92, 0x61, \n\t0x04, 0x94, 0xc1, 0x08, 0x00, 0x54, 0x01, 0x54, 0xa2, 0xe1, 0x01, 0x3c, 0x80, 0xa0, 0x04, 0x12, \n\t0xa2, 0x98, 0x80, 0x49, 0x4c, 0x62, 0x26, 0x02, 0x04, 0x28, 0x48, 0xa4, 0x04, 0x91, 0x4a, 0xa8, \n\t0x49, 0x11, 0x80, 0x00, 0x30, 0x69, 0x06, 0xf4, 0x93, 0x01, 0x08, 0x03, 0x11, 0x00, 0x51, 0x40, \n\t0x40, 0x12, 0x20, 0xd1, 0xba, 0x8d, 0x06, 0x40, 0x28, 0xe4, 0x10, 0x86, 0x85, 0xc8, 0x42, 0x02, \n\t0xc1, 0x20, 0x00, 0x90, 0x5b, 0x01, 0x14, 0x10, 0x20, 0x07, 0xe0, 0x81, 0x0a, 0x02, 0xb6, 0x39, \n\t0x19, 0x80, 0x10, 0x29, 0x48, 0x43, 0x2b, 0x0b, 0xc0, 0x84, 0x64, 0x34, 0xb6, 0x42, 0x14, 0x80, \n\t0x48, 0x26, 0x2e, 0xd1, 0x00, 0x33, 0x14, 0x11, 0x20, 0x02, 0x52, 0x82, 0xa9, 0x45, 0x08, 0xaa, \n\t0x18, 0x00, 0x21, 0x91, 0x9d, 0x12, 0x80, 0x4c, 0xa6, 0xd2, 0x90, 0x40, 0x19, 0x0f, 0x40, 0x64, \n\t0x01, 0x10, 0x68, 0x04, 0x45, 0x20, 0xb2, 0x18, 0x06, 0x20, 0x94, 0x8a, 0x30, 0x90, 0x03, 0xb4, \n\t0x2c, 0x83, 0x69, 0x20, 0x14, 0x50, 0x90, 0x30, 0x09, 0x43, 0x30, 0x80, 0x12, 0x18, 0xc1, 0x95, \n\t0x62, 0x40, 0x52, 0x70, 0x0c, 0x8c, 0x84, 0x89, 0x08, 0xc4, 0x00, 0x09, 0x04, 0x09, 0x00, 0x60, \n\t0xc5, 0x30, 0xa7, 0x60, 0x81, 0x20, 0x32, 0x06, 0x00, 0x99, 0x09, 0x04, 0x0c, 0x18, 0x61, 0x08, \n\t0x10, 0x25, 0x41, 0xc0, 0x14, 0x03, 0x20, 0x02, 0x10, 0x4d, 0x08, 0x04, 0x07, 0x01, 0x33, 0x74, \n\t0xce, 0x22, 0x00, 0x61, 0x61, 0x38, 0x05, 0x0c, 0x46, 0x60, 0xf0, 0x41, 0x02, 0x84, 0x04, 0x08, \n\t0x3e, 0x60, 0x30, 0x0a, 0xa1, 0x41, 0xee, 0x16, 0x02, 0xd8, 0x04, 0x20, 0x83, 0x01, 0x00, 0x01, \n\t0x5b, 0x04, 0x34, 0x08, 0xa0, 0x70, 0xc0, 0xa0, 0x33, 0x5c, 0xd8, 0x03, 0x48, 0x00, 0x3a, 0x1b, \n\t0x00, 0x87, 0x41, 0x70, 0x80, 0x88, 0x00, 0x85, 0x00, 0x8c, 0x28, 0x24, 0xbb, 0x00, 0xe0, 0x50, \n\t0x4b, 0x00, 0x85, 0x10, 0x36, 0x48, 0x49, 0x20, 0x00, 0x14, 0x02, 0x12, 0x08, 0x40, 0xa4, 0x32, \n\t0x04, 0x11, 0x1b, 0x21, 0x0f, 0x80, 0x30, 0x83, 0x62, 0x86, 0x38, 0xd2, 0x25, 0x46, 0xb4, 0x00, \n\t0x89, 0x79, 0x84, 0x0e, 0x40, 0x14, 0x1a, 0x0c, 0xb4, 0x97, 0x4b, 0x0c, 0xf1, 0x00, 0x06, 0x0d, \n\t0x84, 0x02, 0x40, 0x00, 0x80, 0xb2, 0x88, 0x48, 0x02, 0x08, 0x51, 0x08, 0x90, 0x1c, 0x48, 0xa4, \n\t0x0c, 0x80, 0x08, 0xb4, 0x88, 0x8f, 0xa8, 0x64, 0x14, 0x69, 0x33, 0x81, 0x82, 0x23, 0x26, 0x46, \n\t0x8a, 0x02, 0x54, 0x08, 0xc9, 0x10, 0x33, 0x12, 0xa1, 0xc0, 0x86, 0xc0, 0x34, 0x20, 0x40, 0x09, \n\t0x10, 0x51, 0x07, 0x70, 0x41, 0x82, 0x81, 0x10, 0x1e, 0x0c, 0x3a, 0x47, 0x61, 0x02, 0x48, 0x43, \n\t0xcb, 0x0a, 0x02, 0xf1, 0x1c, 0x60, 0x10, 0x05, 0x16, 0x51, 0xaa, 0x88, 0x45, 0x98, 0x82, 0x64, \n\t0x91, 0xb0, 0x32, 0x08, 0x83, 0x01, 0x40, 0xd3, 0x00, 0x39, 0x40, 0x92, 0x40, 0x42, 0x81, 0xe1, \n\t0x08, 0x88, 0xc5, 0x2a, 0x0a, 0x05, 0x50, 0x83, 0xe4, 0x07, 0xa1, 0x10, 0x67, 0x28, 0xa4, 0x88, \n\t0x01, 0x0b, 0x20, 0x14, 0x10, 0x2a, 0xcd, 0x41, 0x28, 0x22, 0x16, 0x18, 0x90, 0xd1, 0x00, 0x44, \n\t0x18, 0x81, 0xa1, 0x00, 0x14, 0x1e, 0x04, 0x22, 0x25, 0xd1, 0x14, 0x58, 0x09, 0x4a, 0x3a, 0x06, \n\t0x83, 0x25, 0x24, 0x01, 0x4c, 0x18, 0x01, 0x22, 0xa8, 0x30, 0x08, 0x41, 0x58, 0xa7, 0x52, 0x81, \n\t0xdc, 0x52, 0x26, 0x00, 0x86, 0x00, 0x38, 0x64, 0x85, 0x07, 0x0c, 0x52, 0x1a, 0x12, 0xa8, 0x04, \n\t0x8e, 0x32, 0x01, 0x41, 0x20, 0xe9, 0x4b, 0x60, 0x76, 0x21, 0x20, 0x2c, 0xa9, 0x00, 0x82, 0x32, \n\t0x64, 0x4a, 0x30, 0x48, 0x4a, 0x02, 0x04, 0x17, 0x10, 0x16, 0x05, 0x10, 0x41, 0x68, 0x71, 0x40, \n\t0x02, 0x20, 0x92, 0x60, 0x0e, 0xc2, 0x31, 0x04, 0x11, 0x83, 0x41, 0x0a, 0xb2, 0x11, 0x00, 0x25, \n\t0x45, 0x84, 0x40, 0x00, 0xda, 0x28, 0x41, 0x00, 0x4b, 0x0c, 0xe6, 0x00, 0x85, 0x50, 0xc8, 0x0a, \n\t0x04, 0x54, 0x30, 0x09, 0x00, 0x0e, 0xa6, 0x6a, 0x02, 0x02, 0x20, 0x0d, 0x56, 0xa0, 0x48, 0x04, \n\t0xa0, 0x90, 0x14, 0x81, 0x08, 0x2a, 0x02, 0x91, 0x30, 0x00, 0x01, 0x4c, 0x20, 0x40, 0x49, 0x29, \n\t0x15, 0x89, 0x04, 0x10, 0xa5, 0x60, 0x90, 0x20, 0x5e, 0x84, 0x20, 0x45, 0x03, 0x07, 0x14, 0x09, \n\t0x24, 0x08, 0x70, 0x8a, 0x92, 0x08, 0x46, 0xe3, 0x30, 0x00, 0x08, 0x01, 0x48, 0x51, 0x89, 0x10, \n\t0x40, 0xa8, 0x08, 0xa0, 0x12, 0x81, 0x34, 0x61, 0x41, 0x24, 0x84, 0x5a, 0x44, 0x24, 0x14, 0x9a, \n\t0x28, 0x68, 0x95, 0x44, 0x60, 0x43, 0x89, 0x80, 0x64, 0x85, 0x88, 0x02, 0x50, 0x01, 0x81, 0x74, \n\t0x18, 0x23, 0x24, 0x41, 0xe1, 0x02, 0xe9, 0x00, 0x0d, 0x04, 0x36, 0xd2, 0xb1, 0x01, 0x00, 0x8d, \n\t0x0e, 0x54, 0x41, 0x09, 0x30, 0x85, 0x08, 0x48, 0x81, 0x29, 0x38, 0x84, 0x4c, 0x28, 0x74, 0x03, \n\t0xa2, 0x0e, 0x20, 0x56, 0x04, 0x22, 0xa0, 0x01, 0x08, 0xc1, 0x84, 0x20, 0x1a, 0xd2, 0x10, 0x2a, \n\t0x11, 0x02, 0x4a, 0x10, 0x01, 0x32, 0xb1, 0x01, 0x12, 0x4a, 0x42, 0x04, 0xb8, 0x0e, 0x24, 0x90, \n\t0x84, 0x16, 0x47, 0x93, 0x0a, 0x44, 0x81, 0x0a, 0x18, 0x30, 0x80, 0x92, 0xb0, 0x11, 0x03, 0x3c, \n\t0xa4, 0x08, 0x00, 0x64, 0x44, 0xca, 0x26, 0xd2, 0x0b, 0x21, 0x88, 0x00, 0xcc, 0x16, 0x83, 0x71, \n\t0x22, 0xd0, 0xd0, 0x87, 0x08, 0xd7, 0x48, 0x0d, 0x00, 0xcb, 0x20, 0x6a, 0x43, 0x82, 0x04, 0x48, \n\t0x1d, 0xc6, 0x20, 0x20, 0x30, 0x05, 0xe1, 0x15, 0x01, 0x10, 0xf1, 0xa9, 0x82, 0x09, 0x98, 0x83, \n\t0x18, 0xa0, 0x60, 0x07, 0xd1, 0x83, 0x00, 0x08, 0x75, 0x02, 0x3c, 0x00, 0x0c, 0xc1, 0x6c, 0x02, \n\t0xba, 0x9a, 0x20, 0x42, 0x26, 0x14, 0x44, 0x20, 0x10, 0x4c, 0x43, 0xe1, 0x5a, 0x81, 0x42, 0x26, \n\t0x84, 0x0d, 0x20, 0x56, 0x00, 0x91, 0x98, 0x80, 0x00, 0x65, 0x12, 0x21, 0x08, 0x00, 0x50, 0x4a, \n\t0x82, 0x02, 0x06, 0xca, 0x82, 0x8c, 0x02, 0x64, 0x00, 0x83, 0xa1, 0x82, 0x50, 0x54, 0x01, 0x54, \n\t0x30, 0xc0, 0x00, 0x09, 0x14, 0xc4, 0x04, 0xa0, 0x03, 0x07, 0xcc, 0x88, 0x48, 0x48, 0xb0, 0x11, \n\t0x14, 0x19, 0x08, 0x88, 0x24, 0xd0, 0x00, 0x12, 0x00, 0x18, 0xc1, 0x0a, 0x80, 0x22, 0x08, 0x8d, \n\t0x45, 0x84, 0x08, 0x25, 0x40, 0x22, 0x94, 0x18, 0xc0, 0x18, 0x47, 0x72, 0x00, 0x64, 0x41, 0x00, \n\t0x24, 0xe2, 0x19, 0x81, 0x14, 0x81, 0x01, 0x14, 0x06, 0x50, 0x0c, 0xc0, 0x82, 0x0c, 0x3a, 0x21, \n\t0x4a, 0x03, 0x08, 0x41, 0x49, 0x06, 0x52, 0x08, 0x85, 0xb1, 0xd2, 0x02, 0x24, 0x00, 0x68, 0x01, \n\t0xd9, 0x12, 0x04, 0x04, 0x00, 0x20, 0x01, 0x01, 0x12, 0x0e, 0x10, 0x52, 0x50, 0x81, 0x40, 0x83, \n\t0xc8, 0x6e, 0x10, 0x22, 0x20, 0x78, 0x01, 0x04, 0x4a, 0x92, 0x61, 0x0d, 0x2c, 0xc2, 0x2c, 0x62, \n\t0x45, 0x4a, 0x84, 0x34, 0x86, 0x08, 0x00, 0xc0, 0x3a, 0x84, 0x24, 0x48, 0xe7, 0x00, 0x84, 0x4a, \n\t0x12, 0x09, 0x81, 0x00, 0x24, 0x65, 0x31, 0xa5, 0x00, 0x56, 0x4c, 0x12, 0x24, 0xa8, 0x9a, 0x30, \n\t0xd2, 0x05, 0x28, 0x53, 0x49, 0x05, 0xc1, 0x4b, 0x60, 0x50, 0x94, 0x11, 0x2c, 0x10, 0x91, 0x02, \n\t0x14, 0xf2, 0xa3, 0x23, 0xdc, 0x98, 0x28, 0x04, 0x43, 0x20, 0x23, 0xd8, 0x00, 0x20, 0x0e, 0x03, \n\t0x20, 0x30, 0x6c, 0x54, 0x04, 0x12, 0x81, 0x01, 0x84, 0x60, 0x54, 0x20, 0x24, 0x11, 0xba, 0xa5, \n\t0x08, 0x0a, 0xc9, 0x40, 0x83, 0x28, 0x2e, 0x39, 0x14, 0x82, 0x52, 0x01, 0x1a, 0x00, 0x81, 0x05, \n\t0x45, 0x2a, 0xa0, 0x18, 0x20, 0x40, 0x42, 0x01, 0x48, 0x00, 0x82, 0xbd, 0x80, 0x12, 0x61, 0x00, \n\t0x31, 0x01, 0x81, 0x08, 0x52, 0x05, 0x62, 0x00, 0x08, 0x18, 0x28, 0xc0, 0x40, 0x08, 0x90, 0x58, \n\t0x06, 0xb1, 0x92, 0x82, 0x60, 0x95, 0x10, 0x36, 0x00, 0x01, 0x05, 0x00, 0x10, 0xa8, 0x81, 0x11, \n\t0x8f, 0x46, 0x38, 0x10, 0x02, 0x30, 0x48, 0x06, 0x22, 0x4a, 0x21, 0x51, 0x21, 0x2d, 0x8c, 0x80, \n\t0x00, 0x25, 0x88, 0xac, 0x51, 0x10, 0x4a, 0x04, 0x87, 0x82, 0x02, 0x0c, 0x08, 0x0b, 0x1c, 0x30, \n\t0x28, 0x12, 0xc0, 0x80, 0x0d, 0x60, 0x82, 0x40, 0xb8, 0x80, 0x91, 0x45, 0x70, 0x44, 0x41, 0x0a, \n\t0xc0, 0x40, 0xa0, 0x16, 0x84, 0x1a, 0x2c, 0x84, 0xc6, 0x09, 0x44, 0x23, 0x0b, 0xad, 0x41, 0x16, \n\t0xc2, 0x70, 0x10, 0x22, 0x1c, 0x15, 0x02, 0xc1, 0x20, 0x86, 0x08, 0x21, 0x44, 0x89, 0xe2, 0x4a, \n\t0x12, 0x01, 0xb1, 0x80, 0x11, 0x08, 0x48, 0x01, 0x48, 0x80, 0x60, 0x12, 0x28, 0x22, 0x07, 0x60, \n\t0xaa, 0x38, 0x15, 0x4e, 0x74, 0x60, 0x02, 0x12, 0x38, 0x84, 0x05, 0x00, 0x87, 0x41, 0xa0, 0x20, \n\t0x4d, 0xc1, 0x02, 0x36, 0x82, 0x0c, 0x28, 0x89, 0x44, 0x36, 0x90, 0x28, 0x18, 0x79, 0x45, 0xa0, \n\t0x00, 0x16, 0xd0, 0x04, 0x30, 0x41, 0xe5, 0x12, 0x81, 0x10, 0xa0, 0x98, 0x02, 0x84, 0x48, 0x40, \n\t0x80, 0x83, 0x90, 0xda, 0x00, 0x60, 0x00, 0xa8, 0x93, 0x20, 0x00, 0x80, 0x5a, 0x50, 0x82, 0x03, \n\t0x20, 0x50, 0x04, 0x4c, 0x70, 0x28, 0xa5, 0xc4, 0x08, 0xa1, 0x10, 0x80, 0x93, 0x80, 0x88, 0x14, \n\t0x26, 0x72, 0x57, 0xca, 0x13, 0x80, 0x41, 0x02, 0x30, 0x81, 0x68, 0x10, 0x41, 0x19, 0x4e, 0x58, \n\t0x02, 0x43, 0xb8, 0x80, 0x0c, 0x00, 0x40, 0x66, 0x31, 0x14, 0x09, 0x80, 0x08, 0x44, 0x22, 0x03, \n\t0x08, 0xc8, 0x02, 0x01, 0x40, 0x20, 0xc9, 0x27, 0x11, 0x12, 0x25, 0x14, 0x11, 0x82, 0x06, 0x90, \n\t0xc0, 0xca, 0x02, 0x44, 0x02, 0x00, 0x09, 0x85, 0xa0, 0x5a, 0x42, 0x90, 0x05, 0x00, 0x53, 0x88, \n\t0x0c, 0x04, 0xd9, 0x90, 0xe1, 0x87, 0x03, 0x2c, 0x40, 0x21, 0x18, 0x44, 0x11, 0x28, 0x62, 0xb0, \n\t0x5a, 0x20, 0x44, 0x0e, 0x0e, 0x22, 0x10, 0x01, 0x24, 0xe1, 0x90, 0x08, 0x72, 0x12, 0x00, 0x00, \n\t0x8c, 0x40, 0x04, 0x06, 0x46, 0x10, 0x0b, 0x08, 0x04, 0x2a, 0x6a, 0x84, 0x00, 0x25, 0x84, 0x40, \n\t0x01, 0x06, 0x03, 0x19, 0xa4, 0x51, 0x10, 0x2d, 0x20, 0x93, 0x23, 0x82, 0xcc, 0x1a, 0xc2, 0x2a, \n\t0x40, 0x00, 0x10, 0x45, 0x95, 0x05, 0x52, 0x40, 0x08, 0x0c, 0x00, 0x48, 0x00, 0x10, 0x24, 0x2a, \n\t0x33, 0x41, 0xcb, 0x61, 0x08, 0x22, 0x40, 0x3e, 0x08, 0x4d, 0x23, 0x20, 0x40, 0xca, 0x88, 0x08, \n\t0x03, 0x4b, 0x14, 0xc2, 0x21, 0x8b, 0x91, 0x81, 0x48, 0x4a, 0x45, 0x82, 0x24, 0xa0, 0x0f, 0x0c, \n\t0x46, 0x10, 0x8b, 0x85, 0x11, 0x04, 0x0d, 0x28, 0x92, 0x62, 0x00, 0xb1, 0x06, 0x46, 0x06, 0x42, \n\t0x90, 0x00, 0x74, 0x1e, 0xec, 0x40, 0x82, 0x90, 0x9a, 0x4d, 0xc8, 0x2e, 0x04, 0xb7, 0x90, 0x08, \n\t0x7d, 0x82, 0x01, 0x20, 0xc7, 0x30, 0x03, 0x68, 0x90, 0x08, 0x28, 0x00, 0x28, 0x05, 0x14, 0x04, \n\t0xa9, 0x20, 0x04, 0x61, 0x04, 0xb1, 0x44, 0x01, 0x50, 0x91, 0x11, 0x90, 0xa0, 0x4a, 0xe4, 0x06, \n\t0x84, 0x08, 0x0d, 0x01, 0x18, 0x4b, 0x08, 0x25, 0x62, 0x80, 0x08, 0x05, 0x08, 0x10, 0x52, 0x2b, \n\t0x88, 0x90, 0x41, 0x00, 0x6a, 0x06, 0x12, 0x21, 0xc0, 0x00, 0xe2, 0x00, 0x03, 0xd0, 0x06, 0x40, \n\t0x0c, 0x61, 0x14, 0x44, 0x62, 0x30, 0x04, 0x18, 0x62, 0x08, 0x81, 0x10, 0x13, 0x3c, 0x1b, 0xc6, \n\t0x02, 0x06, 0x73, 0x95, 0xa5, 0x88, 0x2a, 0x48, 0x40, 0x0a, 0xb0, 0x79, 0x10, 0x49, 0x02, 0xa5, \n\t0xa0, 0x26, 0x70, 0x19, 0x43, 0x26, 0x80, 0x09, 0x23, 0x60, 0xc0, 0x84, 0x00, 0x21, 0x49, 0xac, \n\t0x10, 0x14, 0xc6, 0x68, 0x54, 0x43, 0xab, 0x30, 0x44, 0x41, 0x06, 0xa5, 0xf8, 0x08, 0x40, 0x4a, \n\t0x20, 0x14, 0x20, 0x20, 0x14, 0x89, 0x40, 0xa2, 0x46, 0x62, 0x08, 0x05, 0xb9, 0x10, 0xa1, 0x10, \n\t0x10, 0x81, 0x0c, 0xc1, 0x40, 0x86, 0x42, 0x06, 0x0a, 0x9a, 0x50, 0x45, 0x24, 0x30, 0x91, 0x20, \n\t0xa2, 0x08, 0x84, 0x20, 0x3e, 0x00, 0x61, 0x23, 0xf4, 0x42, 0x89, 0x70, 0x42, 0x22, 0xa0, 0x9c, \n\t0x58, 0x8d, 0x44, 0x25, 0x81, 0xb8, 0x14, 0xce, 0x20, 0x24, 0x21, 0x60, 0x81, 0x14, 0x18, 0x47, \n\t0x50, 0x33, 0xc0, 0x02, 0x04, 0x89, 0x05, 0x30, 0xc4, 0x8a, 0x02, 0x29, 0x8e, 0x09, 0x40, 0x80, \n\t0x19, 0x20, 0x11, 0xc3, 0xc4, 0x08, 0x61, 0x32, 0xa4, 0x5c, 0x8a, 0x81, 0x20, 0x45, 0x02, 0x0b, \n\t0x41, 0xc3, 0xa9, 0x00, 0x82, 0x02, 0x1b, 0x40, 0xd9, 0x64, 0x60, 0x00, 0x70, 0x89, 0xa4, 0x8c, \n\t0x20, 0x2c, 0x05, 0x90, 0x02, 0x40, 0x8c, 0x09, 0x02, 0x64, 0x20, 0x96, 0x05, 0x45, 0xc0, 0x10, \n\t0x93, 0x40, 0x30, 0x31, 0x08, 0x88, 0x14, 0x00, 0x20, 0x11, 0x94, 0x0a, 0x8f, 0x02, 0x82, 0x0a, \n\t0x15, 0x0c, 0x0e, 0x24, 0x4c, 0x34, 0xda, 0x8e, 0x80, 0x10, 0x43, 0x22, 0x00, 0xe0, 0x0c, 0x81, \n\t0x00, 0x28, 0x16, 0x22, 0xb9, 0x0c, 0x95, 0x90, 0xaa, 0x18, 0x84, 0x52, 0x29, 0x10, 0x09, 0x41, \n\t0x20, 0x26, 0x9a, 0xa0, 0x41, 0x58, 0x80, 0x74, 0x40, 0x93, 0x0d, 0xa0, 0x90, 0x06, 0x30, 0x10, \n\t0xa3, 0x82, 0x81, 0x12, 0x80, 0x56, 0xa7, 0x50, 0x00, 0x10, 0x41, 0xcd, 0x00, 0xa7, 0x00, 0xa2, \n\t0x08, 0xcc, 0x06, 0x0e, 0xb1, 0x41, 0x36, 0x91, 0x08, 0xc4, 0x20, 0x40, 0xc2, 0xb1, 0xa0, 0x1d, \n\t0x24, 0x6c, 0x62, 0x42, 0x87, 0xb0, 0x1a, 0x0b, 0x42, 0x94, 0xb8, 0x21, 0x34, 0x07, 0x0a, 0x42, \n\t0x80, 0xd8, 0x80, 0x20, 0x02, 0xc6, 0x04, 0xe3, 0x00, 0x32, 0xd0, 0x00, 0x80, 0x66, 0xc1, 0x22, \n\t0x0c, 0x29, 0xca, 0x40, 0x08, 0x84, 0x29, 0x06, 0x25, 0x00, 0x26, 0x3c, 0x11, 0x18, 0x01, 0x84, \n\t0x08, 0x80, 0x24, 0x20, 0x42, 0x98, 0x84, 0x41, 0x20, 0x20, 0x24, 0x10, 0x8b, 0x1c, 0x43, 0x60, \n\t0x02, 0x14, 0x00, 0x27, 0x30, 0x94, 0x8d, 0x52, 0x84, 0x08, 0x14, 0x18, 0x05, 0x20, 0x38, 0x22, \n\t0xa1, 0x90, 0xa1, 0x0a, 0xcc, 0x0c, 0x00, 0x61, 0x01, 0x64, 0x57, 0x2d, 0x4c, 0x40, 0x01, 0xac, \n\t0x08, 0x16, 0x81, 0x10, 0xb1, 0xc3, 0x10, 0x4d, 0x49, 0x25, 0x46, 0x56, 0x18, 0x24, 0x38, 0x01, \n\t0x04, 0x00, 0x53, 0x80, 0x25, 0x65, 0x18, 0xa2, 0x12, 0x10, 0x13, 0xa0, 0x05, 0x89, 0x62, 0x48, \n\t0x24, 0x29, 0xa8, 0x00, 0x00, 0x01, 0x60, 0x55, 0x42, 0x29, 0x84, 0xc5, 0x80, 0x1c, 0x01, 0x78, \n\t0xb8, 0x05, 0x55, 0x48, 0x32, 0xc0, 0x00, 0x00, 0x90, 0x90, 0x2c, 0x6a, 0xa1, 0x82, 0x0d, 0xe0, \n\t0x56, 0xc9, 0x18, 0x00, 0x10, 0x01, 0x50, 0x94, 0x44, 0x42, 0x90, 0x08, 0x04, 0xa4, 0x86, 0xa2, \n\t0x2c, 0x41, 0x51, 0x9a, 0x48, 0x1b, 0x87, 0x06, 0x21, 0x00, 0x1e, 0x40, 0xc8, 0x82, 0x42, 0x82, \n\t0x20, 0x09, 0x21, 0x94, 0x80, 0x28, 0x51, 0x39, 0x04, 0x8c, 0x10, 0x0b, 0x3a, 0x63, 0x20, 0x20, \n\t0x08, 0x10, 0xe6, 0x04, 0xc1, 0x51, 0x00, 0xa0, 0x48, 0x4e, 0x08, 0x81, 0x08, 0x26, 0xd1, 0x4b, \n\t0x06, 0x40, 0xf4, 0x22, 0x20, 0x18, 0x54, 0x61, 0x38, 0x36, 0xc9, 0x8a, 0x88, 0x12, 0x4c, 0x30, \n\t0x02, 0x13, 0x01, 0x10, 0x01, 0x05, 0x02, 0x22, 0x98, 0x80, 0xe5, 0x06, 0x24, 0x50, 0x12, 0x92, \n\t0x32, 0x48, 0x10, 0x65, 0x08, 0x55, 0x02, 0xa4, 0x28, 0x04, 0xa2, 0x0a, 0x57, 0x82, 0xb1, 0xc8, \n\t0x08, 0x82, 0x42, 0x04, 0x81, 0x12, 0x94, 0x04, 0x2b, 0x0c, 0x45, 0x83, 0x88, 0x40, 0x0c, 0x22, \n\t0x64, 0x10, 0x83, 0x32, 0x70, 0x00, 0x09, 0x10, 0x72, 0x61, 0x00, 0x44, 0x50, 0xc4, 0x12, 0x80, \n\t0x40, 0x02, 0x00, 0x02, 0x01, 0x22, 0x24, 0x69, 0x04, 0x49, 0x03, 0x07, 0x34, 0x00, 0x08, 0x00, \n\t0x01, 0x46, 0x29, 0x54, 0x12, 0x20, 0xa2, 0x40, 0x10, 0xca, 0x00, 0x12, 0x21, 0x91, 0x41, 0x10, \n\t0x80, 0x0e, 0x00, 0xa8, 0x08, 0x21, 0x42, 0x40, 0x4e, 0x05, 0x89, 0x28, 0x88, 0x49, 0x0c, 0x02, \n\t0x44, 0xca, 0x25, 0xb0, 0x13, 0xc8, 0x00, 0xc5, 0x91, 0xa0, 0x28, 0x11, 0x4e, 0x76, 0x42, 0x01, \n\t0x32, 0x11, 0xc6, 0x80, 0x00, 0xc2, 0x38, 0x14, 0x51, 0x81, 0xc3, 0x28, 0x41, 0x00, 0x1a, 0x2c, \n\t0x10, 0x41, 0x58, 0x80, 0x08, 0x17, 0x38, 0xd2, 0x27, 0x02, 0x00, 0x81, 0x1c, 0x90, 0x03, 0xc5, \n\t0x52, 0x91, 0x68, 0xa4, 0x09, 0x88, 0x03, 0x48, 0xc0, 0xd0, 0x05, 0x94, 0x00, 0x20, 0x68, 0x05, \n\t0x3a, 0xae, 0x0c, 0xc2, 0xe7, 0x0a, 0x84, 0x33, 0x84, 0x08, 0x48, 0x20, 0x50, 0x40, 0xd3, 0x05, \n\t0x30, 0xd5, 0xa8, 0x20, 0x03, 0x0b, 0x84, 0x98, 0x04, 0x22, 0x44, 0x25, 0x48, 0x01, 0x64, 0x0a, \n\t0x86, 0x14, 0x82, 0x51, 0x88, 0x80, 0x0a, 0x83, 0x30, 0xa6, 0x82, 0x0a, 0xa0, 0x1c, 0x01, 0x08, \n\t0xc1, 0xb8, 0x01, 0x48, 0x04, 0x6c, 0x4a, 0x86, 0x11, 0x0d, 0x8c, 0x91, 0x8c, 0x0c, 0x02, 0x50, \n\t0x07, 0xa4, 0x08, 0x43, 0x34, 0x56, 0x60, 0x20, 0x10, 0x08, 0x06, 0x68, 0xc4, 0x20, 0xae, 0x3c, \n\t0x81, 0x46, 0x0c, 0x10, 0x40, 0x81, 0x09, 0x80, 0xa2, 0x10, 0x41, 0x93, 0x33, 0x4c, 0x80, 0x21, \n\t0x0c, 0x80, 0xa2, 0x06, 0xc4, 0x00, 0xc5, 0x30, 0xf0, 0x19, 0x03, 0xd0, 0x00, 0xc1, 0x0e, 0x36, \n\t0x00, 0x0d, 0xd1, 0x8c, 0x02, 0x22, 0x13, 0xc8, 0x82, 0x18, 0x53, 0x20, 0x08, 0x84, 0x0a, 0x9a, \n\t0xd0, 0x53, 0x48, 0x00, 0x00, 0x00, 0x10, 0x1c, 0xc4, 0x20, 0x00, 0x90, 0x6a, 0x05, 0x18, 0x06, \n\t0x09, 0x44, 0x10, 0xb1, 0x95, 0x0c, 0x90, 0x05, 0x2e, 0x21, 0x80, 0x08, 0x49, 0x05, 0x00, 0x22, \n\t0x44, 0xc3, 0x10, 0x88, 0xdd, 0xa2, 0x42, 0x35, 0x29, 0x30, 0x45, 0x08, 0x21, 0x78, 0x40, 0x52, \n\t0x04, 0x40, 0x05, 0x6a, 0x10, 0x43, 0x02, 0x88, 0x65, 0x02, 0x42, 0x1e, 0xc0, 0x18, 0x82, 0x34, \n\t0xd0, 0x08, 0x28, 0x85, 0x4a, 0x83, 0x14, 0x02, 0x41, 0x10, 0x33, 0x03, 0x12, 0xa9, 0x1c, 0x0a, \n\t0x0c, 0x04, 0x82, 0x21, 0x1c, 0x86, 0x86, 0x06, 0xd3, 0x68, 0xab, 0xc1, 0x08, 0xc0, 0x40, 0x60, \n\t0xd2, 0x20, 0x10, 0x10, 0x0e, 0x06, 0xe0, 0xa8, 0x05, 0x21, 0x05, 0x81, 0x22, 0x43, 0x9a, 0x95, \n\t0x44, 0x99, 0x06, 0x04, 0x11, 0xf0, 0x31, 0xbc, 0x12, 0x22, 0x54, 0x80, 0x63, 0x36, 0x34, 0x04, \n\t0xc2, 0x40, 0xd1, 0x4a, 0x90, 0x20, 0xc9, 0x00, 0x18, 0x40, 0x50, 0x84, 0x81, 0xc0, 0x4b, 0x68, \n\t0x00, 0x21, 0x90, 0x28, 0xd7, 0x04, 0x20, 0x60, 0x20, 0x04, 0x20, 0x43, 0x41, 0x42, 0x20, 0x18, \n\t0x24, 0x94, 0xc7, 0x80, 0x08, 0x30, 0x03, 0x87, 0x40, 0x1c, 0x46, 0x14, 0x02, 0x20, 0xa6, 0xd5, \n\t0x88, 0x04, 0x20, 0x54, 0x20, 0x29, 0x35, 0x11, 0x87, 0x52, 0x40, 0x60, 0x23, 0xa5, 0x06, 0x0c, \n\t0x44, 0x24, 0x71, 0x20, 0x20, 0xd0, 0xe2, 0x08, 0x40, 0x89, 0x8c, 0x40, 0x18, 0x81, 0x10, 0x30, \n\t0x01, 0x01, 0x09, 0x03, 0x2f, 0x20, 0x34, 0x18, 0x1c, 0x14, 0x8a, 0x0c, 0x58, 0xa0, 0x01, 0xa8, \n\t0x94, 0x47, 0x40, 0x30, 0x04, 0x42, 0x13, 0x99, 0x00, 0x2b, 0x18, 0x20, 0xf2, 0x35, 0x2c, 0x84, \n\t0x40, 0x52, 0x20, 0x83, 0x0c, 0x54, 0x88, 0x20, 0x4c, 0x62, 0xa0, 0x04, 0x15, 0x99, 0xec, 0x0e, \n\t0xa3, 0x02, 0x14, 0x21, 0x40, 0x60, 0x0a, 0x42, 0xe2, 0x80, 0x20, 0x91, 0x08, 0x2e, 0x40, 0x3a, \n\t0x22, 0xbc, 0x02, 0x22, 0x46, 0xc1, 0x60, 0x18, 0x89, 0x4c, 0xa4, 0x02, 0x90, 0x42, 0x20, 0x00, \n\t0xc3, 0xe8, 0x04, 0x10, 0x31, 0x24, 0x44, 0x87, 0x4d, 0x1a, 0x02, 0xa9, 0x0b, 0x90, 0x08, 0x2d, \n\t0x42, 0xd6, 0x6a, 0x10, 0x91, 0x10, 0x0c, 0x42, 0xa4, 0x02, 0x09, 0x48, 0x01, 0x40, 0x42, 0x51, \n\t0x82, 0x00, 0x9d, 0x04, 0xa0, 0x40, 0x36, 0x41, 0x20, 0x04, 0x51, 0x06, 0x46, 0x60, 0x8a, 0x0b, \n\t0x44, 0x01, 0x05, 0x10, 0x92, 0x11, 0x04, 0x21, 0x00, 0x88, 0x24, 0x05, 0x90, 0x13, 0x68, 0x00, \n\t0x43, 0x4c, 0x21, 0x62, 0x22, 0x80, 0x15, 0xa2, 0x14, 0x41, 0x80, 0x11, 0x44, 0x40, 0x82, 0x08, \n\t0x02, 0x40, 0x93, 0x00, 0x52, 0x8e, 0x10, 0x52, 0x82, 0xa4, 0x2c, 0x4a, 0x45, 0x40, 0x04, 0xc0, \n\t0x09, 0xa8, 0x0d, 0x4a, 0x00, 0x12, 0x48, 0x34, 0x89, 0x03, 0xa3, 0x00, 0xb1, 0xe2, 0x28, 0x15, \n\t0x10, 0x09, 0x08, 0xe1, 0x03, 0x93, 0x04, 0x82, 0xa0, 0x46, 0xe2, 0xb0, 0x08, 0x00, 0xc6, 0x00, \n\t0x1c, 0x42, 0xc0, 0x32, 0x01, 0x57, 0x00, 0x02, 0x10, 0x32, 0x06, 0x1c, 0x43, 0x81, 0x5a, 0xc2, \n\t0x01, 0x8e, 0x55, 0x14, 0xab, 0x30, 0x14, 0x09, 0x03, 0x70, 0xc4, 0x23, 0x32, 0xa0, 0x21, 0xa2, \n\t0x44, 0x4d, 0x82, 0x08, 0xd4, 0x68, 0x2a, 0x8c, 0x11, 0x60, 0x06, 0x64, 0x00, 0x16, 0x90, 0x82, \n\t0xa4, 0x00, 0x00, 0x02, 0x09, 0x29, 0x11, 0x4c, 0x44, 0x00, 0x29, 0x05, 0xf0, 0x16, 0x44, 0x50, \n\t0xa0, 0x21, 0x15, 0x1c, 0x49, 0xac, 0x20, 0x42, 0xb8, 0x80, 0x09, 0x48, 0x23, 0x50, 0x44, 0x6a, \n\t0x21, 0x41, 0xc8, 0x80, 0x20, 0x34, 0xe8, 0xb0, 0x09, 0x18, 0x02, 0x00, 0x20, 0x99, 0xb0, 0x45, \n\t0x04, 0x05, 0x04, 0x74, 0x08, 0x10, 0xe1, 0x02, 0x05, 0x0a, 0xc3, 0x40, 0x82, 0xd1, 0x94, 0x00, \n\t0x08, 0x33, 0x42, 0x25, 0xa0, 0x19, 0x40, 0x56, 0x20, 0x20, 0x11, 0xc8, 0x8a, 0x0c, 0x06, 0x86, \n\t0x58, 0x08, 0xc0, 0x04, 0xa3, 0x18, 0xa1, 0x72, 0x80, 0x51, 0x04, 0x88, 0x10, 0x00, 0xa1, 0x14, \n\t0x14, 0x02, 0xec, 0x44, 0x67, 0x02, 0x18, 0x48, 0x11, 0x41, 0x32, 0x00, 0x08, 0x23, 0x08, 0x1b, \n\t0x22, 0x60, 0x60, 0x98, 0x24, 0x10, 0x40, 0xc1, 0x6a, 0x45, 0x48, 0x2a, 0xf4, 0x40, 0x07, 0x42, \n\t0x06, 0x58, 0x98, 0x80, 0x85, 0x62, 0x20, 0x02, 0x31, 0xbb, 0x04, 0x13, 0x82, 0x60, 0x52, 0x0b, \n\t0x91, 0x24, 0x01, 0x61, 0x0c, 0x80, 0x0b, 0x01, 0x20, 0x8c, 0x2c, 0x3c, 0x00, 0x50, 0x31, 0x00, \n\t0x51, 0x48, 0x1a, 0x02, 0x20, 0x22, 0x0d, 0x80, 0xc4, 0x28, 0x06, 0x82, 0x09, 0xcc, 0x43, 0x4d, \n\t0x0a, 0xa1, 0x02, 0x1a, 0x05, 0x86, 0x82, 0x5a, 0x12, 0x62, 0xa4, 0x68, 0x09, 0x0e, 0x20, 0x44, \n\t0x09, 0x10, 0x50, 0x05, 0x89, 0x0a, 0x23, 0x28, 0x0c, 0x94, 0x05, 0x22, 0x40, 0x01, 0x12, 0x02, \n\t0x10, 0x80, 0x21, 0x02, 0x45, 0x08, 0x20, 0xa0, 0x08, 0x02, 0x1a, 0x55, 0xe0, 0x9d, 0x04, 0x51, \n\t0x09, 0x1c, 0x14, 0x23, 0x8a, 0xc1, 0x00, 0x64, 0x36, 0x20, 0xa2, 0x19, 0xd5, 0x42, 0x2c, 0x14, \n\t0x72, 0x40, 0x80, 0x90, 0x0a, 0x2e, 0x54, 0x06, 0x92, 0x26, 0xc0, 0x81, 0x61, 0x00, 0x40, 0x00, \n\t0x25, 0x68, 0x83, 0xa6, 0x34, 0x01, 0xa0, 0x01, 0x85, 0x50, 0x0a, 0x10, 0x65, 0x81, 0x87, 0x49, \n\t0x1a, 0x02, 0x12, 0xa1, 0x38, 0x94, 0x60, 0x48, 0x86, 0x20, 0x62, 0x08, 0x80, 0xe8, 0x09, 0x05, \n\t0x00, 0xf1, 0x21, 0x01, 0xc1, 0x97, 0x48, 0x60, 0xd5, 0x8a, 0x08, 0xa8, 0x10, 0x00, 0x00, 0x01, \n\t0x30, 0x04, 0x68, 0x08, 0x01, 0x1e, 0x80, 0x08, 0x09, 0x94, 0x07, 0x81, 0x00, 0x10, 0x90, 0x20, \n\t0x88, 0x12, 0x85, 0x4c, 0x56, 0x01, 0x06, 0x5d, 0x48, 0x60, 0x46, 0x02, 0x2a, 0x85, 0x40, 0x50, \n\t0x60, 0x10, 0x01, 0x02, 0xaf, 0xa8, 0x58, 0x0e, 0x4a, 0x60, 0xa0, 0x15, 0x11, 0x9d, 0x22, 0x28, \n\t0x86, 0x41, 0xb0, 0x74, 0x48, 0xa8, 0x64, 0x03, 0x02, 0x08, 0xa5, 0x02, 0x0b, 0x06, 0xb1, 0x38, \n\t0x09, 0x40, 0xd4, 0x07, 0x20, 0x84, 0x2a, 0x96, 0x2c, 0x93, 0x08, 0x50, 0x50, 0x69, 0x03, 0xb0, \n\t0x95, 0x0f, 0x70, 0x94, 0xea, 0x30, 0x00, 0x00, 0xe7, 0x02, 0x00, 0x50, 0x01, 0x19, 0x84, 0x86, \n\t0x10, 0x25, 0x02, 0x32, 0x88, 0xc9, 0xc3, 0x24, 0x31, 0xb8, 0x04, 0x24, 0x11, 0x01, 0x30, 0x94, \n\t0x11, 0x0e, 0x20, 0x49, 0x80, 0x12, 0x05, 0x10, 0xa0, 0x90, 0x9e, 0x23, 0x7c, 0x04, 0x18, 0x08, \n\t0x41, 0x08, 0x2c, 0x04, 0x03, 0xc2, 0x93, 0x05, 0x05, 0x08, 0x32, 0x92, 0x18, 0x03, 0xe0, 0x4c, \n\t0x41, 0x0a, 0x02, 0xa2, 0x9c, 0x0c, 0x16, 0x24, 0x18, 0x42, 0x49, 0x18, 0x20, 0x5a, 0x02, 0x40, \n\t0x24, 0x72, 0x19, 0x84, 0x82, 0x45, 0x58, 0x40, 0x29, 0x04, 0x40, 0x08, 0x04, 0x20, 0x73, 0xa0, \n\t0xae, 0x89, 0x59, 0x06, 0x00, 0x80, 0x30, 0x86, 0x30, 0x8d, 0x80, 0x64, 0x06, 0x62, 0x10, 0x08, \n\t0x46, 0x82, 0x40, 0x41, 0x3a, 0x81, 0x8c, 0x47, 0x00, 0x22, 0x42, 0x3b, 0x04, 0x44, 0x11, 0xa1, \n\t0x22, 0xf0, 0xc2, 0x81, 0x10, 0x44, 0x8b, 0x3a, 0x13, 0x41, 0x00, 0xb1, 0x41, 0x42, 0x68, 0x92, \n\t0xe1, 0x04, 0xa4, 0x53, 0x28, 0x00, 0xc4, 0x10, 0x92, 0x69, 0x40, 0x02, 0x16, 0x24, 0xf1, 0x24, \n\t0x2c, 0x50, 0x02, 0x4c, 0x61, 0xa0, 0xa0, 0x10, 0x0e, 0x89, 0x00, 0x41, 0x82, 0xb9, 0x98, 0x90, \n\t0x0e, 0x02, 0xb1, 0x18, 0x1d, 0x20, 0x98, 0x81, 0x10, 0x85, 0x00, 0x98, 0x20, 0x80, 0x02, 0x2a, \n\t0x00, 0x01, 0x12, 0x88, 0x03, 0x42, 0x52, 0x60, 0x70, 0x24, 0x4c, 0x1c, 0x0a, 0x34, 0x72, 0x01, \n\t0x22, 0x61, 0x43, 0x81, 0x10, 0x12, 0x18, 0x92, 0x20, 0x12, 0x00, 0x5a, 0x95, 0x68, 0x20, 0x84, \n\t0x8e, 0x45, 0x26, 0x82, 0x00, 0x8f, 0x30, 0x8c, 0x40, 0x00, 0xb2, 0x01, 0x00, 0x2c, 0x40, 0x80, \n\t0x0c, 0x03, 0x09, 0x80, 0x0c, 0x06, 0x6a, 0x28, 0xc4, 0xf3, 0x8d, 0x99, 0x08, 0x00, 0x04, 0x52, \n\t0x1a, 0xac, 0x04, 0x1b, 0x80, 0x08, 0xc0, 0x39, 0x23, 0x2c, 0x16, 0x0c, 0x62, 0x01, 0xc9, 0x02, \n\t0x24, 0x14, 0xe2, 0x26, 0x60, 0x81, 0x82, 0x80, 0x51, 0x48, 0x72, 0x61, 0x00, 0x92, 0x79, 0x02, \n\t0x86, 0x30, 0xe0, 0x48, 0x21, 0xc4, 0x13, 0x00, 0x50, 0x17, 0x28, 0x29, 0x88, 0x05, 0x09, 0x4c, \n\t0x84, 0x9a, 0x93, 0xc1, 0xc2, 0x61, 0x06, 0x80, 0xc3, 0x04, 0x60, 0x54, 0x0b, 0x18, 0x00, 0xd8, \n\t0x85, 0xc0, 0x88, 0x29, 0x38, 0x10, 0x41, 0x05, 0x50, 0x0a, 0xc6, 0x26, 0x54, 0x80, 0x10, 0x08, \n\t0x0a, 0x65, 0x58, 0x00, 0x81, 0x81, 0x64, 0x80, 0xa8, 0x40, 0x21, 0x91, 0x24, 0x01, 0x5c, 0x09, \n\t0x4c, 0x00, 0x13, 0x16, 0x18, 0x14, 0x0a, 0x42, 0xa0, 0x98, 0x00, 0x48, 0xcd, 0x08, 0x20, 0x86, \n\t0x11, 0x20, 0x00, 0xc4, 0x81, 0x2a, 0xb1, 0x00, 0x88, 0x24, 0x4d, 0x40, 0x0e, 0x84, 0x10, 0x0e, \n\t0x19, 0xda, 0x01, 0x50, 0x36, 0x18, 0x0c, 0x88, 0x86, 0x0c, 0x54, 0xc2, 0x02, 0x09, 0x0d, 0x00, \n\t0x21, 0x38, 0x11, 0x30, 0x88, 0x90, 0x42, 0x8f, 0x08, 0x07, 0x00, 0xae, 0x10, 0x04, 0x00, 0x2a, \n\t0xc6, 0x23, 0x16, 0x45, 0x50, 0x80, 0x0a, 0x50, 0x2a, 0x92, 0x95, 0x58, 0xe0, 0x28, 0x60, 0x81, \n\t0x18, 0x00, 0x54, 0xae, 0x10, 0xf0, 0x00, 0xa9, 0x40, 0x0d, 0x4d, 0x0a, 0x12, 0x58, 0x27, 0x10, \n\t0x01, 0x82, 0x2a, 0x50, 0x08, 0x24, 0x0c, 0x49, 0x68, 0x50, 0xa0, 0x48, 0x94, 0x00, 0xdb, 0x40, \n\t0x00, 0x00, 0x02, 0x11, 0x04, 0x86, 0x25, 0x4c, 0x03, 0x8a, 0x04, 0x04, 0x00, 0x28, 0x5c, 0x53, \n\t0x03, 0x25, 0x00, 0xd0, 0x26, 0x0a, 0x24, 0x28, 0x00, 0x69, 0xd8, 0x00, 0x24, 0x53, 0x50, 0x8e, \n\t0xc0, 0x44, 0x86, 0x0e, 0x20, 0xc1, 0x13, 0x01, 0x9c, 0x29, 0x28, 0x86, 0xc0, 0x14, 0x2d, 0x45, \n\t0x60, 0x02, 0x90, 0x80, 0x01, 0xe9, 0x41, 0x4c, 0x22, 0x84, 0x20, 0x92, 0xc1, 0x92, 0x0e, 0x50, \n\t0x16, 0x48, 0xa1, 0x08, 0xd0, 0x00, 0x20, 0xc0, 0x40, 0x09, 0x40, 0x01, 0x41, 0x6c, 0x12, 0x10, \n\t0x24, 0x15, 0x82, 0x8a, 0x14, 0xe0, 0xe1, 0xaa, 0xb8, 0x18, 0x45, 0x10, 0x50, 0x60, 0x21, 0x09, \n\t0x08, 0xc7, 0x04, 0x06, 0x18, 0x24, 0x40, 0x04, 0x21, 0x08, 0x07, 0x93, 0xb3, 0x05, 0x12, 0x20, \n\t0x00, 0x20, 0x91, 0x15, 0x28, 0x48, 0x29, 0x04, 0xc0, 0x18, 0x04, 0x60, 0x48, 0xa4, 0x44, 0xa2, \n\t0x0a, 0x08, 0x88, 0x88, 0x05, 0x26, 0x00, 0x00, 0xb4, 0xc4, 0x10, 0x8c, 0x30, 0x12, 0xe8, 0x90, \n\t0x10, 0x15, 0x49, 0x04, 0xa0, 0x21, 0x80, 0x70, 0x52, 0x24, 0x0a, 0xb4, 0x90, 0x05, 0x34, 0x80, \n\t0xc9, 0x4a, 0xd0, 0x0b, 0x09, 0x18, 0x82, 0x42, 0x7c, 0x23, 0x61, 0x0c, 0x0c, 0x88, 0x44, 0x04, \n\t0x93, 0xb0, 0x28, 0x3c, 0x0d, 0xa0, 0x32, 0x84, 0x6a, 0x0a, 0xa1, 0xc7, 0x06, 0x26, 0x01, 0x4a, \n\t0x22, 0x15, 0x44, 0x81, 0x14, 0x02, 0x19, 0x28, 0x4c, 0x00, 0x00, 0x10, 0x10, 0x82, 0x98, 0x04, \n\t0x02, 0x29, 0x28, 0xe0, 0x60, 0x0b, 0x01, 0x0b, 0x8a, 0x28, 0x04, 0x00, 0x85, 0x80, 0xc1, 0x08, \n\t0x1e, 0x76, 0x80, 0x01, 0xb0, 0x42, 0x2e, 0x0c, 0x12, 0x30, 0x09, 0x10, 0x15, 0xec, 0x40, 0xa3, \n\t0x02, 0x81, 0x01, 0x90, 0x8d, 0x44, 0xa3, 0xd1, 0x04, 0x14, 0x00, 0x67, 0x00, 0xc2, 0x80, 0x02, \n\t0x60, 0x8f, 0xc4, 0x06, 0x90, 0x18, 0x34, 0xc8, 0x8d, 0x06, 0x20, 0x01, 0x30, 0x20, 0x3c, 0x08, \n\t0x40, 0x00, 0xe4, 0x49, 0x12, 0xcc, 0x08, 0x41, 0x02, 0xf0, 0x08, 0x31, 0x04, 0x02, 0x40, 0x00, \n\t0x04, 0x21, 0x84, 0xa1, 0xd2, 0x43, 0x42, 0x84, 0x09, 0x03, 0x38, 0xda, 0x01, 0x18, 0x24, 0x80, \n\t0x83, 0x31, 0x92, 0xac, 0x00, 0xb0, 0x4b, 0x00, 0xe1, 0xc1, 0x08, 0x44, 0x03, 0x03, 0x00, 0x81, \n\t0x14, 0x82, 0x04, 0x12, 0x60, 0x09, 0x44, 0x11, 0x23, 0x46, 0x24, 0xa0, 0x2c, 0x05, 0x82, 0x82, \n\t0x08, 0xc6, 0x3b, 0xb4, 0x40, 0x04, 0x26, 0x28, 0x15, 0x60, 0x87, 0x10, 0x83, 0x80, 0x04, 0x02, \n\t0x11, 0x2e, 0x1c, 0x48, 0x4d, 0x74, 0x65, 0xc2, 0x92, 0x10, 0x0d, 0x29, 0x08, 0x00, 0x01, 0x01, \n\t0x14, 0xc3, 0x82, 0x38, 0x93, 0x62, 0x00, 0x00, 0x58, 0x68, 0x10, 0x45, 0x03, 0x15, 0x40, 0x04, \n\t0xcd, 0x06, 0x94, 0xb0, 0x00, 0x01, 0x42, 0xe4, 0x0e, 0x42, 0x5a, 0x29, 0xb4, 0x0e, 0xe4, 0x60, \n\t0x10, 0x02, 0x08, 0xd0, 0x80, 0x0c, 0x40, 0x17, 0x82, 0xa5, 0x58, 0x00, 0x60, 0x1e, 0x11, 0x39, \n\t0x3b, 0x85, 0x00, 0x06, 0x76, 0x05, 0x00, 0xb0, 0xe8, 0x00, 0x8b, 0x40, 0x80, 0x38, 0x00, 0x00, \n\t0x50, 0x60, 0x20, 0x04, 0x13, 0x19, 0x28, 0x00, 0x44, 0x06, 0x11, 0x20, 0x1e, 0x30, 0x45, 0x0a, \n\t0x02, 0xf1, 0x8a, 0x12, 0x8c, 0x00, 0x68, 0x50, 0x70, 0x10, 0x0d, 0x81, 0x48, 0x24, 0x12, 0x04, \n\t0x20, 0x00, 0x11, 0x80, 0x2a, 0x58, 0x02, 0xcb, 0x81, 0xa0, 0x06, 0x47, 0x00, 0x44, 0xb1, 0x88, \n\t0x01, 0x42, 0x48, 0x28, 0xe3, 0x22, 0x00, 0x31, 0x51, 0x06, 0x2e, 0x90, 0xc1, 0x10, 0xc1, 0x49, \n\t0x28, 0x50, 0x64, 0x0b, 0x01, 0x00, 0x94, 0x80, 0x08, 0x82, 0x98, 0x38, 0x09, 0x55, 0xa1, 0x24, \n\t0x00, 0x01, 0x00, 0xe1, 0x44, 0x20, 0x1a, 0x13, 0x10, 0x11, 0x04, 0x5a, 0xc4, 0x00, 0x01, 0xc0, \n\t0x26, 0x0c, 0x05, 0x01, 0x6e, 0x32, 0x01, 0x09, 0xd9, 0x89, 0x82, 0x52, 0xa4, 0x62, 0x0c, 0x81, \n\t0x10, 0xcb, 0x10, 0x70, 0x61, 0x84, 0x24, 0x00, 0x03, 0x60, 0x80, 0xa0, 0xa8, 0x50, 0x48, 0x80, \n\t0x44, 0x63, 0x08, 0x84, 0x08, 0x46, 0xc1, 0x52, 0xc4, 0x81, 0x8c, 0x49, 0x92, 0x04, 0x28, 0x10, \n\t0x53, 0x22, 0x60, 0x45, 0x01, 0x5e, 0x25, 0xd8, 0x10, 0x58, 0x00, 0x6d, 0x02, 0x84, 0x03, 0xa1, \n\t0x3c, 0x48, 0x24, 0x32, 0x04, 0x68, 0x01, 0x20, 0x09, 0xc5, 0x00, 0xc1, 0x43, 0x8e, 0x30, 0x42, \n\t0x2c, 0x42, 0xd5, 0xb8, 0x11, 0x00, 0xc2, 0x40, 0x0a, 0x04, 0x2a, 0x30, 0x30, 0x82, 0x4c, 0x00, \n\t0xb3, 0xc0, 0x26, 0x0c, 0x04, 0xe2, 0x20, 0x10, 0xa1, 0x00, 0x90, 0x93, 0x21, 0x28, 0x45, 0x10, \n\t0x30, 0x15, 0x8f, 0x44, 0x46, 0x50, 0x20, 0x0d, 0x8d, 0x01, 0x28, 0x30, 0x65, 0x58, 0x92, 0xe0, \n\t0xc0, 0x8a, 0x08, 0x20, 0x92, 0x0c, 0x20, 0x11, 0x85, 0x42, 0x14, 0x42, 0x08, 0xc1, 0x88, 0xe0, \n\t0x22, 0x13, 0x00, 0x2c, 0x61, 0xd8, 0x49, 0x0a, 0x64, 0xc0, 0x04, 0x80, 0x53, 0x64, 0x04, 0x85, \n\t0xd1, 0x80, 0x59, 0x12, 0x80, 0x08, 0x82, 0x61, 0x09, 0x11, 0x44, 0x20, 0x0e, 0x00, 0x60, 0x0d, \n\t0x19, 0x08, 0x2c, 0x04, 0xa0, 0x10, 0x38, 0x84, 0x03, 0x8e, 0x44, 0x23, 0x98, 0x18, 0x00, 0x44, \n\t0x41, 0x50, 0x53, 0x78, 0x88, 0x09, 0x45, 0x86, 0x60, 0x30, 0x20, 0x00, 0x29, 0x00, 0xc3, 0x52, \n\t0x05, 0x9a, 0x28, 0xc9, 0x15, 0xc2, 0x10, 0x63, 0x50, 0xb2, 0x20, 0x04, 0x22, 0x0a, 0x86, 0x09, \n\t0x0c, 0x45, 0x03, 0x04, 0x32, 0xd0, 0x02, 0xa6, 0x30, 0x18, 0x28, 0x68, 0x02, 0x02, 0x0a, 0x30, \n\t0x51, 0x02, 0x08, 0x06, 0x60, 0x10, 0xd1, 0xc1, 0x82, 0x06, 0xd1, 0xa2, 0x0b, 0xf9, 0x00, 0x2e, \n\t0x18, 0xa4, 0x02, 0x80, 0x4c, 0x58, 0xa3, 0x40, 0x10, 0x80, 0x04, 0x1c, 0x52, 0x03, 0x22, 0x41, \n\t0x81, 0x21, 0x04, 0x06, 0x0c, 0x10, 0x60, 0x00, 0x02, 0x55, 0x13, 0x60, 0x14, 0x00, 0x38, 0x18, \n\t0x01, 0x00, 0x45, 0x02, 0x10, 0x53, 0x31, 0x48, 0x08, 0x20, 0x06, 0xa4, 0x48, 0xaf, 0x40, 0x47, \n\t0x41, 0x60, 0x00, 0x21, 0x1a, 0x28, 0x82, 0x68, 0x74, 0x22, 0x81, 0x9e, 0x18, 0xc9, 0xe4, 0x74, \n\t0xa4, 0x43, 0x01, 0x64, 0x12, 0x23, 0x56, 0xb1, 0x50, 0x00, 0xc0, 0x00, 0x06, 0x00, 0x64, 0xc1, \n\t0xa4, 0x80, 0x03, 0x40, 0x28, 0xc1, 0x80, 0x19, 0x51, 0x04, 0xc1, 0x40, 0x41, 0x90, 0x9d, 0xa1, \n\t0x0c, 0x04, 0x0e, 0x64, 0x10, 0x00, 0x14, 0x92, 0x40, 0x42, 0x61, 0xa1, 0x90, 0xd0, 0x08, 0x0d, \n\t0x30, 0x22, 0x08, 0x00, 0x44, 0x07, 0xe2, 0x34, 0xe4, 0x41, 0x98, 0x84, 0x08, 0x41, 0x08, 0x05, \n\t0x22, 0x0f, 0x30, 0xc0, 0x44, 0x08, 0x13, 0x28, 0x06, 0x80, 0x11, 0x29, 0x48, 0x10, 0x0a, 0x3d, \n\t0x89, 0x10, 0xc2, 0x40, 0x32, 0x10, 0x04, 0xa4, 0x08, 0xcc, 0x34, 0x55, 0x03, 0xac, 0xd0, 0xc2, \n\t0x80, 0x02, 0x86, 0x0a, 0xa5, 0x50, 0x54, 0x20, 0x50, 0x04, 0xaa, 0x02, 0x6c, 0x5a, 0xa2, 0x2c, \n\t0x51, 0xfb, 0x00, 0x39, 0x03, 0x09, 0x40, 0x04, 0x92, 0xb4, 0x0d, 0x44, 0x05, 0x10, 0x86, 0x89, \n\t0x28, 0x21, 0x42, 0x47, 0x0a, 0x12, 0x68, 0x1e, 0xa0, 0x81, 0x02, 0x20, 0xd0, 0x61, 0x2f, 0x00, \n\t0x44, 0x25, 0x20, 0x04, 0x02, 0x0a, 0x98, 0x9a, 0xa0, 0x20, 0x04, 0x00, 0x24, 0x2c, 0x80, 0x02, \n\t0x00, 0x02, 0x48, 0x08, 0x14, 0x92, 0xa0, 0x00, 0x00, 0x52, 0x19, 0x49, 0x92, 0x41, 0x00, 0x44, \n\t0x20, 0x82, 0x44, 0x01, 0x81, 0x4c, 0x57, 0x98, 0x07, 0xe0, 0x96, 0x20, 0x42, 0x31, 0x02, 0xb0, \n\t0x51, 0x0d, 0x69, 0x6c, 0x85, 0x68, 0x24, 0x08, 0x05, 0x04, 0x26, 0xc4, 0xd8, 0x92, 0x85, 0x07, \n\t0x86, 0x38, 0x61, 0x40, 0x82, 0x80, 0x08, 0x02, 0x10, 0x34, 0x02, 0x3d, 0x30, 0x82, 0x0c, 0x40, \n\t0x05, 0x2a, 0x08, 0x50, 0x00, 0x40, 0x18, 0x10, 0x60, 0x15, 0x21, 0x13, 0x60, 0x02, 0x91, 0x18, \n\t0xa4, 0x81, 0x0a, 0x8a, 0x48, 0x14, 0x70, 0x94, 0x81, 0x4b, 0xc0, 0x0e, 0xb5, 0x90, 0x1a, 0x14, \n\t0x48, 0x00, 0x40, 0x12, 0x48, 0x26, 0x6c, 0x00, 0x84, 0x18, 0x10, 0x00, 0x85, 0x70, 0x82, 0xe8, \n\t0x42, 0xa0, 0x22, 0x80, 0x11, 0x40, 0x2b, 0x02, 0x96, 0xc9, 0x88, 0x58, 0x84, 0x0f, 0x30, 0xc5, \n\t0x28, 0x36, 0xe0, 0xc6, 0x4a, 0x10, 0x15, 0x00, 0x18, 0x80, 0x51, 0x08, 0x20, 0x82, 0xb1, 0x11, \n\t0xc0, 0x10, 0x09, 0x12, 0x22, 0x03, 0x21, 0x69, 0x44, 0x0e, 0x40, 0x00, 0x09, 0x02, 0x50, 0x98, \n\t0x4f, 0x00, 0x00, 0xf1, 0x1b, 0x00, 0xc2, 0x28, 0x46, 0x73, 0x82, 0x02, 0x01, 0x09, 0x83, 0x00, \n\t0x81, 0x42, 0x93, 0x0c, 0xc1, 0x02, 0x16, 0x41, 0x80, 0x83, 0x00, 0x50, 0x02, 0x60, 0x00, 0xd2, \n\t0x14, 0xa0, 0x11, 0x2a, 0x70, 0x80, 0x00, 0x03, 0xe1, 0x8b, 0x80, 0x10, 0x95, 0x08, 0x21, 0x51, \n\t0x8f, 0x00, 0x3a, 0x21, 0x83, 0x8a, 0x20, 0x94, 0x40, 0x4c, 0x73, 0x03, 0x07, 0xa8, 0x08, 0x80, \n\t0x18, 0x06, 0xc0, 0x09, 0x45, 0x40, 0x24, 0x10, 0xa0, 0x42, 0xa2, 0xa4, 0x08, 0x04, 0x18, 0x42, \n\t0x41, 0x10, 0x59, 0x01, 0x88, 0x66, 0x05, 0x1a, 0x0f, 0x14, 0x86, 0x81, 0x66, 0xd0, 0x39, 0x00, \n\t0x0c, 0x80, 0x00, 0x70, 0x11, 0x21, 0x12, 0x08, 0xc0, 0xe1, 0x0a, 0x60, 0x09, 0x9c, 0x91, 0x0c, \n\t0xe2, 0x64, 0x25, 0x5a, 0x90, 0x10, 0x08, 0x89, 0x3c, 0x74, 0x71, 0x24, 0x44, 0x05, 0x46, 0x08, \n\t0x00, 0x80, 0x80, 0xa8, 0xd9, 0x01, 0x1c, 0xb6, 0xb1, 0x8a, 0x10, 0x09, 0xaa, 0x56, 0x82, 0x58, \n\t0x00, 0x01, 0x94, 0x2d, 0x14, 0x21, 0xa2, 0x03, 0x85, 0x94, 0x20, 0x28, 0x41, 0x52, 0x80, 0xc5, \n\t0x01, 0x23, 0x08, 0x25, 0x20, 0xb1, 0x40, 0x08, 0x03, 0x00, 0x05, 0xe0, 0x0c, 0x08, 0xc2, 0xa0, \n\t0x06, 0x25, 0xaa, 0x05, 0x54, 0x1f, 0x08, 0x28, 0x60, 0x00, 0x18, 0xed, 0x50, 0x02, 0x02, 0x71, \n\t0x10, 0x28, 0x21, 0x41, 0x6d, 0x10, 0x90, 0x70, 0x22, 0x25, 0x83, 0x81, 0x50, 0xb3, 0xe0, 0x3c, \n\t0x98, 0x06, 0x20, 0x10, 0x55, 0x4b, 0x90, 0xc1, 0xd0, 0xc1, 0x40, 0x02, 0x11, 0x00, 0xb4, 0x40, \n\t0x8c, 0x10, 0x00, 0x4a, 0xa2, 0x90, 0x0c, 0x64, 0x20, 0x10, 0xc3, 0x9b, 0x19, 0x90, 0x01, 0x00, \n\t0x12, 0x28, 0x81, 0x30, 0x0e, 0x86, 0x22, 0x46, 0x99, 0x81, 0x44, 0x1a, 0x08, 0x0c, 0x05, 0xa1, \n\t0x10, 0xf0, 0x0c, 0x21, 0x00, 0xe1, 0x32, 0x00, 0x58, 0x08, 0xe8, 0x00, 0x62, 0x83, 0x18, 0x00, \n\t0x82, 0x47, 0x12, 0x62, 0x59, 0x01, 0xa0, 0x19, 0x80, 0x00, 0x50, 0xa8, 0x38, 0x80, 0x50, 0x48, \n\t0x12, 0xe0, 0x43, 0x18, 0xc8, 0xc4, 0x07, 0x40, 0x02, 0xa0, 0x01, 0x91, 0x05, 0xa8, 0x48, 0x00, \n\t0xc3, 0x0d, 0x09, 0x86, 0xe2, 0x54, 0x50, 0x10, 0x01, 0x91, 0x1a, 0x48, 0x0c, 0x71, 0x10, 0xa9, \n\t0x25, 0x80, 0x84, 0x04, 0x95, 0x48, 0x1f, 0x00, 0xd0, 0x28, 0x04, 0x30, 0x01, 0x27, 0x64, 0x88, \n\t0xe8, 0x0c, 0x06, 0x18, 0xb2, 0xd4, 0x0c, 0xe7, 0x22, 0x06, 0x00, 0x00, 0xac, 0x00, 0x28, 0x12, \n\t0x30, 0x48, 0x38, 0x11, 0x09, 0x8e, 0x42, 0x20, 0xa0, 0x24, 0x10, 0x8e, 0x09, 0x32, 0x10, 0x58, \n\t0x09, 0xd8, 0x93, 0x88, 0x44, 0x32, 0x10, 0x00, 0x84, 0x14, 0x84, 0x12, 0x21, 0x2a, 0xa6, 0x34, \n\t0x82, 0x01, 0x24, 0x43, 0x42, 0x10, 0x01, 0x42, 0x69, 0x00, 0x11, 0xb0, 0x13, 0x48, 0x81, 0x23, \n\t0x44, 0xd2, 0x2a, 0x18, 0x48, 0xd3, 0x04, 0x22, 0x70, 0xa1, 0x04, 0xb0, 0x88, 0x63, 0x06, 0x01, \n\t0x0a, 0x30, 0x81, 0x54, 0x40, 0x60, 0xd0, 0x08, 0x80, 0x30, 0x80, 0x64, 0x1e, 0x04, 0x41, 0x20, \n\t0x30, 0x0a, 0x41, 0x70, 0xe6, 0xc1, 0x19, 0x8c, 0x4e, 0x08, 0x54, 0x11, 0xca, 0x80, 0x20, 0x84, \n\t0x4e, 0x02, 0x30, 0x4b, 0x04, 0x0c, 0x80, 0x09, 0x40, 0xc0, 0x18, 0x29, 0x81, 0x00, 0x0d, 0x64, \n\t0xc6, 0x81, 0x02, 0x00, 0x13, 0x88, 0x60, 0x11, 0x10, 0x2e, 0x48, 0x0e, 0x43, 0x72, 0x50, 0x0a, \n\t0x8a, 0x84, 0xc5, 0x22, 0x20, 0x11, 0x20, 0x83, 0xa1, 0x01, 0x2a, 0x5c, 0x06, 0x32, 0x0c, 0x48, \n\t0x49, 0x8d, 0x42, 0x86, 0x98, 0x08, 0x01, 0x83, 0x43, 0x30, 0x82, 0x50, 0x98, 0x81, 0x49, 0x0a, \n\t0x22, 0x41, 0x6a, 0x84, 0x04, 0x0b, 0x0c, 0x1c, 0x03, 0x42, 0x80, 0x30, 0x56, 0xc1, 0x1c, 0x06, \n\t0x80, 0x30, 0x00, 0x04, 0xa1, 0x0a, 0x23, 0xa0, 0x01, 0x45, 0x10, 0x41, 0x28, 0x90, 0x81, 0x17, \n\t0x5c, 0x89, 0x04, 0x2c, 0x90, 0x00, 0x23, 0x4d, 0xd0, 0x05, 0x20, 0x02, 0x90, 0x8a, 0x25, 0x8a, \n\t0x22, 0x2a, 0x05, 0x30, 0x11, 0xd4, 0x06, 0xa2, 0x44, 0x65, 0x0a, 0x10, 0xc8, 0x05, 0x63, 0x10, \n\t0x50, 0x88, 0x2a, 0x01, 0xc4, 0x29, 0x28, 0x10, 0x20, 0x15, 0x51, 0x58, 0x84, 0x00, 0x44, 0x42, \n\t0x08, 0x80, 0x84, 0x41, 0x00, 0x32, 0xd2, 0x94, 0x10, 0x0c, 0x20, 0x04, 0x06, 0xea, 0x14, 0x60, \n\t0xc2, 0x6a, 0x02, 0x92, 0x21, 0x80, 0xe8, 0x10, 0x0b, 0x44, 0xc5, 0x60, 0x2f, 0x1d, 0xd0, 0x84, \n\t0x08, 0x20, 0x02, 0x84, 0x29, 0x18, 0x06, 0x42, 0x41, 0x50, 0x14, 0x48, 0x02, 0x86, 0x56, 0x21, \n\t0x48, 0x14, 0x01, 0xdb, 0x82, 0x24, 0x80, 0x5b, 0xae, 0x3c, 0x40, 0x80, 0x22, 0x10, 0x53, 0x02, \n\t0xad, 0x0a, 0x20, 0x08, 0x02, 0x18, 0xa5, 0x80, 0x1c, 0x42, 0x60, 0x70, 0xc1, 0x01, 0x0c, 0x96, \n\t0x2c, 0x0e, 0x90, 0x08, 0x09, 0x81, 0x50, 0x2d, 0x26, 0x04, 0xaa, 0x29, 0xc5, 0x01, 0x46, 0x5c, \n\t0x10, 0x53, 0x2b, 0xa8, 0x84, 0x00, 0x38, 0x53, 0x00, 0x01, 0x15, 0x98, 0x86, 0x0a, 0xc2, 0xaa, \n\t0x89, 0x60, 0x4e, 0xa0, 0x52, 0x04, 0x73, 0x8c, 0x40, 0x8a, 0x08, 0x16, 0x50, 0xa2, 0xb1, 0x24, \n\t0x0a, 0x69, 0x42, 0x05, 0x71, 0x24, 0xa0, 0x11, 0x42, 0x04, 0x90, 0xc1, 0x0a, 0x18, 0x08, 0xc9, \n\t0x26, 0x80, 0x01, 0x20, 0x35, 0x4a, 0x08, 0x58, 0xd0, 0x00, 0x91, 0x00, 0x47, 0x04, 0x76, 0x10, \n\t0x00, 0x83, 0x08, 0x80, 0x89, 0x60, 0x34, 0x2a, 0x0d, 0x88, 0x03, 0x86, 0x02, 0x82, 0x80, 0x0c, \n\t0x45, 0x82, 0x01, 0x60, 0x35, 0x60, 0x00, 0x01, 0x03, 0x6c, 0x48, 0x86, 0x90, 0x19, 0x08, 0x09, \n\t0x00, 0x18, 0x54, 0x01, 0x83, 0xe0, 0x47, 0x04, 0x14, 0x40, 0xb9, 0x80, 0x1c, 0x50, 0xaa, 0x02, \n\t0x03, 0x80, 0x00, 0x50, 0x50, 0xa8, 0x10, 0xb3, 0x00, 0x38, 0x44, 0x04, 0xe2, 0x28, 0x10, 0x20, \n\t0x2c, 0x60, 0x18, 0x40, 0x40, 0xa3, 0x41, 0x16, 0x0c, 0x09, 0x40, 0x20, 0x31, 0x31, 0x04, 0x10, \n\t0x19, 0x45, 0x22, 0xa0, 0x08, 0x28, 0x84, 0x45, 0xe0, 0x08, 0x21, 0xe0, 0x83, 0x04, 0x10, 0x43, \n\t0x54, 0x01, 0x82, 0x08, 0x80, 0x82, 0x46, 0x22, 0xe4, 0x10, 0x80, 0x70, 0x02, 0x81, 0x38, 0x51, \n\t0x33, 0x0e, 0x20, 0xcc, 0x28, 0x12, 0x11, 0x91, 0x26, 0xe1, 0x0c, 0x09, 0x18, 0x63, 0x40, 0x00, \n\t0x68, 0x19, 0x8a, 0x24, 0x50, 0x4a, 0x20, 0x25, 0x0d, 0x24, 0x2c, 0x64, 0x70, 0x0e, 0x45, 0x1c, \n\t0x0c, 0x08, 0x94, 0x83, 0x30, 0x28, 0xd7, 0x24, 0x40, 0x52, 0x70, 0x07, 0x20, 0x06, 0x00, 0x52, \n\t0x00, 0x20, 0x29, 0x60, 0x40, 0x84, 0x52, 0x40, 0x12, 0x00, 0x99, 0x10, 0x8f, 0x48, 0x11, 0x01, \n\t0x9d, 0x8c, 0x80, 0x22, 0x0e, 0x83, 0x32, 0x20, 0x4d, 0xc4, 0x03, 0x10, 0x46, 0x22, 0x22, 0xa1, \n\t0x41, 0x08, 0x3c, 0x10, 0xa0, 0x94, 0xc1, 0x91, 0x08, 0x70, 0x62, 0x1b, 0xaa, 0x31, 0x0c, 0x83, \n\t0x50, 0x17, 0xc9, 0x28, 0xc9, 0x01, 0x01, 0x0c, 0x04, 0x68, 0x30, 0x34, 0x40, 0x02, 0x00, 0xc2, \n\t0x43, 0x01, 0x00, 0x13, 0x08, 0x18, 0x00, 0xe2, 0x1f, 0x81, 0x14, 0xaa, 0x4c, 0x30, 0x98, 0x20, \n\t0x20, 0x46, 0xc7, 0x0c, 0x02, 0xc1, 0x80, 0x60, 0x00, 0x81, 0x18, 0x10, 0xe0, 0x2a, 0x49, 0xc8, \n\t0x41, 0x02, 0x26, 0xa2, 0x08, 0x25, 0x8f, 0x20, 0x72, 0x41, 0x1a, 0x00, 0xe1, 0x08, 0x00, 0x1e, \n\t0x20, 0x80, 0x84, 0xc8, 0x01, 0x03, 0x60, 0x43, 0xb9, 0x18, 0x41, 0x10, 0x8c, 0x24, 0xe6, 0x08, \n\t0x8a, 0xbc, 0x02, 0x00, 0x36, 0x41, 0x58, 0xa8, 0xa0, 0xc1, 0x00, 0x02, 0x12, 0x80, 0x83, 0x28, \n\t0x18, 0x65, 0x70, 0xa0, 0x00, 0x01, 0x18, 0x08, 0xa8, 0x22, 0x94, 0x52, 0x30, 0x01, 0x06, 0x04, \n\t0x40, 0xc0, 0x23, 0x07, 0x35, 0x00, 0xaa, 0x10, 0x44, 0x52, 0x09, 0x0c, 0x58, 0xe3, 0x0c, 0x80, \n\t0x10, 0x10, 0x78, 0x00, 0x41, 0x44, 0x41, 0xc1, 0x04, 0x29, 0x99, 0xaa, 0x00, 0x30, 0xc1, 0x10, \n\t0x05, 0x54, 0x29, 0x50, 0xc4, 0x29, 0x84, 0x60, 0x08, 0x44, 0x22, 0x24, 0xd0, 0x21, 0xc8, 0x04, \n\t0x48, 0x0c, 0x25, 0x00, 0x30, 0x40, 0xc6, 0x83, 0x68, 0x36, 0x82, 0x07, 0x1c, 0x89, 0x29, 0x02, \n\t0x22, 0x90, 0x02, 0x41, 0x85, 0x88, 0x0e, 0x02, 0x01, 0x04, 0x58, 0x11, 0x6e, 0x00, 0xb1, 0x69, \n\t0x00, 0x75, 0x94, 0x08, 0x10, 0x02, 0x70, 0x23, 0x95, 0x42, 0xe3, 0x28, 0x82, 0x10, 0x89, 0x14, \n\t0x10, 0x02, 0x0c, 0x80, 0x11, 0x04, 0x21, 0x12, 0x02, 0x66, 0x01, 0x6b, 0x21, 0xc8, 0x0a, 0xc0, \n\t0x24, 0x01, 0xe0, 0x12, 0xdc, 0x04, 0x4e, 0x20, 0x06, 0x0b, 0xb2, 0x90, 0x47, 0x05, 0x0a, 0x05, \n\t0x41, 0xb1, 0x44, 0x41, 0x01, 0x58, 0x94, 0x02, 0x32, 0x9c, 0xc8, 0x28, 0x04, 0x25, 0x50, 0x86, \n\t0x20, 0x06, 0x8b, 0x4c, 0x10, 0x10, 0x0d, 0x8c, 0x40, 0xc4, 0x12, 0x10, 0x08, 0x24, 0x20, 0x80, \n\t0x05, 0x44, 0x12, 0x42, 0x2c, 0xd9, 0x00, 0x4a, 0x04, 0xa2, 0x80, 0xa4, 0x24, 0x0d, 0x46, 0x2e, \n\t0xc4, 0x7b, 0x33, 0x80, 0x54, 0x04, 0x6a, 0x00, 0x00, 0x00, 0x21, 0x40, 0xaa, 0x10, 0xe1, 0xe0, \n\t0xa4, 0x10, 0x51, 0x01, 0x06, 0x90, 0x90, 0xa0, 0xe8, 0x80, 0x05, 0x30, 0x71, 0x28, 0x14, 0xe5, \n\t0x82, 0x43, 0x10, 0xa4, 0x42, 0x90, 0x8c, 0x84, 0x01, 0x58, 0x10, 0x1a, 0x01, 0xb9, 0x06, 0x80, \n\t0x68, 0x82, 0x40, 0x0d, 0x08, 0x14, 0x2a, 0x4c, 0x41, 0xf8, 0xa2, 0x01, 0x10, 0x22, 0x00, 0xa0, \n\t0x20, 0x90, 0xd4, 0x8a, 0x44, 0x0a, 0x52, 0x90, 0xa7, 0x70, 0x41, 0x05, 0x40, 0x01, 0x08, 0x07, \n\t0x80, 0x4d, 0x04, 0x60, 0x40, 0xc8, 0x00, 0x58, 0x94, 0xa0, 0x34, 0x02, 0xe8, 0x08, 0x00, 0x5d, \n\t0x02, 0x04, 0xe1, 0x52, 0x80, 0x28, 0x88, 0x07, 0x1e, 0xd0, 0x18, 0x9d, 0x30, 0x5e, 0x84, 0x28, \n\t0x60, 0x01, 0xbc, 0xb4, 0x0a, 0x00, 0x0e, 0x00, 0x41, 0x10, 0x21, 0x48, 0x80, 0x02, 0x30, 0x51, \n\t0x1c, 0x81, 0x00, 0x68, 0x0a, 0xc1, 0x20, 0x2d, 0x15, 0x0c, 0x61, 0x00, 0xb0, 0xd0, 0x11, 0x11, \n\t0x51, 0x00, 0x60, 0x70, 0x80, 0xb2, 0x69, 0xc5, 0x81, 0x44, 0x82, 0x03, 0x00, 0x8d, 0x41, 0xa8, \n\t0x42, 0x01, 0xaa, 0x82, 0x80, 0x44, 0x4b, 0x72, 0x00, 0x0b, 0xb2, 0x00, 0x18, 0x26, 0x54, 0xc0, \n\t0xc8, 0xa0, 0x54, 0x89, 0x2a, 0x0a, 0x82, 0x29, 0x1b, 0x51, 0x04, 0xc2, 0x52, 0x01, 0xe1, 0x3b, \n\t0x04, 0x48, 0x24, 0x40, 0x83, 0xc1, 0x04, 0x20, 0x12, 0xce, 0x00, 0xa0, 0x03, 0x04, 0x08, 0x01, \n\t0x08, 0x50, 0xd0, 0xb0, 0x08, 0xa4, 0x04, 0x26, 0x00, 0x84, 0xa2, 0x92, 0x00, 0x41, 0xcc, 0x62, \n\t0x80, 0x28, 0x15, 0x61, 0xc4, 0x41, 0x1c, 0xd1, 0x3a, 0x32, 0xc1, 0x09, 0x22, 0x08, 0x51, 0x90, \n\t0x05, 0x0d, 0x13, 0x80, 0x50, 0x00, 0x8a, 0x18, 0x48, 0x00, 0x60, 0x24, 0xe4, 0x42, 0x02, 0xc4, \n\t0x07, 0x42, 0x04, 0x11, 0x41, 0x82, 0x40, 0x00, 0x0d, 0x3a, 0xc0, 0x42, 0x94, 0x9c, 0xc2, 0x44, \n\t0x2e, 0x47, 0x70, 0x98, 0x60, 0x09, 0x2a, 0x60, 0x00, 0x33, 0x25, 0x5c, 0x14, 0x20, 0x00, 0x11, \n\t0x01, 0x08, 0x28, 0x0c, 0x2a, 0x24, 0xc0, 0x12, 0x09, 0x94, 0x0b, 0x8b, 0x22, 0xc0, 0x10, 0x16, \n\t0x70, 0x80, 0x04, 0x30, 0x00, 0xc9, 0xa6, 0xa8, 0x59, 0xa2, 0x02, 0x10, 0x1a, 0x01, 0x94, 0xc7, \n\t0xc1, 0x42, 0xa0, 0x18, 0x32, 0x18, 0x55, 0x20, 0x40, 0x63, 0x00, 0x9a, 0x24, 0xc1, 0x08, 0x00, \n\t0x32, 0x29, 0x00, 0x45, 0x41, 0x89, 0x58, 0x72, 0x80, 0x00, 0x90, 0x1c, 0x44, 0x00, 0x12, 0x18, \n\t0x02, 0x50, 0x08, 0x46, 0x2c, 0x80, 0xcb, 0x30, 0x59, 0x91, 0xec, 0x08, 0x00, 0xc2, 0x09, 0x89, \n\t0x12, 0x40, 0x0c, 0x20, 0x51, 0x02, 0x1c, 0x10, 0x05, 0x02, 0x60, 0xa8, 0xa0, 0x08, 0x0e, 0xa2, \n\t0x4c, 0x96, 0xc0, 0x9c, 0x84, 0x10, 0x82, 0x52, 0x00, 0x31, 0x20, 0xe5, 0x55, 0x28, 0x74, 0x80, \n\t0x18, 0x22, 0x24, 0x04, 0x0a, 0x02, 0xe1, 0x40, 0xa3, 0x99, 0x05, 0xe6, 0x08, 0x91, 0x50, 0x03, \n\t0x14, 0x8e, 0xc1, 0x60, 0x24, 0xeb, 0x12, 0xa0, 0x02, 0x60, 0x60, 0x40, 0x2a, 0x91, 0xf8, 0x80, \n\t0x2c, 0x14, 0x22, 0x48, 0x05, 0x34, 0x91, 0x2c, 0x12, 0xa2, 0x51, 0x81, 0x01, 0x9c, 0x62, 0x08, \n\t0xd1, 0xe1, 0x10, 0x85, 0x50, 0x2e, 0x20, 0x15, 0x80, 0x02, 0x00, 0x16, 0xe6, 0x72, 0x81, 0x13, \n\t0xa5, 0x40, 0xc2, 0x02, 0x02, 0x64, 0x09, 0x80, 0x65, 0x40, 0x80, 0x04, 0x44, 0x20, 0x30, 0x98, \n\t0x11, 0xc5, 0x32, 0x11, 0x50, 0x31, 0x08, 0x80, 0x04, 0x22, 0x77, 0x20, 0x0a, 0x24, 0x98, 0x00, \n\t0x00, 0x20, 0x48, 0xb3, 0x08, 0x88, 0x04, 0x24, 0xb3, 0x0a, 0x96, 0x00, 0x83, 0xa0, 0x34, 0x02, \n\t0x50, 0x39, 0x68, 0x04, 0x48, 0x14, 0x00, 0x00, 0x03, 0x04, 0x0a, 0xc9, 0x58, 0x01, 0x22, 0x0b, \n\t0x81, 0x49, 0x41, 0x2e, 0x25, 0x02, 0x22, 0x01, 0x90, 0x63, 0x60, 0x04, 0x80, 0x14, 0x80, 0x45, \n\t0x06, 0x3a, 0x05, 0x50, 0x23, 0x64, 0x4a, 0x89, 0x06, 0x03, 0x91, 0x84, 0xb4, 0x40, 0x88, 0x52, \n\t0x61, 0x10, 0x89, 0x1c, 0x40, 0x87, 0x20, 0x82, 0x61, 0x12, 0x84, 0x9a, 0x89, 0x40, 0x42, 0x68, \n\t0x00, 0x00, 0x9a, 0x21, 0x20, 0x11, 0xda, 0x84, 0x80, 0x46, 0x45, 0x00, 0x14, 0x01, 0x08, 0xb4, \n\t0x05, 0x24, 0x0e, 0xa1, 0xa2, 0x20, 0x44, 0x80, 0x49, 0x48, 0x06, 0x40, 0xa2, 0xc0, 0x51, 0xc4, \n\t0x68, 0x34, 0x32, 0x00, 0x3c, 0x10, 0x44, 0x1c, 0x11, 0x30, 0x08, 0x00, 0x4e, 0xa8, 0x30, 0x15, \n\t0xd8, 0x31, 0x28, 0x80, 0x28, 0x04, 0x46, 0x08, 0x20, 0xa1, 0x04, 0x42, 0x12, 0xd2, 0x0a, 0x31, \n\t0x01, 0x02, 0x00, 0x04, 0x20, 0x01, 0xac, 0x65, 0x14, 0x0d, 0x58, 0x51, 0x03, 0x10, 0x00, 0x15, \n\t0x08, 0x04, 0x46, 0x89, 0x8f, 0xf0, 0x88, 0x06, 0x08, 0x20, 0xb1, 0x09, 0x68, 0x52, 0x2a, 0x02, \n\t0x33, 0x82, 0x82, 0xa8, 0x08, 0xe4, 0x60, 0x25, 0x03, 0xac, 0x11, 0x00, 0x85, 0x40, 0xb1, 0x92, \n\t0x86, 0x01, 0xc2, 0x03, 0x28, 0x42, 0x30, 0x17, 0x28, 0xd6, 0xa0, 0x26, 0x00, 0x10, 0x00, 0x59, \n\t0x12, 0x08, 0x0a, 0xc2, 0x61, 0x80, 0x95, 0x08, 0x43, 0x62, 0x90, 0x40, 0x31, 0x90, 0x00, 0x04, \n\t0x2a, 0x92, 0x08, 0x80, 0x21, 0x57, 0x0e, 0x30, 0x00, 0x40, 0x22, 0x24, 0x03, 0x45, 0x60, 0x62, \n\t0xa0, 0x90, 0x41, 0x44, 0x00, 0x18, 0x90, 0x98, 0x15, 0x20, 0x05, 0x00, 0x4a, 0x43, 0x62, 0x00, \n\t0x08, 0x90, 0x80, 0x28, 0x00, 0xb1, 0x3f, 0x40, 0x58, 0x4d, 0x24, 0x45, 0x22, 0x18, 0x04, 0x02, \n\t0x26, 0x6a, 0x10, 0x10, 0x84, 0xcc, 0x85, 0x24, 0x28, 0x14, 0x12, 0x94, 0x41, 0x81, 0x60, 0x70, \n\t0x01, 0x88, 0x80, 0x05, 0x01, 0x23, 0x40, 0x34, 0x8a, 0x0b, 0x20, 0x89, 0x40, 0x36, 0x01, 0x21, \n\t0x00, 0x25, 0x58, 0x09, 0x40, 0x91, 0x0b, 0x18, 0x90, 0x00, 0x69, 0x3a, 0x01, 0x83, 0x84, 0x00, \n\t0xca, 0x24, 0x18, 0x02, 0xd2, 0x00, 0x10, 0x41, 0x01, 0x00, 0xc1, 0xa3, 0x04, 0x38, 0x9c, 0x25, \n\t0x04, 0x11, 0x60, 0x31, 0x40, 0xd8, 0x29, 0x20, 0x04, 0x08, 0x0a, 0x14, 0x08, 0xc0, 0x08, 0x01, \n\t0x81, 0x05, 0x0d, 0x95, 0x20, 0x42, 0x61, 0x10, 0x30, 0x8c, 0x0b, 0x08, 0x38, 0x45, 0x1a, 0x2a, \n\t0x98, 0x40, 0x46, 0x74, 0xb4, 0x40, 0x32, 0xd0, 0x08, 0x02, 0x14, 0x02, 0x39, 0x19, 0x20, 0x42, \n\t0x84, 0x22, 0x60, 0x00, 0x01, 0x08, 0x51, 0x09, 0x2c, 0x20, 0x7a, 0x0a, 0x80, 0x90, 0xe4, 0x18, \n\t0x00, 0x50, 0x18, 0x41, 0xc1, 0x27, 0x04, 0x02, 0x4a, 0x20, 0x04, 0x00, 0xc4, 0x1c, 0x15, 0xc0, \n\t0xb0, 0x0c, 0x11, 0x20, 0x06, 0xa6, 0x20, 0xb8, 0x19, 0x8a, 0xa3, 0x58, 0xc2, 0x40, 0x90, 0x01, \n\t0xcb, 0x0c, 0x20, 0x30, 0xd8, 0x83, 0x4c, 0x16, 0x80, 0x0e, 0x20, 0x09, 0x3c, 0x51, 0x54, 0x80, \n\t0x20, 0x07, 0x53, 0x30, 0x3c, 0x4e, 0x65, 0x00, 0x90, 0x48, 0x0e, 0x01, 0x06, 0x84, 0x38, 0x82, \n\t0x8a, 0x18, 0x18, 0x18, 0x40, 0x60, 0x03, 0x11, 0x89, 0x01, 0x53, 0x09, 0x42, 0x22, 0x01, 0x08, \n\t0x05, 0x92, 0x04, 0x58, 0x11, 0x12, 0x82, 0x70, 0x14, 0x82, 0x7c, 0x12, 0x00, 0xa0, 0x89, 0xc8, \n\t0x60, 0x02, 0x00, 0x20, 0x13, 0x7d, 0x48, 0x00, 0x0a, 0x40, 0x4b, 0x03, 0x49, 0x04, 0x84, 0x54, \n\t0x00, 0xb1, 0x96, 0x44, 0x16, 0x2b, 0x54, 0x46, 0x50, 0x10, 0x04, 0x01, 0xc9, 0x64, 0x05, 0x1a, \n\t0x2a, 0xc0, 0x81, 0xc3, 0x12, 0x33, 0x40, 0x12, 0xc4, 0x05, 0x0d, 0x72, 0xa0, 0x40, 0x84, 0x14, \n\t0x10, 0x20, 0x30, 0x00, 0x1a, 0x80, 0x99, 0x8e, 0xc2, 0x6e, 0x30, 0x48, 0x25, 0x45, 0x90, 0x0a, \n\t0x18, 0x60, 0x82, 0x28, 0x20, 0x86, 0x03, 0x10, 0x64, 0x91, 0x90, 0x8c, 0x8a, 0xa0, 0x2e, 0x50, \n\t0x88, 0x0d, 0x30, 0x98, 0x00, 0x08, 0x03, 0x53, 0x1a, 0x29, 0xc9, 0x00, 0x38, 0x01, 0x60, 0x20, \n\t0xc0, 0xcb, 0x00, 0x28, 0x41, 0x08, 0x82, 0xa5, 0x4c, 0x81, 0x26, 0x44, 0x02, 0x30, 0x51, 0x42, \n\t0x0e, 0x00, 0xd0, 0x10, 0xa0, 0x50, 0x81, 0x81, 0x08, 0x54, 0xa3, 0xb3, 0xa0, 0x80, 0x0c, 0x62, \n\t0xa1, 0xa8, 0x09, 0x08, 0x1e, 0x02, 0x22, 0xa4, 0x3b, 0x04, 0x1d, 0x90, 0x05, 0x48, 0x20, 0x38, \n\t0x00, 0x00, 0x08, 0x66, 0x04, 0x50, 0x90, 0x35, 0x04, 0x08, 0x28, 0x40, 0x12, 0x22, 0x01, 0x40, \n\t0xc3, 0x82, 0x04, 0x02, 0x10, 0x03, 0x64, 0xc0, 0xa0, 0x30, 0x00, 0x02, 0x84, 0x20, 0x06, 0x08, \n\t0x48, 0x20, 0xc3, 0x06, 0x68, 0x40, 0x01, 0x50, 0x33, 0x01, 0x01, 0xf8, 0x80, 0x86, 0x02, 0x05, \n\t0x01, 0x28, 0x01, 0x0e, 0x43, 0x42, 0xa3, 0x01, 0x13, 0xb4, 0xce, 0x24, 0x02, 0x00, 0xc0, 0x1c, \n\t0x00, 0x06, 0xa6, 0x40, 0xb2, 0xe2, 0x24, 0xa0, 0x94, 0x4c, 0x40, 0xe0, 0xb1, 0x23, 0x18, 0x08, \n\t0x28, 0x00, 0x05, 0x50, 0x8a, 0x80, 0x01, 0xe0, 0x40, 0x85, 0x38, 0x06, 0x50, 0x01, 0x43, 0x00, \n\t0xd2, 0x08, 0x95, 0xc8, 0x5a, 0x08, 0x00, 0x14, 0x6a, 0x81, 0x09, 0x02, 0x4a, 0x22, 0x84, 0x22, \n\t0x12, 0x00, 0x11, 0x2c, 0x46, 0x26, 0xc1, 0x81, 0x81, 0x01, 0xc8, 0x00, 0x04, 0x09, 0x30, 0x81, \n\t0xc9, 0x4b, 0x58, 0x95, 0x28, 0xa0, 0x04, 0x0c, 0x20, 0x34, 0x40, 0x89, 0x0b, 0x30, 0x4b, 0x0b, \n\t0x04, 0x00, 0x80, 0x09, 0x98, 0x02, 0x02, 0x02, 0x72, 0x52, 0x04, 0x48, 0x00, 0x48, 0x04, 0x30, \n\t0xa0, 0xb4, 0x40, 0x88, 0x87, 0x02, 0x53, 0x18, 0x22, 0x65, 0x45, 0x23, 0x24, 0x00, 0x98, 0x18, \n\t0x09, 0x08, 0x0c, 0x00, 0x60, 0x40, 0xa4, 0xd8, 0x40, 0x42, 0x50, 0xc2, 0x80, 0xa8, 0x05, 0x5d, \n\t0x28, 0x04, 0x04, 0x00, 0xb0, 0xe8, 0x80, 0x82, 0x26, 0x84, 0x20, 0x1e, 0x20, 0xd3, 0xcd, 0x08, \n\t0x07, 0x22, 0x06, 0x14, 0x10, 0x69, 0x0e, 0x05, 0x19, 0x80, 0xd1, 0x84, 0x2a, 0x38, 0x22, 0x8a, \n\t0x11, 0x91, 0x51, 0xc2, 0x06, 0x50, 0x3a, 0xa1, 0x49, 0x04, 0x82, 0x6c, 0x26, 0x52, 0x03, 0x94, \n\t0x80, 0x02, 0x40, 0x10, 0x00, 0x88, 0x50, 0x42, 0xa2, 0x4c, 0x10, 0x79, 0x34, 0x00, 0x8f, 0x84, \n\t0x34, 0x41, 0x49, 0x32, 0x09, 0x42, 0xc0, 0x14, 0x62, 0x03, 0x06, 0x28, 0x48, 0x22, 0x50, 0x60, \n\t0x00, 0xb2, 0xec, 0x00, 0xc2, 0x0e, 0x35, 0x20, 0x80, 0x50, 0x4d, 0x08, 0x00, 0x60, 0x2a, 0x1c, \n\t0xa0, 0x54, 0x20, 0x02, 0x04, 0x10, 0x05, 0x40, 0x8b, 0xe8, 0x62, 0x12, 0x82, 0x0d, 0xc1, 0x92, \n\t0x84, 0x1c, 0x11, 0x81, 0xa4, 0x00, 0x0c, 0x48, 0x54, 0x71, 0x81, 0x91, 0x44, 0x90, 0x28, 0x06, \n\t0x83, 0x8a, 0x12, 0x65, 0x50, 0x60, 0x5c, 0xc4, 0x20, 0x31, 0x05, 0x8c, 0x02, 0x4c, 0x10, 0xa2, \n\t0x94, 0x29, 0x96, 0x08, 0x40, 0x25, 0xa3, 0xb0, 0x68, 0x10, 0x0d, 0x74, 0x01, 0x98, 0x00, 0x81, \n\t0x00, 0x40, 0x00, 0xb2, 0x61, 0x94, 0xa0, 0x04, 0x88, 0x40, 0x00, 0x61, 0x31, 0x14, 0x43, 0x05, \n\t0x16, 0x20, 0xe8, 0x0b, 0x08, 0x17, 0x08, 0x10, 0x00, 0x79, 0x11, 0x01, 0x84, 0x41, 0x1c, 0x90, \n\t0x99, 0x87, 0x84, 0x1a, 0xc0, 0x6c, 0x07, 0x90, 0x82, 0x84, 0xdb, 0x89, 0x28, 0x36, 0x12, 0x11, \n\t0x20, 0x05, 0x03, 0x20, 0x85, 0x02, 0x00, 0xe0, 0x40, 0x02, 0x24, 0x05, 0x32, 0x22, 0x10, 0x09, \n\t0x20, 0x70, 0x80, 0xd0, 0x18, 0xa5, 0x18, 0x80, 0x00, 0x01, 0x80, 0x21, 0x40, 0x0b, 0x6d, 0x00, \n\t0x53, 0x08, 0x11, 0xb0, 0x08, 0x06, 0x2a, 0x62, 0xa0, 0x0d, 0x8c, 0x16, 0x65, 0x40, 0x11, 0x01, \n\t0x06, 0x30, 0x44, 0xc3, 0x02, 0x00, 0x10, 0x10, 0x34, 0xc2, 0x02, 0x0e, 0x30, 0xc8, 0x85, 0xd9, \n\t0x06, 0x09, 0x08, 0x04, 0x82, 0x28, 0x88, 0x03, 0x06, 0x08, 0x20, 0x92, 0x0e, 0x61, 0x81, 0x65, \n\t0x66, 0x01, 0x23, 0x0e, 0xc0, 0x02, 0xac, 0x1a, 0x35, 0x03, 0x13, 0x20, 0xd8, 0x2b, 0x10, 0x04, \n\t0x63, 0x04, 0x68, 0x5d, 0x22, 0x34, 0x40, 0x10, 0x08, 0x1c, 0x48, 0x00, 0x3a, 0x40, 0x50, 0x01, \n\t0x85, 0x50, 0x00, 0x00, 0x01, 0x09, 0x9d, 0x30, 0x8c, 0x08, 0x0e, 0x27, 0x50, 0x0e, 0x28, 0x91, \n\t0x86, 0x04, 0x80, 0x69, 0x30, 0xc5, 0x42, 0xe5, 0x50, 0x82, 0x10, 0x82, 0x3c, 0x86, 0x6c, 0x10, \n\t0x40, 0x43, 0x28, 0x04, 0x42, 0x23, 0x00, 0xa4, 0xb0, 0x09, 0x51, 0xcd, 0x00, 0x24, 0x06, 0xe2, \n\t0x90, 0x61, 0x96, 0x08, 0x22, 0x50, 0x09, 0x02, 0x4d, 0x59, 0x20, 0x42, 0x05, 0x10, 0x04, 0xe4, \n\t0x0c, 0xcb, 0x04, 0x14, 0xc3, 0x22, 0x80, 0x08, 0x21, 0x16, 0x95, 0x61, 0x06, 0xd0, 0x03, 0x0a, \n\t0x1a, 0x10, 0x00, 0x02, 0xb0, 0x40, 0x64, 0x42, 0x04, 0x02, 0x88, 0x40, 0x02, 0xa8, 0x54, 0x04, \n\t0x00, 0x11, 0x58, 0x54, 0x6d, 0x02, 0x23, 0xc2, 0x80, 0x64, 0x80, 0x02, 0x04, 0xf2, 0x00, 0x14, \n\t0x1d, 0x03, 0x66, 0x44, 0xa1, 0x28, 0x00, 0x04, 0x8a, 0x24, 0x62, 0x90, 0x30, 0xa5, 0x41, 0x07, \n\t0x00, 0x1a, 0x40, 0x90, 0xa4, 0x4c, 0x10, 0x41, 0x48, 0x24, 0x61, 0x3c, 0xa8, 0x10, 0x2c, 0x12, \n\t0xe0, 0x01, 0x98, 0x40, 0x80, 0x88, 0x10, 0x41, 0x40, 0x84, 0x91, 0x48, 0x04, 0x40, 0xa3, 0x00, \n\t0x9b, 0xa8, 0x90, 0x24, 0x50, 0x31, 0xa8, 0x83, 0x91, 0x44, 0x42, 0x0a, 0x12, 0x02, 0x30, 0xa8, \n\t0x55, 0xe8, 0x08, 0x41, 0x00, 0x0c, 0x08, 0x12, 0x07, 0x4c, 0xd2, 0x40, 0xac, 0x14, 0x09, 0xe2, \n\t0x02, 0x01, 0x82, 0x9c, 0x00, 0x15, 0x81, 0x20, 0x52, 0x08, 0x01, 0x60, 0x42, 0x0a, 0x46, 0x25, \n\t0x28, 0x94, 0xa5, 0x98, 0x61, 0x48, 0x84, 0x41, 0x80, 0xc4, 0x48, 0x21, 0x02, 0x47, 0x88, 0x89, \n\t0x50, 0x0f, 0x8a, 0x14, 0x12, 0x31, 0x12, 0x05, 0x87, 0x80, 0x32, 0x32, 0x29, 0x80, 0x00, 0xc8, \n\t0x24, 0x72, 0xe0, 0x33, 0x88, 0x41, 0x80, 0x0e, 0x22, 0xa6, 0x43, 0x0c, 0xd0, 0x51, 0x24, 0x48, \n\t0xa0, 0x82, 0x04, 0xfc, 0x86, 0x00, 0x38, 0x11, 0xc3, 0x02, 0x00, 0x43, 0x44, 0x08, 0x86, 0x20, \n\t0x0e, 0x18, 0x54, 0x00, 0x58, 0x01, 0xc8, 0x10, 0x04, 0x81, 0x02, 0x40, 0x20, 0xf8, 0x22, 0xa4, \n\t0x05, 0x4a, 0x24, 0x62, 0x08, 0x06, 0x2c, 0x10, 0x08, 0x06, 0x15, 0x83, 0x98, 0x9c, 0x00, 0x03, \n\t0x28, 0x50, 0x41, 0x36, 0x11, 0x04, 0x82, 0x12, 0x65, 0x28, 0x08, 0x8c, 0x82, 0x68, 0x10, 0x30, \n\t0x82, 0x1f, 0x80, 0x03, 0x63, 0x04, 0x02, 0x82, 0x1c, 0xc4, 0x80, 0xc1, 0x0c, 0x21, 0xa1, 0x04, \n\t0x30, 0x10, 0x08, 0x00, 0xa2, 0xd3, 0xbd, 0x01, 0xc1, 0x41, 0x60, 0x10, 0x08, 0x12, 0x1c, 0x98, \n\t0x44, 0x02, 0x82, 0x7b, 0xa3, 0x40, 0x14, 0xa4, 0x4e, 0x05, 0xc2, 0x04, 0x48, 0x8c, 0x80, 0x04, \n\t0xa2, 0x41, 0x14, 0x21, 0x01, 0x86, 0x22, 0xe5, 0xca, 0x09, 0xbc, 0x0e, 0x81, 0x10, 0xe3, 0x00, \n\t0x38, 0x20, 0x01, 0x88, 0x50, 0x10, 0xa3, 0x8e, 0x20, 0x5c, 0x45, 0x30, 0x54, 0x29, 0x91, 0x68, \n\t0x01, 0xa4, 0x14, 0xa0, 0x10, 0x20, 0x1c, 0x82, 0x6a, 0x44, 0x62, 0x20, 0x02, 0x68, 0x10, 0xc9, \n\t0x4c, 0x40, 0x02, 0x10, 0x0c, 0x0a, 0x4c, 0x68, 0x05, 0xaa, 0xa1, 0x60, 0x50, 0x46, 0x60, 0x80, \n\t0x02, 0x81, 0x40, 0x00, 0x08, 0x3e, 0x14, 0x08, 0x31, 0x31, 0x80, 0x02, 0x3a, 0x46, 0x12, 0x9a, \n\t0x61, 0x00, 0x2d, 0x10, 0x21, 0x81, 0x82, 0xe0, 0xc0, 0x01, 0x00, 0x45, 0x38, 0x01, 0x05, 0x84, \n\t0x0c, 0x48, 0x20, 0x09, 0x9d, 0x00, 0x1e, 0x41, 0x12, 0x23, 0xf1, 0x11, 0x00, 0xc4, 0x42, 0x36, \n\t0x10, 0x89, 0x04, 0xb1, 0x82, 0x43, 0x08, 0x81, 0x08, 0xa6, 0x60, 0x86, 0x60, 0x04, 0xc4, 0x20, \n\t0x2c, 0x41, 0x40, 0x40, 0x00, 0x02, 0x00, 0x12, 0x00, 0x04, 0x60, 0x6e, 0x90, 0xa1, 0x0b, 0x00, \n\t0x93, 0x28, 0x16, 0x01, 0x49, 0x01, 0xf1, 0x40, 0xa0, 0x62, 0xa0, 0xc0, 0x20, 0x90, 0x51, 0x0b, \n\t0x50, 0x01, 0x00, 0x03, 0x39, 0x85, 0x80, 0x34, 0xc5, 0x18, 0x89, 0x01, 0x10, 0x04, 0x02, 0x06, \n\t0xa2, 0xbb, 0x14, 0x08, 0x08, 0x06, 0x80, 0xfa, 0x10, 0x49, 0x1b, 0x84, 0x04, 0xb4, 0x01, 0x30, \n\t0xa0, 0x02, 0xc2, 0x54, 0x23, 0x21, 0x0a, 0xc9, 0x88, 0xa0, 0x00, 0x12, 0x71, 0x16, 0x8c, 0x50, \n\t0xc2, 0x22, 0x60, 0x08, 0xb1, 0x40, 0x06, 0x44, 0x60, 0x12, 0x8a, 0x04, 0x09, 0x46, 0xa2, 0x60, \n\t0x54, 0x40, 0x85, 0x81, 0x84, 0x88, 0x26, 0x62, 0x88, 0x98, 0x08, 0x11, 0x09, 0x16, 0x84, 0x18, \n\t0x02, 0xc5, 0x40, 0x06, 0x04, 0x91, 0x48, 0x30, 0x01, 0x14, 0x01, 0x4a, 0xc7, 0x83, 0x85, 0xa0, \n\t0x8c, 0x28, 0x1a, 0x56, 0x31, 0x89, 0x38, 0x04, 0x69, 0x54, 0x24, 0x30, 0x00, 0x60, 0x40, 0x28, \n\t0x04, 0x10, 0x52, 0x80, 0x4c, 0x02, 0x08, 0x40, 0x92, 0x63, 0x1b, 0xc0, 0x09, 0x09, 0x6a, 0x52, \n\t0x80, 0x20, 0x68, 0x8c, 0x27, 0x10, 0xc0, 0x43, 0x14, 0x0c, 0x43, 0xa2, 0x00, 0x75, 0x31, 0xb7, \n\t0x90, 0x88, 0x60, 0x2a, 0xe0, 0xf0, 0x30, 0x00, 0x00, 0x82, 0x54, 0x15, 0x02, 0x20, 0x01, 0x41, \n\t0x85, 0x04, 0x02, 0x30, 0x89, 0x50, 0x81, 0xc9, 0x00, 0xa6, 0x68, 0x20, 0x04, 0x52, 0x41, 0x20, \n\t0x21, 0x41, 0x04, 0x18, 0x09, 0x40, 0x00, 0x82, 0xca, 0x35, 0xa5, 0x87, 0x40, 0x1e, 0x93, 0x40, \n\t0x20, 0x19, 0x12, 0x80, 0x00, 0x66, 0x62, 0x0c, 0xcd, 0x12, 0x84, 0x4e, 0x81, 0x28, 0x14, 0x00, \n\t0xd1, 0x80, 0x0a, 0x01, 0x81, 0xad, 0x44, 0x97, 0x08, 0x00, 0x40, 0x60, 0x01, 0x11, 0x9a, 0x61, \n\t0x26, 0xc0, 0x81, 0x38, 0x30, 0x54, 0x27, 0x60, 0x21, 0x02, 0x01, 0x34, 0xc4, 0xa0, 0x02, 0xb0, \n\t0x48, 0x86, 0x15, 0xc0, 0x40, 0x40, 0x00, 0x88, 0x06, 0x80, 0x84, 0x40, 0x56, 0x46, 0x01, 0x82, \n\t0x80, 0x41, 0xa9, 0x56, 0x94, 0x0b, 0x25, 0x11, 0x06, 0x2e, 0x10, 0x12, 0x40, 0x2e, 0x00, 0x80, \n\t0x4d, 0x10, 0x11, 0x40, 0x94, 0x0d, 0x00, 0x6c, 0x0c, 0x02, 0x90, 0x12, 0x1c, 0x10, 0x02, 0x62, \n\t0x41, 0x02, 0x02, 0x04, 0x10, 0x2a, 0x08, 0x40, 0x12, 0x11, 0x0c, 0x08, 0xa2, 0x64, 0x27, 0x08, \n\t0xa0, 0x80, 0x0c, 0x46, 0x74, 0x11, 0x89, 0x29, 0x40, 0x49, 0xc6, 0x06, 0xf7, 0x00, 0x80, 0xa5, \n\t0xde, 0x80, 0x68, 0x20, 0x09, 0x03, 0xac, 0x84, 0x00, 0x38, 0x11, 0x02, 0x19, 0x98, 0x09, 0xe2, \n\t0x20, 0x30, 0xa2, 0x08, 0x6c, 0xc1, 0x4a, 0x44, 0x10, 0x31, 0x03, 0x01, 0x1a, 0x28, 0x20, 0xa5, \n\t0x40, 0x0f, 0x44, 0xc2, 0x8a, 0x62, 0xb3, 0x08, 0x27, 0x69, 0x90, 0x20, 0x0e, 0xc2, 0x80, 0x91, \n\t0x68, 0x90, 0x08, 0x3c, 0x14, 0x0b, 0x92, 0x15, 0x4d, 0x80, 0x38, 0x24, 0x30, 0x12, 0x49, 0x14, \n\t0x04, 0x02, 0xa0, 0x42, 0x28, 0x04, 0xc6, 0x01, 0x22, 0x20, 0x71, 0x25, 0x34, 0x83, 0x41, 0x12, \n\t0x91, 0x00, 0x24, 0x3c, 0x41, 0x04, 0x06, 0x07, 0xb8, 0x82, 0x01, 0x1b, 0x8c, 0x50, 0x20, 0x4a, \n\t0x11, 0x98, 0x80, 0x06, 0x48, 0x83, 0xc8, 0x01, 0x88, 0x08, 0x29, 0x74, 0x26, 0x90, 0xa8, 0x00, \n\t0x00, 0x0f, 0x08, 0xa2, 0x92, 0x90, 0x19, 0x1b, 0x44, 0x00, 0x97, 0x42, 0x29, 0x24, 0x11, 0x00, \n\t0x12, 0x10, 0xc2, 0x30, 0xe8, 0x44, 0x22, 0x24, 0x00, 0x00, 0x04, 0x48, 0x11, 0x40, 0x04, 0x03, \n\t0x19, 0xa0, 0xa8, 0x00, 0x04, 0x04, 0x43, 0x60, 0x0a, 0x15, 0x06, 0x03, 0x52, 0xf5, 0x48, 0x00, \n\t0x10, 0x54, 0x00, 0x0c, 0xd4, 0x29, 0x93, 0xd0, 0x90, 0x4d, 0x4e, 0xa2, 0xc9, 0x10, 0x08, 0x12, \n\t0x42, 0x00, 0xe1, 0x03, 0x0a, 0x04, 0x86, 0x80, 0x70, 0x84, 0x32, 0x28, 0x90, 0x4a, 0x61, 0x08, \n\t0x10, 0xb2, 0x94, 0x10, 0x1a, 0x40, 0x40, 0x06, 0x73, 0xac, 0x20, 0x91, 0x20, 0x40, 0x20, 0x99, \n\t0x84, 0x24, 0x4b, 0xe9, 0x08, 0x81, 0x82, 0x00, 0x31, 0x04, 0x86, 0x30, 0x34, 0x09, 0x32, 0x28, \n\t0x41, 0x2c, 0x16, 0x00, 0x61, 0x95, 0xa0, 0x10, 0xca, 0x2a, 0x44, 0x20, 0xa0, 0x00, 0x10, 0x20, \n\t0x68, 0xc6, 0xb1, 0x15, 0xb0, 0x10, 0x2d, 0x18, 0x26, 0x00, 0x30, 0x08, 0xc6, 0x68, 0x00, 0x50, \n\t0x62, 0x28, 0xc8, 0x00, 0x09, 0x08, 0x81, 0x80, 0x11, 0xc0, 0x03, 0x89, 0x06, 0x50, 0x88, 0x1c, \n\t0x01, 0xc2, 0x63, 0x7a, 0x05, 0x49, 0x34, 0x25, 0x8d, 0x00, 0x48, 0x00, 0xa2, 0x16, 0x8d, 0xc0, \n\t0x4a, 0x5c, 0x46, 0x21, 0x0e, 0x25, 0x44, 0x40, 0x16, 0x60, 0x11, 0x91, 0xd0, 0x82, 0xa8, 0x02, \n\t0x40, 0x51, 0x21, 0x11, 0x48, 0x06, 0x58, 0x12, 0xc1, 0x22, 0x10, 0x51, 0x60, 0x10, 0x22, 0x28, \n\t0x82, 0x58, 0x49, 0x0e, 0x02, 0x04, 0x09, 0x09, 0x01, 0x17, 0xa6, 0x10, 0x62, 0x53, 0x8a, 0x08, \n\t0x00, 0x87, 0x10, 0x20, 0xa3, 0x20, 0x44, 0x41, 0x67, 0x0a, 0x05, 0x02, 0x84, 0x18, 0x96, 0x84, \n\t0x06, 0x91, 0x68, 0x04, 0x85, 0x03, 0x20, 0x00, 0x05, 0x73, 0x24, 0x01, 0xc0, 0x48, 0x00, 0xa5, \n\t0x1a, 0x06, 0xf1, 0x4c, 0x26, 0x74, 0x14, 0x00, 0x82, 0x88, 0x88, 0x62, 0x08, 0x02, 0x40, 0xa0, \n\t0x45, 0x40, 0x04, 0x12, 0x92, 0xaa, 0x10, 0x8c, 0x41, 0x09, 0x28, 0x86, 0x00, 0x89, 0x80, 0x01, \n\t0x02, 0x0a, 0x82, 0x81, 0x31, 0xa0, 0x40, 0x00, 0x06, 0x10, 0x89, 0x80, 0x25, 0x0e, 0xec, 0x00, \n\t0x05, 0x82, 0x22, 0xd8, 0x08, 0xa1, 0x40, 0x44, 0xa0, 0x00, 0x41, 0xc8, 0x01, 0x14, 0x05, 0x9b, \n\t0xbc, 0x60, 0x90, 0x88, 0x0e, 0x14, 0x9b, 0x85, 0xc0, 0x94, 0x02, 0x64, 0xa1, 0x10, 0x34, 0x01, \n\t0x01, 0xa1, 0x60, 0xb3, 0x50, 0x0a, 0xb1, 0x4b, 0xc5, 0x02, 0x40, 0x71, 0x10, 0x05, 0x04, 0x47, \n\t0x20, 0x96, 0x48, 0xa5, 0x00, 0x01, 0x09, 0x08, 0x72, 0xd0, 0x08, 0x20, 0x06, 0xa1, 0x0a, 0x92, \n\t0xb2, 0x00, 0x08, 0x10, 0x08, 0x50, 0xc2, 0x08, 0x2e, 0x15, 0x00, 0x4a, 0x78, 0x80, 0x01, 0xa3, \n\t0x80, 0xd1, 0x07, 0x6e, 0x82, 0xa8, 0x30, 0x24, 0x07, 0x00, 0x08, 0x83, 0x80, 0x28, 0xa4, 0x07, \n\t0x08, 0x00, 0x60, 0x43, 0x80, 0x1d, 0xc0, 0xaa, 0x56, 0x87, 0x10, 0x10, 0x1d, 0x4c, 0xa4, 0x06, \n\t0xa3, 0x88, 0x01, 0x00, 0x06, 0x42, 0x2c, 0x80, 0x01, 0x2e, 0x84, 0x00, 0x83, 0x72, 0x06, 0xa2, \n\t0xb4, 0x14, 0x05, 0x04, 0x10, 0x60, 0x2a, 0x99, 0x38, 0x82, 0x23, 0x06, 0x14, 0x12, 0x29, 0x00, \n\t0x54, 0x69, 0x14, 0x61, 0x32, 0x21, 0x28, 0x14, 0x25, 0x60, 0xd0, 0x21, 0x92, 0x00, 0x80, 0x20, \n\t0x40, 0x73, 0xb0, 0x80, 0x00, 0x01, 0x80, 0x58, 0x05, 0x58, 0xa8, 0x29, 0x48, 0x0a, 0x02, 0x55, \n\t0x4a, 0x82, 0x00, 0xd6, 0xc0, 0x20, 0x81, 0x51, 0x0a, 0x88, 0x59, 0x0c, 0x70, 0x82, 0x02, 0x81, \n\t0xe1, 0x88, 0xa8, 0x0a, 0x55, 0x11, 0x04, 0x15, 0x80, 0x07, 0x08, 0x02, 0xc1, 0xb3, 0x08, 0x1b, \n\t0x04, 0x6e, 0x40, 0x60, 0x0d, 0x50, 0x40, 0x4f, 0x70, 0x30, 0x10, 0x20, 0x01, 0x10, 0x63, 0x10, \n\t0xd1, 0x28, 0x86, 0x0c, 0x0a, 0x04, 0x00, 0x44, 0x00, 0xa0, 0x4d, 0x1a, 0xa1, 0x20, 0x51, 0x38, \n\t0x12, 0x44, 0x11, 0x67, 0x12, 0x04, 0x00, 0x89, 0x00, 0xc9, 0x00, 0x28, 0x00, 0x83, 0x00, 0x64, \n\t0x88, 0x00, 0x0a, 0x03, 0xc2, 0x98, 0xc0, 0x08, 0x23, 0x16, 0x07, 0x09, 0xb1, 0x60, 0x08, 0x6a, \n\t0x04, 0xd2, 0x28, 0x08, 0xb5, 0x11, 0x05, 0x10, 0x25, 0x00, 0xa2, 0x08, 0x16, 0x0c, 0x0a, 0x40, \n\t0x00, 0x00, 0x59, 0x03, 0x04, 0x02, 0x92, 0xe3, 0x30, 0x00, 0x81, 0xc5, 0x06, 0x30, 0x98, 0x24, \n\t0x1c, 0x0e, 0x68, 0x20, 0x81, 0x40, 0x02, 0x1d, 0x03, 0x6a, 0x40, 0x41, 0x02, 0x24, 0x24, 0x05, \n\t0x23, 0x54, 0x92, 0x98, 0x08, 0x88, 0x49, 0x02, 0x20, 0x10, 0x90, 0x30, 0xa0, 0x03, 0x82, 0x24, \n\t0x20, 0x31, 0x8a, 0x39, 0x58, 0xa8, 0x32, 0x86, 0x80, 0x89, 0x35, 0x88, 0x85, 0x24, 0x05, 0x41, \n\t0x81, 0x10, 0x08, 0x41, 0x00, 0xd4, 0x00, 0x16, 0x00, 0x12, 0x44, 0x36, 0xc0, 0x68, 0x81, 0x90, \n\t0x0c, 0xcc, 0x76, 0x20, 0x51, 0x2c, 0x21, 0x50, 0xab, 0x14, 0xb0, 0x4a, 0x00, 0x64, 0x14, 0x4d, \n\t0x40, 0xc2, 0x12, 0x8e, 0x54, 0x08, 0x02, 0x40, 0x41, 0x28, 0x00, 0x01, 0x9e, 0x81, 0x40, 0xd4, \n\t0x29, 0x12, 0x24, 0x87, 0x82, 0x08, 0x01, 0x63, 0xa1, 0x00, 0x83, 0x01, 0x00, 0x44, 0xca, 0xa4, \n\t0x45, 0x48, 0x20, 0x20, 0x22, 0x49, 0x1a, 0xc0, 0x02, 0xc5, 0x3a, 0xa0, 0x10, 0x15, 0x45, 0xd1, \n\t0xc0, 0x48, 0xa1, 0xe3, 0x04, 0x10, 0xc0, 0x20, 0x74, 0x11, 0x10, 0x83, 0xb1, 0x49, 0x02, 0x52, \n\t0x14, 0x28, 0x11, 0x75, 0x96, 0xa8, 0x1e, 0x10, 0x60, 0x02, 0xe8, 0x1c, 0x49, 0x28, 0xc2, 0x12, \n\t0x3c, 0x95, 0x00, 0xa2, 0x42, 0x12, 0x00, 0x80, 0x28, 0x13, 0x04, 0x2c, 0x44, 0x20, 0x00, 0x08, \n\t0x09, 0x80, 0x40, 0x10, 0xa9, 0x03, 0x74, 0x41, 0x89, 0x20, 0x22, 0x8a, 0xac, 0xa8, 0x11, 0xa0, \n\t0x42, 0x35, 0x48, 0x8b, 0x40, 0x42, 0x67, 0x10, 0x62, 0x40, 0x12, 0x40, 0x94, 0x42, 0x10, 0x01, \n\t0x4a, 0x0d, 0xa4, 0xc0, 0x60, 0x5e, 0x50, 0x81, 0x16, 0x40, 0xd2, 0x41, 0x44, 0x22, 0x31, 0x08, \n\t0x81, 0x14, 0xc9, 0x10, 0x83, 0x80, 0x84, 0x28, 0x04, 0x21, 0x08, 0x82, 0x83, 0x02, 0x04, 0x42, \n\t0x4c, 0x00, 0x50, 0x8a, 0x2b, 0x54, 0x50, 0x82, 0x46, 0x86, 0x62, 0x02, 0xe9, 0x9c, 0x0c, 0x56, \n\t0x75, 0x01, 0xa1, 0x34, 0x8c, 0x20, 0x2c, 0x84, 0x58, 0x84, 0xd8, 0x05, 0x08, 0x10, 0xc2, 0x19, \n\t0x12, 0xe0, 0xc8, 0x01, 0x14, 0x82, 0x08, 0x08, 0x01, 0x40, 0x88, 0x30, 0xc0, 0x4a, 0x8a, 0xa0, \n\t0x03, 0x40, 0x02, 0x10, 0x8a, 0x1d, 0x00, 0x15, 0x03, 0x6c, 0x10, 0x91, 0x01, 0x81, 0x46, 0x8e, \n\t0x00, 0x22, 0x13, 0x81, 0x38, 0x80, 0xc9, 0x4c, 0xa0, 0x81, 0xa2, 0x50, 0x59, 0x25, 0x64, 0x03, \n\t0x1a, 0x85, 0x18, 0x0c, 0x24, 0x20, 0x00, 0x80, 0x90, 0x01, 0x46, 0x28, 0x1c, 0x05, 0xab, 0x00, \n\t0xac, 0x48, 0xc9, 0x06, 0x66, 0xe0, 0x1c, 0x41, 0x48, 0x08, 0x00, 0x30, 0x41, 0xb0, 0x59, 0xc2, \n\t0x63, 0x24, 0x33, 0x71, 0x24, 0x80, 0x02, 0x4d, 0x48, 0x83, 0x08, 0x20, 0x90, 0x92, 0x40, 0x04, \n\t0x22, 0x12, 0x88, 0xb0, 0x8a, 0x40, 0x2a, 0x90, 0x60, 0x20, 0x75, 0x86, 0x03, 0x08, 0xa3, 0x22, \n\t0xa2, 0xc8, 0x92, 0x4a, 0x10, 0x01, 0x11, 0x88, 0x44, 0x90, 0x89, 0x20, 0x02, 0xa0, 0x8c, 0x25, \n\t0x02, 0x80, 0x72, 0x02, 0xea, 0x06, 0x01, 0x0d, 0x0c, 0x04, 0x21, 0x1b, 0x83, 0x00, 0x04, 0x22, \n\t0x1e, 0xc0, 0x61, 0x22, 0x55, 0x01, 0x84, 0x20, 0x02, 0x92, 0xb0, 0xd4, 0x01, 0x6a, 0x14, 0x83, \n\t0x21, 0x1e, 0xa4, 0x16, 0x00, 0x12, 0x27, 0x08, 0x28, 0x30, 0x11, 0x48, 0x04, 0x00, 0x5a, 0x04, \n\t0x10, 0x0e, 0x4c, 0x44, 0x92, 0x11, 0x14, 0x80, 0x02, 0x09, 0x50, 0x60, 0x29, 0x20, 0x18, 0x12, \n\t0x08, 0x00, 0x24, 0x11, 0x00, 0x40, 0x88, 0xc3, 0x26, 0xd4, 0x02, 0x21, 0x00, 0x18, 0x81, 0x20, \n\t0x41, 0x93, 0x90, 0x8d, 0x54, 0x26, 0x38, 0x04, 0x81, 0x84, 0x68, 0x82, 0x08, 0x3c, 0x61, 0xc0, \n\t0xaa, 0x80, 0x4c, 0x20, 0x46, 0x10, 0x8a, 0x19, 0xa0, 0x40, 0x22, 0x36, 0x40, 0x61, 0x83, 0x21, \n\t0x90, 0x08, 0x22, 0x55, 0xa8, 0xba, 0xa8, 0x42, 0x6c, 0x64, 0x40, 0x40, 0x10, 0x50, 0x0a, 0x0d, \n\t0x00, 0x80, 0x82, 0x24, 0x04, 0x04, 0xa8, 0x0c, 0xf0, 0x70, 0x05, 0xc4, 0x08, 0x05, 0x64, 0x60, \n\t0x51, 0x0a, 0x1d, 0xc0, 0xa0, 0x02, 0x26, 0x30, 0x22, 0x2c, 0x14, 0x05, 0x10, 0x80, 0x69, 0xaa, \n\t0x05, 0x04, 0x20, 0x20, 0x61, 0x50, 0x05, 0x00, 0xc2, 0xc2, 0x08, 0x04, 0xf1, 0x24, 0x64, 0x00, \n\t0xc1, 0x62, 0x82, 0x00, 0x01, 0x50, 0x03, 0x05, 0x18, 0x70, 0x00, 0xa2, 0x10, 0xc0, 0x01, 0x0a, \n\t0x84, 0xc0, 0x19, 0x00, 0x84, 0x04, 0x08, 0xd5, 0x82, 0x07, 0x59, 0x58, 0x40, 0x0c, 0x94, 0x20, \n\t0x08, 0x09, 0x06, 0x44, 0x0a, 0x23, 0x00, 0x0b, 0x14, 0x04, 0x86, 0x54, 0x40, 0xa0, 0x11, 0x51, \n\t0x01, 0x21, 0x68, 0xf2, 0x0a, 0x32, 0x10, 0x11, 0x40, 0x0c, 0x42, 0x28, 0x14, 0x40, 0x08, 0x08, \n\t0x72, 0x30, 0xc0, 0x20, 0xad, 0x58, 0x61, 0x28, 0x45, 0x29, 0x00, 0x48, 0x01, 0x27, 0x24, 0x62, \n\t0xc0, 0x80, 0x05, 0x0a, 0xc1, 0x18, 0x25, 0x19, 0xac, 0x25, 0x80, 0x0b, 0x5a, 0x20, 0x00, 0x15, \n\t0x10, 0x82, 0x01, 0x36, 0x40, 0x51, 0x0a, 0x40, 0xd8, 0x0c, 0x20, 0x92, 0x92, 0x09, 0x19, 0x45, \n\t0x4b, 0x50, 0x83, 0x82, 0xa3, 0xe1, 0x86, 0xea, 0x08, 0x43, 0x91, 0x19, 0x89, 0x13, 0x80, 0x04, \n\t0x84, 0x80, 0x10, 0x15, 0xc2, 0x05, 0x0c, 0xd2, 0xc0, 0x00, 0x48, 0x00, 0xa8, 0x40, 0x21, 0x01, \n\t0x85, 0x14, 0x19, 0xc2, 0x42, 0x60, 0xf0, 0x0a, 0x40, 0x50, 0x42, 0x26, 0x47, 0xc9, 0x22, 0x14, \n\t0x81, 0xa2, 0x20, 0x31, 0x08, 0x21, 0xc1, 0xc0, 0x00, 0x48, 0x22, 0x40, 0x93, 0x88, 0x00, 0x61, \n\t0x44, 0x40, 0x0b, 0x80, 0x69, 0x86, 0xec, 0x0a, 0x36, 0x89, 0x14, 0xf0, 0x51, 0x20, 0x42, 0x21, \n\t0x71, 0x21, 0xd1, 0x0c, 0x20, 0x6c, 0x30, 0x53, 0x00, 0x01, 0x00, 0x23, 0x04, 0x74, 0xa8, 0x34, \n\t0x40, 0x5b, 0xa0, 0x1a, 0x16, 0x01, 0x80, 0x28, 0x0f, 0x08, 0x10, 0x24, 0x80, 0x12, 0x69, 0x04, \n\t0x00, 0x48, 0x40, 0xab, 0x94, 0x38, 0x51, 0x4a, 0x26, 0x67, 0x01, 0x00, 0x6c, 0x86, 0x0e, 0x0a, \n\t0x52, 0x20, 0x0c, 0xa0, 0x14, 0x8c, 0x00, 0x11, 0x83, 0x2c, 0xb0, 0x81, 0x24, 0x00, 0x40, 0x48, \n\t0x1e, 0x31, 0xc5, 0x40, 0x32, 0x20, 0x90, 0x14, 0x80, 0x52, 0x80, 0x48, 0x11, 0x40, 0x23, 0x80, \n\t0x14, 0x02, 0x1c, 0x94, 0xa0, 0x08, 0xcc, 0x4a, 0x08, 0x04, 0x37, 0xb0, 0x2a, 0x05, 0x04, 0x00, \n\t0x30, 0x03, 0x03, 0x36, 0xc1, 0x04, 0x2a, 0x12, 0x54, 0x20, 0xa0, 0xe5, 0x94, 0xa0, 0x16, 0x00, \n\t0x81, 0x92, 0x81, 0x09, 0xc0, 0x54, 0x44, 0xc0, 0xa9, 0x81, 0x8c, 0x00, 0x0c, 0xb0, 0x28, 0x05, \n\t0x34, 0x8f, 0x42, 0x42, 0x21, 0xa0, 0x10, 0x24, 0x99, 0x01, 0x04, 0x91, 0x40, 0x09, 0x50, 0x44, \n\t0x63, 0x62, 0x86, 0x52, 0x18, 0x30, 0x01, 0xa8, 0x00, 0x51, 0x12, 0x82, 0x10, 0x88, 0x01, 0x08, \n\t0x31, 0x00, 0x34, 0x49, 0x42, 0x80, 0x0c, 0x50, 0x02, 0x94, 0x00, 0x13, 0xc7, 0x00, 0x90, 0x22, \n\t0x94, 0xc9, 0x19, 0x04, 0x60, 0x74, 0x71, 0x25, 0x35, 0x8b, 0x41, 0x60, 0x86, 0x08, 0x00, 0x60, \n\t0x40, 0x66, 0x02, 0x90, 0x41, 0x81, 0x81, 0x8e, 0x48, 0x00, 0x43, 0x58, 0x11, 0xb4, 0x13, 0x0b, \n\t0x2a, 0xa5, 0xc0, 0x90, 0x84, 0x06, 0x04, 0x04, 0x03, 0x2a, 0x1d, 0x30, 0x09, 0x89, 0x20, 0x04, \n\t0x81, 0x10, 0x90, 0x10, 0x42, 0x50, 0x02, 0x21, 0x08, 0x30, 0x04, 0xa6, 0x10, 0x00, 0xc2, 0x8e, \n\t0x89, 0x18, 0xa8, 0x00, 0x10, 0x1a, 0xae, 0x64, 0x4a, 0xa2, 0x64, 0x40, 0x60, 0x28, 0x40, 0x1b, \n\t0x00, 0x18, 0x04, 0xc8, 0xa5, 0xc8, 0x17, 0x22, 0x50, 0xe0, 0x20, 0x08, 0x10, 0x40, 0x2c, 0x24, \n\t0x10, 0x5a, 0x89, 0x04, 0x0c, 0xac, 0x06, 0x23, 0x18, 0x27, 0x21, 0x89, 0x4d, 0x10, 0x84, 0xc0, \n\t0x04, 0x38, 0x06, 0x08, 0x22, 0x97, 0xe3, 0x10, 0xd9, 0x44, 0x01, 0x08, 0x00, 0xa0, 0x14, 0x9c, \n\t0x44, 0x01, 0x00, 0x11, 0x41, 0x88, 0x68, 0x84, 0x24, 0x20, 0x72, 0x41, 0x22, 0x44, 0x88, 0x06, \n\t0x2a, 0x00, 0x10, 0x30, 0x59, 0x93, 0x22, 0x00, 0x06, 0xd8, 0x14, 0x2d, 0x41, 0xae, 0x50, 0x20, \n\t0x22, 0x34, 0x80, 0x01, 0x81, 0x20, 0x01, 0x12, 0x00, 0x1d, 0x40, 0xca, 0x34, 0x66, 0x80, 0xb1, \n\t0x48, 0x45, 0x06, 0x12, 0x10, 0x08, 0x89, 0x94, 0x1a, 0x09, 0x58, 0x44, 0x20, 0x02, 0x24, 0xc5, \n\t0x09, 0x3c, 0x02, 0xd0, 0x12, 0x00, 0x10, 0x6a, 0x50, 0x92, 0x8a, 0x04, 0xd8, 0x90, 0xa0, 0x12, \n\t0x41, 0x39, 0x01, 0x21, 0x08, 0x4f, 0x70, 0x60, 0x62, 0x8b, 0x81, 0x42, 0x09, 0x06, 0x87, 0x8a, \n\t0x81, 0x65, 0xd5, 0x04, 0x60, 0x10, 0x01, 0x10, 0xe0, 0x88, 0x82, 0x2c, 0x01, 0x81, 0x24, 0x08, \n\t0x0b, 0x21, 0x62, 0x60, 0x52, 0x32, 0x0d, 0x1c, 0x05, 0x22, 0x14, 0x00, 0xb8, 0x38, 0x00, 0x00, \n\t0x3e, 0xe3, 0x60, 0x83, 0x01, 0x04, 0x00, 0x10, 0x10, 0x20, 0x82, 0x24, 0x06, 0x01, 0x50, 0x50, \n\t0x18, 0x86, 0x08, 0x13, 0x45, 0x0a, 0x82, 0x2b, 0x28, 0xa4, 0x91, 0x60, 0x18, 0x00, 0x89, 0x8f, \n\t0x90, 0x0c, 0x00, 0x4c, 0x01, 0x60, 0x36, 0x1c, 0x58, 0x0c, 0x22, 0x51, 0x18, 0xb0, 0x50, 0x0a, \n\t0xa6, 0x40, 0x46, 0x12, 0x34, 0x80, 0x84, 0x84, 0x48, 0x44, 0x30, 0x01, 0x49, 0x10, 0x0b, 0x42, \n\t0x00, 0x39, 0x24, 0x68, 0x0d, 0x41, 0x22, 0xa2, 0x88, 0x02, 0x2c, 0x40, 0x08, 0x10, 0x50, 0x41, \n\t0x02, 0x15, 0x91, 0x46, 0x22, 0x70, 0x42, 0x91, 0x08, 0x07, 0x25, 0x62, 0x07, 0x48, 0x99, 0x11, \n\t0x44, 0x48, 0x1c, 0x16, 0xe9, 0x3c, 0xc0, 0xc0, 0x40, 0x4e, 0x60, 0x20, 0x0c, 0x9d, 0x00, 0x28, \n\t0x08, 0x24, 0x93, 0x88, 0xd0, 0x01, 0x20, 0x44, 0x33, 0x00, 0x0d, 0x29, 0x90, 0x40, 0x4c, 0x85, \n\t0x01, 0x12, 0x80, 0x42, 0x2c, 0x24, 0x11, 0xc0, 0x00, 0x59, 0x40, 0x8b, 0x04, 0x65, 0x00, 0x2c, \n\t0x55, 0x1c, 0x22, 0x00, 0x04, 0x80, 0x00, 0x5c, 0x88, 0x84, 0x20, 0x07, 0x49, 0x35, 0x84, 0x17, \n\t0x08, 0x0a, 0x70, 0x08, 0x08, 0x00, 0x1e, 0x08, 0x64, 0x04, 0xf2, 0x8c, 0x00, 0xc3, 0xc0, 0x00, \n\t0x04, 0x73, 0x21, 0x01, 0x00, 0xc3, 0x50, 0xb2, 0x0a, 0x88, 0x04, 0x0a, 0x21, 0x14, 0x62, 0x00, \n\t0x13, 0x0c, 0xc0, 0xad, 0x4c, 0xd0, 0x10, 0x0a, 0x21, 0x89, 0x80, 0x10, 0x80, 0x2a, 0xa7, 0x20, \n\t0x91, 0x00, 0x4a, 0x31, 0x0b, 0x30, 0x28, 0x11, 0x00, 0x00, 0x63, 0xc0, 0x10, 0x2d, 0x10, 0xa2, \n\t0x20, 0xc4, 0x8b, 0x3b, 0x28, 0x01, 0xe9, 0x10, 0xc4, 0x40, 0x02, 0x41, 0x10, 0x00, 0x10, 0x80, \n\t0xc1, 0x84, 0x00, 0x90, 0x61, 0x04, 0x11, 0x30, 0x89, 0x98, 0x01, 0x05, 0x4e, 0x02, 0x30, 0x20, \n\t0x08, 0x54, 0x40, 0x12, 0x80, 0x62, 0x84, 0x0c, 0x08, 0x09, 0x40, 0x94, 0x33, 0x04, 0x01, 0x48, \n\t0x81, 0x22, 0x80, 0x02, 0xa6, 0x11, 0x14, 0x23, 0x14, 0x04, 0x6b, 0x20, 0x40, 0x14, 0xa4, 0x10, \n\t0x44, 0x1a, 0x11, 0x40, 0x42, 0x01, 0x34, 0x01, 0x39, 0x08, 0x14, 0x50, 0xa2, 0x14, 0x00, 0x00, \n\t0x03, 0x90, 0x09, 0x0a, 0x24, 0x85, 0x40, 0xb0, 0x51, 0x1f, 0x00, 0x10, 0x82, 0x08, 0x08, 0x2c, \n\t0x41, 0x29, 0x4a, 0x83, 0x80, 0x93, 0x40, 0x56, 0x2b, 0x4e, 0x10, 0xc2, 0x20, 0x48, 0x01, 0x8c, \n\t0x00, 0x70, 0x3a, 0x0c, 0x0c, 0x10, 0x00, 0x28, 0x03, 0x40, 0x3a, 0x18, 0x53, 0x60, 0x60, 0x64, \n\t0x80, 0xb4, 0x24, 0x00, 0x62, 0x08, 0x50, 0x20, 0x06, 0x60, 0x88, 0x20, 0x1a, 0x60, 0x08, 0x11, \n\t0x15, 0x83, 0x0b, 0x38, 0x24, 0x52, 0x98, 0x24, 0x10, 0x28, 0x40, 0x54, 0x08, 0x01, 0xf1, 0xc9, \n\t0x21, 0x30, 0x44, 0x30, 0x89, 0x21, 0x02, 0x0c, 0x40, 0x80, 0x88, 0x36, 0x20, 0x4c, 0x04, 0x74, \n\t0x84, 0x02, 0x00, 0x49, 0x95, 0x48, 0x04, 0x82, 0x6a, 0x38, 0x20, 0x46, 0x2b, 0x40, 0x22, 0xf3, \n\t0x21, 0xd5, 0x00, 0x09, 0x48, 0x03, 0x11, 0x84, 0x4c, 0x80, 0x6a, 0x46, 0xa2, 0x90, 0x92, 0x30, \n\t0x88, 0x06, 0x48, 0xc1, 0x69, 0x07, 0x00, 0x40, 0x02, 0x02, 0x00, 0x29, 0x02, 0x85, 0x14, 0x29, \n\t0x38, 0x40, 0x09, 0xac, 0x98, 0x01, 0x41, 0x20, 0x82, 0x50, 0x82, 0x1d, 0xcf, 0xc0, 0x28, 0x00, \n\t0x10, 0x0c, 0x40, 0x40, 0xc4, 0x10, 0x42, 0x82, 0x06, 0x08, 0x81, 0x08, 0x44, 0x23, 0xd1, 0x81, \n\t0x20, 0xd6, 0x22, 0x58, 0x00, 0x90, 0x08, 0x51, 0x14, 0x03, 0x06, 0x42, 0xc8, 0x07, 0xec, 0x12, \n\t0x82, 0x18, 0x97, 0x43, 0x9b, 0x00, 0x09, 0x4a, 0x04, 0xc0, 0x20, 0x22, 0x60, 0x5e, 0x24, 0x04, \n\t0x93, 0x6a, 0x90, 0x48, 0x44, 0x26, 0x64, 0x41, 0x22, 0x92, 0x48, 0x08, 0x48, 0x16, 0x22, 0xd0, \n\t0x1e, 0x00, 0x49, 0x6f, 0x00, 0x24, 0x08, 0x08, 0xb1, 0xc0, 0xc8, 0x02, 0x20, 0x49, 0x90, 0x04, \n\t0x8c, 0x03, 0x10, 0x84, 0xaa, 0x0d, 0x14, 0x45, 0x61, 0x00, 0x42, 0x63, 0x01, 0x20, 0x01, 0x6a, \n\t0x04, 0x16, 0x20, 0x10, 0x00, 0x82, 0x44, 0x4a, 0x20, 0x33, 0x0c, 0x30, 0x10, 0x82, 0x38, 0x34, \n\t0x91, 0xb0, 0x91, 0x51, 0x41, 0x68, 0x85, 0x22, 0x00, 0x00, 0x97, 0x60, 0x08, 0x52, 0x52, 0xa9, \n\t0x4d, 0x18, 0x0c, 0x56, 0x24, 0xe2, 0x06, 0x58, 0xd0, 0x21, 0x16, 0x44, 0x28, 0x08, 0x21, 0x58, \n\t0x02, 0x22, 0x01, 0xc0, 0x8b, 0x04, 0x05, 0x84, 0x00, 0x11, 0x19, 0x35, 0xf0, 0x8d, 0x40, 0x10, \n\t0x17, 0x02, 0x1a, 0x0c, 0x48, 0x28, 0x52, 0x80, 0x63, 0x14, 0xd1, 0x09, 0x26, 0x48, 0x20, 0x20, \n\t0x35, 0x18, 0x12, 0x40, 0x04, 0x32, 0x82, 0x86, 0x61, 0x00, 0xac, 0x60, 0x00, 0xa0, 0x02, 0x44, \n\t0x48, 0x00, 0x06, 0xa6, 0x90, 0x24, 0x10, 0x0e, 0x65, 0x60, 0x01, 0x08, 0x88, 0x49, 0x18, 0x00, \n\t0x50, 0x41, 0x41, 0x83, 0x24, 0xca, 0xa8, 0x22, 0x40, 0x20, 0xa0, 0x88, 0x14, 0x60, 0x00, 0x07, \n\t0x80, 0x20, 0x18, 0x80, 0x01, 0x14, 0x05, 0x01, 0x9c, 0x04, 0x93, 0x46, 0x08, 0xc3, 0x62, 0x10, \n\t0x14, 0x1a, 0x48, 0x70, 0x10, 0x08, 0x05, 0xa8, 0x11, 0x4c, 0x40, 0xa6, 0x00, 0x20, 0x28, 0x52, \n\t0x01, 0x58, 0x20, 0x09, 0x89, 0x05, 0x86, 0xa0, 0x0c, 0x56, 0xf0, 0x20, 0x88, 0x51, 0x48, 0x04, \n\t0x65, 0x00, 0x8d, 0x01, 0xc5, 0x20, 0x62, 0x00, 0x91, 0x8e, 0x4d, 0xc2, 0x80, 0x12, 0x11, 0x2a, \n\t0x20, 0xd1, 0x11, 0xa1, 0x52, 0x80, 0x48, 0x84, 0xd0, 0x09, 0x28, 0x40, 0x50, 0x89, 0x80, 0x14, \n\t0x06, 0x0c, 0x1a, 0x44, 0x08, 0xba, 0xa5, 0x50, 0xc7, 0x08, 0xa7, 0x22, 0x0a, 0x30, 0x44, 0x00, \n\t0x44, 0xc4, 0xd0, 0x09, 0x10, 0x40, 0x88, 0x48, 0x22, 0xcb, 0x18, 0x84, 0x07, 0x8b, 0x06, 0x41, \n\t0x50, 0x00, 0x49, 0x1a, 0xa2, 0x24, 0x63, 0x23, 0x90, 0x91, 0x02, 0x08, 0x28, 0xa0, 0x08, 0x0a, \n\t0x1c, 0x04, 0x47, 0x2a, 0x05, 0xd8, 0x08, 0x84, 0x10, 0xa8, 0x40, 0x71, 0x58, 0x82, 0x0d, 0x14, \n\t0x00, 0x56, 0xe6, 0x92, 0x8e, 0xd4, 0x00, 0x4d, 0x14, 0x54, 0x49, 0x80, 0x25, 0x0c, 0x01, 0x38, \n\t0x30, 0x08, 0xac, 0x10, 0x90, 0x40, 0x4a, 0x13, 0x63, 0x01, 0x04, 0x01, 0x00, 0x02, 0xd1, 0x19, \n\t0x02, 0xa0, 0x00, 0xae, 0x36, 0x00, 0x80, 0x24, 0xa0, 0x52, 0x8b, 0x00, 0xd0, 0x02, 0x00, 0x51, \n\t0x84, 0x84, 0x0c, 0x02, 0xc3, 0x39, 0x80, 0x8a, 0x44, 0x66, 0x50, 0x08, 0x09, 0x31, 0x08, 0x41, \n\t0x02, 0x07, 0x18, 0xa0, 0x20, 0xc5, 0x2a, 0x12, 0x45, 0x48, 0xa0, 0x68, 0xc6, 0x83, 0x48, 0x20, \n\t0x80, 0x1c, 0x11, 0x45, 0x88, 0x60, 0x56, 0x53, 0x12, 0x60, 0x07, 0x2d, 0x24, 0x04, 0x29, 0x84, \n\t0x20, 0x88, 0x45, 0x08, 0x96, 0x81, 0x84, 0x00, 0x91, 0x04, 0x04, 0x21, 0x09, 0x0e, 0x39, 0x10, \n\t0x28, 0x70, 0x00, 0xc0, 0x20, 0xb0, 0x02, 0x6e, 0x00, 0x82, 0xe3, 0x02, 0x9d, 0x00, 0x2b, 0x74, \n\t0x21, 0xe1, 0x31, 0x15, 0x58, 0xaa, 0x40, 0xe0, 0x20, 0x30, 0x14, 0x52, 0xc4, 0x00, 0x16, 0x68, \n\t0xa0, 0x08, 0x10, 0x82, 0x58, 0x01, 0x18, 0x36, 0xe4, 0x0a, 0x61, 0x44, 0x01, 0xa1, 0x90, 0x94, \n\t0x11, 0xc0, 0x12, 0xc4, 0x13, 0x19, 0x44, 0x09, 0x66, 0x2a, 0x84, 0x18, 0x13, 0x05, 0xcd, 0x40, \n\t0x20, 0x30, 0x81, 0x02, 0x84, 0xd0, 0x40, 0x1e, 0x00, 0x1b, 0x15, 0x70, 0x12, 0x20, 0x22, 0x04, \n\t0x61, 0x05, 0x51, 0x03, 0x08, 0x40, 0x80, 0x8a, 0x8e, 0x30, 0x84, 0x40, 0x08, 0x84, 0x60, 0xb3, \n\t0x01, 0x52, 0x4a, 0x02, 0x06, 0x82, 0xb0, 0x49, 0x40, 0x46, 0x3a, 0x81, 0x00, 0x14, 0x00, 0x88, \n\t0xa4, 0x08, 0x14, 0x2a, 0x34, 0x7c, 0x04, 0x61, 0x00, 0xe1, 0xd8, 0x9c, 0xa4, 0x14, 0x86, 0x44, \n\t0x00, 0x41, 0x21, 0xc8, 0x4d, 0x04, 0x00, 0x02, 0x51, 0x2a, 0x01, 0x9d, 0x04, 0x40, 0x45, 0x60, \n\t0x98, 0x28, 0x42, 0x05, 0x0a, 0xa6, 0x00, 0x02, 0x99, 0x89, 0xa2, 0x20, 0x02, 0x02, 0x2d, 0xe8, \n\t0x10, 0x00, 0x5c, 0xb0, 0x83, 0x02, 0x4c, 0x02, 0xe8, 0x04, 0xa4, 0x02, 0x02, 0x04, 0x88, 0x42, \n\t0x4c, 0x32, 0x90, 0xbb, 0x00, 0xcd, 0x00, 0x72, 0x11, 0x2a, 0x04, 0x85, 0x01, 0x28, 0x10, 0x11, \n\t0xb2, 0x00, 0x88, 0x1a, 0xc3, 0x16, 0x81, 0xd3, 0x00, 0x00, 0x04, 0x87, 0x44, 0x70, 0x58, 0x91, \n\t0x30, 0x04, 0x45, 0x2c, 0x33, 0x28, 0x21, 0x40, 0x88, 0x81, 0x52, 0x80, 0xe8, 0x01, 0xa0, 0x80, \n\t0x0c, 0x36, 0x44, 0xe1, 0x12, 0x88, 0x18, 0xe2, 0x4a, 0x20, 0x0b, 0x20, 0x28, 0x81, 0x00, 0x48, \n\t0xb2, 0x10, 0x06, 0x0d, 0x8e, 0x00, 0x44, 0x15, 0x90, 0xa2, 0x04, 0x82, 0x01, 0x28, 0x42, 0xa8, \n\t0x90, 0x4d, 0x80, 0x25, 0x42, 0x10, 0x02, 0x0e, 0x81, 0x84, 0x2e, 0x54, 0x04, 0x10, 0x21, 0x00, \n\t0xd8, 0x02, 0x78, 0x81, 0x08, 0x06, 0xbc, 0x50, 0x4c, 0x10, 0xd0, 0x00, 0x30, 0xa4, 0x41, 0x22, \n\t0x02, 0x41, 0x51, 0x12, 0x50, 0x08, 0x07, 0x18, 0xb4, 0xe0, 0x01, 0x30, 0x4c, 0x68, 0x00, 0x32, \n\t0x08, 0x95, 0xb8, 0x90, 0xc0, 0x0c, 0xb0, 0x51, 0x10, 0x4c, 0x90, 0xce, 0x44, 0x21, 0xea, 0x00, \n\t0x28, 0x18, 0x0a, 0x10, 0x00, 0x22, 0x18, 0x04, 0x09, 0x05, 0x6a, 0x81, 0x08, 0x27, 0x09, 0x08, \n\t0xc2, 0x74, 0x45, 0x58, 0x00, 0xa1, 0x81, 0x00, 0x12, 0x50, 0x8a, 0x16, 0x04, 0x5a, 0x60, 0x00, \n\t0x86, 0x0a, 0x20, 0xc0, 0x1c, 0x08, 0x02, 0x05, 0x02, 0x1a, 0x41, 0x08, 0x4c, 0x2a, 0x24, 0x01, \n\t0xa1, 0x11, 0x12, 0x46, 0x00, 0x85, 0x80, 0xb8, 0x08, 0x42, 0x20, 0x32, 0x82, 0x30, 0x8a, 0x78, \n\t0x84, 0x89, 0x12, 0x02, 0x12, 0x10, 0x20, 0x81, 0x60, 0x46, 0x52, 0x01, 0x2f, 0x20, 0x10, 0x04, \n\t0x48, 0xa0, 0xe0, 0x00, 0xc4, 0x10, 0xa5, 0x22, 0x04, 0x82, 0x1a, 0x0d, 0x05, 0x04, 0x2a, 0x50, \n\t0x71, 0xa7, 0x04, 0x87, 0x02, 0x18, 0x60, 0xc8, 0x81, 0x1d, 0xc9, 0x00, 0x00, 0x05, 0x29, 0x30, \n\t0x0c, 0x55, 0x00, 0x54, 0x24, 0x03, 0x82, 0x70, 0x03, 0x25, 0x00, 0xb0, 0x40, 0x82, 0x85, 0x95, \n\t0x0d, 0x48, 0x10, 0x49, 0x16, 0x00, 0xd4, 0x08, 0x0e, 0xd4, 0x82, 0x80, 0x00, 0xce, 0xc6, 0x22, \n\t0x02, 0x48, 0x18, 0xb9, 0x52, 0xe0, 0x42, 0x20, 0x11, 0x2c, 0x58, 0x0a, 0x89, 0x48, 0x85, 0xc0, \n\t0x04, 0x05, 0x83, 0x88, 0x00, 0xa5, 0x10, 0x00, 0x30, 0x1f, 0x02, 0x08, 0x00, 0x90, 0x10, 0x45, \n\t0xcc, 0xac, 0x06, 0x70, 0xc0, 0x02, 0x31, 0x07, 0x03, 0x12, 0xe0, 0x22, 0x90, 0x00, 0x4d, 0x80, \n\t0x36, 0x01, 0x80, 0x02, 0xc8, 0x0c, 0x49, 0x18, 0x10, 0x40, 0x18, 0xe4, 0x06, 0x09, 0x22, 0x20, \n\t0x08, 0x08, 0x18, 0x09, 0x21, 0x66, 0x92, 0x09, 0x00, 0xe0, 0x4a, 0x8d, 0x32, 0x10, 0x41, 0x0d, \n\t0x19, 0x41, 0x29, 0x02, 0xb3, 0x40, 0x81, 0x94, 0x18, 0x44, 0x34, 0x03, 0x33, 0xb2, 0x58, 0x08, \n\t0x4c, 0x6c, 0x81, 0x82, 0x94, 0x0c, 0x44, 0x01, 0x44, 0x01, 0x81, 0x31, 0x40, 0xc3, 0x82, 0x00, \n\t0x75, 0xf2, 0x01, 0x18, 0x19, 0xca, 0x36, 0xc0, 0xa1, 0x04, 0x19, 0x10, 0xa1, 0x00, 0x75, 0x80, \n\t0x08, 0x89, 0x86, 0x20, 0x00, 0x01, 0x01, 0xa1, 0x31, 0x46, 0x00, 0x50, 0x01, 0xa0, 0x04, 0x04, \n\t0x05, 0x41, 0x4c, 0x66, 0x08, 0x90, 0x80, 0xd5, 0x01, 0x1c, 0x10, 0xb2, 0x08, 0xd0, 0x82, 0x29, \n\t0x50, 0x01, 0x40, 0x02, 0x70, 0x98, 0x81, 0x28, 0x14, 0x91, 0x9d, 0xd9, 0x98, 0x6f, 0x20, 0x80, \n\t0x02, 0x00, 0x41, 0x00, 0x20, 0x20, 0x04, 0xd3, 0x22, 0x08, 0x0d, 0xac, 0x28, 0x40, 0x70, 0x83, \n\t0xd1, 0x82, 0x09, 0x56, 0x25, 0x09, 0x1c, 0x59, 0x08, 0x82, 0x04, 0x12, 0x1a, 0x08, 0xa0, 0x00, \n\t0x87, 0x02, 0xc2, 0x20, 0x06, 0x41, 0x42, 0x08, 0x40, 0xe3, 0xc8, 0x02, 0x98, 0x83, 0x20, 0x6a, \n\t0x65, 0x5b, 0x02, 0x48, 0x81, 0x41, 0x0c, 0x92, 0xe0, 0x14, 0x18, 0x05, 0x41, 0x10, 0x43, 0x38, \n\t0x2c, 0x20, 0x86, 0x40, 0x0c, 0x46, 0x00, 0x19, 0xd1, 0x11, 0x20, 0x02, 0xd1, 0x10, 0x09, 0x05, \n\t0x01, 0xa6, 0x22, 0x04, 0x90, 0x8c, 0x20, 0x04, 0x00, 0x0e, 0x30, 0x88, 0x80, 0x09, 0x9f, 0x20, \n\t0x08, 0x40, 0x68, 0x20, 0x34, 0x01, 0xa7, 0x64, 0x00, 0x41, 0xb3, 0x24, 0x88, 0x08, 0x14, 0x12, \n\t0x08, 0x91, 0x20, 0x1c, 0x06, 0x00, 0xf0, 0x82, 0x2a, 0xb8, 0x16, 0x08, 0x24, 0xa1, 0x10, 0x10, \n\t0x01, 0x96, 0x4b, 0x56, 0x02, 0x60, 0x18, 0x20, 0x40, 0xa9, 0x58, 0x01, 0x73, 0x82, 0xc0, 0x8a, \n\t0x60, 0x04, 0x14, 0x82, 0x06, 0xdc, 0xda, 0xa8, 0x20, 0x22, 0x02, 0x97, 0x2c, 0x40, 0x04, 0x24, \n\t0x12, 0x21, 0x00, 0xa1, 0xc0, 0x80, 0x78, 0x54, 0x50, 0x23, 0xc1, 0x91, 0x01, 0x12, 0x27, 0x99, \n\t0x20, 0x01, 0x14, 0x04, 0x00, 0x44, 0x09, 0x92, 0x91, 0x40, 0x40, 0x0c, 0x51, 0x10, 0x33, 0x44, \n\t0x41, 0xcc, 0x60, 0xa5, 0x00, 0x08, 0x28, 0x16, 0x08, 0x00, 0x84, 0x33, 0x08, 0x49, 0x0b, 0x2a, \n\t0x04, 0x80, 0xa1, 0x21, 0x04, 0x95, 0x01, 0x0e, 0xa1, 0x50, 0x26, 0x24, 0x04, 0xe9, 0x10, 0xc2, \n\t0x50, 0x98, 0x01, 0xd8, 0xc0, 0x0a, 0x44, 0x30, 0x09, 0x65, 0x02, 0x02, 0x36, 0xd4, 0x22, 0x0a, \n\t0xc4, 0x14, 0x82, 0x00, 0x25, 0x0a, 0x07, 0x84, 0x07, 0x42, 0x12, 0x24, 0x19, 0x88, 0x80, 0x40, \n\t0x6c, 0x20, 0x30, 0x50, 0x82, 0x00, 0x00, 0xc8, 0x0e, 0x82, 0x01, 0xb6, 0x70, 0x84, 0x41, 0x40, \n\t0x27, 0x0b, 0xb4, 0x04, 0x89, 0x00, 0x38, 0x53, 0xca, 0x13, 0x80, 0x54, 0x42, 0x40, 0x84, 0x03, \n\t0x24, 0x6c, 0x44, 0x89, 0x1e, 0xa2, 0x6b, 0x04, 0x21, 0x18, 0x04, 0x00, 0x45, 0xa2, 0x84, 0xc8, \n\t0x01, 0x40, 0x20, 0x60, 0xa8, 0x20, 0x34, 0x82, 0x40, 0x20, 0x06, 0x5a, 0x80, 0x20, 0x80, 0x0a, \n\t0x70, 0x34, 0x52, 0x01, 0x15, 0x0b, 0x60, 0x24, 0xc7, 0x90, 0x32, 0x08, 0x4c, 0x82, 0x04, 0x26, \n\t0x92, 0xa1, 0xc9, 0x41, 0x23, 0x2c, 0x66, 0x29, 0x1d, 0xa5, 0x00, 0x00, 0x10, 0x41, 0xa8, 0x0a, \n\t0x20, 0x5c, 0x21, 0x54, 0xa3, 0x0a, 0x00, 0xb9, 0x40, 0x04, 0x2c, 0x20, 0x00, 0x04, 0x80, 0x03, \n\t0x0c, 0x18, 0xc0, 0x43, 0x00, 0x74, 0x0e, 0xa3, 0x04, 0x42, 0xc3, 0x0c, 0x80, 0xc2, 0x2a, 0x00, \n\t0x00, 0x82, 0x94, 0x48, 0xd2, 0x04, 0x24, 0x01, 0xf8, 0x23, 0x68, 0x12, 0x0c, 0x7c, 0x30, 0x00, \n\t0x03, 0x18, 0x1f, 0x60, 0x26, 0x00, 0x18, 0x04, 0x84, 0x05, 0x67, 0x10, 0x90, 0x02, 0x19, 0x30, \n\t0xcc, 0x86, 0x00, 0x26, 0x50, 0x10, 0x45, 0x47, 0x81, 0x08, 0x42, 0xaa, 0x01, 0xa4, 0x86, 0x29, \n\t0x70, 0x96, 0x00, 0x1d, 0x31, 0xc1, 0xe4, 0x5c, 0x02, 0x20, 0x09, 0x05, 0x14, 0x00, 0x40, 0x83, \n\t0x41, 0x28, 0xa8, 0x90, 0x00, 0x08, 0x32, 0xa0, 0xb7, 0x0d, 0x51, 0x02, 0x24, 0x85, 0x18, 0x0a, \n\t0x40, 0x08, 0x21, 0x12, 0x43, 0x12, 0x12, 0x40, 0x88, 0xa6, 0x06, 0x65, 0xc1, 0x34, 0x1c, 0x54, \n\t0x41, 0x20, 0x01, 0x48, 0x2a, 0x40, 0x05, 0x43, 0x56, 0x80, 0x80, 0x08, 0x34, 0x02, 0x47, 0x12, \n\t0x43, 0x21, 0x08, 0x00, 0x11, 0xc4, 0x0a, 0x01, 0x08, 0x05, 0x0c, 0x4c, 0x00, 0x06, 0x01, 0x70, \n\t0x80, 0x00, 0x5d, 0x48, 0x2c, 0x00, 0x12, 0x09, 0x2d, 0xc2, 0x48, 0x08, 0xe0, 0x19, 0x87, 0x00, \n\t0x98, 0x29, 0x20, 0x13, 0xc2, 0x08, 0x01, 0x81, 0x84, 0x2c, 0x21, 0x18, 0x2a, 0x78, 0x89, 0x05, \n\t0x60, 0x55, 0x00, 0x07, 0x61, 0x14, 0x80, 0x32, 0x14, 0x58, 0xa2, 0xb9, 0x42, 0x2a, 0x0c, 0xe6, \n\t0x52, 0x86, 0x8d, 0x48, 0x04, 0x00, 0xc4, 0xd0, 0x08, 0x28, 0xc3, 0x27, 0x02, 0x31, 0x18, 0x12, \n\t0x80, 0x12, 0x02, 0x02, 0x62, 0x01, 0x27, 0x24, 0x98, 0x01, 0x24, 0x42, 0x82, 0x94, 0x01, 0x16, \n\t0x05, 0x50, 0x34, 0x08, 0x04, 0x84, 0x43, 0x21, 0x08, 0x00, 0xb0, 0x88, 0x90, 0x16, 0x40, 0x40, \n\t0x74, 0x63, 0x2e, 0x00, 0x41, 0x60, 0x02, 0x24, 0x02, 0x02, 0x04, 0x49, 0x81, 0x44, 0x01, 0xc8, \n\t0x2a, 0xc0, 0x15, 0x80, 0x64, 0x24, 0xda, 0x84, 0x01, 0x08, 0x60, 0x08, 0xa1, 0x02, 0x10, 0x39, \n\t0x50, 0x20, 0x04, 0x84, 0x10, 0x12, 0x61, 0x02, 0x49, 0x22, 0xe0, 0x10, 0x3c, 0x61, 0xc6, 0x80, \n\t0x00, 0x86, 0x29, 0xa4, 0x10, 0x90, 0x25, 0x00, 0xc0, 0x80, 0x12, 0x18, 0x95, 0x40, 0x32, 0x12, \n\t0x89, 0x18, 0xd1, 0x02, 0x86, 0x54, 0x81, 0x20, 0x0c, 0x98, 0x06, 0x46, 0x20, 0xc0, 0x40, 0x18, \n\t0x0d, 0x09, 0x27, 0x2e, 0x40, 0x80, 0x2a, 0x40, 0x17, 0x40, 0x68, 0x12, 0x62, 0xa9, 0x0c, 0xc0, \n\t0x82, 0x1e, 0x54, 0xb1, 0x05, 0x28, 0x12, 0x68, 0x24, 0xa6, 0x62, 0x2e, 0x20, 0x51, 0x04, 0x44, \n\t0x91, 0x53, 0x83, 0xc8, 0x00, 0x28, 0x00, 0x42, 0x29, 0x11, 0xa0, 0x06, 0xc8, 0x1a, 0x45, 0x08, \n\t0x10, 0x84, 0x5b, 0x25, 0x10, 0x86, 0xc2, 0x10, 0x48, 0x08, 0x2e, 0x14, 0x22, 0xc0, 0x2d, 0x00, \n\t0x50, 0x42, 0x48, 0xc1, 0x80, 0x81, 0x80, 0x10, 0x01, 0x20, 0x02, 0xc1, 0x15, 0x01, 0x02, 0x48, \n\t0x22, 0x07, 0x82, 0x14, 0x00, 0xd4, 0xc2, 0x02, 0x01, 0x5b, 0x06, 0x25, 0x84, 0x00, 0x02, 0x64, \n\t0xb8, 0x02, 0xc8, 0x8e, 0x89, 0x20, 0x01, 0x8a, 0x12, 0x80, 0x10, 0x8c, 0x02, 0x92, 0x02, 0x80, \n\t0x01, 0x43, 0x2d, 0x08, 0x82, 0x21, 0x00, 0x11, 0x01, 0x8a, 0x12, 0x94, 0x02, 0x03, 0x30, 0xc0, \n\t0x6d, 0x24, 0x86, 0x21, 0x04, 0x50, 0xc0, 0xa0, 0x0e, 0x12, 0x81, 0x29, 0xc4, 0x06, 0x63, 0x00, \n\t0x42, 0x02, 0x80, 0x10, 0x06, 0x0d, 0x08, 0x45, 0x50, 0x01, 0x1c, 0x98, 0x4c, 0x64, 0x64, 0x90, \n\t0x88, 0x30, 0x8a, 0x43, 0x5a, 0x01, 0x11, 0x03, 0xa8, 0x43, 0x20, 0x00, 0x00, 0xa3, 0xb6, 0x24, \n\t0x0e, 0x6b, 0x20, 0xc4, 0x22, 0x00, 0x4c, 0x48, 0xe0, 0x24, 0x21, 0x90, 0x01, 0x8c, 0x88, 0xa8, \n\t0x04, 0x22, 0x68, 0xb3, 0xa5, 0x52, 0x42, 0x4a, 0xc2, 0x0b, 0x1d, 0x00, 0xc8, 0x04, 0x02, 0x10, \n\t0x2a, 0x84, 0x80, 0x08, 0x45, 0x4a, 0x24, 0x8b, 0x00, 0x30, 0x10, 0x21, 0x18, 0x52, 0xc9, 0x02, \n\t0xc5, 0x98, 0x02, 0x10, 0x81, 0x02, 0x21, 0x91, 0x40, 0x65, 0x40, 0x41, 0x90, 0x92, 0x11, 0xd4, \n\t0x20, 0x5a, 0x83, 0x20, 0x00, 0x25, 0x82, 0x0c, 0x06, 0x15, 0x41, 0x16, 0x04, 0x81, 0x02, 0x6a, \n\t0x41, 0x89, 0x12, 0xb1, 0x00, 0x6f, 0x54, 0x01, 0x09, 0x1a, 0x8d, 0x02, 0x00, 0x32, 0xd0, 0x01, \n\t0xa5, 0x15, 0x81, 0x01, 0x10, 0x80, 0x22, 0x00, 0x84, 0xc0, 0x00, 0x58, 0x24, 0xc1, 0x13, 0x09, \n\t0x12, 0xe0, 0x16, 0x84, 0x9a, 0x05, 0x08, 0x53, 0x84, 0x42, 0x00, 0x68, 0x21, 0x21, 0x0a, 0x49, \n\t0x10, 0x10, 0x12, 0x81, 0x10, 0x10, 0x63, 0x42, 0x41, 0x02, 0x01, 0x05, 0xdb, 0xc4, 0x3c, 0x11, \n\t0xb0, 0x00, 0xc9, 0x0c, 0x0e, 0x20, 0x20, 0x12, 0x90, 0x69, 0x08, 0x82, 0x42, 0x01, 0x8b, 0x30, \n\t0x2c, 0x4c, 0x00, 0x22, 0x02, 0x43, 0xa9, 0xc0, 0x84, 0xc8, 0x0c, 0xf2, 0x00, 0x04, 0x60, 0x4a, \n\t0x00, 0x40, 0xa4, 0x08, 0x22, 0x04, 0xc7, 0x04, 0x42, 0x05, 0x20, 0x1d, 0xc1, 0x04, 0x85, 0x6a, \n\t0x20, 0x22, 0x1c, 0xc8, 0x55, 0x88, 0x00, 0x00, 0xa0, 0x05, 0x21, 0x14, 0xc8, 0x48, 0x22, 0x20, \n\t0x1a, 0x10, 0x49, 0x0d, 0x2e, 0xc4, 0x9a, 0x04, 0x01, 0x90, 0x44, 0x12, 0x04, 0x42, 0x21, 0x20, \n\t0x84, 0x22, 0x74, 0x00, 0x60, 0x82, 0x29, 0x40, 0xa8, 0x00, 0x87, 0xb3, 0x98, 0xb4, 0x14, 0x05, \n\t0x40, 0xa2, 0x41, 0x0b, 0x19, 0xce, 0x08, 0x04, 0x02, 0x38, 0x89, 0x15, 0x82, 0xc0, 0x40, 0x50, \n\t0x08, 0xa0, 0x20, 0x03, 0x08, 0x10, 0xa1, 0x90, 0x1d, 0x90, 0x5a, 0x40, 0x06, 0x96, 0xd3, 0x08, \n\t0x81, 0x02, 0x07, 0x00, 0xc0, 0x49, 0x08, 0x8c, 0x80, 0xa4, 0x00, 0xc7, 0x90, 0x2b, 0xc9, 0x88, \n\t0x40, 0x08, 0x20, 0x00, 0xa4, 0x41, 0x04, 0x20, 0x38, 0x52, 0x00, 0x00, 0xc0, 0x13, 0x00, 0x12, \n\t0x00, 0xe2, 0x82, 0x91, 0x03, 0x49, 0x04, 0x84, 0x52, 0x02, 0xa0, 0x4d, 0x21, 0x36, 0x00, 0x8a, \n\t0xb1, 0xd4, 0x4a, 0xee, 0x08, 0x40, 0x48, 0xb2, 0xd0, 0x08, 0x85, 0x30, 0x64, 0x23, 0x39, 0x08, \n\t0x80, 0x0c, 0x0a, 0x90, 0x01, 0x10, 0x51, 0x88, 0x62, 0x40, 0x12, 0x49, 0x1d, 0x2c, 0x80, 0xcd, \n\t0x14, 0xa0, 0x31, 0x21, 0x24, 0x00, 0x86, 0x10, 0xa2, 0xd2, 0x82, 0x05, 0x49, 0x6a, 0x60, 0x00, \n\t0x02, 0x08, 0x35, 0x03, 0x22, 0x54, 0x90, 0xd8, 0xa4, 0x09, 0x59, 0x0a, 0x30, 0x00, 0x08, 0x15, \n\t0x61, 0x00, 0x0a, 0x04, 0xa4, 0xb3, 0x92, 0x00, 0x41, 0x40, 0x00, 0x47, 0x02, 0x00, 0xd4, 0x04, \n\t0xac, 0x0a, 0xa7, 0x10, 0x81, 0x01, 0xc1, 0x0e, 0x22, 0x22, 0x40, 0x24, 0x3c, 0x14, 0x6c, 0x28, \n\t0xc2, 0xd8, 0x18, 0xe1, 0x11, 0x0c, 0x00, 0x00, 0x82, 0x1d, 0xb5, 0x06, 0x01, 0x4e, 0x43, 0x63, \n\t0x0c, 0x4d, 0x8c, 0x08, 0x6c, 0x03, 0x20, 0x8c, 0x4c, 0x08, 0x01, 0x00, 0x32, 0x88, 0x0a, 0x21, \n\t0x0f, 0x45, 0x20, 0x90, 0x43, 0x20, 0x04, 0x16, 0xac, 0x20, 0x54, 0x08, 0x85, 0x51, 0x89, 0xc0, \n\t0x3e, 0x23, 0xb2, 0xa0, 0x0d, 0x10, 0x48, 0x00, 0x34, 0x19, 0xa2, 0xc0, 0x86, 0x40, 0x12, 0xe0, \n\t0x01, 0x0e, 0x20, 0x03, 0x80, 0x00, 0xc0, 0x29, 0x8a, 0x90, 0x46, 0x24, 0x08, 0x84, 0x00, 0x87, \n\t0x89, 0x41, 0x64, 0x38, 0x04, 0x49, 0x04, 0x28, 0xc5, 0x06, 0x0e, 0x93, 0xb0, 0x0a, 0x34, 0x04, \n\t0x04, 0x6c, 0x20, 0x23, 0x1e, 0x81, 0x5a, 0x81, 0x4a, 0x61, 0x90, 0x84, 0x50, 0x0e, 0x42, 0x0c, \n\t0x12, 0xa1, 0x26, 0xa8, 0x88, 0x04, 0x34, 0x10, 0x28, 0x20, 0x90, 0x45, 0x83, 0x30, 0x25, 0x1a, \n\t0x20, 0x8c, 0x41, 0x05, 0x00, 0xc4, 0x48, 0xa8, 0x89, 0x4d, 0x01, 0x08, 0xc2, 0x00, 0xa4, 0x45, \n\t0x58, 0x01, 0x78, 0x31, 0x2b, 0x28, 0x88, 0x06, 0x21, 0x62, 0x10, 0x23, 0x9a, 0x90, 0x88, 0x41, \n\t0x10, 0x80, 0x19, 0x01, 0x40, 0x06, 0x21, 0x48, 0x11, 0x82, 0x20, 0xd0, 0x18, 0x09, 0x04, 0xb1, \n\t0x00, 0x25, 0xc0, 0x00, 0xc6, 0x20, 0x06, 0x22, 0x29, 0x59, 0x53, 0x60, 0x38, 0x81, 0x30, 0x8e, \n\t0x88, 0x06, 0xa4, 0x0e, 0x20, 0xa0, 0x84, 0x00, 0x02, 0x00, 0x20, 0x65, 0x32, 0x84, 0x00, 0x00, \n\t0x0a, 0x12, 0x12, 0x01, 0x2a, 0x18, 0x0f, 0x45, 0x02, 0x92, 0x69, 0x20, 0xa5, 0x51, 0x44, 0x12, \n\t0x44, 0x00, 0x2a, 0x18, 0x0d, 0x24, 0x52, 0xc4, 0x22, 0x8a, 0x80, 0x80, 0x00, 0x20, 0x00, 0xd8, \n\t0x00, 0x25, 0x12, 0x01, 0x44, 0x72, 0x02, 0x8a, 0x7c, 0x10, 0x20, 0x2c, 0x35, 0x52, 0x00, 0x80, \n\t0x90, 0x4a, 0x02, 0x05, 0x80, 0x14, 0x49, 0x18, 0x01, 0x18, 0x92, 0x88, 0xb1, 0x69, 0x18, 0x2c, \n\t0x34, 0x50, 0x4a, 0x80, 0x95, 0x16, 0x82, 0x10, 0x42, 0xa0, 0x0c, 0x90, 0x04, 0xaa, 0x44, 0x26, \n\t0x89, 0x10, 0x24, 0x40, 0x0b, 0x0e, 0x21, 0x20, 0x1c, 0x04, 0x86, 0x08, 0x10, 0xc1, 0x00, 0x0f, \n\t0x30, 0x5c, 0x04, 0x40, 0xa0, 0x2b, 0x98, 0x30, 0xd9, 0x61, 0x72, 0x24, 0x23, 0x21, 0x25, 0x46, \n\t0xe4, 0x1c, 0x00, 0x42, 0x08, 0x00, 0x88, 0xc1, 0x2c, 0x35, 0x20, 0x14, 0x40, 0x00, 0x23, 0x26, \n\t0xf4, 0x20, 0x15, 0x14, 0xda, 0x20, 0x00, 0x40, 0x53, 0x2f, 0xc0, 0xcb, 0x26, 0x52, 0x11, 0x01, \n\t0x06, 0xe1, 0xc0, 0x4a, 0x6a, 0x82, 0x48, 0x12, 0x80, 0x11, 0x00, 0x34, 0x87, 0x00, 0x21, 0xa9, \n\t0x00, 0x4a, 0x22, 0x80, 0x60, 0x33, 0x21, 0x10, 0x0a, 0x18, 0x42, 0xa0, 0x20, 0x3c, 0x92, 0x40, \n\t0x04, 0x61, 0x42, 0x1a, 0x58, 0x02, 0x82, 0x4a, 0x80, 0x00, 0x10, 0xdc, 0x01, 0x21, 0x04, 0xb0, \n\t0x9a, 0x04, 0x04, 0x02, 0x00, 0x28, 0x20, 0x52, 0x19, 0x80, 0xc1, 0xc6, 0x4c, 0x04, 0x28, 0x01, \n\t0x44, 0x93, 0x21, 0x30, 0x40, 0x08, 0xb4, 0x41, 0xc5, 0x28, 0x00, 0x30, 0x8a, 0x01, 0x00, 0x1a, \n\t0x60, 0x04, 0xc0, 0x03, 0xa0, 0x24, 0x14, 0xad, 0x20, 0x04, 0xc1, 0x00, 0x39, 0x48, 0x4c, 0x02, \n\t0xc6, 0x20, 0x20, 0x74, 0x95, 0x00, 0x22, 0x16, 0xc3, 0x1a, 0x00, 0x42, 0x01, 0x12, 0xe3, 0xc1, \n\t0x89, 0x68, 0x10, 0x24, 0x12, 0x86, 0x12, 0x08, 0x20, 0x14, 0x27, 0x00, 0x70, 0x80, 0x09, 0x50, \n\t0x8a, 0x8b, 0x70, 0x81, 0x10, 0x29, 0xcc, 0x01, 0x86, 0x04, 0x01, 0x10, 0x98, 0x3c, 0x50, 0xa0, \n\t0x02, 0x44, 0x00, 0x10, 0x49, 0x0a, 0x80, 0x3a, 0x60, 0x20, 0x15, 0xd0, 0x44, 0x00, 0x08, 0x25, \n\t0x81, 0x3a, 0x00, 0x15, 0xc0, 0x10, 0x42, 0x0a, 0x10, 0xc0, 0x0b, 0x20, 0x08, 0x71, 0x28, 0x2c, \n\t0xc0, 0x99, 0x41, 0x02, 0x30, 0x00, 0x00, 0x80, 0x99, 0x6c, 0x24, 0x63, 0x09, 0x10, 0x50, 0xc5, \n\t0x66, 0x0c, 0x12, 0x0a, 0x01, 0x94, 0x07, 0x0a, 0x42, 0x80, 0xe2, 0xa6, 0x29, 0x8c, 0x20, 0x04, \n\t0x11, 0x10, 0x01, 0x01, 0x18, 0x03, 0x24, 0x40, 0x18, 0x8c, 0x04, 0x88, 0xc6, 0x4c, 0x83, 0x20, \n\t0x09, 0xe0, 0x47, 0x8c, 0x40, 0x40, 0x01, 0x06, 0x25, 0x14, 0xc0, 0x72, 0x05, 0x70, 0x84, 0x40, \n\t0x40, 0x43, 0x20, 0xb0, 0x88, 0x13, 0x88, 0x89, 0xa2, 0x20, 0x55, 0x00, 0x00, 0x20, 0xd3, 0x04, \n\t0x08, 0x12, 0x21, 0x05, 0x08, 0x41, 0x68, 0x4a, 0x16, 0x00, 0x8e, 0x61, 0x00, 0xc6, 0x0c, 0xa2, \n\t0xc9, 0x01, 0xa8, 0x55, 0x00, 0x12, 0x60, 0x6a, 0x87, 0xd8, 0x12, 0x8a, 0x20, 0x14, 0x11, 0x32, \n\t0x00, 0x00, 0xa4, 0x08, 0x06, 0x10, 0x0d, 0x14, 0x10, 0x05, 0x40, 0x01, 0xa0, 0xa8, 0x40, 0x0f, \n\t0x80, 0x42, 0x04, 0x43, 0x37, 0x0c, 0x94, 0x4b, 0x28, 0x80, 0x90, 0x0c, 0x8d, 0x0d, 0xc9, 0x72, \n\t0x30, 0xd8, 0x92, 0x05, 0x01, 0x23, 0x1a, 0x10, 0x00, 0x81, 0x90, 0x06, 0xc5, 0x00, 0xa2, 0x02, \n\t0x88, 0x94, 0x56, 0x00, 0x08, 0x22, 0x49, 0x16, 0xc0, 0x81, 0x21, 0x18, 0xa0, 0x03, 0x11, 0x75, \n\t0x02, 0xc0, 0x46, 0x52, 0x90, 0x28, 0x30, 0x8a, 0x28, 0x30, 0x04, 0x10, 0x8a, 0x19, 0x49, 0x01, \n\t0x2c, 0x07, 0x00, 0x00, 0x44, 0x40, 0x24, 0x0a, 0x97, 0x59, 0x98, 0x01, 0x58, 0xa0, 0x22, 0x01, \n\t0x21, 0x00, 0xf4, 0xda, 0xa8, 0x5e, 0x60, 0x00, 0xac, 0x65, 0x01, 0x80, 0x42, 0xd0, 0x03, 0x00, \n\t0x14, 0x03, 0x4b, 0x02, 0x02, 0x60, 0x16, 0x81, 0x88, 0x84, 0x02, 0x62, 0xaa, 0x14, 0x84, 0xc2, \n\t0x40, 0x52, 0x15, 0x00, 0x95, 0x80, 0x01, 0x04, 0x10, 0x20, 0x08, 0x38, 0x08, 0xd0, 0x60, 0x14, \n\t0x20, 0x88, 0x88, 0x89, 0x14, 0x85, 0x3c, 0x00, 0x82, 0x03, 0x40, 0x90, 0x84, 0x02, 0x62, 0x22, \n\t0x01, 0x40, 0xcc, 0xc1, 0x1e, 0x13, 0x02, 0x2a, 0x20, 0x40, 0x22, 0x00, 0x10, 0x8b, 0x00, 0xa9, \n\t0x83, 0x00, 0x08, 0x85, 0x03, 0x38, 0x69, 0x59, 0x22, 0x54, 0xe1, 0xd0, 0xa0, 0xd4, 0x40, 0x29, \n\t0x12, 0x74, 0x20, 0x21, 0x54, 0x08, 0x08, 0x08, 0xc2, 0x22, 0x2b, 0x90, 0x14, 0x01, 0x4a, 0x53, \n\t0x30, 0x01, 0x30, 0x18, 0x40, 0x44, 0x84, 0x98, 0x30, 0x1c, 0x02, 0x04, 0x10, 0x61, 0x29, 0x08, \n\t0x4c, 0x02, 0x61, 0x10, 0x04, 0x60, 0x98, 0xd0, 0x08, 0x8b, 0x00, 0x14, 0x92, 0x2c, 0x61, 0x06, \n\t0x85, 0x0a, 0x12, 0xa1, 0x1b, 0xe0, 0x83, 0x88, 0x5c, 0x21, 0x48, 0x20, 0x30, 0x41, 0x8a, 0x46, \n\t0x84, 0x50, 0x0e, 0x09, 0x01, 0x05, 0x70, 0x40, 0x81, 0x02, 0x14, 0x01, 0xc8, 0x00, 0xd5, 0x01, \n\t0x20, 0x00, 0x0d, 0x4f, 0x58, 0x00, 0xe0, 0x90, 0x08, 0x50, 0x09, 0x0a, 0x23, 0xcb, 0x0c, 0x09, \n\t0xc4, 0x02, 0x26, 0x86, 0x58, 0x0d, 0x0c, 0x94, 0x41, 0x5a, 0xd2, 0x18, 0x04, 0x80, 0x02, 0x06, \n\t0x40, 0x14, 0xc0, 0x04, 0x11, 0x08, 0x04, 0x42, 0x60, 0x20, 0x03, 0x48, 0xc1, 0x80, 0x42, 0x15, \n\t0x50, 0x18, 0xc1, 0x14, 0x2a, 0x24, 0x55, 0x58, 0x14, 0x64, 0x54, 0x69, 0x20, 0x04, 0x91, 0x90, \n\t0x60, 0x50, 0xc8, 0x22, 0x23, 0x40, 0x21, 0x01, 0x4e, 0x65, 0x08, 0x25, 0x00, 0x18, 0x01, 0x0c, \n\t0x03, 0x20, 0x04, 0xe1, 0x91, 0x34, 0xc1, 0x68, 0x30, 0x41, 0x10, 0x02, 0x21, 0x12, 0x0a, 0x00, \n\t0x04, 0xf0, 0x2c, 0x58, 0x04, 0x8d, 0x00, 0x80, 0x2b, 0xa8, 0x70, 0x16, 0x65, 0x08, 0xc2, 0x80, \n\t0x12, 0x8c, 0x82, 0x44, 0x48, 0x20, 0x30, 0x14, 0x04, 0xc0, 0x81, 0x20, 0x02, 0x42, 0xb0, 0x00, \n\t0x46, 0x80, 0x18, 0x14, 0x02, 0x10, 0x38, 0x4a, 0xc2, 0x60, 0xc0, 0x6a, 0x0a, 0x88, 0x4c, 0x88, \n\t0x20, 0x21, 0xc2, 0x0b, 0xe8, 0xc4, 0xa4, 0x04, 0x40, 0x00, 0x0a, 0x60, 0x58, 0x4c, 0x18, 0x72, \n\t0x89, 0x23, 0x00, 0x0a, 0x20, 0x2a, 0x26, 0x02, 0x08, 0x88, 0x10, 0x04, 0x14, 0x80, 0x20, 0x31, \n\t0x3c, 0x54, 0xc0, 0x00, 0x81, 0xa3, 0x80, 0x44, 0x00, 0x66, 0x24, 0x81, 0x43, 0x16, 0x81, 0x18, \n\t0x87, 0x06, 0x14, 0x20, 0x15, 0x00, 0x04, 0x23, 0x04, 0x46, 0xe2, 0x3f, 0x00, 0x03, 0x04, 0x54, \n\t0x30, 0x61, 0x12, 0xc0, 0x02, 0x41, 0x46, 0x21, 0xc3, 0x8a, 0x14, 0x08, 0x26, 0x30, 0x24, 0x48, \n\t0x21, 0x0d, 0x07, 0xa1, 0x18, 0xa2, 0x70, 0x06, 0x00, 0x92, 0x00, 0x78, 0x47, 0x20, 0xb0, 0x0c, \n\t0x55, 0x00, 0x2e, 0xe2, 0x20, 0x88, 0xb1, 0x8a, 0x8c, 0x02, 0x02, 0x03, 0x0c, 0x81, 0x50, 0x83, \n\t0x44, 0x93, 0x00, 0x26, 0xc1, 0x04, 0x40, 0x20, 0xf1, 0x01, 0x20, 0xc8, 0x11, 0x4e, 0x2e, 0x00, \n\t0x20, 0x23, 0x51, 0x50, 0x20, 0x7c, 0x06, 0x81, 0x08, 0x48, 0x4c, 0x82, 0x14, 0x00, 0xca, 0xa5, \n\t0x44, 0x17, 0x00, 0x08, 0x02, 0x0a, 0x9a, 0x50, 0x10, 0x40, 0x22, 0x40, 0x01, 0x08, 0x75, 0x80, \n\t0x2a, 0x02, 0x46, 0x21, 0x8a, 0x24, 0x49, 0x81, 0x0a, 0x94, 0x03, 0x8d, 0x04, 0x00, 0x24, 0x48, \n\t0xa0, 0x3a, 0x02, 0x01, 0x4c, 0x09, 0x48, 0x22, 0x42, 0x08, 0xc0, 0x13, 0xac, 0x08, 0xb2, 0x91, \n\t0x00, 0x04, 0x98, 0x41, 0x64, 0x01, 0xc1, 0x2a, 0x40, 0x83, 0x21, 0x64, 0x33, 0x1a, 0x08, 0x00, \n\t0x00, 0x20, 0x12, 0x94, 0x4b, 0x95, 0xcc, 0x58, 0x04, 0x20, 0x54, 0x48, 0xa0, 0xa9, 0x08, 0x43, \n\t0x20, 0x01, 0xd0, 0xa0, 0xe1, 0x40, 0x04, 0x06, 0xb7, 0x91, 0x01, 0x29, 0xcb, 0xe0, 0x20, 0x25, \n\t0x18, 0x24, 0x84, 0x00, 0xc0, 0x10, 0x50, 0x01, 0x01, 0x38, 0x00, 0x2c, 0x00, 0x67, 0xa1, 0x18, \n\t0x90, 0x00, 0x8d, 0x68, 0x04, 0x70, 0x28, 0x18, 0x87, 0x83, 0x16, 0x30, 0x62, 0x0c, 0x14, 0x10, \n\t0xaa, 0x30, 0x17, 0xa2, 0xa5, 0xc9, 0x92, 0x44, 0x20, 0xb2, 0x0a, 0x03, 0x5d, 0x01, 0xc4, 0x4e, \n\t0x10, 0x8a, 0x21, 0x40, 0x90, 0x80, 0x2a, 0x24, 0x00, 0x21, 0xf0, 0x41, 0x42, 0x56, 0x02, 0x02, \n\t0x14, 0x60, 0x49, 0x20, 0x02, 0x04, 0x81, 0xa2, 0x08, 0x40, 0x42, 0x00, 0x00, 0x20, 0x23, 0x31, \n\t0x04, 0x88, 0x40, 0x01, 0x61, 0x84, 0x28, 0x46, 0x0c, 0x48, 0xb1, 0xb2, 0x06, 0x20, 0x08, 0x8e, \n\t0x72, 0x30, 0x99, 0x15, 0x31, 0x44, 0x0d, 0x04, 0xa2, 0x63, 0x84, 0x21, 0x90, 0xa2, 0x00, 0xc4, \n\t0x41, 0x05, 0x1c, 0xc8, 0x05, 0x28, 0x11, 0x18, 0x02, 0x49, 0x03, 0x00, 0x18, 0x15, 0xd0, 0xa2, \n\t0x0c, 0xc0, 0x26, 0x46, 0x04, 0x28, 0x02, 0x1d, 0xd1, 0x01, 0x54, 0xe3, 0x8a, 0x80, 0x00, 0x10, \n\t0xce, 0x04, 0x02, 0x10, 0xa3, 0x70, 0x04, 0x03, 0x26, 0x97, 0x09, 0xb3, 0x90, 0x96, 0x00, 0x18, \n\t0x82, 0xc8, 0x21, 0x1c, 0x5c, 0x61, 0x00, 0x41, 0x42, 0x05, 0x80, 0x88, 0x21, 0x08, 0xa0, 0x10, \n\t0x09, 0x15, 0xc0, 0x00, 0x40, 0x01, 0xa8, 0x09, 0x68, 0x1a, 0x8a, 0x50, 0x80, 0xc0, 0x23, 0x80, \n\t0x52, 0xc9, 0x00, 0x47, 0x82, 0x22, 0x01, 0x45, 0x45, 0x40, 0x51, 0x78, 0x05, 0x21, 0x0a, 0x84, \n\t0x66, 0x44, 0x1a, 0x82, 0x01, 0x4b, 0x23, 0x70, 0x45, 0xb0, 0x84, 0x48, 0x40, 0x49, 0x32, 0x10, \n\t0x11, 0x08, 0x98, 0x00, 0x81, 0x28, 0x61, 0x41, 0x0d, 0x14, 0x83, 0x84, 0x20, 0x16, 0x41, 0x96, \n\t0xa0, 0x91, 0x08, 0x2c, 0x70, 0x80, 0x83, 0x51, 0x48, 0x20, 0x28, 0x14, 0x90, 0x01, 0xd9, 0x11, \n\t0x24, 0x5a, 0x21, 0x70, 0x03, 0x38, 0x86, 0xa8, 0x04, 0x20, 0x43, 0x28, 0x08, 0x88, 0x43, 0x6c, \n\t0x86, 0x80, 0x85, 0x28, 0x0a, 0x87, 0x04, 0x41, 0x89, 0x32, 0x00, 0x50, 0x28, 0x12, 0x50, 0x38, \n\t0xb0, 0x80, 0x88, 0xaa, 0x10, 0x24, 0x28, 0x0a, 0xb1, 0x40, 0x22, 0x16, 0x65, 0x10, 0xa9, 0x09, \n\t0x09, 0xc1, 0x04, 0x02, 0x59, 0x1c, 0x84, 0x14, 0x42, 0x02, 0x62, 0x89, 0x0c, 0x20, 0x09, 0x64, \n\t0x40, 0x82, 0x49, 0x0a, 0x21, 0x97, 0x41, 0x52, 0x06, 0x13, 0x04, 0x40, 0x00, 0x62, 0x06, 0x80, \n\t0xa1, 0x84, 0x08, 0x90, 0x00, 0x08, 0x80, 0x60, 0x02, 0x18, 0x41, 0x84, 0x42, 0xe1, 0x82, 0x03, \n\t0x10, 0x40, 0x21, 0x50, 0x02, 0x42, 0x84, 0x04, 0x4a, 0x0a, 0x4a, 0x11, 0xa3, 0x82, 0xac, 0x99, \n\t0x08, 0x56, 0x23, 0x01, 0x0a, 0x8c, 0x5c, 0xa4, 0x46, 0x34, 0x00, 0x88, 0x1c, 0x82, 0x0d, 0x32, \n\t0x11, 0x00, 0x33, 0x81, 0x01, 0x40, 0x08, 0x00, 0x08, 0x2e, 0x80, 0x10, 0x28, 0x68, 0x61, 0x29, \n\t0x02, 0x80, 0x00, 0x46, 0x40, 0x30, 0xa9, 0x00, 0x98, 0x13, 0x2c, 0x10, 0xb0, 0x89, 0x01, 0x30, \n\t0x8c, 0x86, 0x30, 0x23, 0x50, 0x03, 0x00, 0x40, 0x02, 0x08, 0x80, 0xa0, 0x25, 0x10, 0x08, 0xe6, \n\t0x16, 0x04, 0x40, 0x98, 0x20, 0x16, 0x0c, 0x54, 0x41, 0xd2, 0x10, 0x30, 0x12, 0x00, 0x1a, 0x42, \n\t0x82, 0x30, 0x45, 0x19, 0xad, 0x40, 0x83, 0x4a, 0x91, 0xa8, 0x81, 0x00, 0x12, 0x02, 0x51, 0x00, \n\t0x20, 0x9a, 0x04, 0x40, 0x64, 0x68, 0x3c, 0x30, 0xda, 0x41, 0x62, 0xb0, 0x18, 0x10, 0xe9, 0x41, \n\t0x80, 0x0c, 0x36, 0x62, 0x2c, 0x15, 0x85, 0x69, 0x08, 0x11, 0x01, 0x08, 0x68, 0x82, 0x0c, 0x7c, \n\t0x04, 0x32, 0x1a, 0x95, 0x00, 0x6d, 0x60, 0x50, 0x10, 0x87, 0x25, 0x0c, 0x00, 0x4c, 0x80, 0x11, \n\t0x28, 0x80, 0x44, 0x26, 0x58, 0x11, 0x80, 0x85, 0x25, 0x16, 0x4a, 0x0c, 0x41, 0x88, 0x10, 0x04, \n\t0x08, 0x42, 0x42, 0x84, 0x43, 0x80, 0x94, 0x48, 0x02, 0x02, 0x47, 0x49, 0x95, 0x70, 0x09, 0xc0, \n\t0x00, 0x00, 0x09, 0x1a, 0xa4, 0x01, 0x05, 0x20, 0x80, 0x00, 0x09, 0x50, 0x4a, 0x6e, 0x30, 0xb0, \n\t0x00, 0x10, 0x8d, 0x01, 0xaa, 0x0a, 0xd1, 0x4a, 0x07, 0x21, 0x80, 0xa6, 0x00, 0x20, 0x12, 0x2c, \n\t0x48, 0x82, 0x40, 0x20, 0x51, 0x98, 0x24, 0x65, 0x86, 0x20, 0x2a, 0xd0, 0x02, 0x1d, 0x69, 0x08, \n\t0xa0, 0x18, 0x30, 0x43, 0x01, 0x81, 0xca, 0x48, 0x30, 0x21, 0x90, 0xa2, 0x99, 0x00, 0x4d, 0x04, \n\t0x45, 0x80, 0x02, 0x08, 0xc8, 0x08, 0x0c, 0xd2, 0x60, 0xab, 0x75, 0x41, 0x00, 0x30, 0x86, 0x60, \n\t0x04, 0x30, 0x44, 0x29, 0x14, 0x47, 0x32, 0x94, 0x50, 0x0c, 0x80, 0x64, 0xb0, 0x40, 0x0c, 0xd4, \n\t0x14, 0x80, 0x1c, 0x00, 0x18, 0x28, 0xcd, 0x8c, 0x08, 0x00, 0x54, 0xe3, 0x38, 0x04, 0xc0, 0x69, \n\t0x40, 0x45, 0x38, 0xa0, 0x05, 0xc9, 0x22, 0x10, 0x83, 0x20, 0x9c, 0x0c, 0x93, 0x88, 0x60, 0x00, \n\t0x53, 0x94, 0x40, 0x16, 0x22, 0x3c, 0x20, 0x3a, 0x00, 0x14, 0x01, 0xc1, 0x04, 0x86, 0x08, 0x20, \n\t0x40, 0x88, 0x00, 0x30, 0x83, 0x48, 0x18, 0xb0, 0x11, 0x47, 0x08, 0x20, 0xe2, 0x22, 0x80, 0x4f, \n\t0x20, 0x08, 0x80, 0x92, 0x01, 0xa8, 0x05, 0x05, 0x22, 0x04, 0xd3, 0x10, 0xc1, 0x00, 0x8e, 0x0a, \n\t0xc1, 0x00, 0x08, 0x44, 0x0e, 0x4a, 0x48, 0x23, 0x40, 0x80, 0x44, 0x8a, 0x07, 0x40, 0x50, 0x98, \n\t0x37, 0x28, 0x10, 0x66, 0x02, 0x94, 0x69, 0x04, 0x29, 0x10, 0x22, 0x30, 0x40, 0x23, 0x14, 0x74, \n\t0xc4, 0x40, 0x0e, 0x02, 0x00, 0x94, 0x00, 0x09, 0xe8, 0x44, 0x21, 0x90, 0x12, 0x84, 0x81, 0x46, \n\t0x04, 0x46, 0x31, 0x8a, 0x05, 0xc9, 0x01, 0x50, 0x46, 0xc0, 0x07, 0x10, 0xc0, 0x0c, 0x02, 0x84, \n\t0xc0, 0x10, 0x08, 0x80, 0x49, 0x06, 0x02, 0x21, 0x04, 0x24, 0x96, 0x40, 0x04, 0x41, 0x1b, 0x0a, \n\t0x2c, 0x02, 0xca, 0x54, 0x20, 0x03, 0x81, 0xc4, 0x0a, 0x83, 0x40, 0xd2, 0x22, 0x0c, 0x20, 0x46, \n\t0x00, 0x20, 0x40, 0x1b, 0x20, 0x4c, 0x8d, 0x80, 0x6c, 0x60, 0x99, 0x17, 0xd1, 0x45, 0x20, 0x10, \n\t0x22, 0x40, 0xae, 0x00, 0x1c, 0x44, 0x50, 0xb0, 0x10, 0x03, 0x74, 0xc8, 0x41, 0x34, 0x36, 0x40, \n\t0xb1, 0x40, 0x19, 0x00, 0x00, 0x27, 0xc2, 0x22, 0x80, 0x02, 0x61, 0x00, 0xf0, 0x2b, 0x02, 0xb0, \n\t0x40, 0x09, 0x4c, 0x14, 0x09, 0x08, 0x34, 0x04, 0x49, 0x00, 0x92, 0x41, 0xa4, 0x60, 0x08, 0x48, \n\t0x70, 0x21, 0x62, 0xb5, 0x45, 0x13, 0xa8, 0x00, 0x80, 0xb2, 0x10, 0x40, 0x0d, 0x03, 0x30, 0x05, \n\t0x90, 0x11, 0x29, 0x48, 0x8e, 0x40, 0x01, 0x52, 0x11, 0x68, 0x80, 0x89, 0x62, 0x46, 0xa3, 0x28, \n\t0x40, 0x11, 0x00, 0x40, 0xc3, 0xc1, 0x01, 0x11, 0xc5, 0xa9, 0x10, 0x90, 0x11, 0x30, 0x81, 0xc3, \n\t0x06, 0x72, 0x21, 0x03, 0x88, 0x00, 0x03, 0x04, 0x12, 0xa5, 0x60, 0x92, 0x59, 0x04, 0xa1, 0x08, \n\t0x24, 0x21, 0x00, 0xa0, 0x02, 0x24, 0x42, 0x72, 0x10, 0x82, 0x08, 0x80, 0x00, 0x3c, 0x35, 0x11, \n\t0x0b, 0x50, 0x11, 0x48, 0x08, 0xb6, 0x90, 0x11, 0x00, 0x15, 0x00, 0x46, 0x42, 0x00, 0x03, 0xa0, \n\t0x86, 0x02, 0x04, 0x44, 0x09, 0x90, 0x00, 0x18, 0x09, 0x16, 0x02, 0x81, 0x2a, 0x49, 0x1c, 0x0b, \n\t0x50, 0xd1, 0xc0, 0x11, 0x30, 0x03, 0x0d, 0x08, 0xc5, 0x00, 0x88, 0x04, 0x12, 0xc4, 0x20, 0xb0, \n\t0x21, 0x23, 0x00, 0x8f, 0x0c, 0x74, 0x53, 0x91, 0x98, 0x31, 0x10, 0xc0, 0x18, 0xb0, 0x3a, 0x24, \n\t0xf0, 0xc2, 0x00, 0x42, 0x83, 0x82, 0x82, 0x5c, 0x08, 0xa9, 0x20, 0x20, 0x62, 0x07, 0x01, 0x01, \n\t0x03, 0x06, 0xc4, 0x10, 0x05, 0x48, 0xd1, 0x20, 0x2a, 0x42, 0x1a, 0x80, 0x40, 0x52, 0x0e, 0x10, \n\t0x24, 0x11, 0x84, 0x08, 0x41, 0x62, 0x68, 0x25, 0xc0, 0x36, 0x31, 0x41, 0xc0, 0x12, 0x06, 0x01, \n\t0x82, 0x65, 0x0c, 0xaa, 0x24, 0xa0, 0x20, 0x81, 0x10, 0xc4, 0x00, 0x18, 0x05, 0x61, 0x08, 0x10, \n\t0x02, 0x21, 0x4a, 0x51, 0xe2, 0x00, 0xa0, 0x04, 0x82, 0x0a, 0xa2, 0x30, 0x15, 0xcd, 0xd5, 0x22, \n\t0x16, 0x81, 0x08, 0x04, 0xb9, 0x86, 0x01, 0x40, 0x15, 0x23, 0x24, 0x0c, 0x0a, 0x82, 0x60, 0x85, \n\t0x88, 0x0c, 0x01, 0x80, 0x41, 0x50, 0x10, 0x08, 0x3a, 0xa0, 0x81, 0x02, 0x50, 0x34, 0x21, 0x04, \n\t0x5d, 0x50, 0xe1, 0x48, 0x07, 0x0a, 0x0c, 0xd0, 0x01, 0x82, 0x40, 0x24, 0x41, 0x8a, 0x71, 0xc5, \n\t0x24, 0x10, 0xb3, 0x49, 0x04, 0xa1, 0x4c, 0x0a, 0x02, 0xc2, 0x00, 0x82, 0x00, 0x4f, 0x08, 0x02, \n\t0x05, 0x00, 0x08, 0x39, 0x18, 0x8b, 0x04, 0x10, 0x78, 0x20, 0x21, 0xd5, 0x46, 0x02, 0x42, 0x82, \n\t0x06, 0x70, 0x00, 0x44, 0x08, 0x10, 0x90, 0x10, 0x14, 0x4a, 0x08, 0x26, 0xe0, 0x12, 0x8c, 0x18, \n\t0x0a, 0x04, 0x28, 0xc5, 0x01, 0xb3, 0xa0, 0x08, 0x04, 0x48, 0x74, 0x30, 0x12, 0x58, 0x47, 0x83, \n\t0x30, 0x04, 0x39, 0x02, 0x81, 0x01, 0x22, 0x02, 0x96, 0x02, 0x11, 0x44, 0xc0, 0x08, 0x38, 0x94, \n\t0x60, 0x0a, 0xa5, 0x4c, 0xcd, 0x60, 0x91, 0x02, 0x24, 0x80, 0x9c, 0x20, 0x4e, 0x60, 0x68, 0x01, \n\t0x50, 0x01, 0x6c, 0x04, 0x12, 0xc8, 0x10, 0x68, 0x40, 0x8a, 0x02, 0x03, 0x01, 0x83, 0x00, 0x94, \n\t0x00, 0x40, 0xe0, 0xf1, 0x20, 0x19, 0x48, 0x84, 0x04, 0x00, 0x10, 0x89, 0x10, 0x1a, 0x81, 0x14, \n\t0x00, 0x00, 0x03, 0x20, 0x55, 0x24, 0x60, 0x21, 0x11, 0x84, 0x09, 0x4d, 0x82, 0x00, 0x05, 0x23, \n\t0x02, 0x81, 0x09, 0xe1, 0x26, 0x02, 0x42, 0x29, 0x58, 0x82, 0x21, 0x00, 0x22, 0x40, 0x04, 0x05, \n\t0x81, 0xcc, 0x7a, 0x42, 0xa0, 0x8c, 0x84, 0x50, 0x4d, 0x50, 0x06, 0xc0, 0x00, 0x90, 0x83, 0x0c, \n\t0x72, 0x00, 0x98, 0x18, 0x41, 0x81, 0x4b, 0x0e, 0x70, 0x28, 0x20, 0x28, 0x10, 0x60, 0x38, 0x17, \n\t0xa1, 0x99, 0x10, 0x02, 0x41, 0x40, 0x82, 0x82, 0x82, 0x05, 0x14, 0x24, 0x04, 0x01, 0xb1, 0x14, \n\t0x48, 0x98, 0xa2, 0x0a, 0x30, 0x20, 0x06, 0x20, 0x05, 0x02, 0x0c, 0x61, 0x41, 0x16, 0x20, 0x09, \n\t0x22, 0x54, 0x14, 0x01, 0xa8, 0x34, 0x81, 0xa8, 0x12, 0x60, 0x40, 0x97, 0x10, 0x83, 0x40, 0x40, \n\t0x40, 0x48, 0x17, 0x90, 0x02, 0x28, 0x28, 0x40, 0x89, 0x10, 0x09, 0x94, 0x00, 0x44, 0x92, 0x82, \n\t0x19, 0xc1, 0x83, 0x08, 0x10, 0xc3, 0x00, 0x0a, 0x24, 0x18, 0x25, 0x00, 0x07, 0x41, 0x10, 0x01, \n\t0x89, 0x28, 0x20, 0x22, 0x80, 0x82, 0x70, 0x5a, 0x06, 0x12, 0x44, 0x33, 0x00, 0xc1, 0x0a, 0x00, \n\t0x26, 0x20, 0x00, 0x21, 0xa8, 0x5c, 0x81, 0x18, 0x84, 0x5a, 0x9c, 0x19, 0x54, 0xa0, 0x66, 0x45, \n\t0x10, 0x2b, 0x9c, 0x0c, 0x00, 0x32, 0x01, 0x28, 0x19, 0x44, 0x1a, 0x87, 0x72, 0x82, 0x20, 0x34, \n\t0xa0, 0x02, 0x04, 0x08, 0x60, 0x11, 0x13, 0x00, 0x01, 0x23, 0x26, 0x26, 0x5a, 0x29, 0x80, 0x43, \n\t0x88, 0x48, 0x00, 0x90, 0x0a, 0x64, 0x80, 0xce, 0x08, 0x80, 0x90, 0x09, 0x80, 0x52, 0x61, 0x60, \n\t0x60, 0x98, 0x29, 0x54, 0x09, 0x07, 0x44, 0x13, 0x8a, 0x11, 0x20, 0x19, 0x24, 0x28, 0x55, 0x82, \n\t0x93, 0x88, 0x8a, 0x82, 0x04, 0xc5, 0x29, 0x08, 0x80, 0x05, 0x48, 0x20, 0xc1, 0xc1, 0x88, 0xdc, \n\t0x82, 0x22, 0x06, 0x05, 0x38, 0x3c, 0x50, 0x92, 0x45, 0x0a, 0x20, 0xc3, 0x00, 0x10, 0x1b, 0x4c, \n\t0x5a, 0x30, 0x40, 0x0e, 0x29, 0x04, 0x61, 0x02, 0x32, 0x70, 0x00, 0x19, 0x05, 0x89, 0x42, 0x60, \n\t0x42, 0x89, 0x00, 0x02, 0x06, 0x68, 0x06, 0x30, 0xa4, 0x84, 0x49, 0xeb, 0x40, 0x55, 0x1a, 0x88, \n\t0x01, 0x44, 0xa5, 0x04, 0xd2, 0x81, 0x8f, 0x89, 0x11, 0x28, 0x40, 0x60, 0x1b, 0x85, 0xd1, 0x08, \n\t0x41, 0x40, 0x82, 0x0b, 0xb4, 0xb1, 0x0d, 0x64, 0x24, 0x10, 0x0b, 0x01, 0xa4, 0x03, 0x82, 0x0c, \n\t0x03, 0x60, 0x03, 0x54, 0x54, 0xc6, 0x60, 0x60, 0xa2, 0x17, 0x00, 0x1c, 0x08, 0x04, 0x21, 0xf8, \n\t0x94, 0x01, 0x83, 0xab, 0x00, 0x30, 0x10, 0x00, 0x24, 0x00, 0x04, 0x1e, 0x01, 0x60, 0x00, 0x51, \n\t0x88, 0x47, 0x04, 0x84, 0x01, 0x06, 0x95, 0x12, 0x60, 0x40, 0x20, 0x20, 0x02, 0x41, 0xc9, 0x40, \n\t0x32, 0x85, 0x90, 0x2f, 0x84, 0x8e, 0x20, 0x4c, 0x15, 0x71, 0x01, 0x28, 0xc2, 0x00, 0x18, 0x82, \n\t0x00, 0x18, 0x44, 0x50, 0x2d, 0x62, 0x22, 0x58, 0x80, 0x34, 0xc5, 0x68, 0x02, 0xb6, 0x00, 0x02, \n\t0x71, 0xc1, 0x08, 0x00, 0x50, 0x0a, 0x93, 0x84, 0x10, 0x00, 0x2a, 0x02, 0x6b, 0x80, 0x39, 0x17, \n\t0xcd, 0x20, 0x04, 0x00, 0x31, 0x00, 0x00, 0x02, 0x48, 0xb0, 0xa8, 0xac, 0x01, 0x84, 0xc4, 0x2c, \n\t0x41, 0x32, 0x18, 0x40, 0x80, 0x04, 0x0a, 0x10, 0x90, 0x20, 0x20, 0x17, 0x40, 0x10, 0x46, 0x13, \n\t0x18, 0x08, 0x00, 0xac, 0x00, 0x30, 0x00, 0x82, 0x88, 0x08, 0x81, 0x04, 0x40, 0x88, 0x10, 0x49, \n\t0x00, 0x21, 0x14, 0x03, 0x00, 0x10, 0x01, 0x81, 0xc1, 0x30, 0xa2, 0x08, 0x94, 0xf4, 0x01, 0x80, \n\t0x28, 0x13, 0xc1, 0x09, 0xa4, 0x95, 0x21, 0x12, 0x00, 0x49, 0x03, 0xd0, 0xc5, 0x42, 0x56, 0x16, \n\t0x00, 0x05, 0x05, 0x92, 0x64, 0x06, 0x40, 0x60, 0x02, 0x75, 0x0c, 0x2e, 0x08, 0x05, 0x40, 0x22, \n\t0x01, 0x10, 0x81, 0x02, 0xd0, 0x12, 0x30, 0x4d, 0x85, 0x40, 0x0a, 0x16, 0x2a, 0x20, 0x80, 0x84, \n\t0x04, 0x34, 0x30, 0x09, 0x01, 0x8c, 0x46, 0xe0, 0x34, 0x81, 0x3a, 0x38, 0x80, 0x09, 0x81, 0x30, \n\t0x14, 0x02, 0x03, 0xd5, 0x03, 0x07, 0x02, 0x45, 0x40, 0x89, 0x81, 0x40, 0x40, 0x00, 0x15, 0x00, \n\t0x87, 0x24, 0x50, 0x2c, 0x44, 0x60, 0x80, 0x0d, 0x68, 0x59, 0xc4, 0x28, 0xa0, 0x72, 0x01, 0x05, \n\t0x52, 0x48, 0x04, 0x02, 0x88, 0x05, 0xc8, 0x80, 0x42, 0x0c, 0x63, 0xa1, 0x30, 0x88, 0xc2, 0xce, \n\t0x28, 0xd6, 0x20, 0x0a, 0x18, 0x04, 0x41, 0x24, 0x04, 0xa2, 0x28, 0xe4, 0x46, 0xa8, 0x08, 0x70, \n\t0x08, 0xa1, 0x54, 0x85, 0x02, 0x6c, 0x20, 0x11, 0xa0, 0x40, 0x1c, 0x08, 0x54, 0x70, 0x00, 0x18, \n\t0x99, 0x0a, 0xa8, 0x10, 0xa2, 0x08, 0xb8, 0x84, 0xc0, 0x0d, 0x18, 0x81, 0x21, 0x8a, 0x28, 0xc0, \n\t0x61, 0x02, 0xc4, 0x90, 0x01, 0x89, 0x1e, 0x02, 0x00, 0x24, 0x81, 0x04, 0x41, 0x05, 0x80, 0x4c, \n\t0x20, 0xb0, 0x84, 0x54, 0x80, 0x44, 0x4c, 0xb2, 0xa1, 0x00, 0x85, 0x08, 0x00, 0x42, 0x32, 0x02, \n\t0xae, 0x08, 0xd8, 0x05, 0x48, 0x10, 0xc3, 0x26, 0x0c, 0x1a, 0xa2, 0x20, 0x04, 0x80, 0x00, 0x0d, \n\t0x12, 0x83, 0x4c, 0xc1, 0x11, 0x8a, 0x28, 0x04, 0x04, 0x56, 0x81, 0x8b, 0x01, 0x28, 0x01, 0xc9, \n\t0x22, 0x74, 0x48, 0x31, 0x50, 0x00, 0x41, 0x28, 0x30, 0x00, 0x1a, 0x34, 0x0a, 0x40, 0x24, 0x85, \n\t0x1a, 0x12, 0x08, 0xd8, 0x85, 0x02, 0x84, 0x01, 0x31, 0x2d, 0x81, 0x80, 0x00, 0x73, 0xf2, 0x23, \n\t0x08, 0x80, 0x00, 0x54, 0x12, 0xc1, 0x29, 0x0d, 0x13, 0x04, 0x08, 0x54, 0xb0, 0x1c, 0x21, 0x01, \n\t0xc4, 0x76, 0x90, 0x21, 0xa2, 0x01, 0x04, 0x0a, 0x40, 0x01, 0x12, 0x04, 0x40, 0x08, 0x2a, 0x0e, \n\t0x00, 0xc2, 0x16, 0x74, 0x0c, 0xaa, 0x00, 0x80, 0x41, 0x83, 0x91, 0x06, 0x66, 0x06, 0x64, 0x60, \n\t0x95, 0x65, 0x02, 0x09, 0x50, 0x25, 0x08, 0x88, 0x20, 0x88, 0x25, 0x40, 0xa2, 0x6a, 0x1b, 0x60, \n\t0x8f, 0x48, 0x26, 0x20, 0x41, 0x14, 0x00, 0x81, 0x8c, 0x40, 0x82, 0x41, 0x8e, 0x15, 0x08, 0x68, \n\t0x38, 0x14, 0x00, 0x11, 0x8c, 0x41, 0xe2, 0x46, 0xe3, 0x88, 0x31, 0x01, 0x07, 0x82, 0x00, 0x03, \n\t0x82, 0x2a, 0xc9, 0xd3, 0x06, 0x6a, 0x64, 0x10, 0x06, 0x2c, 0x11, 0xa0, 0x60, 0xa6, 0x08, 0x82, \n\t0x90, 0x59, 0x80, 0x30, 0x92, 0x91, 0xa8, 0x10, 0x44, 0x01, 0x28, 0x40, 0x29, 0x00, 0x45, 0xd1, \n\t0x84, 0x12, 0x52, 0x00, 0xb2, 0x8c, 0x41, 0x65, 0x08, 0x22, 0x41, 0x88, 0x10, 0x1c, 0xa2, 0x44, \n\t0x02, 0x83, 0x18, 0x18, 0x16, 0x03, 0x4a, 0xb0, 0x21, 0x03, 0x14, 0x12, 0x8a, 0x40, 0x91, 0x60, \n\t0x04, 0x50, 0x0b, 0x0b, 0x20, 0xd0, 0x02, 0x90, 0x14, 0x06, 0x60, 0x20, 0x10, 0x59, 0x00, 0x09, \n\t0x0a, 0x24, 0x00, 0x14, 0x62, 0x91, 0x10, 0x80, 0x69, 0x54, 0x20, 0x42, 0xa8, 0x44, 0x44, 0xcb, \n\t0x00, 0x00, 0x00, 0x0b, 0x04, 0x40, 0x89, 0x30, 0x81, 0x79, 0x02, 0x40, 0x41, 0x8e, 0x50, 0x14, \n\t0x01, 0xa0, 0x38, 0xd8, 0x01, 0x08, 0x90, 0x01, 0x92, 0xd1, 0x85, 0x60, 0x00, 0x80, 0xd1, 0x38, \n\t0xa0, 0x44, 0x48, 0x0a, 0x80, 0xc0, 0x29, 0xf4, 0x1a, 0x88, 0x44, 0x05, 0x32, 0x20, 0x05, 0x49, \n\t0x49, 0x00, 0xe4, 0x30, 0x81, 0x40, 0x16, 0x82, 0x46, 0x83, 0xb8, 0x03, 0x41, 0x10, 0x2e, 0x10, \n\t0x71, 0x40, 0x24, 0x15, 0x00, 0x49, 0x0a, 0x04, 0x08, 0xbc, 0xc4, 0x00, 0xc2, 0x36, 0x21, 0x80, \n\t0x3a, 0x41, 0x02, 0xa0, 0x20, 0x10, 0x30, 0xa5, 0x00, 0x86, 0x49, 0x30, 0x42, 0x82, 0x90, 0x90, \n\t0xc8, 0x00, 0x12, 0x63, 0x20, 0x04, 0x01, 0x98, 0x49, 0x00, 0x10, 0x12, 0x38, 0xc8, 0xc4, 0x08, \n\t0x06, 0x82, 0xe8, 0x00, 0x09, 0x02, 0x06, 0x00, 0x90, 0x90, 0x0a, 0x1c, 0x02, 0x21, 0x02, 0x84, \n\t0xb0, 0x16, 0x2c, 0x04, 0xa2, 0x58, 0x54, 0xc9, 0x10, 0x61, 0x84, 0x04, 0x04, 0x31, 0x61, 0x90, \n\t0xb8, 0x07, 0x02, 0x40, 0x42, 0x19, 0x00, 0x38, 0x15, 0x4c, 0x42, 0x91, 0x9a, 0x9a, 0x00, 0x46, \n\t0x0e, 0x00, 0x20, 0x61, 0x8c, 0x20, 0x88, 0x02, 0x1a, 0xc7, 0x88, 0x21, 0x90, 0x0b, 0x00, 0x00, \n\t0x43, 0xa0, 0x06, 0xe1, 0x40, 0xa9, 0x20, 0x80, 0x1a, 0x09, 0x88, 0x10, 0x08, 0x4c, 0x00, 0x0b, \n\t0x28, 0x14, 0x18, 0x20, 0x04, 0x93, 0x83, 0x0e, 0x48, 0x40, 0x69, 0x2a, 0x24, 0xa8, 0xb3, 0x00, \n\t0x17, 0x24, 0x10, 0xc0, 0xc8, 0x10, 0x85, 0x40, 0x00, 0x6a, 0x20, 0xc1, 0xb4, 0x50, 0x1a, 0x23, \n\t0x5a, 0x20, 0x60, 0x08, 0x4c, 0x48, 0xc1, 0x04, 0x43, 0xc1, 0xb3, 0x60, 0x85, 0x41, 0x0c, 0x60, \n\t0x41, 0x0a, 0x30, 0xc2, 0x46, 0x40, 0x06, 0x40, 0x80, 0x28, 0xc6, 0x48, 0x18, 0x81, 0x50, 0x14, \n\t0x00, 0x4f, 0x84, 0x0c, 0xb2, 0x32, 0x00, 0x15, 0xc1, 0x62, 0x04, 0x60, 0x00, 0x00, 0x81, 0x82, \n\t0x40, 0x00, 0xc2, 0x02, 0x85, 0x51, 0x58, 0x28, 0x0c, 0xa4, 0x00, 0x21, 0x55, 0x10, 0x21, 0x2a, \n\t0x95, 0x10, 0x92, 0x20, 0x90, 0x2a, 0x62, 0x34, 0xe0, 0x10, 0x11, 0x80, 0x20, 0x36, 0x46, 0x02, \n\t0x38, 0x8c, 0x10, 0x00, 0x14, 0x06, 0x11, 0x82, 0x4d, 0x00, 0x00, 0x14, 0xc1, 0x00, 0x24, 0x60, \n\t0x06, 0x05, 0x02, 0x94, 0x41, 0x3a, 0x9c, 0x89, 0x04, 0x06, 0x22, 0x69, 0x14, 0x50, 0x8d, 0xc2, \n\t0x20, 0x04, 0x5a, 0x3c, 0xa9, 0x92, 0x00, 0x40, 0x90, 0x48, 0x8b, 0x88, 0x08, 0xa7, 0x50, 0x00, \n\t0xd2, 0x00, 0x11, 0x18, 0x68, 0x04, 0x03, 0x20, 0x06, 0x08, 0x10, 0x01, 0x18, 0x46, 0xa2, 0x01, \n\t0x84, 0xca, 0x2c, 0x26, 0x00, 0x81, 0xa1, 0x01, 0x92, 0x49, 0x20, 0x02, 0xd0, 0x10, 0xb0, 0x19, \n\t0x41, 0x64, 0x21, 0x02, 0x01, 0x04, 0x84, 0x4c, 0x20, 0x11, 0x50, 0xb0, 0x70, 0x0c, 0x88, 0x0a, \n\t0x05, 0x41, 0x01, 0x8c, 0x8e, 0x04, 0x50, 0x12, 0x10, 0x90, 0x28, 0xc1, 0xa4, 0x24, 0x86, 0x82, \n\t0x25, 0x60, 0x04, 0x80, 0x0a, 0xc1, 0x79, 0x08, 0x90, 0x80, 0x20, 0x44, 0xd4, 0x20, 0x1c, 0x99, \n\t0x40, 0xa4, 0x48, 0x85, 0x02, 0x89, 0x19, 0x01, 0xc0, 0x70, 0xc1, 0x22, 0x34, 0x81, 0x19, 0xa0, \n\t0x28, 0x24, 0x08, 0x82, 0x64, 0x87, 0xe9, 0x10, 0x46, 0xa8, 0x02, 0xc9, 0x09, 0x41, 0x56, 0x04, \n\t0x41, 0x20, 0x84, 0x40, 0x61, 0x02, 0xa5, 0x18, 0x2f, 0x21, 0x45, 0x40, 0x38, 0x22, 0x0a, 0x92, \n\t0x00, 0x1d, 0x04, 0x06, 0x04, 0xb8, 0x80, 0x80, 0x14, 0x81, 0x4a, 0x02, 0xc2, 0x01, 0xa1, 0x82, \n\t0x88, 0x02, 0x11, 0xba, 0xa8, 0x11, 0x08, 0x60, 0x68, 0x44, 0xc2, 0x15, 0x90, 0x18, 0x88, 0x28, \n\t0x21, 0x98, 0x1c, 0x41, 0x5a, 0xc2, 0x24, 0x00, 0x83, 0x04, 0x0c, 0x86, 0x0c, 0x10, 0x01, 0x28, \n\t0x20, 0xd5, 0x8e, 0x21, 0x2e, 0x04, 0x68, 0x04, 0x11, 0x40, 0xa2, 0x00, 0x03, 0x40, 0x3a, 0x21, \n\t0x01, 0x28, 0x0e, 0x90, 0x20, 0x80, 0xf0, 0x90, 0x41, 0x0a, 0x83, 0x4b, 0x8d, 0x84, 0x04, 0x24, \n\t0x32, 0x95, 0x01, 0x18, 0x08, 0x09, 0x42, 0x3a, 0x20, 0xc8, 0x10, 0x00, 0x83, 0x80, 0x08, 0x40, \n\t0x81, 0x80, 0x51, 0x00, 0x60, 0x00, 0xa5, 0x92, 0x23, 0x04, 0xca, 0x01, 0x04, 0x02, 0x32, 0x81, \n\t0x11, 0x1c, 0x04, 0x2c, 0x10, 0xa2, 0x0b, 0x04, 0x9c, 0x82, 0x2e, 0x41, 0x08, 0x15, 0x80, 0x8d, \n\t0x49, 0x40, 0x42, 0x42, 0x20, 0x08, 0x11, 0x06, 0x30, 0x14, 0x03, 0xa8, 0x30, 0x0e, 0x20, 0x28, \n\t0x10, 0x00, 0x3c, 0x11, 0x52, 0x89, 0x08, 0x61, 0xc0, 0x19, 0x84, 0xc4, 0x24, 0x1a, 0x50, 0x00, \n\t0x08, 0xa0, 0x02, 0x44, 0x0a, 0x20, 0x08, 0x20, 0x10, 0x95, 0x2e, 0x5e, 0x21, 0x40, 0x24, 0x20, \n\t0x84, 0x40, 0x14, 0x27, 0x00, 0xa6, 0x5c, 0x48, 0x88, 0x08, 0x47, 0x08, 0x13, 0x60, 0x10, 0xa2, \n\t0x64, 0x83, 0x01, 0xa8, 0x61, 0x02, 0x00, 0x4a, 0x54, 0x10, 0x21, 0x10, 0x1d, 0xe2, 0x22, 0x02, \n\t0x42, 0x16, 0x44, 0x00, 0x80, 0x04, 0x50, 0x81, 0x10, 0x30, 0x80, 0x0a, 0x12, 0x83, 0x18, 0x8c, \n\t0x84, 0x59, 0x01, 0x00, 0x25, 0x2a, 0x01, 0x0c, 0x4c, 0x01, 0x18, 0x00, 0x00, 0x87, 0x98, 0x0d, \n\t0x03, 0x58, 0x00, 0xc2, 0x30, 0xcd, 0x51, 0x26, 0x40, 0x20, 0x23, 0x04, 0x60, 0x80, 0x09, 0x34, \n\t0xd7, 0x92, 0xa8, 0x01, 0x89, 0x04, 0x20, 0x31, 0x10, 0x2f, 0x21, 0x01, 0x60, 0x52, 0x40, 0x41, \n\t0x90, 0x69, 0x96, 0x06, 0x22, 0x00, 0xc3, 0x02, 0xe5, 0x50, 0x4a, 0x40, 0xe1, 0x30, 0xb0, 0x00, \n\t0x54, 0x2a, 0x40, 0xe1, 0xd0, 0xa1, 0x35, 0x04, 0x05, 0x08, 0x04, 0x20, 0x8e, 0x00, 0x0d, 0x8b, \n\t0x50, 0x92, 0xa0, 0x14, 0x00, 0x18, 0x2d, 0x40, 0xb6, 0x80, 0x02, 0x80, 0x00, 0x47, 0x20, 0x24, \n\t0x50, 0x04, 0x8c, 0x02, 0x26, 0x10, 0x42, 0x12, 0x2b, 0xc5, 0x88, 0xa2, 0x50, 0x30, 0x43, 0x80, \n\t0x88, 0x11, 0xa8, 0x00, 0x14, 0x0a, 0x94, 0x48, 0x82, 0x80, 0x32, 0x87, 0x80, 0x09, 0x21, 0xcc, \n\t0x88, 0x58, 0x00, 0x5b, 0x92, 0x11, 0x88, 0x09, 0x46, 0x04, 0x21, 0x24, 0x01, 0x51, 0x44, 0x10, \n\t0x44, 0x03, 0x80, 0x00, 0x0b, 0x48, 0x1e, 0x61, 0x11, 0x08, 0x84, 0x06, 0x85, 0x02, 0x11, 0x88, \n\t0x01, 0x04, 0x45, 0x01, 0x2a, 0x81, 0x1a, 0x07, 0x08, 0x02, 0x0a, 0x2c, 0x12, 0xc1, 0x24, 0xf8, \n\t0x12, 0x62, 0x00, 0x32, 0x21, 0x08, 0x25, 0x94, 0x82, 0x00, 0x81, 0x60, 0x24, 0x14, 0xc2, 0x42, \n\t0x0a, 0x00, 0x30, 0x9e, 0x01, 0xd4, 0x00, 0x3c, 0x01, 0x30, 0x0d, 0x4c, 0x90, 0x0a, 0x48, 0x54, \n\t0x08, 0x17, 0xf0, 0x18, 0x88, 0x04, 0xc0, 0x91, 0x0e, 0x05, 0x04, 0x00, 0x54, 0x80, 0x02, 0x98, \n\t0x31, 0x80, 0x46, 0x2a, 0x44, 0x60, 0x85, 0x30, 0x1b, 0x4e, 0x00, 0x14, 0x08, 0x2a, 0x18, 0x10, \n\t0x00, 0x14, 0x64, 0x41, 0x01, 0x19, 0xda, 0x81, 0x00, 0x10, 0x48, 0x01, 0x20, 0x02, 0x42, 0x00, \n\t0xa0, 0x48, 0xa0, 0x80, 0x04, 0xc4, 0x04, 0xc1, 0x20, 0x0d, 0xd0, 0x00, 0x8f, 0x04, 0xb3, 0x28, \n\t0x24, 0x09, 0x05, 0x43, 0x20, 0x10, 0x23, 0x01, 0xe8, 0x0c, 0x00, 0x20, 0x20, 0x5a, 0x90, 0x05, \n\t0x8c, 0x00, 0x2c, 0x05, 0x61, 0x00, 0x0d, 0x04, 0x23, 0x10, 0xe2, 0x10, 0x11, 0xe1, 0x0b, 0x00, \n\t0x0c, 0x61, 0x48, 0x08, 0x80, 0x81, 0xc0, 0x6a, 0x37, 0x09, 0x88, 0x20, 0x94, 0x61, 0x7c, 0x10, \n\t0x20, 0x12, 0xf0, 0x0a, 0xa0, 0x00, 0x12, 0xa2, 0x28, 0x54, 0x06, 0x0d, 0x5a, 0x80, 0x00, 0x00, \n\t0xc8, 0x00, 0xa9, 0x48, 0xb0, 0x12, 0xb8, 0x00, 0xc8, 0xc4, 0x2a, 0x00, 0x20, 0xbf, 0x00, 0x08, \n\t0x84, 0x50, 0x12, 0x20, 0x26, 0x60, 0x82, 0x28, 0x24, 0x04, 0xf8, 0x02, 0x15, 0x8b, 0x00, 0x30, \n\t0xe1, 0x10, 0x80, 0x35, 0x41, 0x24, 0x22, 0x24, 0xc0, 0x80, 0x45, 0xc8, 0x80, 0x00, 0x10, 0x38, \n\t0x1c, 0x80, 0x54, 0x01, 0x3a, 0x12, 0x29, 0x10, 0x08, 0xc8, 0x60, 0x40, 0x20, 0x00, 0x07, 0xd1, \n\t0x09, 0x09, 0x78, 0xb6, 0xca, 0x35, 0x38, 0x01, 0x0c, 0x58, 0xc0, 0x20, 0x00, 0x38, 0x10, 0x2e, \n\t0x10, 0x86, 0x31, 0x02, 0xc4, 0x5a, 0x8e, 0x46, 0xe0, 0x92, 0x2a, 0x1c, 0x54, 0x25, 0x00, 0x52, \n\t0x42, 0x8d, 0x41, 0x45, 0x82, 0x20, 0x01, 0x11, 0x02, 0x58, 0x12, 0xc0, 0x00, 0x41, 0x00, 0x18, \n\t0x95, 0x15, 0x2a, 0x50, 0x24, 0xc2, 0x1a, 0x88, 0x0f, 0x00, 0x1a, 0xe0, 0x11, 0x30, 0x34, 0xc0, \n\t0x05, 0x60, 0x41, 0x20, 0x19, 0x00, 0x0a, 0x41, 0x48, 0x07, 0x99, 0x09, 0x88, 0x45, 0x2d, 0x22, \n\t0x82, 0x02, 0x04, 0x35, 0x00, 0x20, 0x04, 0x83, 0xc8, 0x82, 0xb5, 0x04, 0x8d, 0x28, 0x83, 0x43, \n\t0x83, 0x09, 0x08, 0x28, 0x20, 0xa3, 0x00, 0x11, 0x40, 0x0c, 0x80, 0x3a, 0xc0, 0xc3, 0x2a, 0x28, \n\t0x4b, 0x00, 0x4a, 0x40, 0x80, 0x33, 0x81, 0xd4, 0x20, 0x10, 0x84, 0x58, 0x04, 0x18, 0x58, 0xc0, \n\t0x00, 0xe5, 0x42, 0x2a, 0x70, 0x01, 0x08, 0x22, 0x30, 0x19, 0x11, 0xb5, 0x07, 0x8a, 0x10, 0x44, \n\t0x22, 0x90, 0x80, 0xc7, 0x48, 0x42, 0x91, 0x08, 0x11, 0x40, 0x8d, 0x22, 0x02, 0x04, 0xa0, 0x38, \n\t0x05, 0x40, 0x03, 0x08, 0x10, 0xc8, 0x28, 0x8c, 0x04, 0x00, 0x60, 0xa0, 0x02, 0x94, 0x55, 0x11, \n\t0x41, 0x6a, 0x52, 0xb8, 0xa4, 0x24, 0x08, 0xa5, 0x14, 0x12, 0x08, 0x38, 0xc1, 0x11, 0x00, 0x02, \n\t0x01, 0x41, 0x02, 0xc0, 0x49, 0x6a, 0x02, 0x05, 0x8b, 0x80, 0x04, 0x00, 0xa1, 0x00, 0x01, 0x81, \n\t0x80, 0x81, 0x82, 0x8b, 0x0c, 0x14, 0x30, 0x25, 0x44, 0x87, 0x00, 0x42, 0x10, 0x02, 0x18, 0xa8, \n\t0x84, 0x4c, 0x14, 0x60, 0x99, 0x18, 0x88, 0x14, 0x85, 0x60, 0x16, 0x41, 0x20, 0x1d, 0x96, 0x08, \n\t0x42, 0x30, 0x59, 0x24, 0x65, 0x08, 0x26, 0x60, 0x83, 0x22, 0x8c, 0x11, 0x52, 0x08, 0x00, 0x63, \n\t0xa0, 0x88, 0x01, 0x01, 0xa4, 0x06, 0x82, 0x90, 0x83, 0x60, 0x01, 0x04, 0x26, 0x44, 0x62, 0x24, \n\t0x90, 0x01, 0xc0, 0x38, 0x01, 0x01, 0x9c, 0x10, 0x18, 0x4d, 0x16, 0xd1, 0x40, 0xa0, 0xc0, 0x00, \n\t0x06, 0x36, 0xc0, 0x41, 0x1a, 0x94, 0x04, 0xc4, 0x22, 0xe6, 0x00, 0x90, 0x00, 0x46, 0x2d, 0x06, \n\t0x41, 0x02, 0x00, 0x39, 0x93, 0x23, 0x4a, 0x00, 0x01, 0x04, 0x4c, 0x93, 0x44, 0x00, 0x22, 0x49, \n\t0x08, 0x48, 0x12, 0x22, 0x04, 0x02, 0xf2, 0x98, 0x90, 0x53, 0x28, 0x62, 0x34, 0x32, 0xb4, 0x4c, \n\t0xc2, 0x04, 0x6c, 0x14, 0x12, 0x10, 0xc9, 0x85, 0x80, 0x18, 0x35, 0xa1, 0x04, 0x68, 0x45, 0x81, \n\t0x2c, 0x04, 0x80, 0x0c, 0xc8, 0x48, 0xc0, 0x42, 0x00, 0x09, 0x0b, 0x60, 0xc6, 0x24, 0x26, 0x91, \n\t0x11, 0x24, 0xc1, 0x1d, 0x0c, 0x30, 0x34, 0x60, 0x03, 0xa8, 0x5a, 0x08, 0x38, 0x46, 0x60, 0x09, \n\t0x40, 0x10, 0x86, 0x4c, 0x22, 0x61, 0x04, 0x01, 0x00, 0x2a, 0x58, 0x82, 0x90, 0x01, 0x0c, 0x12, \n\t0x0d, 0x0c, 0x73, 0x21, 0x20, 0x84, 0x12, 0x08, 0x40, 0xf0, 0x00, 0x0d, 0x50, 0x92, 0x85, 0x20, \n\t0x10, 0xc0, 0x12, 0x01, 0x03, 0x04, 0x22, 0x05, 0x10, 0x30, 0x34, 0x49, 0x42, 0x00, 0x87, 0x00, \n\t0x02, 0xc0, 0x40, 0x49, 0x20, 0x42, 0x9a, 0xb3, 0x40, 0x80, 0xe4, 0x08, 0x22, 0x20, 0x18, 0x35, \n\t0x8b, 0x88, 0x52, 0x34, 0x0b, 0x25, 0x00, 0x1c, 0x00, 0x0e, 0x32, 0x09, 0x88, 0x91, 0xdc, 0x06, \n\t0x18, 0xb0, 0xab, 0x14, 0x60, 0xc4, 0x00, 0x08, 0x03, 0x2b, 0x02, 0x70, 0x16, 0x48, 0x08, 0xe2, \n\t0x00, 0x2b, 0x08, 0x98, 0x0c, 0x0c, 0x84, 0xa0, 0x28, 0x05, 0x05, 0x64, 0x00, 0x50, 0x19, 0x92, \n\t0x88, 0x03, 0x0c, 0x12, 0x61, 0x28, 0x00, 0xcc, 0x12, 0x02, 0x52, 0x04, 0x41, 0x24, 0x3c, 0x00, \n\t0x21, 0x40, 0x81, 0x1a, 0x2b, 0x09, 0xc2, 0x05, 0x14, 0x71, 0x20, 0xa0, 0x14, 0x00, 0x82, 0x50, \n\t0x60, 0x40, 0xa0, 0x08, 0x03, 0x04, 0x0c, 0x92, 0x10, 0x02, 0x30, 0x42, 0x29, 0x68, 0x22, 0x20, \n\t0x08, 0xf4, 0x00, 0x0e, 0x12, 0x00, 0x50, 0x21, 0x10, 0x8c, 0x21, 0x00, 0x45, 0x60, 0x10, 0x01, \n\t0xc9, 0x84, 0x04, 0x11, 0x18, 0x00, 0x01, 0x17, 0x67, 0x3e, 0x41, 0x80, 0x83, 0xc1, 0xca, 0x80, \n\t0x1a, 0x40, 0xba, 0x80, 0x48, 0x82, 0xca, 0x04, 0x05, 0x81, 0x80, 0x34, 0x18, 0xc0, 0x42, 0xc2, \n\t0x40, 0x30, 0x84, 0x4c, 0x09, 0x12, 0x11, 0x08, 0x26, 0x14, 0x0c, 0xc8, 0x02, 0x60, 0x23, 0xa7, \n\t0x00, 0x49, 0x41, 0x5a, 0xe4, 0x40, 0x88, 0x10, 0x05, 0xa0, 0x6c, 0x02, 0x00, 0x00, 0x01, 0x84, \n\t0x02, 0x12, 0x10, 0x22, 0x01, 0xc8, 0x90, 0x81, 0x20, 0x02, 0x10, 0x82, 0x05, 0x12, 0xa3, 0x28, \n\t0x82, 0x80, 0x04, 0x28, 0x14, 0x40, 0x42, 0x51, 0xa1, 0x84, 0x09, 0x80, 0x82, 0x2e, 0x04, 0x01, \n\t0x32, 0xb4, 0x01, 0x08, 0x0c, 0x06, 0x01, 0xba, 0x05, 0x50, 0x80, 0x54, 0x22, 0x1b, 0x01, 0x38, \n\t0x41, 0xa2, 0x04, 0x41, 0x39, 0x25, 0x00, 0x18, 0x83, 0x70, 0x51, 0x09, 0x1a, 0x80, 0x92, 0x41, \n\t0x42, 0x40, 0x5b, 0x04, 0x20, 0x90, 0x0b, 0x00, 0x30, 0x28, 0x34, 0x61, 0x00, 0x01, 0x1e, 0x72, \n\t0x42, 0x06, 0x19, 0x1c, 0x01, 0x0c, 0x04, 0x71, 0x09, 0x49, 0x00, 0x08, 0x60, 0x00, 0x80, 0x9c, \n\t0x48, 0x49, 0x00, 0x5a, 0x00, 0xa1, 0x2a, 0xa1, 0x1c, 0x06, 0x28, 0x24, 0x50, 0x01, 0x00, 0xc0, \n\t0x08, 0x68, 0x65, 0xa8, 0x22, 0x68, 0x14, 0x20, 0x32, 0x42, 0x03, 0x82, 0x3d, 0x01, 0xc1, 0x0e, \n\t0x82, 0x11, 0x02, 0x20, 0x80, 0x01, 0x02, 0xd4, 0xe9, 0x80, 0x0c, 0x01, 0x29, 0x04, 0x50, 0x12, \n\t0x92, 0x40, 0x81, 0x83, 0x10, 0x20, 0x01, 0x09, 0x80, 0xc3, 0xe6, 0x42, 0x53, 0x13, 0x06, 0x15, \n\t0x80, 0x41, 0x58, 0x14, 0x00, 0x82, 0x1c, 0x88, 0x06, 0x00, 0x02, 0x2a, 0x06, 0x5c, 0x91, 0x00, \n\t0x58, 0x02, 0x8a, 0x90, 0x24, 0x04, 0x06, 0x28, 0x40, 0x30, 0x15, 0x24, 0x81, 0x60, 0x42, 0x46, \n\t0xd9, 0xa0, 0x11, 0x04, 0x46, 0x24, 0x92, 0xc0, 0x28, 0x21, 0x8c, 0x22, 0x00, 0x16, 0x08, 0x11, \n\t0xe1, 0x1d, 0x08, 0x0a, 0x01, 0x09, 0x3b, 0x90, 0x53, 0x20, 0x12, 0x03, 0xc0, 0x84, 0x00, 0x94, \n\t0x02, 0x14, 0xb2, 0x48, 0x38, 0x39, 0x42, 0x21, 0x40, 0xb2, 0xa2, 0x22, 0xc4, 0x90, 0x03, 0x40, \n\t0x70, 0x61, 0x2c, 0xc8, 0x48, 0xe3, 0x06, 0x42, 0x00, 0xac, 0x11, 0x04, 0xc0, 0x08, 0x40, 0x41, \n\t0x01, 0x08, 0x4a, 0x84, 0x48, 0x21, 0xd0, 0x02, 0x81, 0x00, 0x42, 0x20, 0x00, 0xd8, 0x04, 0x84, \n\t0x00, 0x8c, 0x04, 0x64, 0x13, 0x09, 0x35, 0x88, 0x21, 0x12, 0x80, 0x38, 0x0b, 0x24, 0xc2, 0x41, \n\t0x12, 0x80, 0x82, 0x28, 0x28, 0x05, 0x24, 0x74, 0x11, 0xc0, 0x05, 0x09, 0x51, 0x60, 0x28, 0x80, \n\t0xa2, 0x11, 0x24, 0x10, 0x89, 0x00, 0x21, 0x20, 0x85, 0x60, 0x00, 0x0c, 0x00, 0xa4, 0x81, 0x88, \n\t0x1c, 0x0b, 0x06, 0x64, 0x04, 0x32, 0x10, 0x08, 0x86, 0x01, 0x28, 0x43, 0x11, 0x20, 0x68, 0x51, \n\t0x0a, 0x36, 0x60, 0x82, 0xa6, 0x24, 0x87, 0x49, 0x4a, 0x00, 0x00, 0x10, 0xa9, 0x01, 0x81, 0x20, \n\t0x76, 0xca, 0xa1, 0xd5, 0x02, 0x00, 0x28, 0x52, 0x29, 0x22, 0xe0, 0x00, 0x0b, 0x08, 0x90, 0x08, \n\t0x14, 0xb0, 0x00, 0x05, 0x74, 0x50, 0x40, 0x8b, 0x20, 0x56, 0xea, 0x04, 0x30, 0x02, 0x15, 0xd1, \n\t0x00, 0x09, 0x40, 0x42, 0x02, 0x83, 0x30, 0x0a, 0xc8, 0x04, 0x15, 0x22, 0x98, 0x49, 0x09, 0x48, \n\t0x4a, 0x05, 0x02, 0x14, 0x00, 0xce, 0x24, 0x46, 0xc7, 0x23, 0x0d, 0x04, 0x10, 0x8c, 0x44, 0x60, \n\t0x80, 0x84, 0x38, 0x81, 0x02, 0x70, 0x41, 0x90, 0x26, 0x01, 0x40, 0xa1, 0x04, 0xc4, 0x48, 0x20, \n\t0x20, 0x43, 0x02, 0x10, 0xa4, 0x40, 0x1e, 0x44, 0x0a, 0x43, 0x08, 0x05, 0x62, 0x20, 0x18, 0x11, \n\t0x20, 0x70, 0x43, 0x8b, 0x18, 0x60, 0x04, 0x02, 0x16, 0x14, 0x91, 0x09, 0x10, 0x11, 0x20, 0x14, \n\t0x10, 0xe0, 0x08, 0x00, 0x88, 0x09, 0x1c, 0x85, 0x50, 0x2a, 0x08, 0x51, 0x42, 0x22, 0x71, 0x0a, \n\t0x00, 0x41, 0xcc, 0x80, 0x36, 0x04, 0xba, 0x31, 0x28, 0x0c, 0x02, 0x1a, 0x21, 0x01, 0xa0, 0x65, \n\t0x08, 0x01, 0x1a, 0xa4, 0x0b, 0x84, 0x40, 0x1c, 0x43, 0x26, 0x54, 0x8a, 0x08, 0x94, 0x08, 0x0c, \n\t0x04, 0x30, 0x10, 0x0a, 0x80, 0x52, 0x40, 0x40, 0xb0, 0xc3, 0x96, 0x00, 0x19, 0x05, 0x40, 0xa4, \n\t0x51, 0x0e, 0x09, 0xc5, 0x82, 0x28, 0x12, 0x40, 0x05, 0x08, 0x00, 0xc3, 0x10, 0x31, 0x38, 0x25, \n\t0x20, 0x02, 0xa8, 0x40, 0x76, 0x92, 0x01, 0x58, 0x41, 0xc5, 0x00, 0x03, 0x38, 0x04, 0x04, 0x02, \n\t0xa1, 0x44, 0x81, 0x91, 0x33, 0x80, 0x08, 0x20, 0x08, 0x41, 0x01, 0x33, 0x9d, 0x00, 0x40, 0x2a, \n\t0xc4, 0x51, 0x22, 0xf5, 0x0d, 0x4f, 0x00, 0x23, 0x90, 0x2a, 0xb0, 0x4a, 0xa2, 0x04, 0xd0, 0x48, \n\t0x00, 0x04, 0x54, 0xc8, 0x22, 0x92, 0x09, 0x29, 0x90, 0x85, 0x48, 0x0e, 0x00, 0xb0, 0x03, 0x88, \n\t0x4c, 0x84, 0x32, 0x80, 0x0b, 0x14, 0x10, 0x03, 0xc6, 0x50, 0x40, 0x03, 0x21, 0x08, 0x86, 0xe4, \n\t0x08, 0x04, 0x42, 0x32, 0x05, 0x00, 0x6a, 0x0c, 0x34, 0x10, 0xaa, 0x20, 0xc0, 0x64, 0x06, 0x90, \n\t0x12, 0x97, 0x28, 0xc2, 0x28, 0x42, 0x05, 0x88, 0x20, 0x21, 0xc6, 0x80, 0x10, 0x82, 0x81, 0x94, \n\t0x00, 0x1c, 0x01, 0x24, 0x24, 0x49, 0x80, 0x4c, 0x41, 0x46, 0x00, 0x83, 0x68, 0x80, 0x00, 0x48, \n\t0x08, 0x12, 0xc1, 0x61, 0x08, 0x38 \n};\n\n\nstatic bool isprime_slow(int64_t x)\n{\n\tfor (int i = 3; i < 10; ++i) {\n\t\tif (x % gLowPrimes[i] == 0)\n\t\t\treturn false;\n\t}\n\t\n\tfor (int i = 0; i < kPrimesMaskSize; ++i) {\n\t\tif (gPrimesMask[i] == 0) continue;\n\t\tint64_t k = 30 * (i+1);\n\t\tfor (int j = 0; j < 8; ++j) {\n\t\t\tif (!(gPrimesMask[k] & (1 << j))) continue;\n\t\t\tint64_t m = k + gPrimeOffsets[j];\n\t\t\tif (m*m > x) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tif (x % m == 0) return false;\n\t\t}\n\t}\n\t\n\tthrow errOutOfRange;\n}\n\n#include \n\nbool isprime(int64_t x)\n{\n\tif (x <= 30) {\n\t\tif (x < 2) return false; // negatives aren't prime\n\t\treturn gLowPrimesMask & (1 << x);\n\t}\n\t\n\tint bit = x % 30;\n\tint shift = gPrimesShift[bit];\n\tif (shift < 0) return false; // eliminate multiples of 2,3,5.\n\tint64_t byte = x / 30 - 1;\n\t\t\n\tif (byte >= kPrimesMaskSize) return isprime_slow(x);\t\n\t\n\treturn gPrimesMask[byte] & (1 << shift);\n}\n\n\nint64_t nextPrime(int64_t x)\n{\n\tfor (;; ++x) {\n\t\tif (isprime(x)) return x;\n\t}\n}\n\n\n\n\n\n\n"], ["/sapf/src/elapsedTime.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nextern \"C\" {\n\nstatic double gHostClockFreq;\n\nvoid initElapsedTime()\n{\n\tstruct mach_timebase_info info;\n\tmach_timebase_info(&info);\n\tgHostClockFreq = 1e9 * ((double)info.numer / (double)info.denom);\n}\n\ndouble elapsedTime()\n{\n\treturn (double)mach_absolute_time() / gHostClockFreq;\n}\n\n}\n"], ["/sapf/libmanta/MantaMulti.h", "class MantaMulti {\n public:\n MantaMulti(MantaClient *client = NULL) {\n AttachClient(client);\n}\n void AttachClient(MantaClient *client) {\n if(NULL != client)\n {\n ClientList.push_back(client);\n ++ReferenceCount;\n }\n}\n void DetachClient(MantaClient *client) {\n list::iterator foundIter;\n foundIter = find(ClientList.begin(), ClientList.end(), client);\n if(ClientList.end() != foundIter)\n {\n ClientList.erase(foundIter);\n --ReferenceCount;\n }\n}\n int GetReferenceCount() {\n return ReferenceCount;\n}\n protected:\n void PadEvent(int row, int column, int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadEvent(row, column, id, value);\n }\n}\n void SliderEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->SliderEvent(id, value);\n }\n}\n void ButtonEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonEvent(id, value);\n }\n}\n void PadVelocityEvent(int row, int column, int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadVelocityEvent(row, column, id, velocity);\n }\n}\n void ButtonVelocityEvent(int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonVelocityEvent(id, velocity);\n }\n}\n void FrameEvent(uint8_t *frame) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->FrameEvent(frame);\n }\n}\n private:\n list ClientList;\n int ReferenceCount;\n};"], ["/sapf/libmanta/MantaServer.h", "#ifndef _MANTASERVER_H\n#define _MANTASERVER_H\n\n/************************************************************************//**\n * \\class MantaServer\n * \\brief Interface defining all the Messages that can be sent to a Manta\n *\n * The MantaServer virtual class defines all the Messages that the Manta\n * understands, as well as the data structures used as arguments. If you\n * need a pointer to a Manta in your code, you can make it more general by\n * using a MantaServer pointer instead of a pointer to your specific subclass.\n ****************************************************************************/\nclass MantaServer\n{\n public:\n\n enum LEDState {\n Off,\n Amber,\n Red,\n All, // only used in SetPadLEDFrame\n };\n enum LEDControlType {\n PadAndButton,\n Slider,\n Button\n };\n typedef uint8_t LEDFrame[6];\n\n virtual ~MantaServer() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void SetPadLED(LEDState state, int ledID) = 0;\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) = 0;\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) = 0;\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) = 0;\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) = 0;\n virtual void SetButtonLED(LEDState state, int id) = 0;\n virtual void ResendLEDState(void) = 0;\n virtual void ClearPadAndButtonLEDs(void) = 0;\n virtual void ClearButtonLEDs(void) = 0;\n virtual void Recalibrate(void) = 0;\n virtual void SetLEDControl(LEDControlType control, bool state) = 0;\n virtual void SetTurboMode(bool Enabled) = 0;\n virtual void SetRawMode(bool Enabled) = 0;\n virtual void SetMaxSensorValues(int *values) = 0;\n};\n#endif /* _MANTASERVER_H */\n"], ["/sapf/libmanta/MantaExceptions.h", "#ifndef _MANTAEXCEPTIONS_H\n#define _MANTAEXCEPTIONS_H\n\n#include \n\nclass LibusbInitException : public std::runtime_error\n{\n public:\n LibusbInitException() :\n runtime_error(\"Error initializing libusb\")\n {\n }\n};\n\nclass MantaNotConnectedException : public std::runtime_error\n{\n public:\n MantaNotConnectedException(MantaUSB *manta) :\n runtime_error(\"Attempted to access the Manta without connecting\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\nclass MantaNotFoundException : public std::runtime_error\n{\n public:\n MantaNotFoundException() :\n runtime_error(\"Could not find an attached Manta\")\n {\n }\n};\n\nclass MantaOpenException : public std::runtime_error\n{\n public:\n MantaOpenException() :\n runtime_error(\"Could not connect to attached Manta\")\n {\n }\n};\n\nclass MantaCommunicationException : public std::runtime_error\n{\n public:\n MantaCommunicationException(MantaUSB *manta = NULL) :\n runtime_error(\"Communication with Manta interrupted\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\n#endif // _MANTAEXCEPTIONS_H\n"], ["/sapf/src/Types.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Types.hpp\"\n"], ["/sapf/libmanta/MantaClient.h", "#ifndef _MANTACLIENT_H\n#define _MANTACLIENT_H\n\n#include \n\n/************************************************************************//**\n * \\class MantaClient\n * \\brief Interface defining all the Events generated by the Manta\n *\n * The MantaClient virtual class defines all the Events that could be\n * generated by the Manta. Your object should provide implementations\n * to any of these events that you'd like to listen for\n ****************************************************************************/\nclass MantaClient\n{\n public:\n virtual ~MantaClient() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void PadEvent(int row, int column, int id, int value) {}\n virtual void SliderEvent(int id, int value) {}\n virtual void ButtonEvent(int id, int value) {}\n virtual void PadVelocityEvent(int row, int column, int id, int velocity) {}\n virtual void ButtonVelocityEvent(int id, int velocity) {}\n virtual void FrameEvent(uint8_t *frame) {}\n virtual void DebugPrint(const char *fmt, ...) {}\n};\n#endif /* _MANTACLIENT_H */\n"], ["/sapf/libmanta/MantaVersion.h", "#ifndef _MANTAVERSION_H\n#define _MANTAVERSION_H\n\n#define LIBMANTA_MAJOR_VERSION 1\n#define LIBMANTA_MINOR_VERSION 3\n\n#endif // _MANTAVERSION_H\n"]], "task_instance_info": {"created_time": "2025-08-20 20:04:52", "created_task_model": "DeepSeek-R1", "function_skeleton": "static OSStatus createGraph(AUPlayer* player) {}", "code_description": "This code segment functions to: Configure and initialize a system audio output component by specifying its data format, attaching a real-time rendering callback handler, and activating the processing chain for audio signal transmission."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nstatic OSStatus createGraph(AUPlayer* player) {\n AudioComponentInstance outputUnit = openAU(kAudioUnitType_Output, kAudioUnitSubType_DefaultOutput, kAudioUnitManufacturer_Apple);\n if (!outputUnit) return -1;\n \n OSStatus err;\n AudioStreamBasicDescription streamFormat = {\n .mSampleRate = 44100,\n .mFormatID = kAudioFormatLinearPCM,\n .mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved,\n .mFramesPerPacket = 1,\n .mChannelsPerFrame = (UInt32)player->numChannels,\n .mBitsPerChannel = 32,\n .mBytesPerPacket = sizeof(float),\n .mBytesPerFrame = sizeof(float)\n };\n \n err = AudioUnitSetProperty(outputUnit,\n kAudioUnitProperty_StreamFormat,\n kAudioUnitScope_Input,\n 0,\n &streamFormat,\n sizeof(streamFormat));\n if (err) goto error;\n \n AURenderCallbackStruct callback = { inputCallback, player };\n err = AudioUnitSetProperty(outputUnit,\n kAudioUnitProperty_SetRenderCallback,\n kAudioUnitScope_Input,\n 0,\n &callback,\n sizeof(callback));\n if (err) goto error;\n \n err = AudioUnitInitialize(outputUnit);\n if (err) goto error;\n \n err = AudioOutputUnitStart(outputUnit);\n if (err) {\n AudioUnitUninitialize(outputUnit);\n goto error;\n }\n \n player->outputUnit = outputUnit;\n return noErr;\n\nerror:\n AudioComponentInstanceDispose(outputUnit);\n return err;\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 20-05-45"}, "editdistance_info": {"edit_distance": 21.5686, "calculate_time": "2025-08-20 20:05:45", "true_code_clean": "static OSStatus createGraph(AUPlayer* player)\n{\n OSStatus err = noErr;\n\tAudioComponentInstance outputUnit = openAU('auou', 'def ', 'appl');\n\tif (!outputUnit) {\n\t\tpost(\"open output unit failed\\n\");\n\t\treturn 'fail';\n\t}\n\tplayer->outputUnit = outputUnit;\n\tUInt32 flags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;\n\tAudioStreamBasicDescription fmt = { vm.ar.sampleRate, kAudioFormatLinearPCM, flags, 4, 1, 4, (UInt32)player->numChannels, 32, 0 };\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &fmt, sizeof(fmt));\n\tif (err) {\n\t\tpost(\"set outputUnit client format failed\\n\");\n\t\treturn err;\n\t}\n\tAURenderCallbackStruct cbs;\n\tcbs.inputProc = inputCallback;\n\tcbs.inputProcRefCon = player;\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &cbs, sizeof(cbs));\n\tif (err) {\n\t\tpost(\"set render callback failed\\n\");\n\t\treturn err;\n\t}\n\terr = AudioUnitInitialize(outputUnit);\n\tif (err) {\n\t\tpost(\"initialize output unit failed\\n\");\n\t\treturn err;\n\t}\n\terr = AudioOutputUnitStart(outputUnit);\n\tif (err) {\n\t\tpost(\"start output unit failed\\n\");\n\t\treturn err;\n\t}\n\tpost(\"start output unit OK\\n\");\n\treturn noErr;\n}", "predict_code_clean": "static OSStatus createGraph(AUPlayer* player) {\n AudioComponentInstance outputUnit = openAU(kAudioUnitType_Output, kAudioUnitSubType_DefaultOutput, kAudioUnitManufacturer_Apple);\n if (!outputUnit) return -1;\n OSStatus err;\n AudioStreamBasicDescription streamFormat = {\n .mSampleRate = 44100,\n .mFormatID = kAudioFormatLinearPCM,\n .mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved,\n .mFramesPerPacket = 1,\n .mChannelsPerFrame = (UInt32)player->numChannels,\n .mBitsPerChannel = 32,\n .mBytesPerPacket = sizeof(float),\n .mBytesPerFrame = sizeof(float)\n };\n err = AudioUnitSetProperty(outputUnit,\n kAudioUnitProperty_StreamFormat,\n kAudioUnitScope_Input,\n 0,\n &streamFormat,\n sizeof(streamFormat));\n if (err) goto error;\n AURenderCallbackStruct callback = { inputCallback, player };\n err = AudioUnitSetProperty(outputUnit,\n kAudioUnitProperty_SetRenderCallback,\n kAudioUnitScope_Input,\n 0,\n &callback,\n sizeof(callback));\n if (err) goto error;\n err = AudioUnitInitialize(outputUnit);\n if (err) goto error;\n err = AudioOutputUnitStart(outputUnit);\n if (err) {\n AudioUnitUninitialize(outputUnit);\n goto error;\n }\n player->outputUnit = outputUnit;\n return noErr;\nerror:\n AudioComponentInstanceDispose(outputUnit);\n return err;\n}"}} {"repo_name": "sapf", "file_name": "/sapf/src/Spectrogram.cpp", "inference_info": {"prefix_code": "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Spectrogram.hpp\"\n#include \"makeImage.hpp\"\n#include \n#include \n#include \n#include \n\nstatic void makeColorTable(unsigned char* table);\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double i0(double x)\n{\n\tconst double epsilon = 1e-18;\n\tint n = 1;\n\tdouble S = 1., D = 1., T;\n\n\twhile (D > epsilon * S) {\n\t\tT = x / (2 * n++);\n\t\tD *= T * T;\n\t\tS += D;\n\t}\n\treturn S;\n}\n\nstatic void calcKaiserWindowD(size_t size, double* window, double stopBandAttenuation)\n{\n\tsize_t M = size - 1;\n\tsize_t N = M-1;\n#if VERBOSE\n\tprintf(\"FillKaiser %d %g\\n\", M, stopBandAttenuation);\n#endif\n\n\tdouble alpha = 0.;\n\tif (stopBandAttenuation <= -50.)\n\t\talpha = 0.1102 * (-stopBandAttenuation - 8.7);\n else if (stopBandAttenuation < -21.)\n\t\talpha = 0.5842 * pow(-stopBandAttenuation - 21., 0.4) + 0.07886 * (-stopBandAttenuation - 21.);\n\n\tdouble p = N / 2;\n\tdouble kk = 1.0 / i0(alpha);\n\n\tfor(unsigned int k = 0; k < M; k++ )\n\t{\n\t\tdouble x = (k-p) / p;\n\t\t\n\t\t// Kaiser window\n\t\twindow[k+1] *= kk * bessi0(alpha * sqrt(1.0 - x*x) );\n\t}\n\twindow[0] = 0.;\n\twindow[size-1] = 0.;\n#if VERBOSE\n\tprintf(\"done\\n\");\n#endif\n}\n\nconst int border = 8;\n\n", "suffix_code": "\n\n\nstatic void makeColorTable(unsigned char* table)\n{\n\t// white >> red >> yellow >> green >> cyan >> blue >> magenta >> pink >> black\n\t// 0 -20 -40 -60 -80 -100 -120 -140 -160\n\t// 255 224 192 160 128 96 64 32 0\n\t\n\tint colors[9][4] = {\n\t\t{ 0, 0, 64, 255},\t// dk blue\n\t\t{ 0, 0, 255, 255},\t// blue\n\t\t{255, 0, 0, 255},\t// red\n\t\t{255, 255, 0, 255},\t// yellow\n\t\t{255, 255, 255, 255}\t// white\n\t};\n\t\n\tfor (int j = 0; j < 4; ++j) {\n\t\tfor (int i = 0; i < 64; ++i) {\n\t\t\tfor (int k = 0; k < 4; ++k) {\n\t\t\t\tint x = (colors[j][k] * (64 - i) + colors[j+1][k] * i) / 64;\n\t\t\t\tif (x > 255) x = 255;\n\t\t\t\ttable[j*64*4 + i*4 + k + 4] = x;\n\t\t\t}\n\t\t}\n\t}\n\t\n\ttable[0] = 0;\n\ttable[1] = 0;\n\ttable[2] = 0;\n\ttable[3] = 255;\n}\n\n", "middle_code": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor)\n{\n\tint numRealFreqs = 1 << log2bins;\n\tint log2n = log2bins + 1;\n\tint n = 1 << log2n;\n\tint nOver2 = n / 2;\n\tdouble scale = 1./nOver2;\n\tint64_t paddedSize = size + n;\n\tdouble* paddedData = (double*)calloc(paddedSize, sizeof(double));\n\tmemcpy(paddedData + nOver2, data, size * sizeof(double));\n\tdouble* dBMags = (double*)calloc(numRealFreqs + 1, sizeof(double));\n\tdouble hopSize = size <= n ? 0 : (double)(size - n) / (double)(width - 1);\n\tdouble* window = (double*)calloc(n, sizeof(double));\n\tfor (int i = 0; i < n; ++i) window[i] = 1.;\n\tcalcKaiserWindowD(n, window, -180.);\n\tunsigned char table[1028];\n\tmakeColorTable(table);\n\tint heightOfAmplitudeView = 128;\n\tint heightOfFFT = numRealFreqs+1;\n\tint totalHeight = heightOfAmplitudeView+heightOfFFT+3*border;\n\tint topOfSpectrum = heightOfAmplitudeView + 2*border;\n\tint totalWidth = width+2*border;\n\tBitmap* b = createBitmap(totalWidth, totalHeight);\n\tfillRect(b, 0, 0, totalWidth, totalHeight, 160, 160, 160, 255);\n\tfillRect(b, border, border, width, heightOfAmplitudeView, 0, 0, 0, 255);\n\tFFTSetupD fftSetup = vDSP_create_fftsetupD(log2n, kFFTRadix2);\n\tdouble* windowedData = (double*)calloc(n, sizeof(double));\n\tdouble* interleavedData = (double*)calloc(n, sizeof(double));\n\tdouble* resultData = (double*)calloc(n, sizeof(double));\n\tDSPDoubleSplitComplex interleaved;\n\tinterleaved.realp = interleavedData;\n\tinterleaved.imagp = interleavedData + nOver2;\n\tDSPDoubleSplitComplex result;\n\tresult.realp = resultData;\n\tresult.imagp = resultData + nOver2;\n\tdouble maxmag = 0.;\n\tdouble hpos = nOver2;\n\tfor (int i = 0; i < width; ++i) {\n\t\tsize_t ihpos = (size_t)hpos;\n\t\tdouble peak = 1e-20;\n\t\tfor (int w = 0; w < n; ++w) {\n\t\t\tdouble x = paddedData[w+ihpos];\n\t\t\tx = fabs(x);\n\t\t\tif (x > peak) peak = x;\n\t\t}\n\t\tfor (int64_t w = 0; w < n; ++w) windowedData[w] = window[w] * paddedData[w+ihpos];\n\t\tvDSP_ctozD((DSPDoubleComplex*)windowedData, 2, &interleaved, 1, nOver2);\n\t\tvDSP_fft_zropD(fftSetup, &interleaved, 1, &result, 1, log2n, kFFTDirection_Forward);\n\t\tdBMags[0] = result.realp[0] * scale;\n\t\tdBMags[numRealFreqs] = result.imagp[0] * scale;\n\t\tif (dBMags[0] > maxmag) maxmag = dBMags[0];\n\t\tif (dBMags[numRealFreqs] > maxmag) maxmag = dBMags[numRealFreqs];\n\t\tfor (int64_t j = 1; j < numRealFreqs-1; ++j) {\n\t\t\tdouble x = result.realp[j] * scale;\n\t\t\tdouble y = result.imagp[j] * scale;\n\t\t\tdBMags[j] = sqrt(x*x + y*y);\n\t\t\tif (dBMags[j] > maxmag) maxmag = dBMags[j];\n\t\t}\n\t\tdouble invmag = 1.;\n\t\tdBMags[0] = 20.*log2(dBMags[0]*invmag);\n\t\tdBMags[numRealFreqs] = 20.*log10(dBMags[numRealFreqs]*invmag);\n\t\tfor (int64_t j = 0; j <= numRealFreqs-1; ++j) {\n\t\t\tdBMags[j] = 20.*log10(dBMags[j]*invmag);\n\t\t}\n\t\t{\n\t\t\tdouble peakdB = 20.*log10(peak);\n\t\t\tint peakColorIndex = 256. - peakdB * (256. / dBfloor);\n\t\t\tint peakIndex = heightOfAmplitudeView - peakdB * (heightOfAmplitudeView / dBfloor);\n\t\t\tif (peakIndex < 0) peakIndex = 0;\n\t\t\tif (peakIndex > heightOfAmplitudeView) peakIndex = heightOfAmplitudeView;\n\t\t\tif (peakColorIndex < 0) peakColorIndex = 0;\n\t\t\tif (peakColorIndex > 255) peakColorIndex = 255;\n\t\t\tunsigned char* t = table + 4*peakColorIndex;\n\t\t\tfillRect(b, i+border, border+128-peakIndex, 1, peakIndex, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\tfor (int j = 0; j < numRealFreqs; ++j) {\n\t\t\tint colorIndex = 256. - dBMags[j] * (256. / dBfloor); \n\t\t\tif (colorIndex < 0) colorIndex = 0;\n\t\t\tif (colorIndex > 255) colorIndex = 255;\n\t\t\tunsigned char* t = table + 4*colorIndex;\n\t\t\tsetPixel(b, i+border, numRealFreqs-j+topOfSpectrum, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\thpos += hopSize;\n\t}\n\tvDSP_destroy_fftsetupD(fftSetup);\n\twriteBitmap(b, path);\n\tfreeBitmap(b);\n\tfree(dBMags);\n\tfree(paddedData);\n\tfree(window);\n\tfree(windowedData);\n\tfree(interleavedData);\n\tfree(resultData);\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/sapf/src/StreamOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n#include \"dsp.hpp\"\n#include \"SoundFiles.hpp\"\n\nconst Z kOneThird = 1. / 3.;\n\n// list ops\n#pragma mark LIST OPS\n\nstatic void finite_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.pushBool(v.isFinite());\n}\n\nstatic void size_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (v.isList() && !v.isFinite()) \n\t\tth.push(INFINITY);\n\telse \n\t\tth.push(v.length(th));\n}\n\n\nstatic void rank_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tint rank = 0;\n\twhile (a.isVList()) {\n\t\t++rank;\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\t\n\tth.push(rank);\n}\n\nstatic void shape_(Thread& th, Prim* prim)\n{\n\tP shape = new Array(itemTypeZ, 4);\n\t\n\tV a = th.pop();\n\t\n\twhile (a.isVList()) {\n\t\tZ len;\n\t\tif (a.isFinite()) {\n\t\t\tlen = a.length(th);\n\t\t} else {\n\t\t\tlen = INFINITY;\n\t\t}\n\t\tshape->addz(len);\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\tth.push(new List(shape));\n}\n\nstatic void bub_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tP seq = new List(itemTypeV, 1);\n\tseq->add(a);\n\tth.push(seq);\n}\n\nstatic void nbub_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbub : n\");\n\tV a = th.pop();\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\n\t\tP seq = new List(itemTypeV, 1);\n\t\tseq->add(a);\n\t\ta = seq;\n\t}\n\tth.push(a);\n}\n\ntemplate \nstatic void tupleN_(Thread& th, Prim* prim)\n{\n\tP seq = new List(itemTypeV, N);\n\tP arr = seq->mArray;\n\tarr->setSize(N);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v = th.pop();\n\t\tarr->put(N-1-i, v);\n\t}\n\tth.push(seq);\n}\n\ntemplate \nstatic void untupleN_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"unN : s\");\n\t\n\tBothIn in(s);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v;\n\t\tif (in.one(th, v)) {\n\t\t\tpost(\"too few items in list for un%d\", N);\n\t\t\tthrow errFailed;\n\t\t}\n\t\tth.push(v);\n\t}\n}\n\nstatic void reverse_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"reverse : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"reverse\", \"\");\n\t\t\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t}\n\tth.push(s2);\n}\n\ntemplate \nvoid copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[i];\n}\n\ntemplate \nvoid reverse_copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[-i];\n}\n\nstatic List* makeMirror(P const& a, int64_t n, int64_t nr, int64_t roff)\n{\n\tint type = a->elemType;\n\tint64_t size = n + nr;\n\tList* s = new List(type, size);\n\tArray* b = s->mArray();\n\t\n\tb->setSize(size);\n\tif (type == itemTypeV) {\n\t\tV* p = b->v();\n\t\tV* q = a->v();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t} else {\n\t\tZ* p = b->z();\n\t\tZ* q = a->z();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t}\n\treturn s;\n}\n\nstatic void mirror(Thread& th, int w, P s)\n{\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"mirror\", \"\");\n\n\ts = s->pack(th);\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\tint64_t n2 = n-2;\n\t\n\tswitch (w) {\n\t\tcase 0 : {\n\t\t\tif (n < 3) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n2, n2));\n\t\t} break;\n\t\tcase 1 : {\n\t\t\tif (n < 2) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n1, n2));\n\t\t} break;\n\t\tcase 2 : {\n\t\t\tif (n == 0) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n, n1));\n\t\t} break;\n\t}\n}\n\nstatic void mirror0_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror0 : s\");\n\tmirror(th, 0, s);\n}\n\nstatic void mirror1_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror1 : s\");\n\tmirror(th, 1, s);\n}\n\nstatic void mirror2_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror2 : s\");\n\tmirror(th, 2, s);\n}\n\nstatic void rot_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"rot : r\");\n\tP s = th.popList(\"rot : s\");\n\t\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"rot\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->wrapAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->wrapAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void shift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"shift : r\");\n\tP s = th.popList(\"shift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"shift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->at(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->atz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void clipShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"clipShift : r\");\n\tP s = th.popList(\"clipShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->clipAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->clipAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void foldShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"foldShift : r\");\n\tP s = th.popList(\"foldShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->foldAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->foldAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void muss_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"muss : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"muss\", \"\");\n \n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int64_t i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t}\n\tth.push(s2);\n}\n\n\n\n\n\nV do_at(Thread& th, P const& a, Arg i);\nV do_wrapAt(Thread& th, P const& a, Arg i);\nV do_foldAt(Thread& th, P const& a, Arg i);\nV do_clipAt(Thread& th, P const& a, Arg i);\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\n\nclass AtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"AtGenVV\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_at(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->at(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->atz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tWrapAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_wrapAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass FoldAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tFoldAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_foldAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass ClipAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tClipAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_clipAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Z degkey(Z degree, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ fidegree = floor(degree + .5);\n\t//Z frac = degree - fidegree;\n\tint idegree = (int)fidegree;\n\tint modDegree = (int)sc_imod(idegree, degreesPerCycle);\n\t//return frac + scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n\treturn scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n}\n\n\nstatic Z keydeg(Z key, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ cycles, cyckey;\n\tsc_fdivmod(key, cycleWidth, cycles, cyckey);\n\t\n\tZ frac = scale->atz(0) + cycleWidth - cyckey;\n\tZ mindiff = std::abs(frac);\n\tint idegree = 0;\n\tfor (int i = 0; i < degreesPerCycle; ++i) {\n\t\tfrac = std::abs(cyckey - scale->atz(i));\n\t\tif (frac < mindiff) {\n\t\t\tmindiff = frac;\n\t\t\tidegree = i;\n\t\t}\n\t}\n\t\n\treturn idegree + cycles * degreesPerCycle;\n}\n\nclass DegKeyVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _degree;\npublic:\n\n\tDegKeyVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_degkey(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _key;\npublic:\n\n\tKeyDegVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_keydeg(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Gen* newAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new AtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new AtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new AtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newWrapAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new WrapAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new WrapAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new WrapAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newDegKeyGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new DegKeyVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new DegKeyVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new DegKeyZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newKeyDegGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new KeyDegVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new KeyDegVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new KeyDegZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newFoldAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new FoldAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new FoldAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new FoldAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newClipAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new ClipAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new ClipAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new ClipAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nV do_at(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->at(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newAtGen(th, a, b));\n\t} else wrongType(\"at : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_wrapAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->wrapAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newWrapAtGen(th, a, b));\n\t} else wrongType(\"wrapAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn degkey(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newDegKeyGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"degkey : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn keydeg(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newKeyDegGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"keydeg : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_foldAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->foldAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newFoldAtGen(th, a, b));\n\t} else wrongType(\"foldAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_clipAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->clipAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newClipAtGen(th, a, b));\n\t} else wrongType(\"clipAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nstatic void at_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"at : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"at\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_at(th, a, i);\n\tth.push(v);\n}\n\nstatic void wrapAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"wrapAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"wrapAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_wrapAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void degkey_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"degkey : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"degkey\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"degkey : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_degkey(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void keydeg_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"keydeg : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"keydeg\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"keydeg : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_keydeg(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void foldAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"foldAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_foldAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void clipAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"clipAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_clipAt(th, a, i);\n\tth.push(v);\n}\n\n\n#pragma mark CONVERSION\n\n\nstruct VGen : public Gen\n{\n\tZIn _a;\n\t\n\tVGen(Thread& th, Arg a) : Gen(th, itemTypeV, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct ZGen : public Gen\n{\n\tVIn _a;\n\t\n\tZGen(Thread& th, Arg a) : Gen(th, itemTypeZ, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->asFloat();\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic P stringToZList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeZ, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tz[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P stringToVList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeV, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tv[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P vlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"stream to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)v[i].asFloat());\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic P zlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"signal to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)z[i]);\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic void V_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isZList()) {\n\t\tGen* g = new VGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToVList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void Z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tGen* g = new ZGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToZList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void unspell_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(vlistToString(th, list));\n\t} else if (a.isZList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(zlistToString(th, list));\n\t} else if (a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\twrongType(\"unspell : list\", \"List or String\", a);\n\t}\n}\n\n\n\n#pragma mark NUMERIC SERIES\n\n\nstruct Ever : public Gen\n{\n\tV _val;\n\n\tEver(Thread& th, Arg val) : Gen(th, itemTypeV, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Ever\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV v = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = v;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Everz : public Gen\n{\n\tZ _val;\n\n\tEverz(Thread& th, Z val) : Gen(th, itemTypeZ, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Everz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ z = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = z;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_recip;\nextern UnaryOp* gUnaryOpPtr_cb;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstruct By : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tBy(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"By\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Byz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tByz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Byz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Grow : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tGrow(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Grow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Growz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tGrowz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Growz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart *= step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLine : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tCubicLine(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLine\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV cubed = _start.unaryOp(th, gUnaryOpPtr_cb);\t\n\t\t\tout[i] = cubed;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tCubicLinez(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start*start*start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Inv : public Gen\n{\n\tV _start;\n\n\tInv(Thread& th) : Gen(th, itemTypeV, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Inv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV vone = 1.;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\tout[i] = vout;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Invz : public Gen\n{\n\tZ _start;\n\n\tInvz(Thread& th) : Gen(th, itemTypeZ, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Invz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. / start;\n\t\t\tstart += 1.;\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NInv : public Gen\n{\n\tV _start;\n\tint64_t _n;\n\n\tNInv(Thread& th, int64_t n) : Gen(th, itemTypeV, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tV vone = 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\t\tout[i] = vout;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NInvz : public Gen\n{\n\tZ _start;\n\tint64_t _n;\n\n\tNInvz(Thread& th, int64_t n) : Gen(th, itemTypeZ, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInvz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = 1. / start;\n\t\t\t\tstart += 1.;\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NBy : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNBy(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NBy\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NByz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\t\n\tNByz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NByz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\n\nstruct NGrow : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNGrow(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NGrowz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNGrowz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrowz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart *= step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NCubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNCubicLinez(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NCubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start*start*start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct Fib : public Gen\n{\n\tV _a;\n\tV _b;\n \n\tFib(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fib\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV a = _a;\n out[i] = a;\n _a = _b;\n _b = a.binaryOp(th, gBinaryOpPtr_plus, _b);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Fibz : public Gen\n{\n\tZ _a;\n\tZ _b;\n \n\tFibz(Thread& th, Z a, Z b) : Gen(th, itemTypeZ, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fibz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n int n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ a = _a;\n\t\tZ b = _b;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = a;\n Z aa = a;\n a = b;\n b += aa;\n\t\t}\n\t\t_a = a;\n\t\t_b = b;\n\t\tmOut = mOut->nextp();\n }\n};\n\nstatic void L_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tth.push(new List(new Ever(th, th.pop())));\n\t}\n}\n\nstatic void L1_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tP list = new List(itemTypeV, 1);\n\t\tlist->add(th.pop());\n\t\tth.push(list);\n\t}\n}\n\nstatic void ever_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\t\n\tGen* g = new Ever(th, value);\n\tth.push(new List(g));\n}\n\nstatic void everz_(Thread& th, Prim* prim)\n{\n\tZ value = th.popFloat(\"everz : value\");\n\t\n\tGen* g = new Everz(th, value);\n\tth.push(new List(g));\n}\n\nstatic void by_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new By(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nby_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"nby : n\");\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void to_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"to : end\");\n\tZ start = th.popFloat(\"to : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void toz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"toz : end\");\n\tZ start = th.popFloat(\"toz : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv : end\");\n\tZ start = th.popFloat(\"lindiv : start\");\n\tint64_t n = th.popInt(\"lindiv : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindivz : end\");\n\tZ start = th.popFloat(\"lindivz : start\");\n\tint64_t n = th.popInt(\"lindivz : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv : end\");\n\tZ start = th.popFloat(\"expdiv : start\");\n\tint64_t n = th.popInt(\"expdiv : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdivz : end\");\n\tZ start = th.popFloat(\"expdivz : start\");\n\tint64_t n = th.popInt(\"expdivz : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1 : end\");\n\tZ start = th.popFloat(\"lindiv1 : start\");\n\tint64_t n = th.popInt(\"lindiv1 : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1z : end\");\n\tZ start = th.popFloat(\"lindiv1z : start\");\n\tint64_t n = th.popInt(\"lindiv1z : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1 : end\");\n\tZ start = th.popFloat(\"expdiv1 : start\");\n\tint64_t n = th.popInt(\"expdiv1 : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1z : end\");\n\tZ start = th.popFloat(\"expdiv1z : start\");\n\tint64_t n = th.popInt(\"expdiv1z : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void line_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"line : end\");\n\tZ start = th.popFloat(\"line : start\");\n\tZ dur = th.popFloat(\"line : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, (int64_t)n);\n\tth.push(new List(g));\n}\n\nstatic void xline_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"xline : end\");\n\tZ start = th.popFloat(\"xline : start\");\n\tZ dur = th.popFloat(\"xline : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\n\tGen* g;\n\tif (sc_sgn(start) != sc_sgn(end) || start == 0. || end == 0.) {\n\t\tstart = sc_sgn(start) * pow(fabs(start), kOneThird);\n\t\tend = sc_sgn(end) * pow(fabs(end), kOneThird);\n\t\tZ step = (end - start) / n;\t\t\n\t\tg = new NCubicLinez(th, start, step, (int64_t)n);\n\t} else {\n\t\tZ step = pow(end/start, 1. / n);\n\t\tg = new NGrowz(th, start, step, (int64_t)n);\n\t}\n\tth.push(new List(g));\n}\n\n\nstatic void grow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new Grow(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"ngrow : n\");\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void byz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"byz : step\");\n\tZ start = th.popFloat(\"byz : start\");\n\t\n\tGen* g = new Byz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nbyz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"nbyz : step\");\n\tZ start = th.popFloat(\"nbyz : start\");\n\tint64_t n = th.popInt(\"nbyz : n\");\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void growz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"growz : step\");\n\tZ start = th.popFloat(\"growz : start\");\n\t\n\tGen* g = new Growz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrowz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"ngrowz : step\");\n\tZ start = th.popFloat(\"ngrowz : start\");\n\tint64_t n = th.popInt(\"ngrowz : n\");\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void ord_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negs_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void nat_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evens_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void odds_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 2.);\n\tth.push(new List(g));\n}\n\n\nstatic void invs_(Thread& th, Prim* prim)\n{\n\tGen* g = new Inv(th);\n\tth.push(new List(g));\n}\n\nstatic void invz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Invz(th);\n\tth.push(new List(g));\n}\n\nstatic void ninvs_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvs : n\");\n\tGen* g = new NInv(th, n);\n\tth.push(new List(g));\n}\n\nstatic void ninvz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvz : n\");\n\tGen* g = new NInvz(th, n);\n\tth.push(new List(g));\n}\n\n\nstatic void ordz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void natz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evenz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void oddz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 2.);\n\tth.push(new List(g));\n}\n\nstatic void fib_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Fib(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void fibz_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"fibz : b\");\n\tZ a = th.popFloat(\"fibz : a\");\n\t\n\tGen* g = new Fibz(th, a, b);\n\tth.push(new List(g));\n}\n\nstruct Ints : public Gen\n{\n\tZ _a;\n \n\tInts(Thread& th) : Gen(th, itemTypeV, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Ints\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Intz : public Gen\n{\n\tZ _a;\n \n\tIntz(Thread& th) : Gen(th, itemTypeZ, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Intz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstatic void ints_(Thread& th, Prim* prim)\n{\n\tGen* g = new Ints(th);\n\tth.push(new List(g));\n}\n\nstatic void intz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Intz(th);\n\tth.push(new List(g));\n}\n\n#include \"primes.hpp\"\n\nstruct Primes : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimes(Thread& th) : Gen(th, itemTypeV, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primes\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct Primez : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimez(Thread& th) : Gen(th, itemTypeZ, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primez\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n } else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n if (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\n\nstatic void primes_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primes(th);\n\tth.push(new List(g));\n}\n\nstatic void primez_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primez(th);\n\tth.push(new List(g));\n}\n\n\n#pragma mark ORDERING\n\n\nclass Perms : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPerms(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_at(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Perms\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeV, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tV* outItems = arr->v();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nclass Permz : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPermz(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_atz(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Permz\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeZ, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tZ* outItems = arr->z();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nstatic void perms_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"perms : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"perms : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Perms(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permz : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Permz(th, arr);\n\tth.push(new List(g));\n}\n\n\n\nclass PermsWithRepeatedItems : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItems(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_at(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItems\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\n\nclass PermsWithRepeatedItemsZ : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItemsZ(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_atz(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItemsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\nstatic void permswr_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"permswr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permswr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItems(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permzwr_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permzwr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permzwr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItemsZ(th, arr);\n\tth.push(new List(g));\n}\n\n\nstruct Repeat : Gen\n{\n V _a;\n\tint64_t _m;\n \n\tRepeat(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n V a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct RepeatFun : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFun(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _b(0.), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct InfRepeatFun : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFun(Thread& th, Arg a) : Gen(th, itemTypeV, false), _a(a), _b(0.) {}\n\t \n\tvirtual const char* TypeName() const override { return \"InfRepeatFun\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n \n};\n\nstruct Repeatz : Gen\n{\n Z _a;\n\tint64_t _m;\n \n\tRepeatz(Thread& th, Z a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Repeatz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n Z a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct RepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFunz(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _b(0.), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"RepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop().asFloat();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct InfRepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFunz(Thread& th, Arg a) : Gen(th, itemTypeZ, false), _a(a), _b(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"InfRepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop().asFloat();\n\t\t}\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct RCyc : public Gen\n{\n\tV _ref;\n\tP _a0;\n\tP _a;\n\n\tRCyc(Thread& th, Arg ref, P const& a) : Gen(th, a->elemType, false), _ref(ref), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"RCyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tV v = _ref.deref();\n\t\t\tif (v.isList()) {\n\t\t\t\t_a0 = (List*)v.o();\n\t\t\t}\n\t\t\t_a = _a0;\n\t\t}\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Cyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\n\tCyc(Thread& th, P const& a) : Gen(th, a->elemType, false), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) _a = _a0;\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NCyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\tint64_t _n;\n\t\n\tNCyc(Thread& th, int64_t n, P const& a) : Gen(th, a->elemType, true), _a0(a), _a(a), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tif (_n <= 1) {\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\t_a = _a0;\n\t\t\t\t--_n;\n\t\t\t}\n\t\t}\n\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void repeat_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"X : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFun(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Ever(th, a);\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFun(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeat(th, a, n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstatic void repeatz_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"XZ : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFunz(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Everz(th, a.asFloat());\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFunz(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeatz(th, a.asFloat(), n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstruct Silence : Gen\n{\n\tint64_t _m;\n \n\tSilence(Thread& th, int64_t m) : Gen(th, itemTypeZ, true), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Silence\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n\t\t\tmemset(out, 0, n * sizeof(Z));\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstatic void mum_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"mum : duration\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\tif (isinf(t) || (n <= 0 && t > 0.)) {\n\t\tth.push(new List(new Everz(th, 0.)));\n\t} else {\n\t\tGen* g = new Silence(th, n);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstatic void cyc_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\t\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP s = (List*)v.o();\n\t\n\n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n \n\tGen* g = new Cyc(th, s);\n\tth.push(new List(g));\n}\n\n\nstatic void rcyc_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tV v = ref.deref();\n\tif (!v.isList()) {\n\t\twrongType(\"rcyc : ref get\", \"List\", v);\n\t}\n\t\n\tP list = (List*)v.o();\n\t\n\tGen* g = new RCyc(th, ref, list);\n\tth.push(new List(g));\n}\n\n\nstatic void ncyc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ncyc : n\");\n\tP s = th.popList(\"ncyc : seq\");\n \n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n\t\n\tif (n <= 0) {\n\t\tth.push(vm.getNil(s->elemType));\t\t\n\t} else {\n\t\tGen* g = new NCyc(th, n, s);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstruct Append : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAppend(Thread& th, P const& a, Arg b, bool inFinite) : Gen(th, a->elemType, inFinite), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Append\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t\tmOut = mOut->nextp();\n\t\t} else {\n\t\t\tif (_b.isFunOrPrim()) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\t_b.apply(th);\n\t\t\t\t_b = th.pop();\n\t\t\t}\n\t\t\tif (!_b.isList()) {\n\t\t\t\tpost(\"$ : b is not a sequence '%s'\\n\", _b.TypeName());\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tList* b = (List*)_b.o();\n\t\t\tif (elemType != b->elemType) {\n\t\t\t\tpost(\"$ : b item type doesn't match\\n\");\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetDone();\n\t\t\tmOut->link(th, b);\n\t\t}\n\t}\n};\n\n\nstruct Cat : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\n\tCat(Thread& th, Arg a, P const& b) : Gen(th, itemTypeV, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"Cat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isVList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct CatZ : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\n\t// this makes the assumption that all of the sublists of b are finite! if they are not then this will not prevent infinite loops.\n\tCatZ(Thread& th, Arg a, P const& b) : Gen(th, itemTypeZ, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"CatZ\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isZList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\t\t\t\n};\n\n#include \n\nstruct Flat : Gen\n{\n\tstd::stack in; // stack of list continuations\n\n\tFlat(Thread& th, Arg inA) : Gen(th, itemTypeV, inA.isFinite())\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList()) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Flatten : Gen\n{\n\tstd::stack in; // stack of list continuations\n\tsize_t depth;\n\t\n\tFlatten(Thread& th, Arg inA, size_t inDepth) : Gen(th, itemTypeV, inA.isFinite()), depth(inDepth)\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList() && in.size() <= depth) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Keep : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tKeep(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keep\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Take : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tTake(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Take\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeat(th, 0., _n));\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Keepz : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tKeepz(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keepz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Takez : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tTakez(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Takez\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeatz(th, 0., _n));\n setDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstatic void append_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tif (a.isString() && b.isString()) {\n\t\tstd::string s;\n\t\ta.print(th, s);\n\t\tb.print(th, s);\n\t\tth.push(new String(s.c_str()));\n\t} else if (a.isList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(new List(new Append(th, list, b, leastFinite(a,b))));\n\t} else {\n\t\twrongType(\"$ : a\", \"List or String\", a);\n\t}\n}\n\nstruct AppendSubs : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tAppendSubs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AppendSubs\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tif (!a->isList())\n\t\t\t\t\t\twrongType(\"$$ : *a\", \"List\", *a);\n\t\t\t\t\t\n\t\t\t\t\tList* aa = (List*)a->o();\n\t\t\t\t\t\t\n\t\t\t\t\tout[i] = new List(new Append(th, aa, *b, mostFinite(*a,*b)));\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void appendSubs_(Thread& th, Prim* prim)\n{\n\tV b = th.popVList(\"$$ : b\");\n\tV a = th.popVList(\"$$ : a\");\n\t\n th.push(new List(new AppendSubs(th, a, b)));\n}\n\nstatic void cat_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP b = (List*)v.o();\n\n\tb->force(th);\n\tif (b->isEnd()) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\tVIn a_(b);\n\tV a;\n\tif (a_.one(th, a)) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\t\n\t\n\t//V a = b->mArray->v()[0];\n\t\n\tif (a.isString()) {\n\t\tif (!b->isFinite())\n\t\t\tindefiniteOp(\"$/ : list of strings\", \"\");\n\t\t\n\t\tstd::string s;\n\n\t\tVIn in_(b);\n\t\twhile (true) {\n\t\t\tV in;\n\t\t\tif (in_.one(th, in)) {\n\t\t\t\tth.push(new String(s.c_str()));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tin.print(th, s);\n\t\t}\n\t\t\n\t} else if (!a.isList()) {\n\t\twrongType(\"$/ : b\", \"List\", a);\n\t}\n\t\t\n\tGen* g;\n\tif (a.isVList()) g = new Cat(th, a, b);\n\telse g = new CatZ(th, a, b);\n\tth.push(new List(g));\n\n}\n\nstatic void flat_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\n\tif (a.isVList()) th.push(new List(new Flat(th, a)));\n\telse th.push(a);\n}\n\nstatic void flatten_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"flatten : n\");\n\tV a = th.pop();\n\t\n\tif (a.isVList()) th.push(new List(new Flatten(th, a, n)));\n\telse th.push(a);\n}\n\nstatic void N_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"N : n\");\n\tV v = th.pop();\n\t\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void NZ_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"NZ : n\");\n\tV v = th.pop();\n\t\n if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void T_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"T : t\");\n\tV v = th.pop();\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void take_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"take : n\");\n\tP s = th.popList(\"take : s\");\n\n Gen* g;\n\tif (n > 0) {\n\t\tif (s->isVList()) \n\t\t\tg = new Take(th, n, s);\n\t\telse\n\t\t\tg = new Takez(th, n, s);\n\t\tth.push(new List(g));\n } else if (n < 0) {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"take\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tList* s2 = new List(s->elemType, n);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(n);\n\t\tif (s->isVList()) {\n\t\t\tV* p = s2->mArray->v();\n\t\t\tV* q = s->mArray->v();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tfor (int64_t i = 0; i < offset; ++i) p[i] = 0.;\n\t\t\t\tfor (int64_t i = 0, j = offset; i < size; ++i, ++j) p[j] = q[i];\n\t\t\t} else {\n\t\t\t\tfor (int64_t i = 0, j = size - n; i < n; ++i, ++j) p[i] = q[j];\n\t\t\t}\n\t\t} else {\n\t\t\tZ* p = s2->mArray->z();\n\t\t\tZ* q = s->mArray->z();\n\t\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tmemset(p, 0, offset * elemSize);\n\t\t\t\tmemcpy(p + offset, q, size * elemSize);\n\t\t\t} else {\n\t\t\t\tmemcpy(p, q + size - n, n * elemSize);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t\t\n\t} else {\n\t\tif (s->isVList())\n\t\t\tth.push(vm._nilv);\n\t\telse \n\t\t\tth.push(vm._nilz);\n\t\treturn;\n\t\t\n\t}\n}\n\n\n\n\nstatic void skip_positive_(Thread& th, P& list, int64_t n)\n{\n\tif (n <= 0) return;\n\n\tint itemType = list->elemType;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\t\t\tif (list->isVList()) {\n\t\t\t\tfor (int64_t i = 0, j = n; i < remain; ++i, ++j) {\n\t\t\t\t\ta2->v()[i] = a->v()[j];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\t\t\t}\n\t\t\tlist = new List(a2, list->next());\n\t\t\treturn;\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm.getNil(itemType);\n\t}\n}\n\nstatic void skip_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"skip : n\");\n\tP s = th.popList(\"skip : s\");\n\n\tif (n <= 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\n\nstatic void skipT_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\">T : t\");\n\tP s = th.popList(\">T : s\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\nstruct Hops : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHops(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"Hops\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\t\t\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tint64_t hop;\n\t\t\t\tif (_hop.onei(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tskip_positive_(th, _a, hop);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct HopTs : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHopTs(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"HopTs\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tZ hop;\n\t\t\t\tif (_hop.onez(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * hop);\n\t\t\t\t\tskip_positive_(th, _a, n);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void hops_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"N>> : list\");\n\n\tth.push(new List(new Hops(th, n, s)));\n}\n\nstatic void hopTs_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"T>> : list\");\n\n\tth.push(new List(new HopTs(th, n, s)));\n}\n\n\n\n\nstatic void drop_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"drop : n\");\n\tP s = th.popList(\"drop : s\");\n\n\tif (n == 0) {\n\t\tth.push(s);\n\t} else if (n > 0) {\n\t\tskip_positive_(th, s, n);\n\t\tth.push(s);\n\t} else {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"drop\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tint64_t remain = std::max(0LL, size - n);\n\t\tif (remain <= 0) {\n\t\t\tth.push(vm.getNil(s->elemType));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tP s2 = new List(s->elemType, remain);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(remain);\n\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\tif (s->isVList()) {\n\t\t\tV* y = s->mArray->v();\n\t\t\tV* x = s2->mArray->v();\n\t\t\tfor (int64_t i = 0; i < remain; ++i) {\n\t\t\t\tx[i] = y[i];\n\t\t\t}\n\t\t} else {\n\t\t\tmemcpy(s2->mArray->z(), s->mArray->z(), remain * elemSize);\n\t\t}\n\t}\n}\n\nstatic void choff_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"choff : n\");\n\tint64_t c = th.popInt(\"choff : c\");\n\tV a = th.pop();\n\t\n\tP s2 = new List(itemTypeV, n);\n\ts2->mArray->setSize(n);\n\t\n\tif (a.isVList()) {\n\t\tif (!a.isFinite())\n\t\t\tindefiniteOp(\"choff : a\", \"\");\n\t\t\t\n\t\tP aa = ((List*)a.o())->pack(th);\n\t\tint64_t m = aa->length(th);\n\t\tint64_t mn = std::min(m,n);\n\t\tfor (int64_t i = 0; i < mn; ++i) {\n\t\t\tint64_t j = sc_imod(i+c, n);\n\t\t\ts2->mArray->put(j, aa->at(i));\n\t\t}\n\t} else {\n\t\tc = sc_imod(c, n);\n\t\ts2->mArray->put(c, a);\n\t}\n\t\t\n\tth.push(s2);\n}\n\nstatic int64_t countWhileTrue(Thread& th, List* list)\n{\n int64_t n = 0;\n while (list) {\n list->force(th);\n\n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n if (a->at(i).isTrue()) ++n;\n else return n;\n }\n list = list->nextp();\n }\n\treturn n;\n}\n\nstatic void skipWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"skipWhile : s\");\n\n if (f.isList()) {\n int64_t n = countWhileTrue(th, (List*)f.o());\n skip_positive_(th, s, n);\n\t\tth.push(s);\n } else {\n \n List* list = s();\n\n while (1) {\n list->force(th);\n if (list->isEnd()) {\n th.push(vm.getNil(s->elemType));\n return;\n }\n \n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n V v;\n {\n SaveStack ss(th);\n th.push(a->at(i));\n\t\t\t\t\tf.apply(th);\n v = th.pop();\n }\n if (v.isFalse()) {\n if (i == 0) {\n th.push(list);\n } else {\n int64_t remain = asize - i;\n Array* a2 = new Array(s->elemType, remain);\n th.push(new List(a2, list->next()));\n a2->setSize(remain);\n\t\t\t\t\t\tif (a->isV()) {\n\t\t\t\t\t\t\tfor (int64_t j = 0; j < remain; ++j) a2->v()[j] = a->v()[j+i];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmemcpy(a2->v(), a->v() + i, remain * a->elemSize());\n\t\t\t\t\t\t}\n }\n return;\n }\n }\n list = list->nextp();\n }\n th.push(list);\n }\n}\n\n\nstruct KeepWhile : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tKeepWhile(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhile\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZ : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tKeepWhileZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileVZ : Gen\n{\n\tVIn _a;\n\tZIn _b;\n\t\n\tKeepWhileVZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileVZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a;\n\t\t\tZ *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZV : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\t\n\tKeepWhileZV(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZV\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a;\n\t\t\tV *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstatic void keepWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"keepWhile : s\");\n\t\n\tif (s->isZ()) {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhileZV(th, s, f)));\n\t\t}\n\t} else {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileVZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhile(th, s, f)));\n\t\t}\n\t} \n}\n\n\nstruct Tog : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Togz : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tTogz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Togz\"; }\n \t\t\t \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill / 2;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t*out++ = *a;\n\t\t\t\t\t*out++ = *b;\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= 2*n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tog_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Tog(th, a, b)));\n}\n\nstatic void togz_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Togz(th, a, b)));\n}\n\n\n\nstruct Tog1 : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog1(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog1\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\n\nstruct Hang : Gen\n{\n\tP _a;\n\tV _b;\n\n\tHang(Thread& th, P const& a) : Gen(th, itemTypeV, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hang\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->v()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tV* out = mOut->fulfill(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Hangz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tHangz(Thread& th, P const& a) : Gen(th, itemTypeZ, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hangz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->z()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void hang_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"hang : a\");\n\t\n\tif (a->isV())\n\t\tth.push(new List(new Hang(th, a)));\n\telse\n\t\tth.push(new List(new Hangz(th, a)));\n}\n\nstatic void hangz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"hangz : a\");\n\t\n\tth.push(new List(new Hangz(th, a)));\n}\n\n\nstatic void histo_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"histo : n\");\n\tP a = th.popList(\"histo : list\");\n\n\tif (!a->isFinite()) {\n\t\tindefiniteOp(\"histo : list\", \"\");\n\t}\n\t\n\ta = a->pack(th);\n\t\n\tint64_t size = a->mArray->size();\n\t\n\tPoutList = new List(itemTypeZ, n);\n\toutList->mArray->setSize(n);\n\tZ* out = outList->mArray->z();\n\tmemset(out, 0, sizeof(Z) * n);\n\t\n\tZ n1 = n - 1;\n\tif (a->isZ()) {\n\t\tZ* in = a->mArray->z();\n\t\t\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i], 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t} else {\n\t\tV* in = a->mArray->v();\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i].asFloat(), 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t}\n\t\n\tth.push(outList);\n\t\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark MAP FILTER REDUCE\n\n\nstruct Stutter : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tStutter(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutter\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = aa_;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, aa_) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(aa_);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Stutterz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\tZ aa_;\n\t\n\tStutterz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutterz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a = aa_;\n\t\twhile (framesToFill) {\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\taa_ = a;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void filter_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.popList(\"? : a\");\n\n\tif (a.isVList()) {\n\t\tth.push(new List(new Stutter(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Stutterz(th, a, b)));\n\t}\n}\n\n\nstruct Change : Gen\n{\n\tVIn _a;\n\tV _prev;\n\t\n\tChange(Thread& th, Arg a) : Gen(th, itemTypeV, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Change\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n V a;\n for (int i = 0; framesToFill; ) {\n if (_a.one(th, a)) {\n setDone();\n break;\n }\n if (!a.Equals(th, _prev)) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Changez : Gen\n{\n\tZIn _a;\n\tZ _prev;\n\t\n\tChangez(Thread& th, Arg a) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Changez\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n Z a;\n for (int i = 0; framesToFill; ) {\n if (_a.onez(th, a)) {\n setDone();\n break;\n }\n if (a != _prev) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void change_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"change : a\");\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Change(th, a)));\n\t} else {\n\t\tth.push(new List(new Changez(th, a)));\n\t}\n}\n\nstatic void changez_(Thread& th, Prim* prim)\n{\n\tV a = th.popZList(\"change : a\");\n \n th.push(new List(new Changez(th, a)));\n}\n\nstruct Spread : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tSpread(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spread\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tV a = aa_;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Spreadz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\t\n\tSpreadz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spreadz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n \n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void spread_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Spread(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Spreadz(th, a, b)));\n\t}\n}\n\nstatic void spreadz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"spreadz : b\");\n\tV a = th.popZIn(\"spreadz : a\");\n \n th.push(new List(new Spreadz(th, a, b)));\n}\n\nstruct Expand : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tExpand(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expand\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tV a;\n\t\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Expandz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tExpandz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expandz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tZ a;\n\t\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void expand_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Expand(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Expandz(th, a, b)));\n\t}\n}\n\nstatic void expandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"expandz : b\");\n\tV a = th.popZIn(\"expandz : a\");\n \n th.push(new List(new Expandz(th, a, b)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Clump : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tClump(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clump\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeV, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV a;\n\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->add(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Clumpz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tClumpz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clumpz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeZ, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a;\n\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->addz(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void clump_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Clump(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Clumpz(th, a, b)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ShortAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tShortAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ShortAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tShortAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void shortas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new ShortAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new ShortAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"shortas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tV last;\npublic:\n\t\n\tLongAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\n\tZ last;\npublic:\n\t\n\tLongAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"longas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs0 : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tLongAs0(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tV zero(0.);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = zero;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAs0Z : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tLongAs0Z(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0Z\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas0_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs0(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAs0Z(th, a, b)));\n\t} else {\n\t\twrongType(\"longas0 : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \"Play.hpp\"\n\nstatic void play_(Thread& th, Prim* prim)\n{\n\tV v = th.popList(\"play : list\");\n\tplayWithAudioUnit(th, v);\n}\n\nstatic void record_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tV v = th.popList(\"record : list\");\n\trecordWithAudioUnit(th, v, filename);\n}\n\nstatic void stop_(Thread& th, Prim* prim)\n{\n\tstopPlaying();\n}\n\nstatic void stopDone_(Thread& th, Prim* prim)\n{\n\tstopPlayingIfDone();\n}\n\n\nstatic void interleave(int stride, int numFrames, double* in, float* out)\n{\n\tfor (int f = 0, k = 0; f < numFrames; ++f, k += stride)\n\t\tout[k] = in[f];\n}\n\nstatic void deinterleave(int numChans, int numFrames, float* in, double** out)\n{\n\tswitch (numChans) {\n\t\tcase 1 : \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, ++k) {\n\t\t\t\tout[0][f] = in[k];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 2 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=2) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3 : // e.g. W X Y \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=3) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 4 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=4) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 5 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=5) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 6 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=6) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t\tout[5][f] = in[k+5];\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f) {\n\t\t\t\tfor (int c = 0; c < numChans; ++c, ++k) {\n\t\t\t\t\tout[c][f] = in[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nstatic const size_t gSessionTimeMaxLen = 256;\nchar gSessionTime[gSessionTimeMaxLen];\n\n#include \n\nstatic void setSessionTime()\n{\n\ttime_t t;\n\ttm tt;\n\ttime(&t);\n\tlocaltime_r(&t, &tt);\n\tsnprintf(gSessionTime, gSessionTimeMaxLen, \"%04d-%02d%02d-%02d%02d%02d\",\n\t\ttt.tm_year+1900, tt.tm_mon+1, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec);\n}\n\n\nstatic void sfwrite_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.popList(\">sf : channels\");\n\t\n\tsfwrite(th, v, filename, false);\n}\n\nstatic void sfwriteopen_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.pop();\n\n\tsfwrite(th, v, filename, true);\n}\n\n\nstatic void sfread_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.popString(\"sf> : filename\");\n\t\t\n\tsfread(th, filename, 0, -1);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstatic void bench_(Thread& th, Prim* prim)\n{\n\tZIn in[kMaxSFChannels];\n\t\t\n\tint numChannels = 0;\n\t\n\tV v = th.popList(\"bench : channels\");\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin[0].set(v);\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin[i].set(va);\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tdouble t0 = elapsedTime();\n\tbool done = false;\n\tint64_t framesFilled = 0;\n\twhile (!done) {\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].bench(th, n);\n\t\t\tif (imdone) done = true;\n\t\t\tframesFilled += n;\n\t\t}\n\t}\n\tdouble t1 = elapsedTime();\n\t\n\tdouble secondsOfCPU = t1-t0;\n\tdouble secondsOfAudio = (double)framesFilled * th.rate.invSampleRate;\n\tdouble percentOfRealtime = 100. * secondsOfCPU / secondsOfAudio;\n\t\n\tpost(\"bench:\\n\");\n\tpost(\" %f seconds of audio.\\n\", secondsOfAudio);\n\tpost(\" %f seconds of CPU.\\n\", secondsOfCPU);\n\tpost(\" %f %% of real time.\\n\", percentOfRealtime);\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#include \"Spectrogram.hpp\"\n\nstd::atomic gSpectrogramFileCount = 0;\n\nstatic void sgram_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tZ dBfloor = fabs(th.popFloat(\"sgram : dBfloor\"));\n\tP list = th.popZList(\"sgram : signal\");\n\t\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"sgram : signal - indefinite number of frames\", \"\");\n\t}\n\n\tchar path[1024];\n\tif (filename.isString()) {\n\t\tconst char* sgramDir = getenv(\"SAPF_SPECTROGRAMS\");\n\t\tif (!sgramDir || strlen(sgramDir)==0) sgramDir = \"/tmp\";\n\t\tsnprintf(path, 1024, \"%s/%s-%d.jpg\", sgramDir, ((String*)filename.o())->s, (int)floor(dBfloor + .5));\n\t} else {\n\t\tint32_t count = ++gSpectrogramFileCount;\n\t\tsnprintf(path, 1024, \"/tmp/sapf-%s-%04d.jpg\", gSessionTime, count);\n\t}\n\n\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\tint64_t n = array->size();\n\tdouble* z = array->z();\n\tspectrogram((int)n, z, 3200, 11, path, -dBfloor);\n\t\n\t{\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\t\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double kaiser_alpha(double atten)\n{\n\tdouble alpha = 0.;\n\tif (atten > 50.) \n\t\talpha = .1102 * (atten - 8.7);\n\telse if (atten >= 21.)\n\t\talpha = .5842 * pow(atten - 21., .4) + .07886 * (atten - 21.);\n\treturn alpha;\n}\n\nstatic void kaiser(size_t m, double *s, double alpha)\n{\n\tif (m == 0) return;\n\tif (m == 1) {\n\t\ts[0] = 1.;\n\t\treturn;\n\t}\n\tsize_t n = m-1;\n\tdouble p = n / 2.;\n\tdouble rp = 1. / p;\n\tdouble rb = 1. / bessi0(alpha);\n\t\n\tfor (size_t i = 0; i < m; ++i) {\n\t\tdouble x = (i-p) * rp;\n\t\ts[i] = rb * bessi0(alpha * sqrt(1. - x*x));\n\t}\n}\n\nstatic void kaiser_(Thread& th, Prim* prim)\n{\n\tZ atten = fabs(th.popFloat(\"kaiser : stopband attenuation\"));\n\tint64_t n = th.popInt(\"kaiser : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tZ alpha = kaiser_alpha(atten);\n\tkaiser(n, out->mArray->z(), alpha);\n\t\n\tth.push(out);\n}\n\n\nstatic void hanning_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hann_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void hamming_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hamm_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void blackman_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_blkman_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Segment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tBothIn length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tSegment(Thread& th, Arg in, Arg hop, Arg length)\n : Gen(th, itemTypeV, mostFinite(in, hop, length)), in_(in), hop_(hop), length_(length),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Segment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zlength, zhop;\n\t\t\tif (length_.onez(th, zlength)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint length = (int)floor(sr_ * zlength + .5);\n\t\t\tP segment = new List(itemTypeZ, length);\n\t\t\tsegment->mArray->setSize(length);\n\t\t\tbool nomore = in_.fillSegment(th, length, segment->mArray->z());\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n \n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void seg_(Thread& th, Prim* prim)\n{\n\tV length = th.pop();\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n\tth.push(new List(new Segment(th, in, hop, length)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct WinSegment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tP window_;\n int length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tWinSegment(Thread& th, Arg in, Arg hop, P const& window)\n : Gen(th, itemTypeV, mostFinite(in, hop)), in_(in), hop_(hop), window_(window),\n length_((int)window_->size()),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WinSegment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zhop;\n\t\t\t\n\t\t\tP segment = new List(itemTypeZ, length_);\n\t\t\tsegment->mArray->setSize(length_);\n Z* segbuf = segment->mArray->z();\n\t\t\tbool nomore = in_.fillSegment(th, (int)length_, segbuf);\n vDSP_vmulD(segbuf, 1, window_->z(), 1, segbuf, 1, length_);\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void wseg_(Thread& th, Prim* prim)\n{\n\tP window = th.popZList(\"wseg : window\");\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n window = window->pack(th);\n \n\tth.push(new List(new WinSegment(th, in, hop, window->mArray)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void fft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"fft : imag\");\n\tP inReal = th.popZList(\"fft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"fft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"fft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"fft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"fft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\n\tfft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\n\nstatic void ifft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"ifft : imag\");\n\tP inReal = th.popZList(\"ifft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"ifft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"ifft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"ifft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"ifft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\tifft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\nstruct Add : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAdd(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Add\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tV* out = mOut->fulfill(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Addz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tAddz(Thread& th, P const& a, Z b) : Gen(th, itemTypeZ, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Addz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tZ* out = mOut->fulfillz(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void add_(Thread& th, Prim* prim)\n{\n\tV item = th.pop();\n\tP list = th.popList(\"add : list\");\n\tif (list->isZ()) {\n\t\tth.push(new List(new Addz(th, list, item.asFloat())));\n\t} else {\n\t\tth.push(new List(new Add(th, list, item)));\n\t}\n}\n\nstatic void empty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size==0);\n}\n\nstatic void nonempty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size!=0);\n}\n\nstatic void head_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tBothIn in(list);\n\tV v;\n\tif (in.one(th, v)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tth.push(v);\n}\n\nstatic void tail_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tskip_positive_(th, list, 1);\n\tth.push(list);\n}\n\nstatic void uncons_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tlist->force(th);\n\n\tBothIn in(list);\n\tV head;\n\tif (in.one(th, head)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tskip_positive_(th, list, 1);\n\t\n\tth.push(list);\n\tth.push(head);\n}\n\nclass Cons : public Gen\n{\n\tV fun;\npublic:\n\tCons(Thread& th, Arg inFun) : Gen(th, itemTypeV, false), fun(inFun) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Cons\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tSaveStack ss(th);\n\t\tfun.apply(th);\n\t\tV v = th.pop();\n\t\tif (v.isList()) {\n\t\t\tsetDone();\n\t\t\tmOut->link(th, (List*)v.o());\n\t\t} else {\n\t\t\tend();\n\t\t}\n\t}\n};\n\nstatic V cons(Thread& th, Arg head, Arg tail)\n{\n\tif (tail.isFunOrPrim()) {\n\t\tP array = new Array(itemTypeV, 1);\n\t\tarray->add(head);\n\t\treturn new List(array, new List(new Cons(th, tail)));\n\t} else if (tail.isList()) {\n\t\n\t\tP list = (List*)tail.o();\n\t\t\n\t\tlist->force(th);\n\t\t\t\n\t\tint64_t size = list->mArray->size();\n\n\t\tP array = list->mArray;\n\t\tP newArray = new Array(list->ItemType(), size+1);\n\n\t\tP newList = new List(newArray, list->next());\n\n\t\tnewArray->add(head);\n\n\t\tif (list->isZ()) {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tZ z = array->atz(i);\n\t\t\t\tnewArray->add(z);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tV v = array->at(i);\n\t\t\t\tnewArray->add(v);\n\t\t\t}\n\t\t}\n\n\t\treturn newList;\n\t} else {\n\t\twrongType(\"cons : list\", \"List or Fun\", tail);\n\t}\n}\n\nstatic void cons_(Thread& th, Prim* prim)\n{\n\tV head = th.pop();\n\tV tail = th.pop();\n\t\n\tth.push(cons(th, head, tail));\n}\n\nstatic void pack_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"pack : list\");\n\tth.push(list->pack(th));\n}\n\nstatic void packed_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"packed : list\");\n\tth.pushBool(list->isPacked());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n \n\tScan(Thread& th, Arg list, Arg fun, Arg val) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan(th, list, fun, value)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan1 : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n\tbool once_;\n \n\tScan1(Thread& th, Arg list, Arg fun) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), once_(true) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (once_) {\n\t\t\tonce_ = false;\n\t\t\tif (list_.one(th, val_)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = val_;\n\t\t\t--framesToFill;\n\t\t}\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan1(th, list, fun)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Iter : Gen\n{\n V fun_;\n V val_;\n Z index = 0.;\n\t\n\tIter(Thread& th, Arg fun, Arg val) : Gen(th, itemTypeV, true), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Iter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct NIter : Gen\n{\n V fun_;\n V val_;\n\tint64_t n_;\n Z index = 0.;\n \n\tNIter(Thread& th, Arg fun, Arg val, int64_t n) : Gen(th, itemTypeV, false), fun_(fun), val_(val), n_(n) {}\n\t \n\tvirtual const char* TypeName() const override { return \"NIter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (n_ <= 0) {\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tn_ -= n;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void iter_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new Iter(th, fun, value)));\n}\n\nstatic void itern_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"itern : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new NIter(th, fun, value, n)));\n}\n\n\n\nstatic void reduce_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\n\nstatic void reduce1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\tV value;\n\tif (in_.one(th, value)) {\n\t\tth.push(value);\n\t\treturn;\n\t}\n\t\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\nstatic void chain_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"chain : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\n\tbool pushIndex = fun.takes() == 2;\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(value);\n\t\tif (pushIndex) th.push(i);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n\tth.push(value);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Merge : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMerge(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Merge\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \nstruct MergeZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeByKey : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V key_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeByKey(Thread& th, Arg a, Arg b, Arg key) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), key_(key) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeByKey\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tV a, b;\n\t\t\t\tbool aok = aa.dot(th, key_, a);\n\t\t\t\tbool bok = bb.dot(th, key_, b);\n\t\t\t\tif (!aok || !bok) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tflag = ::Compare(th, a, b) < 0;\n\t\t\t\tif (flag) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeCmp : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmp(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmp\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\twhich = left;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\nstruct MergeCmpZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmpZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmpZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = right;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\n\nstatic void merge_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"merge : b\");\n\tV a = th.popList(\"merge : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tif (fun.isString()) {\n\t\t\tth.push(new List(new MergeByKey(th, a, b, fun)));\n\t\t} else {\n\t\t\tth.push(new List(new Merge(th, a, b, fun)));\n\t\t}\n\t} else {\n\t\tpost(\"merge : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\nstatic void mergec_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"mergec : b\");\n\tV a = th.popList(\"mergec : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeCmpZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new MergeCmp(th, a, b, fun)));\n\t} else {\n\t\tpost(\"mergec : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n//evmerge\n\nextern P s_dt;\nextern P s_out;\nP s_dur;\n\nP dtTableMap;\nP restTableMap;\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value);\n\nstatic P makeRestEvent(Z dt)\n{\n\tP
table = new Table(restTableMap);\n\ttable->put(0, V(0.));\n\ttable->put(1, V(dt));\n\ttable->put(2, V(dt));\n\treturn new Form(table);\n}\n\nstruct MergeEvents : Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tZ nextATime = 0.;\n\tZ nextBTime;\n\t\n\tMergeEvents(Thread& th, Arg a, Arg b, Z t) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), nextBTime(t)\n\t{\n\t}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeEvents\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\t{\n\t\t\t\tif (nextATime <= nextBTime) {\n\t\t\t\t\tV aa;\n\t\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\t\tif (nextATime < nextBTime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextBTime - nextATime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tV a;\n\t\t\t\t\tbool aok = aa.dot(th, s_dt, a);\n\t\t\t\t\tif (!aok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dta = a.asFloat();\n\t\t\t\t\tZ dt = std::min(dta, nextBTime - nextATime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, aa), dtTableMap, dt);\n\t\t\t\t\tnextATime += dta;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tV bb;\n\t\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\t\tif (nextBTime < nextATime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextATime - nextBTime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tV b;\n\t\t\t\t\tbool bok = bb.dot(th, s_dt, b);\n\t\t\t\t\tif (!bok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dtb = b.asFloat();\n\t\t\t\t\tZ dt = std::min(dtb, nextATime - nextBTime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, bb), dtTableMap, dt);\n\t\t\t\t\tnextBTime += dtb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstatic void evmerge_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evmerge : t\");\n\tV b = th.popVList(\"evmerge : b\");\n\tV a = th.popVList(\"evmerge : a\");\n\tth.push(new List(new MergeEvents(th, a, b, t)));\n}\n\nstatic void evrest_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evrest : t\");\n\tth.push(makeRestEvent(t));\n}\n\nstatic void evdelay_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evdelay : t\");\n\tV a = th.popVList(\"evdelay : a\");\n\tth.push(cons(th, makeRestEvent(t), a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CompareFun\n{\npublic:\n\tCompareFun() {}\n\tvirtual ~CompareFun() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) = 0;\n};\n\nclass VLess : public CompareFun\n{\npublic:\n\tVLess() {}\n\t~VLess() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) < 0; }\n};\n\nclass VGreater : public CompareFun\n{\npublic:\n\tVGreater() {}\n\t~VGreater() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) > 0; }\n};\n\nclass VCompareF : public CompareFun\n{\n\tV fun;\npublic:\n\tVCompareF(V inFun) : fun(inFun) {}\n\t~VCompareF() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\n\n\nclass ZCompareFun\n{\npublic:\n\tZCompareFun() {}\n\tvirtual ~ZCompareFun() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) = 0;\n};\n\nclass ZLess : public ZCompareFun\n{\npublic:\n\tZLess() {}\n\t~ZLess() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a < b; }\n};\n\nclass ZCompareF : public ZCompareFun\n{\n\tV fun;\npublic:\n\tZCompareF(V inFun) : fun(inFun) {}\n\t~ZCompareF() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\nclass ZGreater : public ZCompareFun\n{\npublic:\n\tZGreater() {}\n\t~ZGreater() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a > b; }\n};\n\n\nstatic void merge(Thread& th, int64_t an, V* a, int64_t bn, V* b, V* c, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, int64_t bn, Z* b, Z* c, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, V* tmp, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* tmp, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const V* in, V* out, CompareFun* compare)\n{\n\tV* tmp = new V[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const Z* in, Z* out, ZCompareFun* compare)\n{\n\tZ* tmp = new Z[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void merge(Thread& th, int64_t an, V* a, Z* az, int64_t bn, V* b, Z* bz, V* c, Z* cz, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, Z* az, int64_t bn, Z* b, Z* bz, Z* c, Z* cz, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, Z* az, V* c, Z* cz, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* az, Z* c, Z* cz, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\n\nstatic void grade(Thread& th, int64_t n, const V* in, Z* zout, CompareFun* compare)\n{\n\tV* out = new V[n];\n\tV* tmp = new V[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void grade(Thread& th, int64_t n, const Z* in, Z* zout, ZCompareFun* compare)\n{\n\tZ* out = new Z[n];\n\tZ* tmp = new Z[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void sort_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void sortf_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"sort : fun\");\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(list->ItemType(), n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void sort_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void gradef_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"grade : fun\");\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFN(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP);\n#define DEFNnoeach(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP, V(0.), true);\n\nvoid AddStreamOps();\nvoid AddStreamOps()\n{\n\tinitFFT();\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\ts_dur = getsym(\"dur\");\n\tdtTableMap = new TableMap(V(s_dt));\n\trestTableMap = new TableMap(3);\n\trestTableMap->put(0, s_out, s_out->Hash());\n\trestTableMap->put(1, s_dur, s_dur->Hash());\n\trestTableMap->put(2, s_dt, s_dt->Hash());\n\t\n\tvm.addBifHelp(\"\\n*** list conversion ***\");\n\tDEF(V, 1, 1, \"(signal --> stream) converts a signal or string to a stream.\")\n\tDEF(Z, 1, 1, \"(series --> signal) converts a stream or string to a signal.\")\t\n\tDEF(L, 1, 1, \"(anything --> stream) streams are returned as is. anything else is made into an infinite stream of itself.\")\n\tDEF(L1, 1, 1, \"(anything --> stream) streams are returned as is. anything else is wrapped in a one item list.\")\n\tDEF(unspell, 1, 1, \"(sequence --> string) converts a stream of numbers or a signal to a string.\")\n\n\tvm.addBifHelp(\"\\n*** basic list operations ***\");\n\n\tDEF(size, 1, 1, \"(seq --> num) Return the length of a sequence if it is finite. Returns inf if the sequence is of indefinite length (It may not actually be infinitely long).\")\n\tDEF(rank, 1, 1, \"(a --> n) Return the rank of an object. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(shape, 1, 1, \"(a --> [n..]) Return the shape of an object. Axes of indefinite length are represented by inf. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(finite, 1, 1, \"(seq --> bool) Returns 1 if the sequence is finite, 0 if indefinite.\")\n\n\tDEF(empty, 1, 1, \"(list --> bool) returns whether the list is empty.\")\n\tDEF(nonempty, 1, 1, \"(list --> bool) returns whether the list is nonempty.\")\n\tDEF(head, 1, 1, \"(list --> item) returns first item of list. fails if list is empty.\")\n\tDEF(tail, 1, 1, \"(list --> list) returns the rest of the list after the first item. fails if list is empty.\")\n\tDEF(add, 2, 1, \"(list item --> list) returns a new list with the item added to the end.\")\t\n\tDEF(cons, 2, 1, \"(list item --> list) returns a new list with the item added to the front.\")\t\n\tDEF(uncons, 1, 2, \"(list --> tail head) returns the tail and head of a list. fails if list is empty.\")\n\tDEF(pack, 1, 1, \"(list --> list) returns a packed version of the list.\");\n\tDEF(packed, 1, 1, \"(list --> bool) returns whether the list is packed.\");\n\n\tvm.addBifHelp(\"\\n*** list generation ***\");\n\n\tDEFnoeach(ord, 0, 1, \"(--> series) return an infinite series of integers ascending from 1.\")\n\tDEFnoeach(nat, 0, 1, \"(--> series) return an infinite series of integers ascending from 0.\")\n\tDEFnoeach(invs, 0, 1, \"(--> series) return an infinite series of reciprocals. equivalent to ord 1/\")\n\tDEFnoeach(negs, 0, 1, \"(--> series) return an infinite series of integers descending from -1.\")\n\tDEFnoeach(evens, 0, 1, \"(--> series) return an infinite series of ascending non-negative even integers.\")\n\tDEFnoeach(odds, 0, 1, \"(--> series) return an infinite series of ascending non-negative odd integers.\")\n\tDEFnoeach(ints, 0, 1, \"(--> series) return the infinite series [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primes, 0, 1, \"(--> series) returns a finite series of prime numbers up to 1000039.\")\n\tDEFAM(fib, kk, \"(a b --> series) returns a fibonacci series starting with the two numbers given.\") \n\n\tDEFnoeach(ordz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 1.\")\n\tDEFnoeach(natz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 0.\")\n\tDEFnoeach(invz, 0, 1, \"(--> signal) return an infinite signal of reciprocals. equivalent to ordz 1/\")\n\tDEFnoeach(negz, 0, 1, \"(--> signal) return an infinite signal of integers descending from -1.\")\n\tDEFnoeach(evenz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative even integers.\")\n\tDEFnoeach(oddz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative odd integers.\")\n\tDEFnoeach(intz, 0, 1, \"(--> signal) return the infinite signal [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primez, 0, 1, \"(--> signal) returns a finite signal of prime numbers up to 1000039.\")\t\n\tDEFMCX(fibz, 2, \"(a b --> signal) returns a fibonacci signal starting with the two numbers given.\")\n\n\tDEFAM(ninvs, k, \"(n --> stream) return a finite stream of n reciprocals. equivalent to n 1 1 nby 1/\")\n\tDEFMCX(ninvz, 1, \"(n --> signal) return a finite signal of n reciprocals. equivalent to n 1 1 nbyz 1/\")\n\t\n\tDEF(ever, 1, 1, \"(value --> series) return an infinite stream of value.\")\n\tDEFAM(by, kk, \"(start step --> series) return an infinite arithmetic series.\") \n\tDEFAM(nby, kkk, \"(n start step --> series) return a finite arithmetic series.\") \n\tDEFAM(grow, kk, \"(start step --> series) return an infinite geometric series.\") \n\tDEFAM(ngrow, kkk, \"(start step --> series) return a finite geometric series.\") \n\tDEFAM(to, kk, \"(a b --> series) return a finite series from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFMCX(everz, 1, \"(value --> signal) return an infinite signal of value.\")\n\tDEFMCX(byz, 2, \"(start step --> series) return an infinite arithmetic series as a signal.\") \n\tDEFMCX(nbyz, 3, \"(start step --> series) return a finite arithmetic series as a signal.\") \n\tDEFMCX(growz, 2, \"(start step --> series) return an infinite geometric series as a signal.\") \n\tDEFMCX(ngrowz, 3, \"(start step --> series) return a finite geometric series as a signal.\") \n\tDEFMCX(toz, 2, \"(a b --> series) return a finite signal from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFAM(lindiv, kkk, \"(n start end --> series) returns a series of n equal steps from start to end.\") \n\tDEFAM(expdiv, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start to end.\") \n\tDEFMCX(lindivz, 3, \"(n start end --> series) returns a signal of n equal steps from start to end.\") \n\tDEFMCX(expdivz, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start to end.\") \n\n\tDEFAM(lindiv1, kkk, \"(n start end --> series) returns a series of n equal steps from start up to but not including end.\") \n\tDEFAM(expdiv1, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start up to but not including end.\") \n\tDEFMCX(lindiv1z, 3, \"(n start end --> series) returns a signal of n equal steps from start up to but not including end.\") \n\tDEFMCX(expdiv1z, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start up to but not including end.\") \n\n\tDEFMCX(line, 3, \"(dur start end --> z) return a signal ramping linearly from start to end in dur seconds.\") // mcx\n\tDEFMCX(xline, 3, \"(dur start end --> z) return a signal ramping exponentially from start to end in dur seconds.\") // mcx\n\n\tvm.addBifHelp(\"\\n*** list reduction operations ***\");\n\tDEFAM(reduce, aak, \"(list value fun --> value) applies fun to each item in list and the current value to get a new value. returns the ending value.\")\n\tDEFAM(reduce1, ak, \"(list fun --> value) like reduce except that the initial value is the first item in the list.\")\n\n\tDEFAM(scan, aak, \"(list value fun --> list) applies fun to each item in list and the current value to get a new value, which is added to the output list.\")\n\tDEFAM(scan1, ak, \"(list fun --> list) like scan except that the initial value is the first item in the list.\")\n\tDEFAM(iter, ak, \"(value fun --> list) returns an infinite list of repeated applications of fun to value.\")\n\tDEFAM(itern, akk, \"(value fun n --> list) returns a list of n repeated applications of fun to value.\")\n \t\n\tDEFAM(chain, akk, \"(value fun n --> list) returns the result of n repeated applications of fun to value.\")\n \n\tvm.addBifHelp(\"\\n*** list ordering operations ***\");\n\tDEF(cyc, 1, 1, \"(list --> list) makes a finite list become cyclic.\")\n\tDEFAM(ncyc, ak, \"(n list --> list) concatenates n copies of a finite list.\")\n\tDEF(rcyc, 1, 1, \"(ref --> list) gets a new list from ref each time list is exhausted.\")\n\n\tvm.defautomap(\"X\", \"ak\", repeat_, \"(value n --> stream) makes a list containing n copies of value. If value is a function, then the results of applying the function with an integer count argument is used as the contents of the output list.\");\n\tvm.defmcx(\"XZ\", 2, repeatz_, \"(value n --> signal) returns a signal with value repeated n times.\");\n\tvm.defmcx(\"mum\", 1, mum_, \"(t --> signal) returns a signal of t seconds of silence.\");\n\n\tvm.def(\"$\", 2, 1, append_, \"(listA listB --> out) returns the concatenation of listA and listB.\");\n\tvm.defmcx(\"$z\", 2, append_, \"(signalA signalB --> signal) returns the concatenation of signalA and signalB.\");\n\t\n\tvm.def(\"$$\", 2, 1, appendSubs_, \"(listA listB --> out) return the concatenation of the sublists of listA and listB. equivalent to (listA @ listB @ $)\");\n\tvm.def(\"$/\", 1, 1, cat_, \"(list --> out) returns the concatenation of the sub-lists of the input list.\");\n\tDEF(flat, 1, 1, \"(list --> list) flattens a list.\")\n\tDEFAM(flatten, ak, \"(list n --> list) makes a list n levels flatter.\")\n\tvm.defautomap(\"keep\", \"ak\", N_, \"(list n --> list) returns a list of the first n items of the input list.\");\n\t\n\tDEFAM(T, zk, \"(signal t --> signal) returns a signal of the first t seconds of the input signal.\");\n\tvm.defautomap(\"T>\", \"zk\", skipT_, \"(signal t --> signal) skips the first t seconds of the input signal.\");\n\tvm.defautomap(\"N>\", \"ak\", skip_, \"(list n --> list) skips the first n items of the input list.\");\n\tvm.def(\"N>>\", 2, 1, hops_, \"(list hops --> listOfLists) returns a list of tails of the input list. equivalent to (list (hops 0 | L 0 cons +\\\\) N>).\");\n\tvm.defautomap(\"T>>\", \"za\", hopTs_, \"(signal hops --> listOfSignals) returns a list of tails of the input list. equivalent to (signal (hops 0 | L 0 cons +\\\\) T>).\");\n\tDEFAM(N, ak, \"(list n --> list) returns a list of the first n items of the input list.\") \n\tDEFAM(NZ, zk, \"(signal n --> signal) returns a signal of the first n items of the input signal. automaps over streams.\") \n\t\n\tDEFAM(skip, ak, \"(list n --> list) skips the first n items of the input list.\") \n\n\tDEFAM(take, ak, \"(list n --> list) returns a list of the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\tDEFAM(drop, ak, \"(list n --> list) skips the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\t\n\tDEFAM(choff, akk, \"(channel(s) c n --> out) takes a finite list of channels or a single signal and places it into an array of n channels beginning at offset c. Other channels are set to zero.\");\n\n\tDEF(tog, 2, 1, \"(a b --> series) return a series alternating between a and b.\")\n\tDEFMCX(togz, 2, \"(a b --> signal) return a signal alternating between a and b.\")\n\tDEF(sel, 2, 1, \"(a j --> out) select. a is a list of lists. out[i] is a[j][i]\")\n\tDEF(sell, 2, 1, \"(a j --> out) lazy select. a is a list of lists. out[i] is the next value from a[j].\")\n\n\tvm.def(\"?\", 2, 1, filter_, \"(a b --> out) the output list contains a[i] repeated b[i] times. If b is a list of booleans (1 or 0) then this functions as a filter.\");\n\tDEF(spread, 2, 1, \"(a n --> out) inserts n[i] zeroes after a[i].\")\t\n\tDEFMCX(spreadz, 2, \"(a n --> signal) inserts n[i] zeroes after a[i]. automaps over stream inputs.\")\t\n\n\tDEF(change, 1, 1, \"(a --> b) eliminates sequential duplicates in a signal or stream.\")\t\n\tDEFMCX(changez, 1, \"(a --> b) eliminates sequential duplicates in a signal. automaps over streams.\")\t\n\tDEF(expand, 2, 1, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out.\")\t\n\tDEFMCX(expandz, 2, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out. automaps over stream inputs.\")\t\n\n\tDEF(clump, 2, 1, \"(a n --> out) groups elements from list a into sub-lists of size n.\")\t\n\tDEF(hang, 1, 1, \"(a --> out) repeats the last value of a finite list indefinitely.\")\t\n\tDEFMCX(hangz, 1, \"(a --> out) repeats the last value of a finite signal indefinitely. automaps over streams.\")\t\n\tDEFAM(histo, ak, \"(a n --> out) makes a histogram of the finite stream a.\")\t\n\tvm.defautomap(\"histoz\", \"zk\", histo_, \"(a n --> out) makes a histogram of the finite signal a. automaps over streams.\");\n\n\tDEF(keepWhile, 2, 1, \"(a b --> out) return items from a while items from b are true.\")\n\tDEF(skipWhile, 2, 1, \"(a b --> out) skip items from a while items from b are true.\")\n\t\n\tDEF(flop, 1, 1, \"(a --> b) returns the transpose of the list of lists a. At least one of the dimensions must be finite.\")\t\n\tDEF(flops, 1, 1, \"(a --> b) like flop, but signals are treated as scalars and not flopped.\")\n\tDEF(flop1, 1, 1, \"(a --> b) like flop, but if list a is not a list of lists then it is wrapped in a list. compare: [[1 2 3][[4 5] 6 7]] @ flop $/ with: [[1 2 3][[4 5] 6 7]] @ flop1 $/\")\t\n\tDEF(lace, 1, 1, \"(a --> b) returns the concatenation of the transpose of the list of lists a.\")\t\n\tDEFAM(merge, aak, \"(a b fun --> c) merges two lists according to the function given. The function should work like <.\")\n\tDEFAM(mergec, aak, \"(a b fun --> c) merges two lists without duplicates according to the function given. The function should work like cmp.\")\n\t\n\tDEF(perms, 1, 1, \"(a --> b) returns a list of all permutations of the input list.\")\n\tDEFMCX(permz, 1, \"(a --> b) returns a list of all permutations of the input signal. automaps over streams.\")\n\t\n\tDEF(permswr, 1, 1, \"(a --> b) returns a list of all unique permutations of an input stream with repeated elements.\")\n\tDEFMCX(permzwr, 1, \"(a --> b) returns a returns a list of all unique permutations of an input signal with repeated elements. automaps over streams.\")\n\t\n\tDEF(shortas, 2, 1, \"(a b --> a') makes list a as short as list b.\")\n\tDEF(longas, 2, 1, \"(a b --> a') makes list a as long as list b by repeating the last item.\")\n\tDEF(longas0, 2, 1, \"(a b --> a') makes list a as long as list b by appending zeroes.\")\n\n\t// array ops\n\n\tvm.addBifHelp(\"\\n*** list ops ***\");\n\n\tDEF(bub, 1, 1, \"(a --> [a]) makes the top item on the stack into a one item list. i.e. puts a bubble around it.\")\n\tDEF(nbub, 2, 1, \"(a n --> [[..[a]..]]) embeds the top item in N one item lists.\")\n\n\tvm.def(\"2ple\", 2, 1, tupleN_<2>, \"(a b --> [a b]) make a pair from the top two stack items.\");\n\tvm.def(\"3ple\", 3, 1, tupleN_<3>, \"(a b c --> [a b c]) make a triple from the top three stack items.\");\n\tvm.def(\"4ple\", 4, 1, tupleN_<4>, \"(a b c d --> [a b c d]) make a quadriple from the top four stack items.\");\n\tvm.def(\"5ple\", 5, 1, tupleN_<5>, \"(a b c d e --> [a b c d e]) make a quintuple from the top five stack items.\");\n\tvm.def(\"6ple\", 6, 1, tupleN_<6>, \"(a b c d e f --> [a b c d e f]) make a sextuple from the top six stack items.\");\n\tvm.def(\"7ple\", 7, 1, tupleN_<7>, \"(a b c d e f g --> [a b c d e f g]) make a septuple from the top seven stack items.\");\n\tvm.def(\"8ple\", 8, 1, tupleN_<8>, \"(a b c d e f g h --> [a b c d e f g h]) make an octuple from the top eight stack items.\");\n\t\n\tvm.defautomap(\"2ples\", \"kk\", tupleN_<2>, \"(a b --> [[a0 b0][a1 b1]..[aN bN]]) make a sequence of pairs from the sequences a and b.\");\n\tvm.defautomap(\"3ples\", \"kkk\", tupleN_<3>, \"(a b c --> [[a0 b0 c0][a1 b1 c1]..[aN bN cN]]) make a sequence of triples from the sequences a, b and c.\");\n\tvm.defautomap(\"4ples\", \"kkkk\", tupleN_<4>, \"(a b c d --> seq) make a sequence of quadruples from the sequences a, b, c and d.\");\n\tvm.defautomap(\"5ples\", \"kkkkk\", tupleN_<5>, \"(a b c d e --> seq) make a sequence of quintuples from the sequences a through e.\");\n\tvm.defautomap(\"6ples\", \"kkkkkk\", tupleN_<6>, \"(a b c d e f--> seq) make a sequence of sextuples from the sequences a through f.\");\n\tvm.defautomap(\"7ples\", \"kkkkkkk\", tupleN_<7>, \"(a b c d e f g--> seq) make a sequence of septuples from the sequences a through g.\");\n\tvm.defautomap(\"8ples\", \"kkkkkkkk\", tupleN_<8>, \"(a b c d e f g h --> seq) make a sequence of octuples from the sequences a through h.\");\n\n\tDEFNnoeach(\"un2\", 1, 2, untupleN_<2>, \"([a0 a1 .. aN-1] --> a0 a1) Push two items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un3\", 1, 3, untupleN_<3>, \"([a0 a1 .. aN-1] --> a0 a1 a2) Push three items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un4\", 1, 4, untupleN_<4>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3) Push four items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un5\", 1, 5, untupleN_<5>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3 a4) Push five items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un6\", 1, 6, untupleN_<6>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a5) Push six items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un7\", 1, 7, untupleN_<7>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a6) Push seven items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un8\", 1, 8, untupleN_<8>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a7) Push eight items from a sequence onto the stack.\")\n\n\tDEF(reverse, 1, 1, \"(a --> b) reverses a finite sequence.\")\n\tDEF(mirror0, 1, 1, \"(a --> b) cyclic mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2]\")\n\tDEF(mirror1, 1, 1, \"(a --> b) odd mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2 1]\")\n\tDEF(mirror2, 1, 1, \"(a --> b) even mirror of a sequence. [1 2 3 4] --> [1 2 3 4 4 3 2 1]\")\n\tDEFAM(rot, ak, \"(seq M --> seq') rotation of a sequence by M places. M > 0 moves right.\") \n\tDEFAM(shift, ak, \"(seq M --> seq') shift of a sequence by M places. zeroes are shifted in to fill vacated positions.\") \n\tDEFAM(clipShift, ak, \"(seq M --> seq') shift of a sequence by M places. the end value is copied in to fill vacated positions.\") \n\tDEFAM(foldShift, ak, \"(seq M --> seq') shift of a sequence by M places. values from the cyclic mirrored sequence are copied in to fill vacated positions.\") \n\tDEF(muss, 1, 1, \"(a --> b) puts a finite sequence into a random order.\")\n\n\tDEF(at, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return zero.\") \n\tDEF(wrapAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the value at the end point.\") \n\tDEF(foldAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the items from the cyclic sequence.\") \n\tDEF(clipAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return items from the cyclic mirrored sequence.\") \n\tDEF(degkey, 2, 1, \"(degree scale --> converts scale degree(s) to keys, given a scale\");\n\tDEF(keydeg, 2, 1, \"(key scale --> converts key(s) to scale degree(s), given a scale\");\n\n\t\n\tDEF(sort, 1, 1, \"(in --> out) ascending order sort of the input list.\");\n\tDEFAM(sortf, ak, \"(in fun --> out) sort of the input list using a compare function.\");\n\tDEFN(\"sort>\", 1, 1, sort_gt_, \"(in --> out) descending order sort of the input list.\");\n\t\n\tDEF(grade, 1, 1, \"(in --> out) ascending order sorted indices of the input list.\");\n\tDEFAM(gradef, ak, \"(in fun --> out) sorted indices of the input list using a compare function.\");\n\tDEFN(\"grade>\", 1, 1, grade_gt_, \"(in --> out) descending order sorted indices of the input list.\");\n\n\tvm.addBifHelp(\"\\n*** event list operations ***\");\n\tDEFAM(evmerge, aak, \"(a b t --> c) merges event list 'b' with delay 't' with event list 'a' according to their delta times\")\n\tDEFAM(evdelay, ak, \"(a t --> c) delay an event list by adding a preceeding rest of duration 't'\")\n\tDEFAM(evrest, aak, \"(t --> c) returns a rest event for duration 't'.\")\n\t\n\tvm.addBifHelp(\"\\n*** dsp operations ***\");\n\t\n\tDEFMCX(kaiser, 2, \"(n stopBandAttenuation --> out) returns a signal filled with a kaiser window with the given stop band attenuation.\")\n\tDEFMCX(hanning, 1, \"(n --> out) returns a signal filled with a Hanning window.\")\n\tDEFMCX(hamming, 1, \"(n --> out) returns a signal filled with a Hamming window.\")\n\tDEFMCX(blackman, 1, \"(n --> out) returns a signal filled with a Blackman window.\")\n\tDEFMCX(fft, 2, \"(re im --> out) returns the complex FFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\tDEFMCX(ifft, 2, \"(re im --> out) returns the complex IFFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\n\tDEFAM(seg, zaa, \"(in hops durs --> out) divide input signal in to a stream of signal segments of given duration stepping by hop time.\")\n\tDEFAM(wseg, zaz, \"(in hops window --> out) divide input signal in to a stream of windowed signal segments of lengths equal to the window length, stepping by hop time.\")\n\n\tvm.addBifHelp(\"\\n*** audio I/O operations ***\");\n\tDEF(play, 1, 0, \"(channels -->) plays the audio to the hardware.\")\n\tDEF(record, 2, 0, \"(channels filename -->) plays the audio to the hardware and records it to a file.\")\n\tDEFnoeach(stop, 0, 0, \"(-->) stops any audio playing.\")\n\tvm.def(\"sf>\", 1, 0, sfread_, \"(filename -->) read channels from an audio file. not real time.\");\n\tvm.def(\">sf\", 2, 0, sfwrite_, \"(channels filename -->) writes the audio to a file.\");\n\tvm.def(\">sfo\", 2, 0, sfwriteopen_, \"(channels filename -->) writes the audio to a file and opens it in the default application.\");\n\t//vm.def(\"sf>\", 2, sfread_);\n\tDEF(bench, 1, 0, \"(channels -->) prints the amount of CPU required to compute a segment of audio. audio must be of finite duration.\")\t\n\tvm.def(\"sgram\", 3, 0, sgram_, \"(signal dBfloor filename -->) writes a spectrogram to a file and opens it.\");\n\n\tsetSessionTime();\n\n}\n\n"], ["/sapf/src/OscilUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n\n#include \"OscilUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"dsp.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst int kNumTables = 30; // third octave tables.\nconst int kWaveTableSize = 16384;\nconst int kWaveTableMask = kWaveTableSize - 1;\n//const int kWaveTableByteSize = kWaveTableSize * sizeof(Z);\nconst int kWaveTableTotalSize = kWaveTableSize * kNumTables;\n//const Z kPhaseInc = kTwoPi / kWaveTableSize;\nconst Z kWaveTableSizeF = kWaveTableSize;\n\n// the maximum number of harmonics is actually 1024, but 1290 is needed for extrapolation.\nconst int kMaxHarmonics = 1290;\nconst int gNumHarmonicsForTable[kNumTables+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 101, 128, 161, 203, 256, 322, 406, 512, 645, 812, 1024, 1290 };\n\nint gWaveTableSize[kNumTables];\n\nconst double kMaxHarmonicsF = kMaxHarmonics;\n\n\nZ gTableForNumHarmonics[kMaxHarmonics+1];\nZ gHertzToHarmonics[kMaxHarmonics+1];\n\nstatic void fillHarmonicsTable()\n{\t\n\tdouble maxval = kNumTables - 1.0000001;\n\t\n\tint t = 0;\n\tfor (int i = 1; i < kMaxHarmonics; ++i) {\n\t\tif (gNumHarmonicsForTable[t] < i && t < kNumTables) ++t;\n\t\t//int t1 = std::clamp(t-1, 0, kNumTables-1);\n\t\t\n\t\tdouble frac = (double)(i - gNumHarmonicsForTable[t]) / (double)(gNumHarmonicsForTable[t] - gNumHarmonicsForTable[t-1]);\n\t\tdouble ft = t - 1 + frac;\n\t\tgTableForNumHarmonics[i] = ft;\n\t}\n\t\t\n\tgTableForNumHarmonics[0] = 0.;\n\tgTableForNumHarmonics[kMaxHarmonics] = maxval;\n}\n\nstatic void zeroTable(size_t n, Z* table)\n{\n\tmemset(table, 0, n * sizeof(Z));\n}\n\nstatic void normalize(int n, Z* buf)\n{\n\tZ maxabs = 0.;\n\tfor (int i = 0; i < n; ++i) {\n\t\tmaxabs = std::max(maxabs, fabs(buf[i]));\n\t}\n\tif (maxabs > 0.) {\n\t\tZ scale = 1. / maxabs;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tbuf[i] *= scale;\n\t\t}\n\t}\n}\n\n\nstatic void fillWaveTable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* table)\n{\n\tconst size_t kWaveTableSize2 = kWaveTableSize / 2;\n\tconst Z two_pi = 2. * M_PI;\n\t\n\tZ real[kWaveTableSize2];\n\tZ imag[kWaveTableSize2];\n\tZ polar[kWaveTableSize];\n\tZ rect[kWaveTableSize];\n\t\n\tzeroTable(kWaveTableSize2, real);\n\tzeroTable(kWaveTableSize2, imag);\n\n\n\tZ w = M_PI_2 / n;\n\tfor (int i = 0; i < n; ++i) {\n\t\tZ smoothAmp = smooth == 0. ? 1. : pow(cos(w*i), smooth);\n\t\t//fillHarmonic(i+1, *amps * smoothAmp, *phases, table);\n\t\treal[i+1] = *amps * smoothAmp;\n\t\timag[i+1] = (*phases - .25) * two_pi;\n\t\tamps += ampStride;\n\t\tphases += phaseStride;\n\t}\n\t\n\tDSPDoubleSplitComplex in;\n\tin.realp = real;\n\tin.imagp = imag;\n\t\n\tvDSP_ztocD(&in, 1, (DSPDoubleComplex*)polar, 2, kWaveTableSize2);\n\tvDSP_rectD(polar, 2, rect, 2, kWaveTableSize2);\n\tvDSP_ctozD((DSPDoubleComplex*)rect, 2, &in, 1, kWaveTableSize2);\n\trifft(kWaveTableSize, real, imag, table);\n}\n\nstatic void fill3rdOctaveTables(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* tables)\n{\t\n\t// tables is assumed to be allocated to kNumTables * kWaveTableSize samples\n\tfor (int i = 0; i < kNumTables; ++i) {\n\t\tint numHarmonics = std::min(n, gNumHarmonicsForTable[i]);\n\t\tfillWaveTable(numHarmonics, amps, ampStride, phases, phaseStride, smooth, tables + i * kWaveTableSize);\n\t}\n\t\n\tnormalize(kWaveTableTotalSize, tables);\n}\n\nstatic P makeWavetable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth)\n{\n\tP list = new List(itemTypeZ, kWaveTableTotalSize);\n\tP array = list->mArray;\n\t\n\tZ* tables = array->z();\n\t\t\n\tfill3rdOctaveTables(n, amps, ampStride, phases, phaseStride, smooth, tables);\n\tarray->setSize(kWaveTableTotalSize);\n\t\n\treturn list;\n}\n\nstatic void wavefill_(Thread& th, Prim* prim)\n{\n\tZ smooth = th.popFloat(\"wavefill : smooth\");\n\tV phases = th.popZIn(\"wavefill : phases\");\n\tV amps = th.popZIn(\"wavefill : amps\");\n\t\t\n\tP ampl;\n\tP phasel;\n\tZ *phasez, *ampz;\n\tint phaseStride, ampStride; \n\tint64_t n = kMaxHarmonics;\n\tif (phases.isZList()) {\n\t\tphasel = ((List*)phases.o())->packSome(th, n);\n\t\tphasez = phasel->mArray->z();\n\t\tphaseStride = 1;\n\t} else {\n\t\tphasez = &phases.f;\n\t\tphaseStride = 0;\n\t}\n\t\n\tif (amps.isZList()) {\n\t\tampl = ((List*)amps.o())->packSome(th, n);\n\t\tampz = ampl->mArray->z();\n\t\tampStride = 1;\n\t} else {\n\t\tampz = &s.f;\n\t\tampStride = 0;\n\t}\n\t\n\tP list = makeWavetable((int)n, ampz, ampStride, phasez, phaseStride, smooth);\n\tth.push(list);\n}\n\nP gParabolicTable;\nP gTriangleTable;\nP gSquareTable;\nP gSawtoothTable;\n\nstatic void makeClassicWavetables()\n{\n\t//fprintf(stdout, \"computing wave tables\\n\");\n\tZ amps[kMaxHarmonics+1];\n\tZ phases[kMaxHarmonics+1];\n\tZ smooth = 0.;\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i;\n\t}\n\tphases[0] = .25;\n\tgParabolicTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = -1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i;\n\t}\n\n\tphases[0] = 0.;\n\tgTriangleTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t++i;\n\t}\n\tphases[0] = 0.;\n\tgSquareTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i;\n\t}\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tphases[i] = 0.;\t\t++i;\n\t\tphases[i] = .5;\t\t++i;\n\t}\n\tgSawtoothTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases+1, 1, smooth);\n\t\n\tvm.addBifHelp(\"\\n*** classic wave tables ***\");\n\tvm.def(\"parTbl\", gParabolicTable);\t\tvm.addBifHelp(\"parTbl - parabolic wave table.\");\n\tvm.def(\"triTbl\", gTriangleTable);\t\tvm.addBifHelp(\"triTbl - triangle wave table.\");\n\tvm.def(\"sqrTbl\", gSquareTable);\t\t\tvm.addBifHelp(\"sqrTbl - square wave table.\");\n\tvm.def(\"sawTbl\", gSawtoothTable);\t\tvm.addBifHelp(\"sawTbl - sawtooth wave table.\");\n\n\t//fprintf(stdout, \"done computing wave tables\\n\");\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Osc : public ZeroInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOsc(Thread& th, P const& inArray, Z ifreq, Z iphase) : ZeroInputUGen(th, false),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscPM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOscPM(Thread& th, P const& inArray, Z ifreq, Arg phasemod) : OneInputUGen(th, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* phasemod, int phasemodStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscFM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFM(Thread& th, P const& inArray, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\t\t\t\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstruct OscFMPM : public TwoInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFMPM(Thread& th, P const& inArray, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFMPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstatic void newOsc(Thread& th, Arg freq, Arg phase, P const& tables)\n{\n\tif (freq.isZList()) {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscFMPM(th, tables->mArray, freq, phase)));\n\t\t} else {\n\t\t\tth.push(new List(new OscFM(th, tables->mArray, freq, phase.asFloat())));\n\t\t}\n\t} else {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscPM(th, tables->mArray, freq.asFloat(), phase)));\n\t\t} else {\n\t\t\tth.push(new List(new Osc(th, tables->mArray, freq.asFloat(), phase.asFloat())));\n\t\t}\n\t}\n}\n\n\nstatic void osc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"osc : tables\");\n\tV phase = th.popZIn(\"osc : phase\");\n\tV freq = th.popZIn(\"osc : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"osc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tnewOsc(th, freq, phase, tables);\n}\n\nstatic void par_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"par : phase\");\n\tV freq = th.popZIn(\"par : freq\");\n\n\tnewOsc(th, freq, phase, gParabolicTable);\n}\n\nstatic void tri_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"tri : phase\");\n\tV freq = th.popZIn(\"tri : freq\");\n\n\tnewOsc(th, freq, phase, gTriangleTable);\n}\n\nstatic void saw_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"saw : phase\");\n\tV freq = th.popZIn(\"saw : freq\");\n\n\tnewOsc(th, freq, phase, gSawtoothTable);\n}\n\nstatic void square_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"square : phase\");\n\tV freq = th.popZIn(\"square : freq\");\n\n\tnewOsc(th, freq, phase, gSquareTable);\n}\n\nstruct OscPWM : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscPWM(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscPWM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\n\t\t\tZ pphase2 = pphase1 + *duty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\t\t\tout[i] = .5 * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct VarSaw : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tVarSaw(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"VarSaw\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\t\t\t\n\t\t\tZ zduty = std::clamp(*duty, .01, .99);\n\t\t\tZ pphase2 = pphase1 + zduty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\n\t\t\tZ amp = .25 / (zduty - zduty * zduty);\n\t\t\tout[i] = amp * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstatic void oscp_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"oscp : tables\");\n\tV duty = th.popZIn(\"oscp : phaseOffset\");\n\tV phase = th.popZIn(\"oscp : phase\");\n\tV freq = th.popZIn(\"oscp : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"oscp : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void pulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"pulse : phaseOffset\");\n\tV phase = th.popZIn(\"pulse : phase\");\n\tV freq = th.popZIn(\"pulse : freq\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void vsaw_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"vsaw : phaseOffset\");\n\tV phase = th.popZIn(\"vsaw : phase\");\n\tV freq = th.popZIn(\"vsaw : freq\");\n\n\tP tables = gParabolicTable;\n\n\tth.push(new List(new VarSaw(th, tables->mArray, freq, phase, duty)));\n}\n\n\n\nstruct SyncOsc : public TwoInputUGen\n{\n\tP const array;\n\tZ sinePhaseStart;\n\tZ sinePhaseReset;\n\tZ sinePhaseEnd;\n Z wavePhaseResetRatio;\n\tZ phase1;\n\tZ phase2a;\n\tZ phase2b;\n\tZ freqmul1;\n\tZ freqmul2;\n\tZ freqLimit;\n\tZ* tables;\n bool once = true;\n\t\n\tSyncOsc(Thread& th, P const& inArray, Arg freq1, Arg freq2) : TwoInputUGen(th, freq1, freq2),\n\t\tarray(inArray),\n sinePhaseStart(kSineTableSize/4),\n\t\tsinePhaseReset(kSineTableSize/2),\n\t\tsinePhaseEnd(sinePhaseStart + sinePhaseReset),\n wavePhaseResetRatio(kWaveTableSizeF / sinePhaseReset),\n\t\tphase1(sinePhaseStart), \n phase2a(0.), \n phase2b(0.),\n\t\tfreqmul1(.5 * th.rate.radiansPerSample * gInvSineTableOmega),\n\t\tfreqmul2(kWaveTableSizeF * th.rate.invSampleRate),\n\t\tfreqLimit(th.rate.freqLimit),\n\t\ttables(array->z())\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SyncOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq1, Z* freq2, int freq1Stride, int freq2Stride)\n\t{\n if (once) {\n once = false;\n phase2b = kWaveTableSizeF * (fabs(*freq2) / fabs(*freq1));\n }\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq1 = fabs(*freq1);\n\t\t\tZ ffreq2 = fabs(*freq2);\n\t\t\tfreq1 += freq1Stride;\n\t\t\tfreq2 += freq2Stride;\n\t\t\t\t\t\t\t\t\t\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq2), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase2a = floor(phase2a);\n\t\t\tint index2a = (int)iphase2a;\n\t\t\tZ fracphase2a = phase2a - iphase2a;\n\n\t\t\tZ iphase2b = floor(phase2b);\n\t\t\tint index2b = (int)iphase2b;\n\t\t\tZ fracphase2b = phase2b - iphase2b;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates an (extremely quiet) broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ sawA = oscilLUT2(tableA, tableB, index2a, mask, fracphase2a, fractable);\n\t\t\tZ sawB = oscilLUT2(tableA, tableB, index2b, mask, fracphase2b, fractable);\n\t\t\t\n\t\t\tZ window = .5 - .5 * tsinx(phase1);\n\t\t\tout[i] = sawB + window * (sawA - sawB);\n \n\t\t\tZ freq2inc = ffreq2 * freqmul2;\n\n\t\t\tphase2a += freq2inc;\n\t\t\tif (phase2a >= kWaveTableSizeF) phase2a -= kWaveTableSizeF;\n\n\t\t\tphase2b += freq2inc;\n\t\t\tif (phase2b >= kWaveTableSizeF) phase2b -= kWaveTableSizeF;\n\n\t\t\tphase1 += ffreq1 * freqmul1;\n\t\t\tif (phase1 >= sinePhaseEnd) {\n\t\t\t\tphase1 -= sinePhaseReset;\n \n // reset and swap phases\n phase2b = phase2a;\n phase2a = wavePhaseResetRatio * (phase1 - sinePhaseStart) * (ffreq2 / ffreq1); // reset to proper fractional position. \n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ssaw_(Thread& th, Prim* prim)\n{\n\tV freq2 = th.popZIn(\"ssaw : freq2\");\n\tV freq1 = th.popZIn(\"ssaw : freq1\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\nstatic void sosc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"sosc : tables\");\n\tV freq2 = th.popZIn(\"sosc : freq2\");\n\tV freq1 = th.popZIn(\"sosc : freq1\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"sosc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFSaw : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFSaw2 : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw2(Thread& th, Arg freq, Arg phasem) : TwoInputUGen(th, freq, phasem), phase(0.), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw2\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasem, int freqStride, int phasemStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ pphase = phase + 2. * *phasem - 1.;\n\t\t\tif (pphase >= 1.) do { pphase -= 2.; } while (pphase >= 1.);\n\t\t\telse if (pphase < -1.) do { pphase += 2.; } while (pphase < -1.);\n\t\t\tout[i] = pphase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFTri : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFTri(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(2. * th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFTri\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase <= 1. ? phase : 2. - phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 3.) phase -= 4.;\n\t\t\telse if (phase < -1.) phase += 4.;\n\t\t}\n\t}\n};\n\nstatic void lfsaw_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsaw : phase\");\n\tV freq = th.popZIn(\"lfsaw : freq\");\n\n\tth.push(new List(new LFSaw(th, freq, phase)));\n}\n\nstatic void lftri_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lftri : phase\");\n\tV freq = th.popZIn(\"lftri : freq\");\n\n\tth.push(new List(new LFTri(th, freq, phase)));\n}\n\nstruct LFPulse : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulse(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? 1. : 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? 1.f : 0.f;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFPulseBipolar : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulseBipolar(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulseBipolar\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? *duty : *duty - 1. ;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? *duty : *duty - 1.;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFSquare : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSquare(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSquare\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\tout[i] = phase < .5 ? 1. : -1.;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Vosim : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tVosim(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invSampleRate), freqLimit(.5*th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = (freqLimit / *freq);\n\t\t\tout[i] = sc_squared(std::sin(M_PI*std::min(maxnth, *nth)*phase)) * sc_squared(1.-phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\telse if (phase < 0.) phase += 1.;\n\t\t}\n\t}\n};\n\n\nstatic void vosim_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"vosim : n\");\n\tZ phase = th.popFloat(\"vosim : phase\");\n\tV freq = th.popZIn(\"vosim : freq\");\n\n\tth.push(new List(new Vosim(th, freq, phase, n)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SmoothSaw : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSaw(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tout[i] = phase-phase*std::pow(std::abs(phase),std::min(maxnth, *nth));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct SmoothSawPWM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSawPWM(Thread& th, Arg freq, Z iphase, Arg nth, Arg duty) : ThreeInputUGen(th, freq, nth, duty), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, Z* duty, int freqStride, int nthStride, int dutyStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tZ w = *duty;\n\t\t\tZ u = .5*phase - .5;\n\t\t\tZ wphase = (w+u)/(w*phase-u);\n\t\t\tout[i] = wphase*(1.-std::pow(std::abs(phase),std::min(maxnth, *nth)));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tduty += dutyStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\n\nstatic void smoothsawpwm_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"smoothsawpwm : duty\");\n\tV n = th.popZIn(\"smoothsawpwm : n\");\n\tZ phase = th.popFloat(\"smoothsawpwm : phase\");\n\tV freq = th.popZIn(\"smoothsawpwm : freq\");\n\n\tth.push(new List(new SmoothSawPWM(th, freq, phase, n, duty)));\n}\n\n\nstatic void smoothsaw_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"smoothsaw : n\");\n\tZ phase = th.popFloat(\"smoothsaw : phase\");\n\tV freq = th.popZIn(\"smoothsaw : freq\");\n\n\tth.push(new List(new SmoothSaw(th, freq, phase, n)));\n}\n\nstatic void lfpulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulse : duty\");\n\tZ phase = th.popFloat(\"lfpulse : phase\");\n\tV freq = th.popZIn(\"lfpulse : freq\");\n\n\tth.push(new List(new LFPulse(th, freq, phase, duty)));\n}\n\nstatic void lfpulseb_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulseb : duty\");\n\tZ phase = th.popFloat(\"lfpulseb : phase\");\n\tV freq = th.popZIn(\"lfpulseb : freq\");\n\n\tth.push(new List(new LFPulseBipolar(th, freq, phase, duty)));\n}\n\nstatic void lfsquare_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsquare : phase\");\n\tV freq = th.popZIn(\"lfsquare : freq\");\n\n\tth.push(new List(new LFSquare(th, freq, phase)));\n}\n\n\n\n\nstruct Impulse : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tImpulse(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t\tif (phase == 0.) phase = 1.; // force an initial impulse.\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Impulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\tout[i] = 1.;\n\t\t\t} else {\n\t\t\t\tout[i] = 0.;\n\t\t\t}\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstatic void impulse_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"impulse : phase\");\n\tV freq = th.popZIn(\"impulse : freq\");\n\n\tth.push(new List(new Impulse(th, freq, phase)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct SinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n#if 1\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n#else\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n#endif\n\t}\n};\n\nstruct SinOsc2 : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc2(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc2\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct TSinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tTSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"TSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\n\nstruct FSinOsc : public ZeroInputUGen\n{\n\tZ freq;\n\tZ b1, y1, y2;\n\t\n\tFSinOsc(Thread& th, Z ifreq, Z iphase) : ZeroInputUGen(th, false), \n\t\tfreq(ifreq * th.rate.radiansPerSample), \n\t\tb1(2. * cos(freq))\n\t{\n\t\tiphase = sc_wrap(iphase, 0., 1.) * kTwoPi;\n\t\ty1 = sin(iphase-freq);\n\t\ty2 = sin(iphase-2.*freq);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ zy1 = y1;\n\t\tZ zy2 = y2;\n\t\tZ zb1 = b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = zb1 * zy1 - zy2;\n\t\t\tout[i] = y0;\n\t\t\tzy2 = zy1;\n\t\t\tzy1 = y0;\n\t\t}\n\t\ty1 = zy1;\n\t\ty2 = zy2;\n\t}\n};\n\n\n\nstruct SinOscPMFB : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ y1;\n\t\n\tSinOscPMFB(Thread& th, Arg freq, Z iphase, Arg phasefb) : TwoInputUGen(th, freq, phasefb), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMFB\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasefb, int freqStride, int phasefbStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = sin(phase + *phasefb * y1);\n\t\t\tout[i] = y0;\n\t\t\ty1 = y0;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasefb += phasefbStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPM : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPM(Thread& th, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase + *phasemod * kTwoPi;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n\t}\n};\n\nstruct SinOscM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscM(Thread& th, Arg freq, Z iphase, Arg mul, Arg add) : ThreeInputUGen(th, freq, mul, add), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* mul, Z* add, int freqStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPMM : public FourInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPMM(Thread& th, Arg freq, Arg phasemod, Arg mul, Arg add)\n\t\t: FourInputUGen(th, freq, phasemod, mul, add), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* mul, Z* add, int freqStride, int phasemodStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase + *phasemod) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void tsinosc_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"tsinosc : iphase\");\n\tV freq = th.popZIn(\"tsinosc : freq\");\n\n th.push(new List(new SinOsc2(th, freq, phase)));\n}\n\nstatic void sinosc_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"sinosc : phase\");\n\tV freq = th.popZIn(\"sinosc : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPM(th, freq, phase)));\n\t} else if (freq.isZList()) {\n\t\tth.push(new List(new SinOsc(th, freq, phase.f)));\n\t} else {\n\t\tth.push(new List(new FSinOsc(th, freq.f, phase.f)));\n\t}\n}\n\nstatic void sinoscm_(Thread& th, Prim* prim)\n{\n\tV add = th.popZIn(\"sinoscm : mul\");\n\tV mul = th.popZIn(\"sinoscm : add\");\n\tV phase = th.popZIn(\"sinoscm : phase\");\n\tV freq = th.popZIn(\"sinoscm : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPMM(th, freq, phase, mul, add)));\n\t} else {\n\t\tth.push(new List(new SinOscM(th, freq, phase.f, mul, add)));\n\t}\n}\n\n\nstatic void sinoscfb_(Thread& th, Prim* prim)\n{\n\tV fb = th.popZIn(\"sinoscfb : fb\");\n\tZ iphase = th.popFloat(\"sinoscfb : phase\");\n\tV freq = th.popZIn(\"sinoscfb : freq\");\n\n\tth.push(new List(new SinOscPMFB(th, freq, iphase, fb)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Blip : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ nyq_;\n\tBlip(Thread& th, Arg freq, Z iphase, Arg numharms)\n\t\t: TwoInputUGen(th, freq, numharms), phase(sc_wrap(2. * iphase - 1., -1., 1.)), freqmul(th.rate.radiansPerSample),\n\t\tnyq_(th.rate.sampleRate * .5)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Blip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* numharms, int freqStride, int numharmsStride) \n\t{\n\t\tZ nyq = nyq_;\n\t\t\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\t\t\tZ ffreq = *freq * freqmul;\n\n\t\t\tZ maxN = floor(nyq / ffreq);\n\t\t\tZ N = *numharms;\n\t\t\t\n\t\t\tif (N > maxN) N = maxN;\n\t\t\telse if (N < 1.) N = 1.;\n\t\t\t\n\t\t\tZ Na = floor(N);\n\t\t\tZ Nb = Na + 1.;\n\t\t\t\n\t\t\tZ frac = N - Na;\n\t\t\tZ Na_scale = .5 / Na;\n\t\t\tZ Nb_scale = .5 / Nb;\n\n\t\t\tZ Na2 = 2. * Na + 1.;\n\t\t\tZ Nb2 = Na2 + 2.;\n\n\t\t\tZ d = 1. / sin(phase);\n\t\t\tZ a = Na_scale * (sin(Na2 * phase) * d - 1.);\n\t\t\tZ b = Nb_scale * (sin(Nb2 * phase) * d - 1.);\n\n\t\t\tfrac = sc_scurve0(frac); // this eliminates out a broadband tick in the spectrum.\n\n\t\t\tout[i] = a + frac * (b - a);\n\n\t\t\tphase += ffreq;\n\t\t\tfreq += freqStride;\n\t\t\tnumharms += numharmsStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < -kTwoPi) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void blip_(Thread& th, Prim* prim)\n{\n\tV numharms = th.popZIn(\"blip : numharms\");\n\tZ phase = th.popFloat(\"blip : phase\");\n\tV freq = th.popZIn(\"blip : freq\");\n\n\tth.push(new List(new Blip(th, freq, phase, numharms)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF1 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF1(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF1\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = *coef;\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scale = (a - 1.)/(an1 - 1.);\n\t\t\tout[i] = scale * (sin(p1) - a * sin(p1-p2) - an1 * (sin(p1 + N1*p2) - a * sin(p1 + N*p2)))/(1. + a2 - 2. * a * cos(p2));\nprintf(\"%d %f\\n\", i, out[i]);\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf1_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf1 : numharms\");\n\tV coef = th.popZIn(\"dsf1 : coef\");\n\tV modRatio = th.popZIn(\"dsf1 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf1 : carRatio\");\n\tV freq = th.popZIn(\"dsf1 : freq\");\n\n\tth.push(new List(new DSF1(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF3 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF3(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF3\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = std::clamp(*coef, -.9999, .9999);\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scalePeak = (a - 1.)/(2.*an1 - a - 1.);\n\t\t\tZ scale = scalePeak;\n\t\t\tZ denom = (1. + a2 - 2. * a * cos(p2));\n\t\t\tout[i] = scale * sin(p1) * (1. - a2 - 2. * an1 * (cos(N1*p2) - a * cos(N*p2)))/denom;\n\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf3_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf3 : numharms\");\n\tV coef = th.popZIn(\"dsf3 : coef\");\n\tV modRatio = th.popZIn(\"dsf3 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf3 : carRatio\");\n\tV freq = th.popZIn(\"dsf3 : freq\");\n\n\tth.push(new List(new DSF3(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct KlangOsc\n{\n\tKlangOsc(Arg f, Arg a, Z p) :\n\t\tfreq(f), amp(a), phase(p) {}\n\t\t\n\tZIn freq;\n\tZIn amp;\n\tZ phase;\n};\n\nstruct Klang : public Gen\n{\n\tstd::vector _oscs;\n\tZ _freqmul, _K;\n\tZ _nyq, _cutoff, _slope;\n\t\n\tKlang(Thread& th, V freqs, V amps, V phases)\n\t\t: Gen(th, itemTypeZ, false),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 / th.rate.sampleRate),\n\t\t\t_nyq(th.rate.sampleRate * .5),\n\t\t\t_cutoff(_nyq * .8),\n\t\t\t_slope(1. / (_nyq - _cutoff))\n\t{\n\t\tint64_t numOscs = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, freqs.length(th));\n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, amps.length(th));\n\t\t}\n\t\tif (phases.isList()) {\n\t\t\tphases = ((List*)phases.o())->pack(th);\n\t\t\tnumOscs = std::min(numOscs, phases.length(th));\n\t\t}\n\t\t\n\t\tif (numOscs == LONG_MAX) numOscs = 1;\n\t\t\n\t\tfor (int64_t i = 0; i < numOscs; ++i) {\n\t\t\tKlangOsc kf(freqs.at(i), amps.at(i), phases.atz(i));\n\t\t\t_oscs.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"Klang\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\tZ* out0 = mOut->fulfillz(mBlockSize);\n\t\tmemset(out0, 0, mBlockSize * sizeof(Z));\n\t\tint maxToFill = 0;\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ nyq = _nyq;\n\t\tZ cutoff = _cutoff;\n\t\tZ slope = _slope;\n\t\tfor (size_t osc = 0; osc < _oscs.size(); ++osc) {\n\t\t\tint framesToFill = mBlockSize;\n\t\t\tKlangOsc& ko = _oscs[osc];\n\t\t\tZ phase = ko.phase;\n\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp;\n\t\t\t\tint n, freqStride, ampStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (ko.freq(th, n, freqStride, freq) || ko.amp(th, n, ampStride, amp)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ ffreq = *freq;\n\t\t\t\t\tif (ffreq > cutoff) {\n\t\t\t\t\t\tif (ffreq < nyq) {\n\t\t\t\t\t\t\tout[i] += (cutoff - ffreq) * slope * *amp * tsin(phase);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] += *amp * tsin(phase);\n\t\t\t\t\t}\n\t\t\t\t\tphase += ffreq * freqmul;\n\t\t\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tko.freq.advance(n);\n\t\t\t\tko.amp.advance(n);\n\t\t\t}\n\t\t\tko.phase = phase;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\nstatic void klang_(Thread& th, Prim* prim)\n{\n\tV phases\t= th.popZInList(\"klang : phases\");\n\tV amps\t\t= th.popZInList(\"klang : amps\");\n\tV freqs = th.popZInList(\"klang : freqs\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (phases.isVList() && !phases.isFinite())\n\t\tindefiniteOp(\"klank : phases\", \"\");\n\n\tth.push(new List(new Klang(th, freqs, amps, phases)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddOscilUGenOps()\n{\n\tfillHarmonicsTable();\n\n\tvm.addBifHelp(\"\\n*** wavetable generation ***\");\n\tDEFAM(wavefill, aak, \"(amps phases smooth -> wavetable) generates a set 1/3 octave wavetables for table lookup oscillators. sin(i*theta + phases[i])*amps[i]*pow(cos(pi*i/n), smooth). smoothing reduces Gibb's phenomenon. zero is no smoothing\")\n\t\n\tmakeClassicWavetables();\n\n\tvm.addBifHelp(\"\\n*** oscillator unit generators ***\");\n\t\n\tDEFMCX(osc, 3, \"(freq phase wavetable --> out) band limited wave table oscillator. wavetable is a table created with wavefill.\")\n\tDEFMCX(oscp, 4, \"(freq phase phaseOffset wavetable --> out) band limited wave table oscillator pair with phase offset.\")\n\tDEFMCX(sosc, 2, \"(freq1 freq2 wavetable --> out) band limited hard sync wave table oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(par, 2, \"(freq phase --> out) band limited parabolic wave oscillator.\")\n\tDEFMCX(tri, 2, \"(freq phase --> out) band limited triangle wave oscillator.\")\n\tDEFMCX(square, 2, \"(freq phase --> out) band limited square wave oscillator.\")\n\tDEFMCX(saw, 2, \"(freq phase --> out) band limited sawtooth wave oscillator.\")\n\tDEFMCX(pulse, 3, \"(freq phase duty --> out) band limited pulse wave oscillator.\")\n\tDEFMCX(vsaw, 3, \"(freq phase duty --> out) band limited variable sawtooth oscillator.\")\n\tDEFMCX(ssaw, 2, \"(freq1 freq2 --> out) band limited hard sync sawtooth oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(blip, 3, \"(freq phase numharms --> out) band limited impulse oscillator.\")\n\tDEFMCX(dsf1, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 1\")\n\tDEFMCX(dsf3, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) two sided bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 3\")\n\t\n\tDEFMCX(lftri, 2, \"(freq phase --> out) non band limited triangle wave oscillator.\")\n\tDEFMCX(lfsaw, 2, \"(freq phase --> out) non band limited sawtooth wave oscillator.\")\n\tDEFMCX(lfpulse, 3, \"(freq phase duty --> out) non band limited unipolar pulse wave oscillator.\")\n\tDEFMCX(lfpulseb, 3, \"(freq phase duty --> out) non band limited bipolar pulse wave oscillator.\")\n\tDEFMCX(lfsquare, 2, \"(freq phase --> out) non band limited square wave oscillator.\")\n\tDEFMCX(impulse, 2, \"(freq phase --> out) non band limited single sample impulse train oscillator.\")\n\tDEFMCX(smoothsaw, 3, \"(freq phase nth --> out) smoothed sawtooth.\")\n\tDEFMCX(smoothsawpwm, 4, \"(freq phase nth duty --> out) smoothed sawtooth.\")\n\tDEFMCX(vosim, 3, \"(freq phase nth --> out) vosim sim.\")\n\tDEFMCX(sinosc, 2, \"(freq phase --> out) sine wave oscillator.\")\n\tDEFMCX(tsinosc, 2, \"(freq iphase --> out) sine wave oscillator.\")\n\tDEFMCX(sinoscfb, 3, \"(freq phase feedback --> out) sine wave oscillator with self feedback phase modulation\")\n\tDEFMCX(sinoscm, 4, \"(freq phase mul add --> out) sine wave oscillator with multiply and add.\")\n\n\tDEF(klang, 3, 1, \"(freqs amps iphases --> out) a sine oscillator bank. freqs amps and iphases are arrays.\")\n}\n\n\n\n"], ["/sapf/src/UGen.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n\nstruct MulAdd : public ThreeInputUGen\n{\n\tMulAdd(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MulAdd\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = *a * *b + *c;\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_neg;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_minus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstatic void madd_(Thread& th, Prim* prim)\n{\n\tV c = th.popZIn(\"*+ : c\");\n\tV b = th.popZIn(\"*+ : b\");\n\tV a = th.popZIn(\"*+ : a\");\n\n\tif (a.isReal() && b.isReal() && c.isReal()) {\n\t\tth.push(a.f * b.f + c.f);\n\t} else {\n\t\tif (c.isReal()) {\n\t\t\tif (c.f == 0.) {\n\t\t\t\tif (a.isReal() && a.f == 1.) { th.push(b); return; }\n\t\t\t\tif (b.isReal() && b.f == 1.) { th.push(a); return; }\n\t\t\t\tif (a.isReal() && a.f == -1.) { th.push(b.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tif (b.isReal() && b.f == -1.) { th.push(a.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tth.push(a.binaryOp(th, gBinaryOpPtr_mul, b)); return;\n\t\t\t}\n\t\t}\n\t\tif (a.isReal()) {\n\t\t\tif (a.f == 0.) { th.push(c); return; }\n\t\t\tif (a.f == 1.) { th.push(b.binaryOp(th, gBinaryOpPtr_plus, c)); return; }\n\t\t\tif (a.f == -1.) { th.push(b.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tif (b.isReal()) {\n\t\t\tif (b.f == 0.) { th.push(c); return; } \n\t\t\tif (b.f == 1.) { th.push(a.binaryOp(th, gBinaryOpPtr_plus, c)); return; } \n\t\t\tif (b.f == -1.) { th.push(a.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tth.push(new List(new MulAdd(th, a, b, c)));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Fadeout : Gen\n{\n\tZIn _a;\n\tint64_t _sustainTime;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadeout(Thread& th, Arg a, Z sustainTime, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_sustainTime = (int64_t)floor(th.rate.sampleRate * sustainTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_sustainTime = std::max(1LL, _sustainTime);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadeout\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_sustainTime <= 0) {\n\t\t\tif (_fadeTime <= 0) {\n\t\t\t\tend();\n\t\t\t} else {\n\t\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t\t_fadeTime -= framesToFill;\n\t\t\t\twhile (framesToFill) {\n\t\t\t\t\tint n = framesToFill;\n\t\t\t\t\tint astride;\n\t\t\t\t\tZ *a;\n\t\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\t setDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t_amp = amp;\n\t\t\t\t\t\t_a.advance(n);\n\t\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\t\tout += n;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t produce(framesToFill);\n\t\t\t}\n\t\t} else {\n int framesToFill = (int)std::min(_sustainTime, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _sustainTime -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\n\nstruct Fadein : Gen\n{\n\tZIn _a;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadein(Thread& th, Arg a, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = .001;\n\t\t_fade = pow(1000., 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadein\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_fadeTime <= 0) {\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t} else {\n\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t_fadeTime -= framesToFill;\n\t\t\twhile (framesToFill) {\n\t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t setDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t}\n\t\t\t}\n\t\t produce(framesToFill);\n\t\t}\n\t}\n};\n\nstatic void fadeout_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadeout : fadeTime\");\n\tZ sustain = th.popFloat(\"fadeout : sustainTime\");\n\tV in = th.popZIn(\"fadeout : in\");\n\n\tth.push(new List(new Fadeout(th, in, sustain, fade)));\n}\n\nstatic void fadein_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadein : fadeTime\");\n\tV in = th.popZIn(\"fadein : in\");\n\n\tth.push(new List(new Fadein(th, in, fade)));\n}\n\nstruct Endfade : Gen\n{\n\tZIn _a;\n\tint64_t _startupTime;\n\tint64_t _holdTime;\n\tint64_t _holdTimeRemaining;\n\tint64_t _fadeTime;\n\tZ _amp, _fade, _threshold;\n\t\n\tEndfade(Thread& th, Arg a, Z startupTime, Z holdTime, Z fadeTime, Z threshold) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_startupTime = (int64_t)floor(th.rate.sampleRate * startupTime + .5);\n\t\t_holdTime = (int64_t)floor(th.rate.sampleRate * holdTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_startupTime = std::max(0LL, _startupTime);\n\t\t_holdTime = std::max(1LL, _holdTime);\n\t\t_holdTimeRemaining = _holdTime;\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_threshold = threshold;\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Endfade\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (_startupTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _startupTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_startupTime -= n;\n\t\t\t\t}\n\t\t\t} else if (_holdTimeRemaining > 0) {\n \t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint framesFilled = 0;\n\t\t\t\t\tfor (int i = 0; i < n && _holdTimeRemaining > 0; ++i) {\n\t\t\t\t\t\tZ z = *a;\n\t\t\t\t\t\tif (std::abs(z) >= _threshold) {\n\t\t\t\t\t\t\t_holdTimeRemaining = _holdTime;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t--_holdTimeRemaining;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t++framesFilled;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(framesFilled);\n\t\t\t\t\tframesToFill -= framesFilled;\n\t\t\t\t\tout += framesFilled;\n\t\t\t\t}\n\t\t\t} else if (_fadeTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _fadeTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_fadeTime -= n;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void endfade_(Thread& th, Prim* prim)\n{\n\tZ threshold = th.popFloat(\"endfade : threshold\");\n\tZ fade = th.popFloat(\"endfade : fadeTime\");\n\tZ hold = th.popFloat(\"endfade : holdTime\");\n\tZ startup = th.popFloat(\"endfade : startupTime\");\n\tV in = th.popZIn(\"endfade : in\");\n\n\tth.push(new List(new Endfade(th, in, startup, hold, fade, threshold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Imps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, invdur_;\n\tZ freqmul_;\n\tbool once;\n\n\tImps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate), once(false)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Imps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tonce = true;\n\t\t\t\t}\n\n\t\t\t\tif (once) {\n\t\t\t\t\tout[i] = val_;\n\t\t\t\t\tonce = false;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\t\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Steps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\n\tSteps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Steps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Gates : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn hold_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, hdur_;\n\tZ freqmul_;\n\n\tGates(Thread& th, Arg durs, Arg vals, Arg hold, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, hold)), durs_(durs), vals_(vals), hold_(hold), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Gates\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_) || hold_.onez(th, hdur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = phase_ < hdur_ ? val_ : 0.;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Lines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, slope_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Lines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tslope_ = (newval_ - oldval_) / dur_;\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_ + slope_ * phase_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct XLines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, ratio_, step_;\n\tZ phase_, dur_, invdur_, freq_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tXLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"XLines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t\t//oldval_ = oldval_ * pow(ratio_, phase_ * invdur_);\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = pow(ratio_, freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\toldval_ *= step_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_ * pow(ratio_, phase_ * invdur_);\n\n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\trate += rateStride;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Curves : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn curves_;\n\tZIn rate_;\n\tZ oldval_, newval_, step_;\n\tZ phase_, dur_, curve_, invdur_, freq_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tCurves(Thread& th, Arg durs, Arg vals, Arg curves, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, curves)), durs_(durs), vals_(vals), curves_(curves), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Curves\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tdur_ = std::max(dur_, 1e-4);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n //!! not correct\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n \n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n \n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Cubics : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tCubics(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Cubics\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tc0 = y1;\n\t\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n/*\nd = duration of accelerando in beats\na = duration of accelerando in seconds\n\nr0 = starting tempo in beats per second\nr1 = ending tempo in beats per second\n\nc = (r1 - r0) / d\n\nduration of accelerando in seconds\na = log(r1/r0) / c\n\ntempo for next sample\nr(0) = r0\nr(n) = r(n-1) * exp(c / sr)\n\nbeat for next sample\nb(n) = r(n)/c - r0/c\n\nb(0) = 0\nb(n) = b(n-1) + r(n)/sr \n\n*/\n\n\nstruct Tempo : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ beat_ = 0.;\n\tZ dur_ = 0.;\n\tZ lastTime_ = 0.;\n\tZ nextTime_ = 0.;\n\tZ invsr_;\n\tZ c_, r0_, r1_;\n\tbool once = true;\n\n\tTempo(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Tempo\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t// numerically it would be better to subtract off dur each time, but we need to recreate the same loss of precision over time\n\t\t\t\t// as will be experienced from an integration of tempo occuring outside of this generator. otherwise there would be a drift\n\t\t\t\t// between when tempo changes occur and the beat time as integrated from the tempo.\n\t\t\t\twhile (beat_ >= nextTime_) {\n\t\t\t\t\tdo {\n\t\t\t\t\t\tr0_ = r1_;\n\t\t\t\t\t\tif (vals_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tc_ = (r1_ - r0_) / dur_;\n\t\t\t\t\tlastTime_ = nextTime_;\n\t\t\t\t\tnextTime_ += dur_;\n\t\t\t\t}\n\n\t\t\t\tZ tempo = *rate * (r0_ + (beat_ - lastTime_) * c_);\n\t\t\t\tout[i] = tempo;\n\t\t\t\tbeat_ += tempo * invsr_;\n\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Beats : public Gen\n{\n\tZIn tempo_;\n\tZ beat_ = 0.;\n\tZ invsr_;\n\n\tBeats(Thread& th, Arg tempo) : Gen(th, itemTypeZ, tempo.isFinite()), tempo_(tempo),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Beats\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ beat = beat_;\n\t\twhile (framesToFill) {\n\t\t\tZ* tempo;\n\t\t\tint n = framesToFill;\n\t\t\tint tempoStride;\n\t\t\tif (tempo_(th, n, tempoStride, tempo)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tZ invsr = invsr_;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = beat;\n\t\t\t\tbeat += *tempo * invsr;\n\t\t\t\ttempo += tempoStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttempo_.advance(n);\n\t\t}\n\t\tbeat_ = beat;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct ADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn rate_;\n\tint stage_ = 0;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ noteOff_;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tZ beat_ = 0.;\n\tbool once = true;\n\tint sustainStage_;\n\n\tADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg rate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\trate_(rate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\t\tnoteOff_ = durs_[sustainStage_];\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"ADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (1) {\n\t\t\t\t\tif (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else if (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ < NumStages){\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tbeat_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct GatedADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn gate_;\n\tint stage_ = NumStages;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\tint sustainStage_;\n\n\tGatedADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg gate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\tgate_(gate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"GatedADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* gate;\n\t\t\tint n = framesToFill;\n\t\t\tint gateStride;\n\t\t\tif (gate_(th, n, gateStride, gate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n Z g = *gate;\n gate += gateStride;\n if (stage_ >= NumStages) {\n // waiting for trigger\n if (*gate > 0.) {\n stage_ = 0;\n } else {\n out[i] = 0.;\n --framesToFill;\n continue;\n }\n }\n\t\t\t\twhile (1) { \n if (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else if (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tgate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void imps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"imps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Imps(th, durs, vals, rate)));\n}\n\nstatic void steps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"steps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Steps(th, durs, vals, rate)));\n}\n\nstatic void gates_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"gates : rate\");\n\tV hold = th.pop();\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Gates(th, durs, vals, hold, rate)));\n}\n\nstatic void lines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Lines(th, durs, vals, rate)));\n}\n\nstatic void xlines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"xlines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new XLines(th, durs, vals, rate)));\n}\n\nstatic void cubics_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"cubics : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Cubics(th, vals, rate)));\n}\n\nstatic void curves_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"curves : rate\");\n\tV durs = th.pop();\n\tV param = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Curves(th, durs, vals, param, rate)));\n}\n\nstatic void tempo_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"tempo : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Tempo(th, vals, rate)));\n}\n\nstatic void beats_(Thread& th, Prim* prim)\n{\n\tV tempo = th.popZIn(\"beats : tempo\");\n\n\tth.push(new List(new Beats(th, tempo)));\n}\n\nstatic void adsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"adsr : tempo\");\n\tZ noteDur = th.popFloat(\"adsr : noteDur\");\n\tZ amp = th.popFloat(\"adsr : amp\");\n\n\tP list = th.popList(\"adsr : [attack decay sustain release]\");\n\tconst int kNumADSRStages = 4;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"adsr : [attack decay sustain release] list should have 4 elements.\");\n\t}\n\t\t\n\tZ relTime = env[3];\n\tZ susLvl = env[2];\n\tZ dcyTime = env[1];\n\tZ atkTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 2)));\n}\n\nstatic void dadsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dadsr : tempo\");\n\tZ noteDur = th.popFloat(\"dadsr : noteDur\");\n\tZ amp = th.popFloat(\"dadsr : amp\");\n\n\tP list = th.popList(\"dadsr : [delay attack decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 5;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack decay sustain release] list should have 5 elements.\");\n\t}\n\t\n\tZ relTime = env[4];\n\tZ susLvl = env[3];\n\tZ dcyTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 3)));\n}\n\nstatic void dahdsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dahdsr : tempo\");\n\tZ noteDur = th.popFloat(\"dahdsr : noteDur\");\n\tZ amp = th.popFloat(\"dahdsr : amp\");\n\n\tP list = th.popList(\"dahdsr : [delay attack hold decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 6;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack hold decay sustain release] list should have 6 elements.\");\n\t}\n\t\n\tZ relTime = env[5];\n\tZ susLvl = env[4];\n\tZ dcyTime = env[3];\n\tZ hldTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, hldTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., 0., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 4)));\n}\n\n\n\n\nstruct K2A : public Gen\n{\n\tint n_;\n\tint remain_;\n\tZ slopeFactor_;\n\tBothIn vals_;\n\tZ oldval_, newval_, slope_;\n\tbool once = true;\n\n\tK2A(Thread& th, int n, Arg vals) : Gen(th, itemTypeZ, vals.isFinite()), vals_(vals),\n\t\tn_(n), remain_(0), slopeFactor_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2A\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, oldval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tif (vals_.onez(th, newval_) ) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tslope_ = slopeFactor_ * (newval_ - oldval_);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = oldval_;\n\t\t\t\toldval_ += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct K2AC : public Gen\n{\n\tBothIn vals_;\n\tint n_;\n\tint remain_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ slope_;\n\tbool once = true;\n\n\tK2AC(Thread& th, int n, Arg vals)\n\t\t: Gen(th, itemTypeZ, vals.isFinite()), vals_(vals), n_(n), remain_(0),\n\t\tphase_(0), slope_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2AC\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tx = 0.;\n\t\t\t\ty0 = y1;\n\t\t\t\ty1 = y2;\n\t\t\t\ty2 = y3;\n\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tc0 = y1;\n\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\t\t\t\tx += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void k2a_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV a = th.popZIn(\"kr : signal\");\n\t\n\tth.push(new List(new K2A(th, n, a)));\n}\n\nstatic void k2ac_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"krc : n\");\n\tV a = th.popZIn(\"krc : signal\");\n\t\n\tth.push(new List(new K2AC(th, n, a)));\n}\n\nP gK2A;\nP gK2AC;\n\nstatic void kr_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"kr : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2A->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\nstatic void krc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"krc : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, (int)n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2AC->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFNoise0 : public Gen\n{\n\tZIn rate_;\n\tZ val_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise0(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise0\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\tval_ = r.drand2();\n\t\t\t\t}\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise1 : public Gen\n{\n\tZIn rate_;\n\tZ oldval_, newval_;\n\tZ slope_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise1(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\tnewval_ = oldval_ = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise1\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\tnewval_ = r.drand2();\n\t\t\t\t\tslope_ = newval_ - oldval_;\n\t\t\t\t}\n\t\t\t\tout[i] = oldval_ + slope_ * x;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise3 : public Gen\n{\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise3(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\ty1 = r.drand2();\n\t\ty2 = r.drand2();\n\t\ty3 = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise3\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\ty3 = r.drand2() * 0.8; // 0.8 because cubic interpolation can overshoot up to 1.25 if inputs are -1,1,1,-1.\n\t\t\t\t\tc0 = y1;\n\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void lfnoise0_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise0 : freq\");\n\n\tth.push(new List(new LFNoise0(th, rate)));\n}\n\nstatic void lfnoise1_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise1 : freq\");\n\n\tth.push(new List(new LFNoise1(th, rate)));\n}\n\nstatic void lfnoise3_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise3 : freq\");\n\n\tth.push(new List(new LFNoise3(th, rate)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\ntemplate \nstruct SymmetricEnv : public Gen\n{\n\tZ xinc;\n\tZ x;\n\tint64_t n_;\n\t\n\tSymmetricEnv(Thread& th, Z dur, Z scale) : Gen(th, itemTypeZ, true), x(-scale)\n\t{\n\t\tZ n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\tn_ = (int64_t)n;\n\t\txinc = 2. * scale / n;\n\t}\n\t\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tZ* out = mOut->fulfillz(n);\n\t\tstatic_cast(this)->F::calc(n, out);\n\t\tmOut = mOut->nextp();\n\t\tn_ -= n;\n\t\tif (n_ == 0) {\n\t\t\tend();\n\t\t}\n\t}\n};\n\ntemplate \nstruct TriggeredSymmetricEnv : public Gen\n{\n\tZIn trig_;\n\tBothIn dur_;\n\tBothIn amp_;\n\tZ xinc;\n\tZ x;\n\tZ scale_;\n\tZ ampval_;\n\tint64_t n_ = 0;\n\t\n\tTriggeredSymmetricEnv(Thread& th, Arg trig, Arg dur, Arg amp, Z scale)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), dur_(dur), amp_(amp), scale_(scale)\n\t{\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (n_) {\n\t\t\t\tn = (int)std::min((int64_t)n, n_);\n\t\t\t\tstatic_cast(this)->F::calc(n, ampval_, out);\n\t\t\t\tn_ -= n;\n\t\t\t\ttrig += n * trigStride;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tZ dur;\n\t\t\t\t\t\tif (dur_.onez(th, dur)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tx = -scale_;\n\t\t\t\t\t\tZ zn = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\t\t\t\t\tn_ = (int64_t)zn;\n\t\t\t\t\t\txinc = 2. * scale_ / zn;\n\t\t\t\t\t\tint n2 = (int)std::min((int64_t)(n-i), n_);\n\t\t\t\t\t\tstatic_cast(this)->F::calc(n2, ampval_, out+i);\n\t\t\t\t\t\tn_ -= n2;\n\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\ti += n2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct TriggeredSignal : public Gen\n{\n\tZIn trig_;\n\tZIn list_;\n\tBothIn amp_;\n\tV in_;\n\tZ ampval_;\n\tbool waiting_ = true;\n\tZ counter_ = 0.;\n\t\n\tTriggeredSignal(Thread& th, Arg trig, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), amp_(amp), in_(in)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"TriggeredSignal\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!waiting_) {\n\t\t\t\tZ* list;\n\t\t\t\tint listStride;\n\t\t\t\tif (list_(th, n, listStride, list)) {\n\t\t\t\t\twaiting_ = true;\n\t\t\t\t\tgoto waiting;\n\t\t\t\t}\n\t\t\t\tZ amp = ampval_;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = amp * *list;\n\t\t\t\t\tlist += listStride;\n\t\t\t\t}\n\t\t\t\tlist_.advance(n);\n\t\t\t} else {\n\t\twaiting:\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tV in = in_;\n\t\t\t\t\t\tif (in.isFunOrPrim()) {\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tth.push(counter_);\n\t\t\t\t\t\t\t\tin.apply(th);\n\t\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tin = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcounter_ += 1.;\n\t\t\t\t\t\tlist_.set(in);\n\t\t\t\t\t\tZ* list;\n\t\t\t\t\t\tint listStride;\n\t\t\t\t\t\tint n2 = n-i;\n\t\t\t\t\t\tif (list_(th, n2, listStride, list)) {\n\t\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tZ amp = ampval_;\n\t\t\t\t\t\t\tfor (int j = i; j < i+n2; ++j) {\n\t\t\t\t\t\t\t\tout[j] = amp * *list;\n\t\t\t\t\t\t\t\tlist += listStride;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\t\ti += n2;\n\t\t\t\t\t\t\tlist_.advance(n2);\n\t\t\t\t\t\t\twaiting_ = i < n;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tsig_(Thread& th, Prim* prim)\n{\n\tV amp = th.pop();\n\tV in = th.pop();\n\tV trig = th.popZIn(\"tsig : trig\");\n\n\tth.push(new List(new TriggeredSignal(th, trig, in, amp)));\n}\n\nstruct ParEnv : public SymmetricEnv\n{\n\tParEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"ParEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void parenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"parenv : dur\");\n\n\tth.push(new List(new ParEnv(th, dur)));\n}\n\nstruct TParEnv : public TriggeredSymmetricEnv\n{\n\tTParEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TParEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tparenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tparenv : amp\");\n\tV dur = th.popZIn(\"tparenv : dur\");\n\tV trig = th.popZIn(\"tparenv : trig\");\n\n\tth.push(new List(new TParEnv(th, trig, dur, amp)));\n}\n\nstruct QuadEnv : public SymmetricEnv\n{\n\tQuadEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"QuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2*x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void quadenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"quadenv : dur\");\n\n\tth.push(new List(new QuadEnv(th, dur)));\n}\n\nstruct TQuadEnv : public TriggeredSymmetricEnv\n{\n\tTQuadEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TQuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2*x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tquadenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tquadenv : amp\");\n\tV dur = th.popZIn(\"tquadenv : dur\");\n\tV trig = th.popZIn(\"tquadenv : trig\");\n\n\tth.push(new List(new TQuadEnv(th, trig, dur, amp)));\n}\n\n\nstruct OctEnv : public SymmetricEnv\n{\n\tOctEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"OctEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\t\n\t\t\tout[i] = 1. - x4*x4;\n\t\t\t\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void octenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"octenv : dur\");\n\n\tth.push(new List(new OctEnv(th, dur)));\n}\n\nstruct TOctEnv : public TriggeredSymmetricEnv\n{\n\tTOctEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TOctEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\tout[i] = amp * (1. - x4*x4);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void toctenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toctenv : amp\");\n\tV dur = th.popZIn(\"toctenv : dur\");\n\tV trig = th.popZIn(\"toctenv : trig\");\n\n\tth.push(new List(new TOctEnv(th, trig, dur, amp)));\n}\n\nstruct TriEnv : public SymmetricEnv\n{\n\tTriEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TriEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. - fabs(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trienv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trienv : dur\");\n\n\tth.push(new List(new TriEnv(th, dur)));\n}\n\nstruct TTriEnv : public TriggeredSymmetricEnv\n{\n\tTTriEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTriEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * (1. - fabs(x));\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrienv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrienv : amp\");\n\tV dur = th.popZIn(\"ttrienv : dur\");\n\tV trig = th.popZIn(\"ttrienv : trig\");\n\n\tth.push(new List(new TTriEnv(th, trig, dur, amp)));\n}\n\nstruct Tri2Env : public SymmetricEnv\n{\n\tTri2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Tri2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tri2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"tri2env : dur\");\n\n\tth.push(new List(new Tri2Env(th, dur)));\n}\n\nstruct TTri2Env : public TriggeredSymmetricEnv\n{\n\tTTri2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTri2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttri2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttri2env : amp\");\n\tV dur = th.popZIn(\"ttri2env : dur\");\n\tV trig = th.popZIn(\"ttri2env : trig\");\n\n\tth.push(new List(new TTri2Env(th, trig, dur, amp)));\n}\n\n\nstruct TrapezEnv : public SymmetricEnv\n{\n\tTrapezEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapezenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapezenv : dur\");\n\n\tth.push(new List(new TrapezEnv(th, dur)));\n}\n\n\nstruct TTrapezEnv : public TriggeredSymmetricEnv\n{\n\tTTrapezEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapezenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapezenv : amp\");\n\tV dur = th.popZIn(\"ttrapezenv : dur\");\n\tV trig = th.popZIn(\"ttrapezenv : trig\");\n\n\tth.push(new List(new TTrapezEnv(th, trig, dur, amp)));\n}\n\n\nstruct Trapez2Env : public SymmetricEnv\n{\n\tTrapez2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Trapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapez2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapez2env : dur\");\n\n\tth.push(new List(new Trapez2Env(th, dur)));\n}\n\nstruct TTrapez2Env : public TriggeredSymmetricEnv\n{\n\tTTrapez2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapez2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapez2env : amp\");\n\tV dur = th.popZIn(\"ttrapez2env : dur\");\n\tV trig = th.popZIn(\"ttrapez2env : trig\");\n\n\tth.push(new List(new TTrapez2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct CosEnv : public SymmetricEnv\n{\n\tCosEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"CosEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void cosenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"cosenv : dur\");\n\n\tth.push(new List(new CosEnv(th, dur)));\n}\n\n\nstruct TCosEnv : public TriggeredSymmetricEnv\n{\n\tTCosEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TCosEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tcosenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tcosenv : amp\");\n\tV dur = th.popZIn(\"tcosenv : dur\");\n\tV trig = th.popZIn(\"tcosenv : trig\");\n\n\tth.push(new List(new TCosEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct HanEnv : public SymmetricEnv\n{\n\tHanEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"HanEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void hanenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"hanenv : dur\");\n\n\tth.push(new List(new HanEnv(th, dur)));\n}\n\n\nstruct THanEnv : public TriggeredSymmetricEnv\n{\n\tTHanEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THanEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void thanenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"thanenv : amp\");\n\tV dur = th.popZIn(\"thanenv : dur\");\n\tV trig = th.popZIn(\"thanenv : trig\");\n\n\tth.push(new List(new THanEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct Han2Env : public SymmetricEnv\n{\n\tHan2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Han2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void han2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"han2env : dur\");\n\n\tth.push(new List(new Han2Env(th, dur)));\n}\n\n\nstruct THan2Env : public TriggeredSymmetricEnv\n{\n\tTHan2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THan2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = amp * y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void than2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"than2env : amp\");\n\tV dur = th.popZIn(\"than2env : dur\");\n\tV trig = th.popZIn(\"than2env : trig\");\n\n\tth.push(new List(new THan2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct GaussEnv : public SymmetricEnv\n{\n\tZ widthFactor;\n\tGaussEnv(Thread& th, Z dur, Z width) : SymmetricEnv(th, dur, 1.), widthFactor(-1. / (2. * width * width)) {}\n\t\n\tvirtual const char* TypeName() const override { return \"GaussEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = exp(x * x * widthFactor);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void gaussenv_(Thread& th, Prim* prim)\n{\n\tZ width = th.popFloat(\"gaussenv : width\");\n\tZ dur = th.popFloat(\"gaussenv : dur\");\n\n\tth.push(new List(new GaussEnv(th, dur, width)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Pause : public Gen\n{\n\tZIn _in;\n\tZIn _amp;\n\t\n\tPause(Thread& th, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, amp.isFinite()), _in(in), _amp(amp)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pause\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *amp;\n\t\t\tint n, ampStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_amp(th, n, ampStride, amp) ) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint framesThisTime = n;\n\t\t\twhile (framesThisTime) {\n\t\t\t\tint zerolen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp <= 0.; ++i) {\n\t\t\t\t\t*out++ = 0.;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t++zerolen;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= zerolen;\n\t\t\t\t\n\t\t\t\tint seglen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp > 0.; ++i) {\n\t\t\t\t\t++seglen;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tamp -= seglen * ampStride;\n\n\t\t\t\tint seglenRemain = seglen;\n\t\t\t\twhile (seglenRemain) {\n\t\t\t\t\tZ *in;\n\t\t\t\t\tint n2, inStride;\n\t\t\t\t\tn2 = seglenRemain;\n\t\t\t\t\tif (_in(th, n2, inStride, in) ) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0; i < n2; ++i) {\n\t\t\t\t\t\tout[i] = *amp * *in;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t}\n\t\t\t\t\tout += n2;\n\t\t\t\t\t_in.advance(n2);\n\t\t\t\t\tseglenRemain -= n2;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= seglen;\n\t\t\t\t\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\t_amp.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pause_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"pause : amp\");\n\tV in = th.popZIn(\"pause : in\");\n\n\tth.push(new List(new Pause(th, in, amp)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nP s_tempo;\nP s_dt;\nP s_out;\n\nclass OverlapAddInputSource;\nclass OverlapAddOutputChannel;\n\nclass OverlapAddBase : public Object\n{\nprotected:\n\tOverlapAddOutputChannel* mOutputs = nullptr;\n\tP mActiveSources;\n\tbool mFinished = false;\n\tbool mNoMoreSources = false;\n\tint mNumChannels;\npublic:\n OverlapAddBase(int numChannels);\n virtual ~OverlapAddBase();\n\n\tvirtual const char* TypeName() const override { return \"OverlapAddBase\"; }\n\n\tvirtual bool pull(Thread& th);\n\tvirtual void addNewSources(Thread& th, int blockSize) = 0;\n\n\tP createOutputs(Thread& th);\n void fulfillOutputs(int blockSize);\n void produceOutputs(int shrinkBy);\n int renderActiveSources(Thread& th, int blockSize, bool& anyDone);\n void removeInactiveSources();\n};\n\nclass OverlapAdd : public OverlapAddBase\n{\nprotected:\n\tVIn mSounds;\n\tBothIn mHops;\n\tZIn mRate;\n\tZ mBeatTime;\n\tZ mNextEventBeatTime;\n\tZ mEventCounter;\n\tZ mRateMul;\n\tint64_t mSampleTime;\n\tint64_t mPrevChaseTime;\n\t\n\tP mChasedSignals;\n\npublic:\n\tOverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels);\n\tvirtual ~OverlapAdd() {}\n\t\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n\t\t\n\tvirtual void addNewSources(Thread& th, int blockSize) override;\n\tvoid chaseToTime(Thread& th, int64_t inSampleTime);\n};\n\nclass OverlapAddInputSource : public Object\n{\npublic:\n\tP mNextSource;\n\tstd::vector mInputs;\n\tint mOffset;\n\tbool mSourceDone;\n\t\n\tOverlapAddInputSource(Thread& th, List* channels, int inOffset, P const& inNextSource) \n\t\t: mNextSource(inNextSource), mOffset(inOffset), mSourceDone(false)\n\t{\n\t\tif (channels->isVList()) {\n\t\t\tP packedChannels = channels->pack(th);\n\t\t\tArray* a = packedChannels->mArray();\n\t\t\t\n\t\t\t// put channels into mInputs\n\t\t\tmInputs.reserve(a->size());\n\t\t\tfor (int i = 0; i < a->size(); ++i) {\n\t\t\t\tZIn zin(a->v()[i]);\n\t\t\t\tmInputs.push_back(zin);\n\t\t\t}\n\t\t} else {\n\t\t\tZIn zin(channels);\n\t\t\tmInputs.push_back(zin);\n\t\t}\n\t}\n\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n};\n\nclass OverlapAddOutputChannel : public Gen\n{\n\tfriend class OverlapAddBase;\n\tP mOverlapAddBase;\n\tOverlapAddOutputChannel* mNextOutput;\n\t\npublic:\t\n\tOverlapAddOutputChannel(Thread& th, OverlapAddBase* inOverlapAdd)\n : Gen(th, itemTypeZ, false), mOverlapAddBase(inOverlapAdd), mNextOutput(nullptr)\n\t{\n\t}\n\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmOverlapAddBase = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"OverlapAddOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mOverlapAddBase->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nOverlapAddBase::OverlapAddBase(int numChannels)\n\t: mNumChannels(numChannels)\n{\n}\n\nOverlapAddBase::~OverlapAddBase()\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tOverlapAddOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nOverlapAdd::OverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels)\n\t: OverlapAddBase(numChannels),\n mSounds(sounds), mHops(hops), mRate(rate),\n\tmBeatTime(0.), mNextEventBeatTime(0.), mEventCounter(0.), mRateMul(th.rate.invSampleRate),\n\tmSampleTime(0), mPrevChaseTime(0),\n\tmChasedSignals(chasedSignals)\n{\n}\n\nP OverlapAddBase::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n OverlapAddOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n OverlapAddOutputChannel* c = new OverlapAddOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nvoid OverlapAdd::addNewSources(Thread& th, int blockSize)\n{\t\t\t\n\t// integrate tempo and add new sources.\n\tZ* rate;\n\tint rateStride;\n\tif (mRate(th, blockSize, rateStride, rate)) {\n\t\tmNoMoreSources = true;\n\t} else if (!mNoMoreSources) {\n\t\tZ beatTime = mBeatTime;\n\t\tZ nextEventBeatTime = mNextEventBeatTime;\n\t\tZ ratemul = mRateMul;\n\t\tfor (int i = 0; i < blockSize; ++i) {\n\t\t\twhile (beatTime >= nextEventBeatTime) {\n\t\t\t\n\t\t\t\tchaseToTime(th, mSampleTime + i);\n\t\t\t\n\t\t\t\tV newSource;\n\t\t\t\tif (mSounds.one(th, newSource)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\tif (newSource.isFun()) {\n\t\t\t\t\tSaveStack ss(th);\t\n\t\t\t\t\tth.push(mEventCounter);\n\t\t\t\t\tnewSource.apply(th);\n\t\t\t\t\tnewSource = th.pop();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tV out;\n\t\t\t\tZ deltaTime;\n\t\t\t\tif (mHops.onez(th, deltaTime)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (newSource.isForm()) {\n\t\t\t\t\tif (mChasedSignals()) {\n\t\t\t\t\t\tV parents[2];\n\t\t\t\t\t\tparents[0] = mChasedSignals;\n\t\t\t\t\t\tparents[1] = newSource;\n\t\t\t\t\t\tnewSource = linearizeInheritance(th, 2, parents);\n\t\t\t\t\t}\n\t\t\t\t\tnewSource.dot(th, s_out, out);\n\t\t\t\t\tV hop;\n\t\t\t\t\tif (newSource.dot(th, s_dt, hop) && hop.isReal()) {\n\t\t\t\t\t\tdeltaTime = hop.f;\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\t\t\t\t\tout = newSource;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// must be a finite array with fewer than mNumChannels\n\t\t\t\tif (out.isZList() || (out.isVList() && out.isFinite())) {\n\t\t\t\t\tList* s = (List*)out.o();\n\t\t\t\t\t// create an active source:\n\t\t\t\t\tP source = new OverlapAddInputSource(th, s, i, mActiveSources);\n\t\t\t\t\tmActiveSources = source;\n\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\tnextEventBeatTime += deltaTime;\n\t\t\t\tmEventCounter += 1.;\n\t\t\t}\n\t\t\tbeatTime += *rate * ratemul;\n\t\t\trate += rateStride;\n\t\t}\n\t\tmBeatTime = beatTime;\n\t\tmNextEventBeatTime = nextEventBeatTime;\n\t\tmSampleTime += blockSize;\n\t\t\n\t\tmRate.advance(blockSize);\n\n\t\tchaseToTime(th, mSampleTime);\n\t}\n}\n\nvoid OverlapAddBase::fulfillOutputs(int blockSize)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut) {\n\t\t\tZ* out = output->mOut->fulfillz(blockSize);\n\t\t\tmemset(out, 0, output->mBlockSize * sizeof(Z));\n\t\t}\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nint OverlapAddBase::renderActiveSources(Thread& th, int blockSize, bool& anyDone)\n{\n\tint maxProduced = 0;\n\tOverlapAddInputSource* source = mActiveSources();\n\twhile (source) {\n\t\tint offset = source->mOffset;\n\t\tint pullSize = blockSize - offset;\n\t\tstd::vector& sourceChannels = source->mInputs;\n\t\tbool allOutputsDone = true; // initial value for reduction on &&\n\t\tOverlapAddOutputChannel* output = mOutputs;\n\t\tfor (size_t j = 0; j < sourceChannels.size() && output; ++j, output = output->mNextOutput) {\n\t\t\tif (output->mOut) {\n\t\t\t\tZIn& zin = sourceChannels[j];\n\t\t\t\tif (zin.mIsConstant && zin.mConstant.f == 0.)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tint n = pullSize;\n\t\t\t\tZ* out = output->mOut->mArray->z() + offset;\n\t\t\t\tif (!zin.mix(th, n, out)) {\n\t\t\t\t\tallOutputsDone = false;\n\t\t\t\t}\n\t\t\t\tmaxProduced = std::max(maxProduced, n);\n\t\t\t}\n\t\t}\n\t\tsource->mOffset = 0;\n\t\tif (allOutputsDone) {\n\t\t\t// mark for removal from mActiveSources\n\t\t\tsource->mSourceDone = true;\n anyDone = true;\n\t\t}\n\t\tsource = source->mNextSource();\n\t}\n\treturn maxProduced;\n}\n\nvoid OverlapAddBase::removeInactiveSources()\n{\n\tP source = mActiveSources();\n\tP prevSource = nullptr;\n\tmActiveSources = nullptr;\n\t\n\twhile (source) {\n\t\tP nextSource = source->mNextSource;\n\t\tsource->mNextSource = nullptr;\n\t\tif (!source->mSourceDone) {\n\t\t\tif (prevSource()) prevSource->mNextSource = source;\n\t\t\telse mActiveSources = source;\n prevSource = source;\n\t\t}\n\t\tsource = nextSource;\n\t}\n}\n\nvoid OverlapAddBase::produceOutputs(int shrinkBy)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nbool OverlapAddBase::pull(Thread& th)\n{\n\tif (mFinished) {\n\t\treturn mFinished;\n }\n\t\n\tOverlapAddOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\taddNewSources(th, blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n bool anyDone = false;\n\tint maxProduced = renderActiveSources(th, blockSize, anyDone);\n\t\t\t\n\tmFinished = mNoMoreSources && mActiveSources() == nullptr;\n\tint shrinkBy = mFinished ? blockSize - maxProduced : 0;\n\t\n\tproduceOutputs(shrinkBy);\n\n\tif (anyDone)\n removeInactiveSources();\n\t\n\treturn mFinished; \n}\n\nvoid OverlapAdd::chaseToTime(Thread& th, int64_t inSampleTime)\n{\n\tint64_t n = inSampleTime - mPrevChaseTime;\n\tmPrevChaseTime = inSampleTime;\n\n\tif (mChasedSignals() && n > 0) {\n\t\tmChasedSignals = mChasedSignals->chaseForm(th, n);\n\t}\n}\n\n\nconst int64_t kMaxOverlapAddChannels = 10000;\n\nstatic void ola_(Thread& th, Prim* prim)\n{\n\tint64_t numChannels = th.popInt(\"ola : numChannels\");\n\tV rate = th.pop();\n\tV hops = th.popZInList(\"ola : hops\");\n\tV sounds = th.pop();\n\n\tif (numChannels > kMaxOverlapAddChannels) {\n\t\tpost(\"ola : too many channels\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tP chasedSignals;\n\tif (rate.isForm()) {\n\t\tchasedSignals = (Form*)rate.o();\n\t\trate = 1.;\n\t\tchasedSignals->dot(th, s_tempo, rate);\n\t}\n\n\tP ola = new OverlapAdd(th, sounds, hops, rate, chasedSignals, (int)numChannels);\n\t\n\tth.push(ola->createOutputs(th));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ITD;\n\nclass ITD_OutputChannel : public Gen\n{\n\tfriend class ITD;\n\tP mITD;\n\t\npublic:\t\n\tITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmITD = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ITD_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nstruct ITD : public Gen\n{\n\tZIn in_;\n\tZIn pan_;\n\tZ maxdelay_;\n\tZ half;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\n\tITD_OutputChannel* mLeft;\n\tITD_OutputChannel* mRight;\n\t\n\tITD(Thread& th, Arg in, Arg pan, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), pan_(pan), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\thalf = (int32_t)ceil(sr * maxdelay * .5 + .5);\n\t\tbufSize = NEXTPOWEROFTWO(2 * (int)half + 3);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~ITD() { delete mLeft; delete mRight; free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"ITD\"; }\n\t\n\tP createOutputs(Thread& th);\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, panStride;\n\t\t\tZ *in, *pan;\n\t\t\tif (in_(th, n, inStride, in) || pan_(th, n, panStride, pan)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., *pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Lout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., -*pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Rout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tRout += Routstride;\n\t\t\t\t\t}\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tpan += panStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tpan_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nITD_OutputChannel::ITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD) : Gen(th, itemTypeZ, inFinite), mITD(inITD)\n{\n}\n\nvoid ITD_OutputChannel::pull(Thread& th)\n{\n\tmITD->pull(th);\n}\n\nP ITD::createOutputs(Thread& th)\n{\n\tmLeft = new ITD_OutputChannel(th, finite, this);\n\tmRight = new ITD_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\nstatic void itd_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"itd : maxdelay\");\n\tV pan = th.popZIn(\"itd : pan\");\n\tV in = th.popZIn(\"itd : in\");\n \n\tP itd = new ITD(th, in, pan, maxdelay);\n\n\tP s = itd->createOutputs(th);\n\n\tth.push(s);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ninline Z fast_sin1(Z x)\n{\n\tx = x - floor(x + .5);\n\t\n Z y = x * (8. - 16. * fabs(x));\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\ninline Z fast_cos1(Z x)\n{\n\treturn fast_sin1(x + .25);\n}\n\ninline Z fast_pan(Z x)\n{\n\tZ y = .75 + x * (.5 - .25 * x);\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\nstruct Pan2Out;\n\nstruct Pan2 : public Object\n{\n\tZIn _in;\n\tZIn _pos;\n\t\n\tPan2Out* mLeft;\n\tPan2Out* mRight;\n\t\t\n\tPan2(Thread& th, Arg inIn, Arg inPos)\n\t\t: _in(inIn), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inIn, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Pan2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Pan2Out : public Gen\n{\n\tP mPan2;\n\t\n\tPan2Out(Thread& th, bool inFinite, P const& inPan2) : Gen(th, itemTypeZ, inFinite), mPan2(inPan2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmPan2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pan2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmPan2->pull(th);\n\t}\n\t\n};\n\nvoid Pan2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b;\n\t\tint n, aStride, bStride;\n\t\tn = framesToFill;\n\t\tif (_in(th, n, aStride, a) || _pos(th, n, bStride, b)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (bStride == 0) {\n\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * Lpan;\n\t\t\t\t*Rout = z * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * fast_pan(-x);\n\t\t\t\t*Rout = z * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_in.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Pan2::createOutputs(Thread& th)\n{\n\tmLeft = new Pan2Out(th, finite, this);\n\tmRight = new Pan2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void pan2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"pan2 : pos\");\n\tV in = th.popZIn(\"pan2 : in\");\n\n\tP pan = new Pan2(th, in, pos);\n\n\tP s = pan->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Balance2Out;\n\nstruct Balance2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tBalance2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Balance2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Balance2Out : public Gen\n{\n\tP mBalance2;\n\t\n\tBalance2Out(Thread& th, bool inFinite, P const& inBalance2) : Gen(th, itemTypeZ, inFinite), mBalance2(inBalance2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmBalance2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Balance2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmBalance2->pull(th);\n\t}\n\t\n};\n\nvoid Balance2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t*Lout = *a * Lpan;\n\t\t\t\t*Rout = *b * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t*Lout = *a * fast_pan(-x);\n\t\t\t\t*Rout = *b * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Balance2::createOutputs(Thread& th)\n{\n\tmLeft = new Balance2Out(th, finite, this);\n\tmRight = new Balance2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void bal2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"bal2 : pos\");\n\tV R = th.popZIn(\"bal2 : right\");\n\tV L = th.popZIn(\"bal2 : left\");\n\n\tP bal = new Balance2(th, L, R, pos);\n\n\tP s = bal->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Rot2Out;\n\nstruct Rot2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tRot2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Rot2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Rot2Out : public Gen\n{\n\tP mRot2;\n\t\n\tRot2Out(Thread& th, bool inFinite, P const& inRot2) : Gen(th, itemTypeZ, inFinite), mRot2(inRot2)\n\t{\n\t}\n\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmRot2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rot2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmRot2->pull(th);\n\t}\n\t\n};\n\nvoid Rot2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tif (_L.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = - R * sn;\n\t\t\t\t\t*Rout = R * cs;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else if (_R.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\t*Lout = L * cs;\n\t\t\t\t\t*Rout = L * sn;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ L = *a;\n\t\t\t\tZ R = *b;\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Rot2::createOutputs(Thread& th)\n{\n\tmLeft = new Rot2Out(th, finite, this);\n\tmRight = new Rot2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void rot2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"rot2 : pos\");\n\tV R = th.popZIn(\"rot2 : right\");\n\tV L = th.popZIn(\"rot2 : left\");\n\n\tP rot2 = new Rot2(th, L, R, pos);\n\n\tP s = rot2->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Fade2 : public Gen\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\t\n\tFade2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: Gen(th, itemTypeZ, mostFinite(inL, inR, inPos)), _L(inL), _R(inR), _pos(inPos)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fade2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *a, *b, *c;\n\t\t\tint n, aStride, bStride, cStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (cStride == 0) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\tZ Lpan = fast_pan(-x);\n\t\t\t\tZ Rpan = fast_pan(x);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a * Lpan + *b * Rpan;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t\tout[i] = *a * fast_pan(-x) + *b * fast_pan(x);\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tc += cStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_L.advance(n);\n\t\t\t_R.advance(n);\n\t\t\t_pos.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void fade2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"fade2 : pos\");\n\tV R = th.popZIn(\"fade2 : right\");\n\tV L = th.popZIn(\"fade2 : left\");\n\n\tth.push(new List(new Fade2(th, L, R, pos)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Trig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Trig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur > 0. && prev <= 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct NegTrig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tNegTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(-1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NegTrig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur >= 0. && prev < 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void tr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"tr : in\");\n\n\tth.push(new List(new Trig(th, in)));\n}\n\nstatic void ntr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"ntr : in\");\n\n\tth.push(new List(new NegTrig(th, in)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Gate : public TwoInputUGen\n{\n\tZ phase;\n\tZ freq;\n\tGate(Thread& th, Arg trig, Arg hold)\n\t\t: TwoInputUGen(th, trig, hold), phase(INFINITY), freq(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gate\"; }\n\t\n\tvoid calc(int n, Z* out, Z* trig, Z* hold, int trigStride, int holdStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ t = *trig;\n\t\t\tif (t > 0.) {\n\t\t\t\tphase = 0.;\n\t\t\t}\n\t\t\tout[i] = phase < *hold ? 1. : 0.;\n\t\t\tphase += freq;\n\t\t\ttrig += trigStride;\n\t\t\thold += holdStride;\n\t\t}\n\t}\n};\n\nstatic void gate_(Thread& th, Prim* prim)\n{\n\tV hold = th.popZIn(\"gate : hold\");\n\tV in = th.popZIn(\"gate : in\");\n\n\tth.push(new List(new Gate(th, in, hold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SampleAndHold : public Gen\n{\n\tZIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSampleAndHold(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SampleAndHold\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *tr;\n\t\t\tint n, inStride, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) val = *in;\n\t\t\t\tout[i] = val;\n\t\t\t\tin += inStride;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void sah_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"sah : trigger\");\n\tV in = th.popZIn(\"sah : in\");\n\n\tth.push(new List(new SampleAndHold(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Sequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Sequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tval = z;\n\t\t\t\t}\n\t\t\t\tout[i] = val;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void seq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"seq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new Sequencer(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct ImpulseSequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\t\n\tImpulseSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ImpulseSequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = z;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void iseq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"iseq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new ImpulseSequencer(th, in, trigger)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct PulseDivider : public Gen\n{\n\tZIn _tr;\n\tZIn _div;\n\tZ _count;\n\t\n\tPulseDivider(Thread& th, Arg tr, Arg div, Z start)\n\t\t: Gen(th, itemTypeZ, mostFinite(tr, div)), _tr(tr), _div(div), _count(start - 1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PulseDivider\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr, *div;\n\t\t\tint n, trStride, divStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr) || _div(th, n, divStride, div)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\t_count += 1.;\n\t\t\t\t\tZ idiv = floor(*div + .5);\n\t\t\t\t\tif (_count >= idiv) {\n\t\t\t\t\t\t_count -= idiv;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = _count == 0. ? *tr : 0.;\n\t\t\t\t} else out[i] = 0.;\n\t\t\t\ttr += trStride;\n\t\t\t\tdiv += divStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t\t_div.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pdiv_(Thread& th, Prim* prim)\n{\n\tZ start = th.popFloat(\"pdiv : istart\");\n\tV div = th.popZIn(\"pdiv : n\");\n\tV in = th.popZIn(\"pdiv : in\");\n\n\tth.push(new List(new PulseDivider(th, in, div, start)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Clip : public ThreeInputUGen\n{\n\t\n\tClip(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Clip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = std::clamp(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Wrap : public ThreeInputUGen\n{\n\t\n\tWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Wrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_wrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Fold : public ThreeInputUGen\n{\n\t\n\tFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_fold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\n\nstruct IWrap : public ThreeInputUGen\n{\n\t\n\tIWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IWrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_iwrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct IFold : public ThreeInputUGen\n{\n\t\n\tIFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IFold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_ifold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstatic void clip_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"clip : hi\");\n\tV lo = th.popZIn(\"clip : lo\");\n\tV in = th.popZIn(\"clip : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(std::clamp(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Clip(th, in, lo, hi)));\n\t}\n}\n\nstatic void wrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"wrap : hi\");\n\tV lo = th.popZIn(\"wrap : lo\");\n\tV in = th.popZIn(\"wrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_wrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Wrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void fold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"fold : hi\");\n\tV lo = th.popZIn(\"fold : lo\");\n\tV in = th.popZIn(\"fold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_fold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Fold(th, in, lo, hi)));\n\t}\n}\n\nstatic void iwrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"iwrap : hi\");\n\tV lo = th.popZIn(\"iwrap : lo\");\n\tV in = th.popZIn(\"iwrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_iwrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IWrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void ifold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"ifold : hi\");\n\tV lo = th.popZIn(\"ifold : lo\");\n\tV in = th.popZIn(\"ifold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_ifold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IFold(th, in, lo, hi)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \n\nstruct MouseUGenGlobalState {\n\tfloat mouseX, mouseY;\n\tbool mouseButton;\n} gMouseUGenGlobals;\n\nstatic void* gstate_update_func(void* arg)\n{\n\tMouseUGenGlobalState* gstate = &gMouseUGenGlobals;\n\n\tCGDirectDisplayID display = kCGDirectMainDisplay; // to grab the main display ID\n\tCGRect bounds = CGDisplayBounds(display);\n\tfloat rscreenWidth = 1. / bounds.size.width;\n\tfloat rscreenHeight = 1. / bounds.size.height;\n\tfor (;;) {\n\t\tHIPoint point;\n\t\tHICoordinateSpace space = 2;\n\t\tHIGetMousePosition(space, nullptr, &point);\n\n\t\tgstate->mouseX = point.x * rscreenWidth; //(float)p.h * rscreenWidth;\n\t\tgstate->mouseY = 1. - point.y * rscreenHeight; //(float)p.v * rscreenHeight;\n\t\tgstate->mouseButton = GetCurrentButtonState();\n\t\tusleep(17000);\n\t}\n\n\treturn 0;\n}\n\nZ gMouseLagTime = .1;\nZ gMouseLagMul = log001 / gMouseLagTime;\n\nstruct MouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct MouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void mousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousex : hi\");\n\tV lo = th.popZIn(\"mousex : lo\");\n\t\n\tth.push(new List(new MouseX(th, lo, hi)));\n}\n\nstatic void mousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousey : hi\");\n\tV lo = th.popZIn(\"mousey : lo\");\n\t\n\tth.push(new List(new MouseY(th, lo, hi)));\n}\n\nstatic void xmousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousex : hi\");\n\tV lo = th.popZIn(\"xmousex : lo\");\n\t\n\tth.push(new List(new ExpMouseX(th, lo, hi)));\n}\n\nstatic void xmousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousey : hi\");\n\tV lo = th.popZIn(\"xmousey : lo\");\n\t\n\tth.push(new List(new ExpMouseY(th, lo, hi)));\n}\n\nstatic void mousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousex1 : hi\");\n\tZ lo = th.popFloat(\"mousex1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseX * (hi - lo);\n\tth.push(z);\n}\n\nstatic void mousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousey1 : hi\");\n\tZ lo = th.popFloat(\"mousey1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseY * (hi - lo);\n\tth.push(z);\n}\n\nstatic void xmousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousex1 : hi\");\n\tZ lo = th.popFloat(\"xmousex1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseX);\n\tth.push(z);\n}\n\nstatic void xmousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousey1 : hi\");\n\tZ lo = th.popFloat(\"xmousey1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseY);\n\tth.push(z);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps();\nvoid AddOscilUGenOps();\nvoid AddDelayUGenOps();\n\nvoid AddUGenOps()\n{\n\ts_tempo = getsym(\"tempo\");\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\n\tpthread_t mouseListenThread;\n\tpthread_create (&mouseListenThread, nullptr, gstate_update_func, (void*)0);\n\n\tvm.addBifHelp(\"\\n*** unit generators ***\");\n\tvm.defmcx(\"*+\", 3, madd_, \"(a b c --> out) multiply add. a b * c +\");\n\n AddOscilUGenOps();\n AddFilterUGenOps();\n AddDelayUGenOps();\n\t\n\tvm.addBifHelp(\"\\n*** plugs ***\");\n\n\tvm.addBifHelp(\"\\n*** control rate subgraphs ***\");\n\tgK2A = automap(\"zk\", 2, new Prim(k2a_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tgK2AC = automap(\"zk\", 2, new Prim(k2ac_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tDEF(kr, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then linearly upsamples all returned signals by n.\")\n\tDEF(krc, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then cubically upsamples all returned signals by n.\")\n\t\n\tvm.addBifHelp(\"\\n*** control function unit generators ***\");\n\tDEFAM(imps, aaz, \"(values durs rate --> out) single sample impulses.\");\n\tDEFAM(steps, aaz, \"(values durs rate --> out) steps\");\n\tDEFAM(gates, aaaz, \"(values durs holds rate --> out) gates\");\n\tDEFAM(lines, aaz, \"(values durs rate --> out) lines\");\n\tDEFAM(xlines, aaz, \"(values durs rate --> out) exponential lines\");\n\tDEFAM(cubics, az, \"(values rate --> out) cubic splines\");\n\tDEFAM(curves, aaaz, \"(values curvatures durs rate --> out) curves.\");\n\t\n\n\tvm.addBifHelp(\"\\n*** random control unit generators ***\");\n\tDEFMCX(lfnoise0, 1, \"(freq --> out) step noise source.\");\n\tDEFMCX(lfnoise1, 1, \"(freq --> out) ramp noise source.\");\n\tDEFMCX(lfnoise3, 1, \"(freq --> out) cubic spline noise source.\");\n\t\n\tvm.addBifHelp(\"\\n*** tempo unit generators ***\");\n\tDEFAM(tempo, az, \"([bps dur bps dur ...] rate --> out) returns a signal of tempo vs time given a list of interleaved tempos (in beats per second) and durations (in beats).\");\n\tDEFAM(beats, z, \"(tempo --> beats) integrates a tempo signal to produce a signal of the time in beats.\");\n\n\tvm.addBifHelp(\"\\n*** envelope unit generators ***\");\n\tvm.addBifHelp(\"\\nFor asr, adsr, dadsr, dahdsr envelopes, the arguments are as follows:\");\n\tvm.addBifHelp(\" delay - a time in seconds. a period of time before the attack segment where the amplitude is zero.\");\n\tvm.addBifHelp(\" attack - a time in seconds to rise from zero to the level specified by the amp argument.\");\n\tvm.addBifHelp(\" hold - a time in seconds to hold at the level specified by the amp argument.\");\n\tvm.addBifHelp(\" delay - a time in seconds to fall from amp to the sustain level.\");\n\tvm.addBifHelp(\" sustain - a level from zero to one which is multiplied by the amp argument. The envelope holds at this level until released.\");\n\tvm.addBifHelp(\" release - a time in seconds to fall from the current level to zero. A release begins whenever the beat time (the integral of tempo), exceeds dur.\");\n\tvm.addBifHelp(\" amp - an amplitude that scales the peak and sustain levels of the envelope.\");\n\tvm.addBifHelp(\" dur - a time in beats to release the envelope.\");\n\tvm.addBifHelp(\" tempo - a signal giving the tempo in beats per second versus time.\");\n\tvm.addBifHelp(\"\");\n\n\tDEFAM(adsr, akkz, \"([attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dadsr, akkz, \"([delay attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dahdsr, akkz, \"([delay attack hold decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tvm.addBifHelp(\"\");\n \n\tDEFAM(endfade, zkkkk, \"(in startupTime holdTime fadeTime threshold --> out) after startupTime has elapsed, fade out the sound when peak amplitude has dropped below threshold for more than the holdTime.\");\n\tDEFAM(fadeout, zkk, \"(in sustainTime fadeTime --> out) fadeout after sustain.\");\n\tDEFAM(fadein, zk, \"(in fadeTime --> out) fade in.\");\n\tDEFAM(parenv, k, \"(dur --> out) parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(quadenv, k, \"(dur --> out) 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(octenv, k, \"(dur --> out) 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(trienv, k, \"(dur --> out) triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(tri2env, k, \"(dur --> out) triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(trapezenv, k, \"(dur --> out) trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(trapez2env, k, \"(dur --> out) trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(cosenv, k, \"(dur --> out) cosine envelope.\")\n\tDEFAM(hanenv, k, \"(dur --> out) hanning envelope.\")\n\tDEFAM(han2env, k, \"(dur --> out) hanning squared envelope.\")\n\tDEFAM(gaussenv, kk, \"(dur width --> out) gaussian envelope. exp(x^2/(-2*width^2)) for x from -1 to 1\")\n\n\tDEFAM(tsig, zza, \"(trig signal amp --> out) trigger a signal.\")\n\n\tDEFAM(tparenv, zaa, \"(trig dur amp --> out) triggered parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(tquadenv, zaa, \"(trig dur amp --> out) triggered 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(toctenv, zaa, \"(trig dur amp --> out) triggered 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(ttrienv, zaa, \"(trig dur amp --> out) triggered triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(ttri2env, zaa, \"(trig dur amp --> out) triggered triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(ttrapezenv, zaa, \"(trig dur amp --> out) triggered trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(ttrapez2env, zaa, \"(trig dur amp --> out) triggered trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(tcosenv, zaa, \"(trig dur amp --> out) triggered cosine envelope.\")\n\tDEFAM(thanenv, zaa, \"(trig dur amp --> out) triggered hanning envelope.\")\n\tDEFAM(than2env, zaa, \"(trig dur amp --> out) triggered hanning squared envelope.\")\n\t\n\tvm.addBifHelp(\"\\n*** spawn unit generators ***\");\n\tDEF(ola, 4, \"(sounds hops rate numChannels --> out) overlap add. This is the basic operator for polyphony. \")\n\n\tvm.addBifHelp(\"\\n*** pause unit generator ***\");\n\tDEFMCX(pause, 2, \"(in amp --> out) pauses the input when amp is <= 0, otherwise in is multiplied by amp.\")\n\n\tvm.addBifHelp(\"\\n*** panner unit generators ***\");\n\tDEFAM(itd, zzk, \"(in pan maxdelay --> out) interaural time delay.\");\n\tDEFMCX(pan2, 2, \"(in pos --> [left right]) stereo pan. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(rot2, 3, \"(left right pos --> [left right]) stereo rotation. pos 0 is no rotation, +/-1 is 180 degrees, -.5 is -90 degrees, +.5 is +90 degrees.\")\n\tDEFMCX(bal2, 3, \"(left right pos --> [left right]) stereo balance control. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(fade2, 3, \"(left right pos --> out) cross fade between two inputs. pos 0 is equal mix. pos -1 is all left, pos +1 is all right.\")\n\n\t\n\tvm.addBifHelp(\"\\n*** trigger unit generators ***\");\n\tDEFMCX(tr, 1, \"(in --> out) transitions from nonpositive to positive become single sample impulses.\")\n\tDEFMCX(ntr, 1, \"(in --> out) transitions from negative to nonnegative become single sample impulses.\")\n\tDEFMCX(gate, 1, \"(in hold --> out) outputs 1 for hold seconds after each trigger, else outputs zero.\")\n\tDEFMCX(sah, 2, \"(in trigger --> out) sample and hold\")\n\tDEFAM(seq, az, \"(in trigger --> out) pulls one value from the input for each trigger. output sustains at that level until the next trigger.\")\n\tDEFAM(iseq, az, \"(in trigger --> out) pulls one value from the input for each trigger. outputs that value for one sample. outputs zero when there is no trigger.\")\n\tDEFMCX(pdiv, 3, \"(in n istart --> out) pulse divider. outputs one impulse from the output for each n impulses in the input. istart is an offset. istart = 0 outputs a pulse on the first input pulse.\")\n\t\n\t\n\tvm.addBifHelp(\"\\n*** bounds unit generators ***\");\n\tDEFMCX(clip, 3, \"(in lo hi --> out) constrain the input to the bounds by clipping.\")\n\tDEFMCX(wrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping.\")\n\tDEFMCX(fold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges.\")\n\tDEFMCX(iwrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping. all inputs treated as integers.\")\n\tDEFMCX(ifold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges. all inputs treated as integers.\")\n\n\tvm.addBifHelp(\"\\n*** mouse control unit generators ***\");\n\tDEFMCX(mousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\n\n\tDEFMCX(mousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\t\n}\n"], ["/sapf/src/DelayUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"DelayUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass DelayN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\n\tDelayN(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n int32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n out[i] = buf[(bufPos-offset) & bufMask];\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayn_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayn : maxdelay\");\n\tV delay = th.popZIn(\"delayn : delay\");\n\tV in = th.popZIn(\"delayn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayN(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayL(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayl_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayl : maxdelay\");\n\tV delay = th.popZIn(\"delayl : delay\");\n\tV in = th.popZIn(\"delayl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayL(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayC(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayc_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayc : maxdelay\");\n\tV delay = th.popZIn(\"delayc : delay\");\n\tV in = th.popZIn(\"delayc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayC(th, in, delay, maxdelay)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass Flange : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlange(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flange() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flange\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) - zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flangep : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlangep(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flangep() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flangep\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) + zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void flange_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flange : maxdelay\");\n\tV delay = th.popZIn(\"flange : delay\");\n\tV in = th.popZIn(\"flange : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flange : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flange(th, in, delay, maxdelay)));\n}\n\nstatic void flangep_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flangep : maxdelay\");\n\tV delay = th.popZIn(\"flangep : delay\");\n\tV in = th.popZIn(\"flangep : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flangep : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flangep(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass CombN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay + 1.));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(std::abs(zdelay) * sr + .5));\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(std::abs(zdelay) * sr + .5);\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combn : decay\");\n\tZ maxdelay = th.popFloat(\"combn : maxdelay\");\n\tV delay = th.popZIn(\"combn : delay\");\n\tV in = th.popZIn(\"combn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ z = fb * (a + frac * (b - a));\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combl : decay\");\n\tZ maxdelay = th.popFloat(\"combl : maxdelay\");\n\tV delay = th.popZIn(\"combl : delay\");\n\tV in = th.popZIn(\"combl : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combc : decay\");\n\tZ maxdelay = th.popFloat(\"combc : maxdelay\");\n\tV delay = th.popZIn(\"combc : delay\");\n\tV in = th.popZIn(\"combc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass LPCombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZIn lpfreq_;\n\tZ maxdelay_;\n\tZ y1_;\n\tZ freqmul_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tLPCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay, Arg lpfreq) : Gen(th, itemTypeZ, false),\n\t\t\tin_(in), delay_(delay), decay_(decay), lpfreq_(lpfreq), maxdelay_(maxdelay), y1_(0.), freqmul_(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~LPCombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"LPCombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tZ y1 = y1_;\n\t\tZ freqmul = freqmul_;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride, lpfreqStride;\n\t\t\tZ *in, *delay, *decay, *lpfreq;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay) || lpfreq_(th, n, lpfreqStride, lpfreq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (lpfreqStride == 0) {\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n }\n\t\t\t\ty1_ = y1;\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tlpfreq_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void lpcombc_(Thread& th, Prim* prim)\n{\n\tV lpfreq = th.popZIn(\"lpcombc : lpfreq\");\n\tV decay = th.popZIn(\"lpcombc : decay\");\n\tZ maxdelay = th.popFloat(\"lpcombc : maxdelay\");\n\tV delay = th.popZIn(\"lpcombc : delay\");\n\tV in = th.popZIn(\"lpcombc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"lpcombc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new LPCombC(th, in, delay, maxdelay, decay, lpfreq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass AllpassN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(zdelay * sr + .5);\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasn : decay\");\n\tZ maxdelay = th.popFloat(\"alpasn : maxdelay\");\n\tV delay = th.popZIn(\"alpasn : delay\");\n\tV in = th.popZIn(\"alpasn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasl : decay\");\n\tZ maxdelay = th.popFloat(\"alpasl : maxdelay\");\n\tV delay = th.popZIn(\"alpasl : delay\");\n\tV in = th.popZIn(\"alpasl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasc : decay\");\n\tZ maxdelay = th.popFloat(\"alpasc : maxdelay\");\n\tV delay = th.popZIn(\"alpasc : delay\");\n\tV in = th.popZIn(\"alpasc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\nclass FDN;\n\nclass FDN_OutputChannel : public Gen\n{\n\tfriend class FDN;\n\tP mFDN;\n\t\npublic:\t\n\tFDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmFDN = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FDN_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nclass FDN : public Object\n{\n\tZIn in_;\n\tZIn wet_;\n\tZ decayLo_;\n\tZ decayMid_;\n\tZ decayHi_;\n\tZ mindelay_;\n\tZ maxdelay_;\n\tZ sr_;\n\t\n\tZ a1Lo, a1Hi;\n\tZ scaleLoLPF, scaleLoHPF, scaleHiLPF, scaleHiHPF;\n\tFDN_OutputChannel* mLeft;\n\tFDN_OutputChannel* mRight;\n\t\n\tstatic const int kNumDelays = 16;\n\t\n\tstruct FDNDelay\n\t{\n\t\tZ* buf;\n\t\tint size, mask, rpos, wpos, offset;\n\t\tZ delay, gain;\n\t\tZ fbLo, fbMid, fbHi;\n\t\tZ x1A, x1B, x1C, x1D;\n\t\tZ y1A, y1B, y1C, y1D;\n\t\t\n\t\tFDNDelay()\n\t\t{\n\t\t}\n\t\t~FDNDelay() { free(buf); }\n\t\t\n\t\tvoid set(Thread& th, const FDN& fdn, Z inDelay, int& ioSampleDelay)\n\t\t{\n\t\t\tint sampleDelay = (int)(th.rate.sampleRate * inDelay);\n\t\t\tif (sampleDelay <= ioSampleDelay) sampleDelay = ioSampleDelay + 2;\n\t\t\tsampleDelay = (int)nextPrime(sampleDelay);\n\t\t\tioSampleDelay = sampleDelay;\n\t\t\tZ actualDelay = (Z)sampleDelay * th.rate.invSampleRate;\n\t\t\tsize = NEXTPOWEROFTWO(sampleDelay);\n\t\t\tmask = size - 1;\n\t\t\tprintf(\"delay %6d %6d %6d %f\\n\", sampleDelay, size, mask, actualDelay);\n\t\t\trpos = 0;\n\t\t\twpos = sampleDelay;\n\t\t\tbuf = (Z*)calloc(size, sizeof(Z));\n\t\t\tconst Z n1 = 1. / sqrt(kNumDelays);\n\t\t\t//const Z n1 = 1. / kNumDelays;\n\t\t\tfbLo = n1 * calcDecay(actualDelay / fdn.decayLo_);\n\t\t\tfbMid = n1 * calcDecay(actualDelay / fdn.decayMid_);\n\t\t\tfbHi = n1 * calcDecay(actualDelay / fdn.decayHi_);\n\t\t\ty1A = 0.;\n\t\t\ty1B = 0.;\n\t\t\ty1C = 0.;\n\t\t\ty1D = 0.;\n\t\t\tx1A = 0.;\n\t\t\tx1B = 0.;\n\t\t\tx1C = 0.;\n\t\t\tx1D = 0.;\n\t\t}\n\t};\n\npublic:\n\n\tFDNDelay mDelay[kNumDelays];\n\t\n\tFDN(Thread& th, Arg in, Arg wet, Z mindelay, Z maxdelay, Z decayLo, Z decayMid, Z decayHi, Z seed)\n\t\t: in_(in), wet_(wet),\n\t\tdecayLo_(decayLo), decayMid_(decayMid), decayHi_(decayHi),\n\t\tmindelay_(mindelay), maxdelay_(maxdelay)\n\t{\n\t\tsr_ = th.rate.sampleRate;\n\t\tZ freqmul = th.rate.invNyquistRate * kFirstOrderCoeffScale;\n\t\ta1Lo = t_firstOrderCoeff(freqmul * 200.);\n\t\ta1Hi = t_firstOrderCoeff(freqmul * 2000.);\n\t\tscaleLoLPF = .5 * (1. - a1Lo);\n\t\tscaleLoHPF = .5 * (1. + a1Lo);\n\t\tscaleHiLPF = .5 * (1. - a1Hi);\n\t\tscaleHiHPF = .5 * (1. + a1Hi);\n\t\t\n\t\tZ delay = mindelay;\n\t\tZ ratio = maxdelay / mindelay;\n\t\tZ interval = pow(ratio, 1. / (kNumDelays - 1.));\n\t\tint prevSampleDelay = 0;\n\t\tfor (int i = 0; i < kNumDelays; ++i) {\n\t\t\tdouble expon = (random() / 2147483647. - .5) * 0.8;\n\t\t\tdouble deviation = pow(interval, expon);\n\t\t\tmDelay[i].set(th, *this, delay * deviation, prevSampleDelay);\n\t\t\tdelay *= interval;\n\t\t}\n\t\t\n\t}\n\t\n\t~FDN() { delete mLeft; delete mRight; }\n\t\n\tvirtual const char* TypeName() const override { return \"FDN\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tvoid matrix(Z x[kNumDelays])\n\t{\n\t\tZ a0 = x[ 0];\n\t\tZ a1 = x[ 1];\n\t\tZ a2 = x[ 2];\n\t\tZ a3 = x[ 3];\n\t\tZ a4 = x[ 4];\n\t\tZ a5 = x[ 5];\n\t\tZ a6 = x[ 6];\n\t\tZ a7 = x[ 7];\n\t\tZ a8 = x[ 8];\n\t\tZ a9 = x[ 9];\n\t\tZ a10 = x[10];\n\t\tZ a11 = x[11];\n\t\tZ a12 = x[12];\n\t\tZ a13 = x[13];\n\t\tZ a14 = x[14];\n\t\tZ a15 = x[15];\n\n\t\tZ b0 = a0 + a1;\n\t\tZ b1 = a0 - a1;\n\t\tZ b2 = a2 + a3;\n\t\tZ b3 = a2 - a3;\n\t\tZ b4 = a4 + a5;\n\t\tZ b5 = a4 - a5;\n\t\tZ b6 = a6 + a7;\n\t\tZ b7 = a6 - a7;\n\t\tZ b8 = a8 + a9;\n\t\tZ b9 = a8 - a9;\n\t\tZ b10 = a10 + a11;\n\t\tZ b11 = a10 - a11;\n\t\tZ b12 = a12 + a13;\n\t\tZ b13 = a12 - a13;\n\t\tZ b14 = a14 + a15;\n\t\tZ b15 = a14 - a15;\n\n\t\tZ c0 = b0 + b2;\n\t\tZ c1 = b1 + b3;\n\t\tZ c2 = b0 - b2;\n\t\tZ c3 = b1 - b3;\n\t\tZ c4 = b4 + b6;\n\t\tZ c5 = b5 + b7;\n\t\tZ c6 = b4 - b6;\n\t\tZ c7 = b5 - b7;\n\t\tZ c8 = b8 + b10;\n\t\tZ c9 = b9 + b11;\n\t\tZ c10 = b8 - b10;\n\t\tZ c11 = b9 - b11;\n\t\tZ c12 = b12 + b14;\n\t\tZ c13 = b13 + b15;\n\t\tZ c14 = b12 - b14;\n\t\tZ c15 = b13 - b15;\n\n\t\tZ d0 = c0 + c4;\n\t\tZ d1 = c1 + c5;\n\t\tZ d2 = c2 + c6;\n\t\tZ d3 = c3 + c7;\n\t\tZ d4 = c0 - c4;\n\t\tZ d5 = c1 - c5;\n\t\tZ d6 = c2 - c6;\n\t\tZ d7 = c3 - c7;\n\t\tZ d8 = c8 + c12;\n\t\tZ d9 = c9 + c13;\n\t\tZ d10 = c10 + c14;\n\t\tZ d11 = c11 + c15;\n\t\tZ d12 = c8 - c12;\n\t\tZ d13 = c9 - c13;\n\t\tZ d14 = c10 - c14;\n\t\tZ d15 = c11 - c15;\n\n\t\tx[ 0] = d0 + d8;\n\t\tx[ 1] = d1 + d9;\n\t\tx[ 2] = d2 + d10;\n\t\tx[ 3] = d3 + d11;\n\t\tx[ 4] = d4 + d12;\n\t\tx[ 5] = d5 + d13;\n\t\tx[ 6] = d6 + d14;\n\t\tx[ 7] = d7 + d15;\n\t\tx[ 8] = d0 - d8;\n\t\tx[ 9] = d1 - d9;\n\t\tx[10] = d2 - d10;\n\t\tx[11] = d3 - d11;\n\t\tx[12] = d4 - d12;\n\t\tx[13] = d5 - d13;\n\t\tx[14] = d6 - d14;\n\t\tx[15] = d7 - d15;\n\t}\n \n\tvirtual void pull(Thread& th) \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, wetStride;\n\t\t\tZ *in;\n\t\t\tZ *wet;\n\t\t\tif (in_(th, n, inStride, in) || wet_(th, n, wetStride, wet)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x[kNumDelays];\n\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\n\t\t\t\t\t\t// read from delay line\n\t\t\t\t\t\tZ x0 = d.buf[d.rpos & d.mask];\n\n\t\t\t\t\t\t// attenuate and filter the output of the delay line.\n\t\t\t\t\t\t\n\t\t\t\t\t\t// high crossover\n\t\t\t\t\t\tZ x0A = scaleHiHPF * x0;\n\t\t\t\t\t\tZ x0B = scaleHiLPF * x0 ;\n\t\t\t\t\t\tZ y0A = x0A - d.x1A + a1Hi * d.y1A;\t// hpf -> high band\n\t\t\t\t\t\tZ y0B = x0B + d.x1B + a1Hi * d.y1B;\t// lpf -> low + mid\n\t\t\t\t\t\td.y1A = y0A;\n\t\t\t\t\t\td.y1B = y0B;\n\t\t\t\t\t\td.x1A = x0A;\n\t\t\t\t\t\td.x1B = x0B;\n\t\t\t\t\t\t\n\t\t\t\t\t\t// low crossover\n\t\t\t\t\t\tZ x0C = scaleLoHPF * y0B;\n\t\t\t\t\t\tZ x0D = scaleLoLPF * y0B;\n\t\t\t\t\t\tZ y0C = x0C - d.x1C + a1Lo * d.y1C;\t// hpf -> mid band\n\t\t\t\t\t\tZ y0D = x0D + d.x1D + a1Lo * d.y1D;\t// lpf -> low band\n\t\t\t\t\t\td.y1C = y0C;\n\t\t\t\t\t\td.y1D = y0D;\n\t\t\t\t\t\td.x1C = x0C;\n\t\t\t\t\t\td.x1D = x0D;\n\t\t\t\t\t\t\n\t\t\t\t\t\tx[j] = d.fbLo * y0D + d.fbMid * y0C + d.fbHi * y0A;\n\n\t\t\t\t\t\t++d.rpos;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tmatrix(x);\n\t\t\t\t\t\n\t\t\t\t\tZ ini = *in;\n\t\t\t\t\tZ w = *wet;\n\t\t\t\t\t*Lout = ini + w * (x[1] - ini);\n\t\t\t\t\t*Rout = ini + w * (x[2] - ini);\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\n\t\t\t\t\t// write back to delay line\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j) \n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\td.buf[d.wpos & d.mask] = x[j] + ini;\n\t\t\t\t\t\t++d.wpos;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tin += inStride;\n\t\t\t\t\twet += wetStride;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nFDN_OutputChannel::FDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN)\n : Gen(th, itemTypeZ, inFinite), mFDN(inFDN)\n{\n}\n\nvoid FDN_OutputChannel::pull(Thread& th)\n{\n\tmFDN->pull(th);\n}\n\nP FDN::createOutputs(Thread& th)\n{\n\tmLeft = new FDN_OutputChannel(th, finite, this);\n\tmRight = new FDN_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void fdn_(Thread& th, Prim* prim)\n{\n\tZ seed = th.popFloat(\"fdn : seed\");\n\tZ maxdelay = th.popFloat(\"fdn : maxdelay\");\n\tZ mindelay = th.popFloat(\"fdn : mindelay\");\n\tZ decayHi = th.popFloat(\"fdn : decayHi\");\n\tZ decayMid = th.popFloat(\"fdn : decayMid\");\n\tZ decayLo = th.popFloat(\"fdn : decayLo\");\n\tV wet = th.popZIn(\"fdn : wet\");\n\tV in = th.popZIn(\"fdn : in\");\n \n\tP fdn = new FDN(th, in, wet, mindelay, maxdelay, decayLo, decayMid, decayHi, seed);\n\t\n\tP s = fdn->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddDelayUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** delay unit generators ***\");\n\tDEFAM(delayn, zzk, \"(in delay maxdelay --> out) delay line with no interpolation.\");\n\tDEFAM(delayl, zzk, \"(in delay maxdelay --> out) delay line with linear interpolation.\");\n\tDEFAM(delayc, zzk, \"(in delay maxdelay --> out) delay line with cubic interpolation.\");\n\tDEFAM(flange, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. delay can be negative. latency is maxdelay.\");\n\tDEFAM(flangep, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. adds delayed signal instead of subtracts.\");\n\t\n\tDEFAM(combn, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with no interpolation.\");\n\tDEFAM(combl, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with linear interpolation.\");\n\tDEFAM(combc, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with cubic interpolation.\");\n\tDEFAM(lpcombc, zzkzz, \"(in delay maxdelay decayTime lpfreq --> out) low pass comb delay filter with cubic interpolation.\");\n\t\n\tDEFAM(alpasn, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with no interpolation.\");\n\tDEFAM(alpasl, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with linear interpolation.\");\n\tDEFAM(alpasc, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with cubic interpolation.\");\n\t//DEFAM(fdn, zzkkkkkk, \"(in wet decayLo decayMid decayHi mindelay maxdelay rseed --> out) feedback delay network reverb.\");\n}\n\n\n"], ["/sapf/src/MathOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathOps.hpp\"\n#include \"clz.hpp\"\n#include \n#include \"primes.hpp\"\n#include \n\n\n\nV BinaryOp::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpGen(th, this, a, b));\n}\n\nV BinaryOp::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpZGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n}\n\nvoid UnaryOp::loop(Thread& th, int n, V *a, int astride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->unaryOp(th, this);\n\t\ta += astride;\n\t} \n}\n\nvoid BinaryOp::loop(Thread& th, int n, V *a, int astride, V *b, int bstride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, *b);\n\t\ta += astride;\n\t\tb += bstride;\n\t} \n}\n\nvoid BinaryOp::loopzv(Thread& th, int n, Z *aa, int astride, V *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa;\n\t\tArg b = *bb; \n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\nvoid BinaryOp::loopvz(Thread& th, int n, V *aa, int astride, Z *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa; \n\t\tArg b = *bb;\n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\n\nvoid BinaryOp::scan(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = x = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::pairs(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, x);\n\t\tx = *a;\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::reduce(Thread& th, int n, V& z, V *a, int astride)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tx = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\n\nvoid UnaryOpZGen::pull(Thread& th) {\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ *a;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, out);\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nvoid BinaryOpZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\nvoid BinaryOpLinkZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_b.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else if (_b(th, n,bstride, b)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nstatic void DoPairwise(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new PairsOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new PairsOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoScan(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new ScanOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new ScanOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIPairwise(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IPairsOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IPairsOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoIScan(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IScanOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IScanOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z, *x;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = kDefaultVBlockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = 0., *x;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = th.rate.blockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reducez(n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z = b, *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\twhile(1) {\n\t\t\tn = kDefaultVBlockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = b.asFloat(), *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\twhile(1) {\n\t\t\tn = th.rate.blockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reducez(n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n#define UNARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.unaryOp(th, &gUnaryOp_##NAME); \\\n\t\tth.push(c); \\\n\t} \\\n\n\n#define BINARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV b = th.pop(); \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.binaryOp(th, &gBinaryOp_##NAME, b); \\\n\t\tth.push(c); \\\n\t} \\\n\tstatic void NAME##_reduce_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoReduce(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_scan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_pairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_iscan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_ipairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\n#define DEFINE_UNOP_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV(NAME, CODE, VVNAME) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *x, int astride, Z *y) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVNAME(y, x, &n); \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *x; y[i] = CODE; x += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV2(NAME, CODE, VVCODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (Z)(CODE); aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_BOOL_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_BOOL_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (CODE) ? 1. : 0.; \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n\n\n\n\n\n#define DEFINE_BINOP_FLOAT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOAT_STRING(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE); \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOATVV(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tVVCODE; \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_FLOATVV1(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tif (astride == 1 && bstride == 1) { \\\n\t\t\t\t VVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t\t} \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_INT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa, double bb) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\tint64_t b = (int64_t)bb; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; int64_t b = (int64_t)*bb; out[i] = (Z)(CODE); aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t b = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = (Z)b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; Z x = CODE; out[i] = x; a = (int64_t)x; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; a = (int64_t)(CODE); aa += astride; } \\\n\t\t\tz = (Z)a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_BOOL_FLOAT(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = (CODE) ? 1. : 0.; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE) ? 1. : 0.; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\nDEFINE_UNOP_BOOL_INT(isalnum, isalnum((int)a))\nDEFINE_UNOP_BOOL_INT(isalpha, isalpha((int)a))\nDEFINE_UNOP_BOOL_INT(isblank, isblank((int)a))\nDEFINE_UNOP_BOOL_INT(iscntrl, iscntrl((int)a))\nDEFINE_UNOP_BOOL_INT(isdigit, isdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isgraph, isgraph((int)a))\nDEFINE_UNOP_BOOL_INT(islower, islower((int)a))\nDEFINE_UNOP_BOOL_INT(isprint, isprint((int)a))\nDEFINE_UNOP_BOOL_INT(ispunct, ispunct((int)a))\nDEFINE_UNOP_BOOL_INT(isspace, isspace((int)a))\nDEFINE_UNOP_BOOL_INT(isupper, isupper((int)a))\nDEFINE_UNOP_BOOL_INT(isxdigit, isxdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isascii, isascii((int)a))\n\nDEFINE_UNOP_BOOL_FLOAT(not, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonneg, a >= 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonpos, a <= 0.)\nDEFINE_UNOP_BOOL_FLOAT(isneg, a < 0.)\nDEFINE_UNOP_BOOL_FLOAT(ispos, a > 0.)\nDEFINE_UNOP_BOOL_FLOAT(iszero, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(isint, (a - floor(a)) == 0.)\nDEFINE_UNOP_BOOL_INT(iseven, !(a & 1))\nDEFINE_UNOP_BOOL_INT(isodd, (a & 1))\nDEFINE_UNOP_BOOL_INT(isprime, isprime(a))\n\nDEFINE_UNOP_BOOL_FLOAT(isfinite, std::isfinite(a))\nDEFINE_UNOP_BOOL_FLOAT(isinf, std::isinf(a))\nDEFINE_UNOP_BOOL_FLOAT(isnormal, std::isnormal(a))\nDEFINE_UNOP_BOOL_FLOAT(isnan, std::isnan(a))\nDEFINE_UNOP_BOOL_FLOAT(signbit, std::signbit(a))\n\nstruct UnaryOp_ToZero : public UnaryOp {\n\tvirtual const char *Name() { return \"ToZero\"; }\n\tvirtual double op(double a) { return 0.; }\n\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) {\n\t\tLOOP(i,n) { out[i] = 0.; }\n\t}\n};\nUnaryOp_ToZero gUnaryOp_ToZero; \n\nDEFINE_UNOP_FLOATVV2(neg, -a, vDSP_vnegD(const_cast(aa), astride, out, 1, n))\nDEFINE_UNOP_FLOAT(sgn, sc_sgn(a))\nDEFINE_UNOP_FLOATVV(abs, fabs(a), vvfabs)\n\nDEFINE_UNOP_INT(tolower, tolower((int)a))\nDEFINE_UNOP_INT(toupper, toupper((int)a))\nDEFINE_UNOP_INT(toascii, toascii((int)a))\n\nDEFINE_UNOP_FLOATVV2(frac, a - floor(a), vvfloor(out, aa, &n); vDSP_vsubD(out, 1, aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV(floor, floor(a), vvfloor)\nDEFINE_UNOP_FLOATVV(ceil, ceil(a), vvceil)\nDEFINE_UNOP_FLOATVV(rint, rint(a), vvnint)\n\nDEFINE_UNOP_FLOAT(erf, erf(a))\nDEFINE_UNOP_FLOAT(erfc, erfc(a))\n\nDEFINE_UNOP_FLOATVV(recip, 1./a, vvrec)\nDEFINE_UNOP_FLOATVV(sqrt, sc_sqrt(a), vvsqrt)\nDEFINE_UNOP_FLOATVV(rsqrt, 1./sc_sqrt(a), vvrsqrt)\nDEFINE_UNOP_FLOAT(cbrt, cbrt(a))\nDEFINE_UNOP_FLOATVV2(ssq, copysign(a*a, a), vDSP_vssqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV2(sq, a*a, vDSP_vsqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOAT(cb, a*a*a)\nDEFINE_UNOP_FLOAT(pow4, sc_fourth(a))\nDEFINE_UNOP_FLOAT(pow5, sc_fifth(a))\nDEFINE_UNOP_FLOAT(pow6, sc_sixth(a))\nDEFINE_UNOP_FLOAT(pow7, sc_seventh(a))\nDEFINE_UNOP_FLOAT(pow8, sc_eighth(a))\nDEFINE_UNOP_FLOAT(pow9, sc_ninth(a))\n\nDEFINE_UNOP_FLOATVV(exp, exp(a), vvexp)\nDEFINE_UNOP_FLOATVV(exp2, exp2(a), vvexp2)\nDEFINE_UNOP_FLOAT(exp10, pow(10., a))\nDEFINE_UNOP_FLOATVV(expm1, expm1(a), vvexpm1)\nDEFINE_UNOP_FLOATVV(log, sc_log(a), vvlog)\nDEFINE_UNOP_FLOATVV(log2, sc_log2(a), vvlog2)\nDEFINE_UNOP_FLOATVV(log10, sc_log10(a), vvlog10)\nDEFINE_UNOP_FLOATVV(log1p, log1p(a), vvlog1p)\nDEFINE_UNOP_FLOATVV(logb, logb(a), vvlogb)\n\nDEFINE_UNOP_FLOAT(sinc, sc_sinc(a))\n\nDEFINE_UNOP_FLOATVV(sin, sin(a), vvsin)\nDEFINE_UNOP_FLOATVV(cos, cos(a), vvcos)\nDEFINE_UNOP_FLOATVV2(sin1, sin(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvsin(out, out, &n))\nDEFINE_UNOP_FLOATVV2(cos1, cos(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvcos(out, out, &n))\nDEFINE_UNOP_FLOATVV(tan, tan(a), vvtan)\nDEFINE_UNOP_FLOATVV(asin, asin(a), vvasin)\nDEFINE_UNOP_FLOATVV(acos, acos(a), vvacos)\nDEFINE_UNOP_FLOATVV(atan, atan(a), vvatan)\nDEFINE_UNOP_FLOATVV(sinh, sinh(a), vvsinh)\nDEFINE_UNOP_FLOATVV(cosh, cosh(a), vvcosh)\nDEFINE_UNOP_FLOATVV(tanh, tanh(a), vvtanh)\nDEFINE_UNOP_FLOATVV(asinh, asinh(a), vvasinh)\nDEFINE_UNOP_FLOATVV(acosh, acosh(a), vvacosh)\nDEFINE_UNOP_FLOATVV(atanh, atanh(a), vvatanh)\n\nDEFINE_UNOP_FLOAT(J0, j0(a))\nDEFINE_UNOP_FLOAT(J1, j1(a))\nDEFINE_UNOP_FLOAT(Y0, y0(a))\nDEFINE_UNOP_FLOAT(Y1, y1(a))\n\nDEFINE_UNOP_FLOAT(tgamma, tgamma(a))\nDEFINE_UNOP_FLOAT(lgamma, lgamma(a))\n\nstatic void sc_clipv(int n, const Z* in, Z* out, Z a, Z b)\n{\n\tfor (int i = 0; i < n; ++i) {\n\t\tout[i] = std::clamp(in[i], a, b);\n\t}\n}\n\nDEFINE_UNOP_FLOATVV2(inc, a+1, Z b = 1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(dec, a-1, Z b = -1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(half, a*.5, Z b = .5; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(twice, a*2., Z b = 2.; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n))\n\n\nDEFINE_UNOP_FLOATVV2(biuni, a*.5+.5, Z b = .5; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibi, a*2.-1., Z b = 2.; Z c = -1.; vDSP_vsmulD(aa, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOATVV2(biunic, std::clamp(a,-1.,1.)*.5+.5, Z b = .5; sc_clipv(n, aa, out, -1., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibic, std::clamp(a,0.,1.)*2.-1., Z b = 2.; Z c = -1.; sc_clipv(n, aa, out, 0., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOAT(cmpl, 1.-a)\n\nDEFINE_UNOP_FLOATVV2(ampdb, sc_ampdb(a), Z b = 1.; vDSP_vdbconD(const_cast(aa), astride, &b, out, 1, n, 1))\nDEFINE_UNOP_FLOAT(dbamp, sc_dbamp(a))\n\nDEFINE_UNOP_FLOAT(hzo, sc_hzoct(a))\nDEFINE_UNOP_FLOAT(ohz, sc_octhz(a))\n\nDEFINE_UNOP_FLOAT(hzst, sc_hzkey(a))\nDEFINE_UNOP_FLOAT(sthz, sc_keyhz(a))\n\nDEFINE_UNOP_FLOAT(hznn, sc_hznn(a))\nDEFINE_UNOP_FLOAT(nnhz, sc_nnhz(a))\n\nDEFINE_UNOP_FLOAT(centsratio, sc_centsratio(a))\nDEFINE_UNOP_FLOAT(ratiocents, sc_ratiocents(a))\n\nDEFINE_UNOP_FLOAT(semiratio, sc_semiratio(a))\nDEFINE_UNOP_FLOAT(ratiosemi, sc_ratiosemi(a))\n\nDEFINE_UNOP_FLOATVV2(degrad, a*kDegToRad, Z b = kDegToRad; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(raddeg, a*kRadToDeg, Z b = kRadToDeg; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(minsec, a*kMinToSecs, Z b = kMinToSecs; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(secmin, a*kSecsToMin, Z b = kSecsToMin; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(bpmsec, kMinToSecs / a, Z b = kMinToSecs; vDSP_svdivD(&b, const_cast(aa), astride, out, 1, n))\n\nDEFINE_UNOP_FLOAT(distort, sc_distort(a))\nDEFINE_UNOP_FLOAT(softclip, sc_softclip(a))\n\nDEFINE_UNOP_FLOAT(rectWin, sc_rectWindow(a))\nDEFINE_UNOP_FLOAT(triWin, sc_triWindow(a))\nDEFINE_UNOP_FLOAT(bitriWin, sc_bitriWindow(a))\nDEFINE_UNOP_FLOAT(hanWin, sc_hanWindow(a))\nDEFINE_UNOP_FLOAT(sinWin, sc_sinWindow(a))\nDEFINE_UNOP_FLOAT(ramp, sc_ramp(a))\nDEFINE_UNOP_FLOAT(scurve, sc_scurve(a))\nDEFINE_UNOP_FLOAT(sigm,\t\ta/sqrt(1.+a*a))\n\nDEFINE_UNOP_FLOAT(zapgremlins, zapgremlins(a))\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nDEFINE_BINOP_BOOL_FLOAT(lt, a < b, strcmp(a, b) < 0)\nDEFINE_BINOP_BOOL_FLOAT(le, a <= b, strcmp(a, b) <= 0)\nDEFINE_BINOP_BOOL_FLOAT(gt, a > b, strcmp(a, b) > 0)\nDEFINE_BINOP_BOOL_FLOAT(ge, a >= b, strcmp(a, b) >= 0)\nDEFINE_BINOP_BOOL_FLOAT(eq, a == b, strcmp(a, b) == 0)\nDEFINE_BINOP_BOOL_FLOAT(ne, a != b, strcmp(a, b) != 0)\nDEFINE_BINOP_FLOAT_STRING(cmp, sc_cmp(a, b), sc_sgn(strcmp(a, b)))\n\nDEFINE_BINOP_FLOATVV1(copysign, copysign(a, b), vvcopysign(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\nDEFINE_BINOP_FLOATVV1(nextafter, nextafter(a, b), vvnextafter(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\n\n// identity optimizations of basic operators.\n\n\tstruct BinaryOp_plus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus gBinaryOp_plus;\n\tBinaryOp* gBinaryOpPtr_plus = &gBinaryOp_plus;\n\tBINARY_OP_PRIM(plus)\n\n\n\tstruct BinaryOp_plus_link : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus_link gBinaryOp_plus_link;\n\tBinaryOp* gBinaryOpPtr_plus_link = &gBinaryOp_plus_link;\n\tBINARY_OP_PRIM(plus_link)\n\n\n\tstruct BinaryOp_minus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"minus\"; }\n\t\tvirtual double op(double a, double b) { return a - b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\tif (*aa != 0.) {\n\t\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, const_cast(aa), out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\tif (*bb != 0.) {\n\t\t\t\t\tZ b = -*bb;\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, &b, out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vsubD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a - b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_minus gBinaryOp_minus;\n\tBinaryOp* gBinaryOpPtr_minus = &gBinaryOp_minus;\n\tBINARY_OP_PRIM(minus)\n\n\n\n\tstruct BinaryOp_mul : public BinaryOp {\n\t\tvirtual const char *Name() { return \"mul\"; }\n\t\tvirtual double op(double a, double b) { return a * b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else if (*aa == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(bb, bstride, aa, out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += astride; }\n\t\t\t\t} else if (*bb == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(aa, astride, bb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a * b; aa += astride; bb += bstride; }\n\t\t\t\tvDSP_vmulD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a * b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_mul gBinaryOp_mul;\n\tBinaryOp* gBinaryOpPtr_mul = &gBinaryOp_mul;\n\tBINARY_OP_PRIM(mul)\n\n\n\tstruct BinaryOp_div : public BinaryOp {\n\t\tvirtual const char *Name() { return \"div\"; }\n\t\tvirtual double op(double a, double b) { return a / b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0 && *aa == 0.) {\n\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tZ rb = 1. / *bb;\n\t\t\t\t\tvDSP_vsmulD(const_cast(aa), astride, &rb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vdivD(const_cast(bb), bstride, const_cast(aa), astride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a / b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a / b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_div gBinaryOp_div;\n\tBinaryOp* gBinaryOpPtr_div = &gBinaryOp_div;\n\tBINARY_OP_PRIM(div)\n\nDEFINE_BINOP_FLOAT(mod, sc_fmod(a, b))\nDEFINE_BINOP_FLOAT(remainder, remainder(a, b))\n\nDEFINE_BINOP_INT(idiv, sc_div(a, b))\nDEFINE_BINOP_INT(imod, sc_imod(a, b))\n\nDEFINE_BINOP_FLOATVV1(pow, sc_pow(a, b), vvpow(out, bb, aa, &n))\nDEFINE_BINOP_FLOATVV1(atan2, atan2(a, b), vvatan2(out, aa, bb, &n))\n\nDEFINE_BINOP_FLOAT(Jn, jn((int)b, a))\nDEFINE_BINOP_FLOAT(Yn, yn((int)b, a))\n\nDEFINE_BINOP_FLOATVV(min, fmin(a, b), vDSP_vminD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOATVV(max, fmax(a, b), vDSP_vmaxD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(dim, fdim(a, b))\nDEFINE_BINOP_FLOAT(xor, fdim(a, b))\n\nDEFINE_BINOP_FLOAT(avg2, (a + b) * .5)\nDEFINE_BINOP_FLOAT(absdif, fabs(a - b))\nDEFINE_BINOP_FLOATVV(hypot, hypot(a, b), vDSP_vdistD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(sumsq, a*a + b*b)\nDEFINE_BINOP_FLOAT(difsq, a*a - b*b)\nDEFINE_BINOP_FLOAT(sqsum, sc_squared(a + b))\nDEFINE_BINOP_FLOAT(sqdif, sc_squared(a - b))\n\nDEFINE_BINOP_FLOAT(thresh, a < b ? 0. : a)\nDEFINE_BINOP_FLOAT(absthresh, fabs(a) < b ? 0. : a)\nDEFINE_BINOP_FLOAT(amclip, b <= 0. ? 0. : a * b)\nDEFINE_BINOP_FLOAT(scaleneg, a < 0. ? a * b : a)\n\nDEFINE_BINOP_FLOAT(ring1, a * b + a)\nDEFINE_BINOP_FLOAT(ring2, a * b + a + b)\nDEFINE_BINOP_FLOAT(ring3, a*a*b)\nDEFINE_BINOP_FLOAT(ring4, a*b*(a - b))\n\nDEFINE_BINOP_INT(gcd, sc_gcd(a, b))\nDEFINE_BINOP_INT(lcm, sc_lcm(a, b))\n\nDEFINE_BINOP_FLOAT(clip2, std::clamp(a, -b, b))\nDEFINE_BINOP_FLOAT(wrap2, sc_wrap(a, -b, b))\nDEFINE_BINOP_FLOAT(fold2, sc_fold(a, -b, b))\nDEFINE_BINOP_INT(iwrap2, sc_iwrap(a, -b, b))\nDEFINE_BINOP_INT(ifold2, sc_ifold(a, -b, b))\nDEFINE_BINOP_FLOAT(excess, a - std::clamp(a, -b, b))\n\nDEFINE_BINOP_FLOAT(clip0, std::clamp(a, 0., b))\nDEFINE_BINOP_FLOAT(wrap0, sc_wrap(a, 0., b))\nDEFINE_BINOP_FLOAT(fold0, sc_fold(a, 0., b))\n\nDEFINE_BINOP_FLOAT(round, sc_round(a, b))\nDEFINE_BINOP_FLOAT(roundUp, sc_roundUp(a, b))\nDEFINE_BINOP_FLOAT(trunc, sc_trunc(a, b))\n\n\n#define DEFN(FUNNAME, OPNAME, HELP) \tvm.def(OPNAME, 1, 1, FUNNAME##_, \"(x --> z) \" HELP);\n#define DEFNa(FUNNAME, OPNAME, HELP) \tDEFN(FUNNAME, #OPNAME, HELP)\n#define DEF(NAME, HELP) \tDEFNa(NAME, NAME, HELP); \n\n#define DEFNa2(FUNNAME, OPNAME, HELP) \t\\\n\t(vm.def(#OPNAME, 2, 1, FUNNAME##_, \"(x y --> z) \" HELP), \\\n\tvm.def(#OPNAME \"/\", 1, 1, FUNNAME##_reduce_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\\", 1, 1, FUNNAME##_scan_, nullptr), \\\n\tvm.def(#OPNAME \"^\", 1, 1, FUNNAME##_pairs_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\i\", 2, 1, FUNNAME##_iscan_, nullptr), \\\n\tvm.def(#OPNAME \"^i\", 1, 1, FUNNAME##_ipairs_, nullptr));\n\n#define DEF2(NAME, HELP) \tDEFNa2(NAME, NAME, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMathOps();\nvoid AddMathOps()\n{\t\n\tfillSineTable();\n\tfillDBAmpTable();\n\tfillDecayTable();\n fillFirstOrderCoeffTable();\n\n\tvm.addBifHelp(\"\\n*** unary math ops ***\");\n\tDEF(isalnum, \"return whether an ASCII value is alphanumeric.\")\n\tDEF(isalpha, \"return whether an ASCII value is alphabetic.\")\n\tDEF(isblank, \"return whether an ASCII value is a space or tab character.\")\n\tDEF(iscntrl, \"return whether an ASCII value is a control character.\")\n\tDEF(isdigit, \"return whether an ASCII value is a digit.\")\n\tDEF(isgraph, \"return whether an ASCII value is a graphic character.\");\n\tDEF(islower, \"return whether an ASCII value is lower case.\")\n\tDEF(isprint, \"return whether an ASCII value is a printable character.\")\n\tDEF(ispunct, \"return whether an ASCII value is a punctuation character.\")\n\tDEF(isspace, \"return whether an ASCII value is a graphic character.\")\n\tDEF(isupper, \"return whether an ASCII value is upper case.\")\n\tDEF(isxdigit, \"return whether an ASCII value is a hexadecimal digit.\")\n\tDEF(isascii, \"return whether a value is ASCII\")\n\n\tDEF(tolower, \"convert an ASCII character value to lower case.\")\n\tDEF(toupper, \"convert an ASCII character value to upper case.\")\n\tDEF(toascii, \"convert a value to ASCII by stripping the upper bits.\")\n\n\tDEFN(nonpos, \"0<=\", \"less than or equal to zero.\")\n\tDEFN(nonneg, \"0>=\", \"greater than or equal to zero.\")\n\tDEFN(isneg, \"0<\", \"less than zero.\")\n\tDEFN(ispos, \"0>\", \"greater than zero.\")\n\tDEFN(iszero, \"0=\", \"equal to zero.\")\n\tDEFN(iseven, \"even?\", \"is even.\")\n\tDEFN(isodd, \"odd?\", \"is odd.\")\n\tDEFN(isprime, \"prime?\", \"is prime.\")\n\tDEFN(isint, \"int?\", \"is integer.\")\n\t\n\tDEF(isfinite, \"is x a finite number.\")\n\tDEF(isinf, \"is x an infinity.\")\n\tDEF(isnan, \"is x not a number.\")\n\tDEF(isnormal, \"is x a normalized number (as opposed to denormals).\")\n\tDEF(signbit, \"sign bit of x.\")\n\t\t\n\tDEF(abs, \"absolute value.\")\n\tDEF(sgn, \"signum function. returns -1 when x < 0, 0 when x == 0, 1 when x > 0.\")\n\tDEFN(not, \"~\", \"logical negation. returns 1 when x == 0, else returns 0.\")\n\tDEF(neg, \"negative. -x\")\n\tDEF(sqrt, \"square root.\")\n\tDEF(cbrt, \"cube root.\")\n\tDEF(rsqrt, \"reciprocal square root.\")\n\tDEF(sq, \"square. x x *\")\n\tDEF(ssq, \"signed square. x x abs *\")\n\tDEF(cb, \"x cubed. x 3 ^\")\n\tDEFN(sq, \"^2\", \"x squared. x x *\")\n\tDEFN(cb, \"^3\", \"x cubed. x 3 ^\")\n\tDEFN(pow4, \"^4\", \"x to the fourth power. x 4 ^\")\n\tDEFN(pow5, \"^5\", \"x to the fifth power. x 5 ^\")\n\tDEFN(pow6, \"^6\", \"x to the sixth power. x 6 ^\")\n\tDEFN(pow7, \"^7\", \"x to the seventh power. x 7 ^\")\n\tDEFN(pow8, \"^8\", \"x to the eighth power. x 8 ^\")\n\tDEFN(pow9, \"^9\", \"x to the ninth power. x 9 ^\")\n\n\tDEF(recip, \"reciprocal.\")\n\tDEFN(recip, \"1/\", \"reciprocal. 1 x /\")\n\tDEF(exp, \"e to the x.\")\n\tDEF(exp2, \"2 to the x.\")\n\tDEF(exp10, \"10 to the x.\")\n\tDEFN(exp, \"e^\", \"e to the x.\")\n\tDEFN(exp2, \"2^\", \"2 to the x.\")\n\tDEFN(exp10, \"10^\", \"10 to the x.\")\n\tDEF(expm1, \"computes exp(x-1) accurately even for very small values of x.\")\n\tDEF(log, \"base e log of x.\")\n\tDEF(log2, \"base 2 log of x.\")\n\tDEF(log10, \"base 10 log of x.\")\n\tDEF(log1p, \"computes the value of log(1+x) accurately even for very small values of x.\")\n\tDEF(logb, \"x log2 floor\")\n\n\tDEF(frac, \"fractional part.\")\n\tDEF(floor, \"nearest integer <= x.\")\n\tDEF(ceil, \"nearest integer >= x.\")\n\tDEF(rint, \"nearest integer.\")\n\tDEF(erf, \"the error function.\")\n\tDEF(erfc, \"the complement of the error function.\")\n\n\tDEF(sinc, \"sinc. x sin x /\")\n\tDEF(sin, \"sine.\")\n\tDEF(cos, \"cosine.\")\n\tDEF(sin1, \"sine(x * 2pi).\")\n\tDEF(cos1, \"cosine(x * 2pi).\")\n\tDEF(tan, \"tangent.\")\n\tDEF(asin, \"arcsine.\")\n\tDEF(acos, \"arccosine.\")\n\tDEF(atan, \"arctangent.\")\n\tDEF(sinh, \"hyperbolic sine.\")\n\tDEF(cosh, \"hyperbolic cosine.\")\n\tDEF(tanh, \"hyperbolic tangent.\")\n\tDEF(asinh, \"hyperbolic arcsine.\")\n\tDEF(acosh, \"hyperbolic arccosine.\")\n\tDEF(atanh, \"hyperbolic arctangent.\")\n\t\n\tDEF(J0, \"zeroth Bessel function of the first kind evaluated at x.\")\n\tDEF(J1, \"first Bessel function of the first kind evaluated at x.\")\n\tDEF(Y0, \"zeroth Bessel function of the second kind evaluated at x.\")\n\tDEF(Y1, \"first Bessel function of the second kind evaluated at x.\")\n\n\tDEF(tgamma, \"the gamma function.\")\n\tDEF(lgamma, \"natural logarithm of the absolute value of the gamma function.\")\n\n\tDEF(inc, \"increment. x 1 +\")\n\tDEF(dec, \"decrement. x 1 -\")\n\tDEF(half, \"x .5 *\")\n\tDEF(twice, \"x 2 *\")\n\tDEFN(inc, \"++\", \"increment. x 1 +\")\n\tDEFN(dec, \"--\", \"decrement. x 1 -\")\n\tDEFN(half, \"/2\", \"half.\")\n\tDEFN(twice, \"*2\", \"twice.\")\n\tDEF(biuni, \"convert bipolar to unipolar. .5 * .5 +\")\n\tDEF(unibi, \"convert unipolar to bipolar. 2 * 1 -\")\n\tDEF(biunic, \"convert bipolar to unipolar with clipping to range. -1 1 clip .5 * .5 +\")\n\tDEF(unibic, \"convert unipolar to bipolar with clipping to range. 0 1 clip 2 * 1 -\")\n\tDEF(cmpl, \"unipolar complement. 1 x -\")\n\n\tDEF(ampdb, \"convert linear amplitude to decibels.\")\n\tDEF(dbamp, \"convert decibels to linear amplitude.\")\n\t\n\tDEF(ohz, \"convert octaves to Hertz. Octave 0.0 is middle C.\")\n\tDEF(hzo, \"convert Hertz to octaves. Octave 0.0 is middle C.\")\n\tDEF(nnhz, \"convert MIDI note numbers to Hertz. 60 is middle C.\")\n\tDEF(hznn, \"convert Hertz to MIDI note numbers. 60 is middle C.\")\n\n\tDEF(centsratio, \"convert an interval in cents to a ratio.\")\n\tDEF(ratiocents, \"convert a ratio to an interval in cents.\")\n\n\tDEF(semiratio, \"convert an interval in semitones to a ratio.\")\n\tDEF(ratiosemi, \"a ratio to an interval in semitones.\")\n\n\tDEF(minsec, \"convert from minutes to seconds. also for converting from bps to bpm\")\n\tDEF(secmin, \"convert from seconds to minutes. also for converting from bpm to bps.\")\n\tDEF(bpmsec, \"convert from beats per minute to a period in seconds(e.g. for delay times)\")\n\tDEF(degrad, \"convert from degrees to radians.\")\n\tDEF(raddeg, \"convert from radians to degrees.\")\n\n\tDEF(distort, \"sigmoid wave distortion function. x/sqrt(1 + x^2)\")\n\tDEF(softclip, \"sigmoid wave distortion function. returns x when abs(x) < .5, else returns (abs(x) - .25) / x\")\n\tDEF(sigm, \"sigmoid wave distortion function. x/sqrt(1+x*x).\")\n\n\tDEF(rectWin, \"rectangular window for x in the interval [0,1].\")\n\tDEF(triWin, \"triangular window for x in the interval [0,1].\")\n\tDEF(bitriWin, \"triangular window for x in the interval [-1,1]\")\n\tDEF(hanWin, \"hanning window for x in the interval [0,1]\")\n\tDEF(sinWin, \"sine window for x in the interval [0,1]\")\n\tDEF(ramp, \"return 0 when x <= 0, return x when 0 < x < 1, return 1 when x > 1.\")\n\tDEF(scurve, \"return 0 when x <= 0, return 3*x*x - 2*x*x*x when 0 < x < 1, return 1 when x > 1.\")\n\n\tDEF(zapgremlins, \"\")\n\n\t/////////////////////////////////////////////////////\n\n\tvm.addBifHelp(\"\\n*** binary math ops ***\");\n\tvm.addBifHelp(\"\\n All built-in binary math operators have the following variations defined:\");\n\tvm.addBifHelp(\" op/ (list --> z) reducing math operator.\");\n\tvm.addBifHelp(\" op\\\\ (list --> z) scanning math operator.\");\n\tvm.addBifHelp(\" op^ (list --> z) pairwise math operator.\");\n\tvm.addBifHelp(\" op/i (list init --> z) reducing math operator with initial value.\");\n\tvm.addBifHelp(\" op\\\\i (list init --> z) scanning math operator with initial value.\");\n\tvm.addBifHelp(\" op^i (list init --> z) pairwise math operator with initial value.\");\n\tvm.addBifHelp(\" For example, + has the following variations: +/ +\\\\ +^ +/i +\\\\i +^i\");\n\tvm.addBifHelp(\"\");\n\t\n\n\tvm.plusFun = DEFNa2(plus, +, \"addition.\")\n\tDEFNa2(plus_link, +>, \"addition. For lists, acts as if shorter list were extended with zeroes.\")\n\tDEFNa2(minus, -, \"subtraction.\")\n\tvm.mulFun = DEFNa2(mul, *, \"multiplication.\")\n\tDEFNa2(div, /, \"real division.\")\n\tDEFNa2(mod, %, \"modulo.\")\n\tDEF2(idiv, \"integer division.\")\n\tDEF2(imod, \"integer modulo.\")\n\tDEF2(remainder, \"remainder.\")\n\n\tDEFNa2(lt, <, \"less than.\")\n\tDEFNa2(le, <=, \"less than or equal.\")\n\tDEFNa2(gt, >, \"greater than.\")\n\tDEFNa2(ge, >=, \"greater than or equal.\")\n\tDEFNa2(eq, ==, \"equal.\")\n\tDEFNa2(ne, !=, \"not equal.\")\n\n\tDEF2(cmp, \"returns -1 when x < y, returns 1 when x > y, returns 0 when x == y.\")\n\n\tDEF2(copysign, \"copy the sign of y to the value of x.\")\n\tDEF2(nextafter, \"return the next machine representable number from x in direction y.\")\n\n\tDEF2(pow, \"x to the power y.\")\n\tDEFNa2(pow, ^, \"x to the power y.\")\n\tDEF2(atan2, \"arctangent of y/x.\")\n\t\n\tDEF2(Jn, \"yth Bessel function of the first kind evaluated at x.\")\n\tDEF2(Yn, \"yth Bessel function of the second kind evaluated at x.\")\n\n\tvm.minFun = DEFNa2(min, &, \"return the minimum of x and y. functions as logical AND.\")\n\tvm.maxFun = DEFNa2(max, |, \"return the maximum of x and y. functions as logical OR.\")\n\n\tDEF2(avg2, \"x y + .5 *\")\n\tDEF2(dim, \"positive difference of x and y. x y - 0 |\")\n\tDEF2(absdif, \"x y - abs\")\n\tDEF2(hypot, \"x sq y sq + sqrt\")\n\tDEF2(sumsq, \"x sq y sq +\")\n\tDEF2(difsq, \"x sq y sq -\")\n\tDEF2(sqsum, \"x y + sq\")\n\tDEF2(sqdif, \"x y - sq\")\n\n\tDEF2(thresh, \"returns 0 when x < y, else returns x.\")\n\tDEF2(absthresh, \"returns 0 when |x| < y, else returns x.\")\n\tDEF2(amclip, \"returns 0 when y <= 0, else returns x*y.\")\n\tDEF2(scaleneg, \"returns x*y when x < 0, else returns x.\")\n\n\tDEF2(ring1, \"x y * x +\")\n\tDEF2(ring2, \"x y * x + y +\")\n\tDEF2(ring3, \"x sq y *\")\n\tDEF2(ring4, \"x y * x y - *\")\n\n\tDEF2(gcd, \"greatest common divisor.\")\n\tDEF2(lcm, \"least common multiple.\")\n\n\tDEF2(clip0, \"clip x between 0 and y.\")\n\tDEF2(wrap0, \"wrap x between 0 and y.\")\n\tDEF2(fold0, \"fold x between 0 and y.\")\n\n\tDEF2(clip2, \"clip x between -y and y.\")\n\tDEF2(wrap2, \"wrap x between -y and y.\")\n\tDEF2(fold2, \"fold x between -y and y.\")\n\tDEF2(iwrap2, \"wrap integer x between -y and y.\")\n\tDEF2(ifold2, \"fold integer x between -y and y.\")\n\tDEF2(excess, \"return the excess after clipping. x x y clip2 -\")\n\n\tDEF2(round, \"round x to nearest multiple of y.\")\n\tDEF2(roundUp, \"round x to nearest multiple of y >= x.\")\n\tDEF2(trunc, \"round x to nearest multiple of y <= x\")\n\n}\n\n"], ["/sapf/src/RandomOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark RANDOM STREAMS\n\n\ntemplate \nvoid swapifgt(T& a, T& b) { \n\tif (a > b) {\n\t\tT t = a;\n\t\ta = b;\n\t\tb = t;\n\t}\n}\n\n\nstruct URand : ZeroInputGen\n{\t\n RGen r;\n \n\tURand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct URandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tURandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\n\nstruct NURand : NZeroInputGen\n{\t\n RGen r;\n \n\tNURand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct NURandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNURandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct BRand : ZeroInputGen\n{\t\n RGen r;\n \n\tBRand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct BRandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tBRandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct NBRand : NZeroInputGen\n{\t\n RGen r;\n \n\tNBRand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct NBRandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNBRandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct Rand : TwoInputGen\n{\t\n RGen r;\n \n\tRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Randz : TwoInputUGen\n{\t\n RGen r;\n \n\tRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Randz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void urands_(Thread& th, Prim* prim)\n{\n\tGen* g = new URand(th);\n\tth.push(new List(g));\n}\n\nstatic void urandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new URandz(th);\n\tth.push(new List(g));\n}\n\nstatic void brands_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRand(th);\n\tth.push(new List(g));\n}\n\nstatic void brandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRandz(th);\n\tth.push(new List(g));\n}\n\nstatic void nurands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurands : n\");\n\tGen* g = new NURand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nurandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurandz : n\");\n\tGen* g = new NURandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrands : n\");\n\tGen* g = new NBRand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrandz : n\");\n\tGen* g = new NBRandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void rands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Rand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void randz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"randz : hi\");\n\tV a = th.popZIn(\"randz : lo\");\n\t\n\tGen* g = new Randz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrands : n\");\n\t\n\tGen* g = new NRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nrandz : hi\");\n\tV a = th.popZIn(\"nrandz : lo\");\n\tint64_t n = th.popInt(\"nrandz : n\");\n\t\n\tGen* g = new NRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void urand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand();\n\tth.push(z);\n}\n\nstatic void brand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand2();\n\tth.push(z);\n}\n\n\nstatic void newseed_(Thread& th, Prim* prim)\n{\n\tV v;\n\tv.i = timeseed();\n\tth.push(v);\n}\n\nstatic void setseed_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isReal()) wrongType(\"setseed : seed\", \"Float\", v);\n\tth.rgen.init(v.i);\n}\n\nstatic void rand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"rand : hi\");\n\tZ a = th.popFloat(\"rand : lo\");\n\t\n\tswapifgt(a, b);\n\tZ z = th.rgen.rand(a, b);\n\tth.push(z);\n}\n\nstruct Coin : OneInputGen\n{\t\n RGen r;\n \n\tCoin(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Coinz : OneInputUGen\n{\t\n RGen r;\n \n\tCoinz(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoin : NOneInputGen\n{\t\n RGen r;\n \n\tNCoin(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoinz : NOneInputUGen\n{\t\n RGen r;\n \n\tNCoinz(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void coin_(Thread& th, Prim* prim)\n{\n\tZ p = th.popFloat(\"coin : p\");\n\t\n\tZ z = th.rgen.coin(p);\n\tth.push(z);\n}\n\nstatic void coins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coin(th, a);\n\tth.push(new List(g));\n}\n\nstatic void coinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coinz(th, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoins : n\");\n\t\n\tGen* g = new NCoin(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoinz : n\");\n\t\n\tGen* g = new NCoinz(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstruct IRand : TwoInputGen\n{\t\n RGen r;\n \n\tIRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tIRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NIRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNIRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNIRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new IRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"irandz : hi\");\n\tV a = th.popZIn(\"irandz : lo\");\n\t\n\tGen* g = new IRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirands : n\");\n\t\n\tGen* g = new NIRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nirandz : hi\");\n\tV a = th.popZIn(\"nirandz : lo\");\n\tint64_t n = th.popInt(\"nirandz : n\");\n\t\n\tGen* g = new NIRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"irand : hi\");\n\tint64_t a = th.popInt(\"irand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tswapifgt(a, b);\n\tZ z = (Z)r.irand(a, b);\n\tth.push(z);\n}\n\n\nstruct ExcRand : TwoInputGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExcRandz : TwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\t\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExcRand : NTwoInputGen\n{\t\n RGen r;\n \tint64_t prev;\n \n\tNExcRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExcRandz : NTwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tNExcRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void eprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExcRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void eprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprandz : hi\");\n\tV a = th.popZIn(\"eprandz : lo\");\n\t\n\tGen* g = new ExcRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"neprands : n\");\n\t\n\tGen* g = new NExcRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprands : hi\");\n\tV a = th.popZIn(\"eprands : lo\");\n\tint64_t n = th.popInt(\"neprandz : n\");\n\t\n\tGen* g = new NExcRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstruct ExpRand : TwoInputGen\n{\t\n RGen r;\n \n\tExpRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExpRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tExpRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExpRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNExpRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExpRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNExpRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void xrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExpRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"xrandz : hi\");\n\tV a = th.popZIn(\"xrandz : lo\");\n\t\n\tGen* g = new ExpRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nxrands : n\");\n\t\n\tGen* g = new NExpRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nxrandz : hi\");\n\tV a = th.popZIn(\"nxrandz : lo\");\n\tint64_t n = th.popInt(\"xrandz : n\");\n\t\n\tGen* g = new NExpRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"xrand : hi\");\n\tZ a = th.popFloat(\"xrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.xrand(a, b);\n\tth.push(z);\n}\n\nstruct ILinRand : TwoInputGen\n{\t\n RGen r;\n \n\tILinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ILinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tILinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NILinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNILinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NILinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNILinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ILinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"ilinrandz : hi\");\n\tV a = th.popZIn(\"ilinrandz : lo\");\n\t\n\tGen* g = new ILinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nilinrands : n\");\n\t\n\tGen* g = new NILinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nilinrandz : hi\");\n\tV a = th.popZIn(\"nilinrandz : lo\");\n\tint64_t n = th.popInt(\"nilinrandz : n\");\n\t\n\tGen* g = new NILinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"ilinrand : hi\");\n\tint64_t a = th.popInt(\"ilinrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tint64_t x;\n\tif (b < a) { x = a; a = b; b = x; }\n\tZ z = (Z)r.ilinrand(a, b);\n\tth.push(z);\n}\n\n\n\nstruct LinRand : TwoInputGen\n{\t\n RGen r;\n \n\tLinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct LinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tLinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NLinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNLinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NLinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNLinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void linrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new LinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\t\n\tGen* g = new LinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"linrandz : n\");\n\t\n\tGen* g = new NLinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\tint64_t n = th.popInt(\"randz : n\");\n\t\n\tGen* g = new NLinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"linrand : hi\");\n\tZ a = th.popFloat(\"linrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.linrand(a, b);\n\tth.push(z);\n}\n\n\nstruct Rand2 : OneInputGen\n{\t\n RGen r;\n \n\tRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Rand2z : OneInputUGen\n{\t\n RGen r;\n \n\tRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct XorNoise1 : OneInputUGen\n{\t\n uint64_t x = 0xA40203C12F2AD936LL;\n\t\n\tXorNoise1(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise1\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct XorNoise2 : OneInputUGen\n{\t\n uint64_t s[2] = { 0xA40203C12F2AD936LL, 0x9E390BD16B74D6D3LL };\n\t\n\tXorNoise2(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise2\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint32_t raprng(uint64_t i, uint64_t seed)\n{\n// http://cessu.blogspot.com/2008/11/random-access-pseudo-random-numbers.html\n uint64_t r = (2857720171ULL * ((uint32_t) i)) ^ 0x1EF57D8A7B344E7BULL;\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n r += r >> 32;\n r = (2857720171ULL * ((uint32_t) (i ^ r))) ^ (0xD9EA571C8AF880B6ULL + seed);\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n return uint32_t(r + (r >> 32));\n}\n\n\nstruct RandomAccessNoise : OneInputUGen\n{\n uint64_t seed = 0xA40203C12F2AD936LL;\n\tuint64_t k = 0;\n\t\n\tRandomAccessNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RandomAccessNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t hash64shift(uint64_t key)\n{\n key = (~key) + (key << 21); // key = (key << 21) - key - 1;\n key = key ^ (key >> 24);\n key = (key + (key << 3)) + (key << 8); // key * 265\n key = key ^ (key >> 14);\n key = (key + (key << 2)) + (key << 4); // key * 21\n key = key ^ (key >> 28);\n key = key + (key << 31);\n return key;\n}\n\nstruct WangNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tWangNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WangNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t Hash128to64(uint64_t x, uint64_t y) {\n\tconst uint64_t kMul = 0x9ddfea08eb382d69ULL;\n\tuint64_t a = (x ^ y) * kMul;\n\ta ^= (a >> 47);\n\tuint64_t b = (y ^ a) * kMul;\n\tb ^= (b >> 47);\n\tb *= kMul;\n\treturn b;\n}\n\n\nstruct CityNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tCityNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"CityNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Violet : OneInputUGen\n{\t\n RGen r;\n\tZ prev;\n \n\tViolet(Thread& th, Arg a) : OneInputUGen(th, a), prev(0.)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Violet\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = .5 * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = a * r.drand() - a2;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ x = a * r.drand() - .5 * a;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void rand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2s : n\");\n\t\n\tGen* g = new NRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2z : n\");\n\t\n\tGen* g = new NRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstatic void white_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void wangwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"wangwhite : a\");\n\tGen* g = new WangNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void citywhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"citywhite : a\");\n\tGen* g = new CityNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rawhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"rawhite : a\");\n\tGen* g = new RandomAccessNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite : a\");\n\tGen* g = new XorNoise1(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite2_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite2 : a\");\n\tGen* g = new XorNoise2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void violet_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Violet(th, a);\n\tth.push(new List(g));\n}\n\n\nstatic void rand2_(Thread& th, Prim* prim)\n{\n\tZ a = th.popFloat(\"rand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = 2. * a * r.drand() - a;\n\tth.push(z);\n}\n\nstruct IRand2 : OneInputGen\n{\t\n RGen r;\n \n\tIRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRand2z : OneInputUGen\n{\t\n RGen r;\n \n\tIRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNIRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNIRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2s : n\");\n\t\n\tGen* g = new NIRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2z : n\");\n\t\n\tGen* g = new NIRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2_(Thread& th, Prim* prim)\n{\n\tint64_t a = th.popInt(\"irand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = floor((2. * a + 1.) * r.drand() - a);\n\tth.push(z);\n}\n\n\nstruct Pick : ZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPick(Thread& th, P const& array) : ZeroInputGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Pickz : ZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPickz(Thread& th, P const& array) : ZeroInputUGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstruct NPick : NZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPick(Thread& th, int64_t n, P const& array) : NZeroInputGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NPickz : NZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPickz(Thread& th, int64_t n, P const& array) : NZeroInputUGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstatic void picks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"picks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"picks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pick(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pickz(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npicks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npicks : list\");\n\tint64_t n = th.popInt(\"npicks : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npicks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPick(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npickz : list\");\n\tint64_t n = th.popInt(\"npickz : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPickz(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pick_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pick : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\tint64_t n = a->mArray->size();\n\tth.push(a->at(th.rgen.irand0(n)));\n}\n\nstatic int64_t weightIndex(int64_t n, Z* z, Z r)\n{\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += z[i];\n\t\tif (r < sum) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn n-1;\n}\n\nstruct WPick : ZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPick(Thread& th, P const& array, P const& weights) : ZeroInputGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct WPickz : ZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPickz(Thread& th, P const& array, P const& weights) : ZeroInputUGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstruct NWPick : NZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPick(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NWPickz : NZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPickz(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputUGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstatic P sumWeights(P& weights)\n{\n\tconst int64_t n = weights->size();\n\n\tP summedWeights = new Array(itemTypeZ, n);\n\tsummedWeights->setSize(n);\n\t\n\tZ sum = 0.;\n\tZ* z = summedWeights->z();\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += weights->atz(i);\n\t\tz[i] = sum;\n\t}\n\tZ scale = 1. / sum;\n\t\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tz[i] *= scale;\n\t}\n\t\n\treturn summedWeights;\n}\n\nstatic void wpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpicks : weights\");\n\tP a = th.popList(\"wpicks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new WPick(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void wpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpickz : weights\");\n\tP a = th.popList(\"wpickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n \n\tGen* g = new WPickz(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpicks : weights\");\n\tP a = th.popList(\"nwpicks : list\");\n\tint64_t n = th.popInt(\"nwpicks : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPick(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpickz : weights\");\n\tP a = th.popList(\"nwpickz : list\");\n\tint64_t n = th.popInt(\"nwpickz : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPickz(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wpick_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpick : weights\");\n\tP a = th.popList(\"wpick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpick : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpick : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->pack(th);\n\t\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\tconst int64_t n = aa->size();\n\tconst int64_t wn = wa->size();\n\n\tif (n != wn) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push(aa->at(i));\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push(aa->at(n-1));\n}\n\n\nstruct WRand : ZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRand(Thread& th, P const& weights) : ZeroInputGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct WRandz : ZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRandz(Thread& th, P const& weights) : ZeroInputUGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRand : NZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRand(Thread& th, int64_t n, P const& weights) : NZeroInputGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRandz : NZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRandz(Thread& th, int64_t n, P const& weights) : NZeroInputUGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\n\nstatic void wrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrands : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRand(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void wrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrandz : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRandz(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrands : weights\");\n\tint64_t n = th.popInt(\"nwrands : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRand(th, n, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrandz : weights\");\n\tint64_t n = th.popInt(\"nwrandz : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRandz(th, n, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wrand_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrand : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrand : weights must be finite\",\"\");\n\t\n\tw = w->pack(th);\n\t\n\tP wa = w->mArray;\n\tconst int64_t n = wa->size();\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push((Z)i);\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push((Z)(n-1));\n}\n\n\nstruct GrayNoise : OneInputUGen\n{\t\n RGen r;\n\tint32_t counter_;\n \n\tGrayNoise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"GrayNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 4.65661287308e-10f;\n\t\tint32_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstruct Gray64Noise : OneInputUGen\n{\t\n RGen r;\n\tint64_t counter_;\n \n\tGray64Noise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gray64Noise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 1.084202172485504434e-19;\n\t\tint64_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstatic void gray_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray : a\");\n\t\n\tth.push(new List(new GrayNoise(th, a)));\n}\n\nstatic void gray64_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray64 : a\");\n\t\n\tth.push(new List(new Gray64Noise(th, a)));\n}\n\nstruct PinkNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tout[i] = *aa * (u.f - 3.);\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct PinkNoise0 : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise0(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tdice[i] = 0;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise0\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\tconst double scale = pow(2.,-47.)/17.;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tout[i] = *aa * (scale * double(total + newrand)) - 1;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct BlueNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\tZ prev;\n\t\n\tBlueNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a), prev(0.)\n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"BlueNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tZ x = 4. * *aa * (u.f - 3.);\n\t\t\t\t\tout[i] = x - prev;\n\t\t\t\t\tprev = x;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void pink_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink : a\");\n\t\n\tth.push(new List(new PinkNoise(th, a)));\n}\n\nstatic void pink0_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink0 : a\");\n\t\n\tth.push(new List(new PinkNoise0(th, a)));\n}\n\nstatic void blue_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"blue : a\");\n\t\n\tth.push(new List(new BlueNoise(th, a)));\n}\n\n\nstruct BrownNoise : Gen\n{\n\tZIn _a;\n\tZ total_;\n\t\n\tBrownNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\ttotal_ = r.drand2();\n \n\t}\n \n\tvirtual const char* TypeName() const override { return \"BrownNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ z = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tz += r.drand16();\n\t\t\t\t\tif (z > 1.) z = 2. - z;\n\t\t\t\t\telse if (z < -1.) z = -2. - z;\n\t\t\t\t\tout[i] = *aa * z;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = z;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void brown_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"brown : a\");\n\t\n\tth.push(new List(new BrownNoise(th, a)));\n}\n\nstruct Dust : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * z / thresh : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Dust2 : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust2(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust2\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * (2. * z / thresh - 1.) : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Velvet : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tVelvet(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Velvet\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ thresh2 = .5 * thresh;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? (zfulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct TooshPlus : Gen\n{\n\tZIn _delay;\n\tZIn _amp;\n\tint64_t _counter;\n\tZ sampleRate;\n\t\n\tTooshPlus(Thread& th, Arg delay, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(delay, amp)), _delay(delay), _amp(amp), sampleRate(th.rate.sampleRate)\n\t{\n\t\t_counter = th.rgen.trand();\n\t}\n \n\tvirtual const char* TypeName() const override { return \"TooshPlus\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void toosh_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toosh : amp\");\n\tV delay = th.popZIn(\"toosh : delay\");\n \n\tth.push(new List(new Toosh(th, delay, amp)));\n}\n\nstatic void tooshp_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tooshp : amp\");\n\tV delay = th.popZIn(\"tooshp : delay\");\n \n\tth.push(new List(new TooshPlus(th, delay, amp)));\n}\n\nstruct Crackle : Gen\n{\n\tZIn _param;\n\tZ _y1, _y2;\n\t\n\tCrackle(Thread& th, Arg param) \n : Gen(th, itemTypeZ, param.isFinite()), _param(param), _y1(th.rgen.drand()), _y2(0.)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Crackle\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint paramStride;\n\t\t\tZ *param;\n\t\t\tif (_param(th, n, paramStride, param)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n Z y1 = _y1;\n Z y2 = _y2;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n Z y0 = fabs(y1 * *param - y2 - 0.05);\n y2 = y1; y1 = y0;\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\tparam += paramStride;\n\t\t\t\t}\n _y1 = y1;\n _y2 = y2;\n\t\t\t\t_param.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void crackle_(Thread& th, Prim* prim)\n{\n\tV param = th.popZIn(\"cracke : param\");\n \n\tth.push(new List(new Crackle(th, param)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD RANDOM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n\nvoid AddRandomOps();\nvoid AddRandomOps()\n{\n\tvm.addBifHelp(\"\\n*** random number generation ***\");\n\n\tDEFnoeach(newseed, 0, 1, \"(--> seed) make a new random seed.\");\n\tDEFnoeach(setseed, 1, 0, \"(seed -->) set the random seed.\");\n\n\t\n\tvm.addBifHelp(\"\\n*** single random numbers ***\");\n\tDEFAM(rand, kk, \"(a b --> r) return a uniformly distributed random real value from a to b.\")\n\tDEFAM(coin, k, \"(p --> r) return 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(rand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(irand, kk, \"(a b --> r) return a uniformly distributed random integer value from a to b.\")\n\tDEFAM(irand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(xrand, kk, \"(a b --> r) return a exponentially distributed random real value from a to b.\") \n\tDEFAM(linrand, kk, \"(a b --> r) return a linearly distributed random real value from a to b.\")\t \n\tDEFAM(ilinrand, kk, \"(a b --> r) return a linearly distributed random integer value from a to b.\") \n\tDEF(wrand, 1, 1, \"(w --> r) return a randomly chosen index from a list of probability weights. w should sum to one.\") \n\tDEF(pick, 1, 1, \"(a --> r) return a randomly chosen element from the finite list a.\") \n\tDEF(wpick, 2, 1, \"(a w --> r) return a randomly chosen element from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random streams ***\");\n\tDEFAM(rands, kk, \"(a b --> r) return a stream of uniformly distributed random real values from a to b.\")\n\tDEFAM(coins, k, \"(p --> r) return a stream of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(eprands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b, excluding the previously returned value.\")\t\n\tDEFAM(rand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(irands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b.\")\n\tDEFAM(irand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(xrands, kk, \"(a b --> r) return a stream of exponentially distributed random real values from a to b.\")\n\tDEFAM(linrands, kk, \"(a b --> r) return a stream of linearly distributed random real values from a to b.\")\n\tDEFAM(ilinrands, kk, \"(a b --> r) return a stream of linearly distributed random integer values from a to b.\")\n\tDEF(wrands, 1, 1, \"(w --> r) return a stream of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEF(picks, 1, 1, \"(a --> r) return a stream of randomly chosen elements from the finite list a.\") \n\tDEF(wpicks, 2, 1, \"(a w --> r) return a stream of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random signals ***\");\n\tDEFMCX(randz, 2, \"(a b --> r) return a signal of uniformly distributed random real values from a to b.\")\n\tDEFMCX(coinz, 1, \"(p --> r) return a signal of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(eprandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(rand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(irandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b.\")\n\tDEFMCX(irand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(xrandz, 2, \"(a b --> r) return a signal of exponentially distributed random real values from a to b.\")\n\tDEFMCX(linrandz, 2, \"(a b --> r) return a signal of linearly distributed random real values from a to b.\")\n\tDEFMCX(ilinrandz, 2, \"(a b --> r) return a signal of linearly distributed random integer values from a to b.\")\n\tDEFMCX(wrandz, 1, \"(w --> r) return a signal of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(pickz, 1, \"(a --> r) return a signal of randomly chosen elements from the finite list a.\") \n\tDEFMCX(wpickz, 2, \"(a w --> r) return a signal of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** finite random streams ***\");\n\tDEFAM(nrands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random real values from a to b.\")\n\tDEFAM(ncoins, kk, \"(n p --> r) return a stream of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(neprands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b, excluding the previously returned value.\")\n\tDEFAM(nrand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nirands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b.\")\n\tDEFAM(nirand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nxrands, kkk, \"(n a b --> r) return a stream of n exponentially distributed random real values from a to b.\")\n\tDEFAM(nlinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random real values from a to b.\")\n\tDEFAM(nilinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random integer values from a to b.\")\n\tDEFAM(nwrands, ka, \"(n w --> r) return a stream of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFAM(npicks, ka, \"(n a --> r) return a stream of n randomly chosen elements from the finite list a.\") \n\tDEFAM(nwpicks, kaa, \"(n a w --> r) return a stream of n randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** finite random signals ***\");\n\tDEFMCX(nrandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random real values from a to b.\")\n\tDEFMCX(ncoinz, 2, \"(n p --> r) return a signal of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(neprandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(nrand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nirandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b.\")\n\tDEFMCX(nirand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nxrandz, 3, \"(n a b --> r) return a signal of n exponentially distributed random real values from a to b.\")\n\tDEFMCX(nlinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random real values from a to b.\")\n\tDEFMCX(nilinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random integer values from a to b.\")\t\n\tDEFMCX(nwrandz, 2, \"(n w --> r) return a signal of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(npickz, 2, \"(n a --> r) return a signal of n randomly chosen elements from the finite signal a.\") \n\tDEFMCX(nwpickz, 3, \"(n a w --> r) return a signal of n randomly chosen elements from the finite signal a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** noise unit generators ***\");\n\tDEFMCX(violet, 1, \"(amp --> z) violet noise\")\n\tDEFMCX(blue, 1, \"(amp --> z) blue noise\")\n\tDEFMCX(xorwhite, 1, \"(amp --> z) white noise\")\n\tDEFMCX(xorwhite2, 1, \"(amp --> z) white noise\")\n\tDEFMCX(rawhite, 1, \"(amp --> z) white noise based on Cessu's random access random numbers\")\n\tDEFMCX(wangwhite, 1, \"(amp --> z) white noise based on Thomas Wang's integer hash\")\n\tDEFMCX(citywhite, 1, \"(amp --> z) white noise based on a function from CityHash\")\n\tDEFMCX(white, 1, \"(amp --> z) white noise\")\n\tDEFMCX(pink, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(pink0, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(brown, 1, \"(amp --> z) brown noise\")\n\tDEFMCX(gray, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(gray64, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(dust, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from 0 to a and whose average density is in impulses per second.\")\t\n\tDEFMCX(dust2, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from -a to +a and whose average density is in impulses per second.\")\n\tDEFMCX(velvet, 2, \"(density amp --> z) a stream of impulses whose amplitude is randomly either -a or +a and whose average density is in impulses per second.\")\n\tDEFMCX(toosh, 2, \"(delay amp --> z) flanged noise. difference of two white noise sources with a delay.\")\n\tDEFMCX(tooshp, 2, \"(delay amp--> z) flanged noise. sum of two white noise sources with a delay. no null at delay == 0. \")\n\tDEFMCX(crackle, 1, \"(param --> z) a chaotic generator.\")\t\n}\n\n\n"], ["/sapf/src/FilterUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"FilterUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// classes for specializing feedback\n\nstruct NormalFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return x; }\n};\n\nstruct TanhApproximationFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return sc_tanh_approx(x); }\n};\n\nstruct UnityHardClipFeedback : public Gen\n{\n\tstatic inline double feedback(double x)\n\t{\n\t\tif (x <= -1.) return -1.;\n\t\tif (x >= 1.) return 1.;\n\t\treturn x;\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag : lagTime\");\n\tV in = th.popZIn(\"lag : in\");\n\n\tth.push(new List(new Lag(th, in, lagTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag2 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag2(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag2_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag2 : lagTime\");\n\tV in = th.popZIn(\"lag2 : in\");\n\n\tth.push(new List(new Lag2(th, in, lagTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag3 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag3(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag3_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag3 : lagTime\");\n\tV in = th.popZIn(\"lag3 : in\");\n\n\tth.push(new List(new Lag3(th, in, lagTime)));\n}\n\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstruct LagUD : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ b1 = y0 > y1 ? b1r : b1f;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ lagTime = y0 > y1 ? *riseTime : *fallTime;\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud : fallTime\");\n\tV riseTime = th.popZIn(\"lagud : riseTime\");\n\tV in = th.popZIn(\"lagud : in\");\n\n\tth.push(new List(new LagUD(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD2 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD2(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud2_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud2 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud2 : riseTime\");\n\tV in = th.popZIn(\"lagud2 : in\");\n\n\tth.push(new List(new LagUD2(th, in, riseTime, fallTime)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD3 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD3(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud3_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud3 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud3 : riseTime\");\n\tV in = th.popZIn(\"lagud3 : in\");\n\n\tth.push(new List(new LagUD3(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct FirstOrderLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct FirstOrderHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void lpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf1 : freq\");\n\tV in = th.popZIn(\"lpf1 : in\");\n\n\tth.push(new List(new FirstOrderLPF(th, in, freq)));\n}\n\nstatic void hpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf1 : freq\");\n\tV in = th.popZIn(\"hpf1 : in\");\n\n\tth.push(new List(new FirstOrderHPF(th, in, freq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0inv = 1. / a0;\n\t\t\t\tZ a1 = a0inv * (-2. * cs);\n\t\t\t\tZ a2 = a0inv * (1. - alpha);\n\t\t\t\tZ b1 = a0inv * (1. - cs);\n\t\t\t\tZ b0 = a0inv * (.5 * b1);\n\t\t\t\tZ b2 = a0inv * b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct LPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\t\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\nstruct HPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct HPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ntemplate \nstruct RLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RLPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRLPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\ntemplate \nstruct RHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRHPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RHPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRHPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct BPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b0 = alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * (x0 - x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstruct BSF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBSF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BSF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (x0 + x2 + a1 * (x1 - y1) - a2 * y2) * a0r;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\n\nstruct APF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tAPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"APF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2; \n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (a2 * (x0 - y2) + a1 * (x1 - y1)) * a0r + x2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct PEQ : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tPEQ(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PEQ\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alphaA = alpha * A;\n\t\t\t\tZ alphaOverA = alpha / A;\n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alphaOverA;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alphaOverA;\n\t\t\t\n\t\t\t\tZ b0 = 1. + alphaA;\n\t\t\t\tZ b2 = 1. - alphaA;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + a1 * (x1 - y1) + b2 * x2 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLowShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct HighShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHighShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HighShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 + Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 + Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 - Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ a2 = Ap1 - Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf1 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tLowShelf1(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf1\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ sqrt_g = t_dbamp(.25 * *gain);\n\t\t\t\tZ d = *freq * freqmul;\n\t\t\t\t\n\t\t\t\tZ p = 1. - d*sqrt_g;\n\t\t\t\tZ q = 1. - d/sqrt_g;\n\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = x0 + q * x1 - p * y1;\n\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct RLowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLowShelf(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = A*( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*A*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = A*( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void lpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf : freq\");\n\tV in = th.popZIn(\"lpf : in\");\n\n\tth.push(new List(new LPF(th, in, freq)));\n}\n\nstatic void lpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf2 : freq\");\n\tV in = th.popZIn(\"lpf2 : in\");\n\n\tth.push(new List(new LPF2(th, in, freq)));\n}\n\nstatic void hpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf : freq\");\n\tV in = th.popZIn(\"hpf : in\");\n\n\tth.push(new List(new HPF(th, in, freq)));\n}\n\nstatic void hpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf2 : freq\");\n\tV in = th.popZIn(\"hpf2 : in\");\n\n\tth.push(new List(new HPF2(th, in, freq)));\n}\n\n\n\nstatic void rlpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf : rq\");\n\tV freq = th.popZIn(\"rlpf : freq\");\n\tV in = th.popZIn(\"rlpf : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2 : rq\");\n\tV freq = th.popZIn(\"rlpf2 : freq\");\n\tV in = th.popZIn(\"rlpf2 : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf : rq\");\n\tV freq = th.popZIn(\"rhpf : freq\");\n\tV in = th.popZIn(\"rhpf : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2 : rq\");\n\tV freq = th.popZIn(\"rhpf2 : freq\");\n\tV in = th.popZIn(\"rhpf2 : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\nstatic void rlpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpfc : rq\");\n\tV freq = th.popZIn(\"rlpfc : freq\");\n\tV in = th.popZIn(\"rlpfc : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2c : rq\");\n\tV freq = th.popZIn(\"rlpf2c : freq\");\n\tV in = th.popZIn(\"rlpf2c : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpfc : rq\");\n\tV freq = th.popZIn(\"rhpfc : freq\");\n\tV in = th.popZIn(\"rhpfc : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2c : rq\");\n\tV freq = th.popZIn(\"rhpf2c : freq\");\n\tV in = th.popZIn(\"rhpf2c : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\n\nstatic void bpf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bpf : bw\");\n\tV freq = th.popZIn(\"bpf : freq\");\n\tV in = th.popZIn(\"bpf : in\");\n\n\tth.push(new List(new BPF(th, in, freq, bw)));\n}\n\nstatic void bsf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bsf : bw\");\n\tV freq = th.popZIn(\"bsf : freq\");\n\tV in = th.popZIn(\"bsf : in\");\n\n\tth.push(new List(new BSF(th, in, freq, bw)));\n}\n\nstatic void apf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"apf : bw\");\n\tV freq = th.popZIn(\"apf : freq\");\n\tV in = th.popZIn(\"apf : in\");\n\n\tth.push(new List(new APF(th, in, freq, bw)));\n}\n\nstatic void peq_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"peq : gain\");\n\tV bw = th.popZIn(\"peq : bw\");\n\tV freq = th.popZIn(\"peq : freq\");\n\tV in = th.popZIn(\"peq : in\");\n\n\tth.push(new List(new PEQ(th, in, freq, bw, gain)));\n}\n\nstatic void lsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf(th, in, freq, gain)));\n}\n\nstatic void hsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"hsf : gain\");\n\tV freq = th.popZIn(\"hsf : freq\");\n\tV in = th.popZIn(\"hsf : in\");\n\n\tth.push(new List(new HighShelf(th, in, freq, gain)));\n}\n\n\nstatic void lsf1_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf1(th, in, freq, gain)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Resonz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tResonz(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Resonz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. - .5 * w0 * *rq;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Ringz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _ringTime;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul, _K;\n\t\n\tRingz(Thread& th, Arg in, Arg freq, Arg ringTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, ringTime)), _in(in), _freq(freq), _ringTime(ringTime),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Ringz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *ringTime;\n\t\t\tint n, inStride, freqStride, ringTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tringTime += ringTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_ringTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Formlet : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _atkTime;\n\tZIn _dcyTime;\n\tZ _x1a, _x2a, _y1a, _y2a;\n\tZ _x1b, _x2b, _y1b, _y2b;\n\tZ _freqmul, _K;\n\t\n\tFormlet(Thread& th, Arg in, Arg freq, Arg atkTime, Arg dcyTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, atkTime, dcyTime)),\n\t\t\t_in(in), _freq(freq), _atkTime(atkTime), _dcyTime(dcyTime),\n\t\t\t_x1a(0.), _x2a(0.), _y1a(0.), _y2a(0.),\n\t\t\t_x1b(0.), _x2b(0.), _y1b(0.), _y2b(0.),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Formlet\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1a = _x1a;\n\t\tZ x2a = _x2a;\n\t\tZ y1a = _y1a;\n\t\tZ y2a = _y2a;\n\t\tZ x1b = _x1b;\n\t\tZ x2b = _x2b;\n\t\tZ y1b = _y1b;\n\t\tZ y2b = _y2b;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *atkTime, *dcyTime;\n\t\t\tint n, inStride, freqStride, atkTimeStride, dcyTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _atkTime(th, n, atkTimeStride, atkTime) || _dcyTime(th, n, dcyTimeStride, dcyTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ Ra = 1. + K / *atkTime;\n\t\t\t\tZ Rb = 1. + K / *dcyTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1a = 2. * Ra * cs;\n\t\t\t\tZ a2a = -(Ra * Ra);\n\t\t\t\tZ a1b = 2. * Rb * cs;\n\t\t\t\tZ a2b = -(Rb * Rb);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0a = *in;\n\t\t\t\tZ y0a = b0 * (x0a - x2a) + a1a * y1a + a2a * y2a;\n\t\t\t\n\t\t\t\tZ x0b = *in;\n\t\t\t\tZ y0b = b0 * (x0b - x2b) + a1b * y1b + a2b * y2b;\n\t\t\t\t\n\t\t\t\tout[i] = y0b - y0a;\n\t\t\t\ty2a = y1a;\n\t\t\t\ty1a = y0a;\n\t\t\t\tx2a = x1a;\n\t\t\t\tx1a = x0a;\n\n\t\t\t\ty2b = y1b;\n\t\t\t\ty1b = y0b;\n\t\t\t\tx2b = x1b;\n\t\t\t\tx1b = x0b;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tatkTime += atkTimeStride;\n\t\t\t\tdcyTime += dcyTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_atkTime.advance(n);\n\t\t\t_dcyTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1a = x1a;\n\t\t_x2a = x2a;\n\t\t_y1a = y1a;\n\t\t_y2a = y2a;\n\t\t\n\t\t_x1b = x1b;\n\t\t_x2b = x2b;\n\t\t_y1b = y1b;\n\t\t_y2b = y2b;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct KlankFilter\n{\n\tKlankFilter(V f, V a, V r) : \n\t\tfreq(f), amp(a), ringTime(r),\n\t\tx1(0.), x2(0.), y1(0.), y2(0.) {}\n\t\n\tZIn freq, amp, ringTime;\n\tZ x1, x2, y1, y2;\n\t\n};\n\nstruct Klank : public Gen\n{\n\tZIn _in;\n\tstd::vector _filters;\n\tZ _freqmul, _K;\n\tZ* inputBuffer;\n\t\n\tKlank(Thread& th, Arg in, V freqs, V amps, V ringTimes)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t\tinputBuffer = new Z[mBlockSize];\n\t\n\t\tint64_t numFilters = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, freqs.length(th)); \n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, amps.length(th)); \n\t\t}\n\t\tif (ringTimes.isVList()) { \n\t\t\tringTimes = ((List*)ringTimes.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, ringTimes.length(th)); \n\t\t}\n\t\t\n\t\tif (numFilters == LONG_MAX) numFilters = 1;\n\t\t\n\t\tfor (ssize_t i = 0; i < numFilters; ++i) {\n\t\t\tKlankFilter kf(freqs.at(i), amps.at(i), ringTimes.at(i));\n\t\t\t_filters.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\n\tvirtual ~Klank()\n\t{\n\t\tdelete [] inputBuffer;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Klank\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\t\n\t\t// copy input\n\t\tint numInputFrames = mBlockSize;\n\t\tif (_in.fill(th, numInputFrames, inputBuffer, 1))\n\t\t{\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tint maxToFill = 0;\n\n\t\tZ* out0 = mOut->fulfillz(numInputFrames);\n\t\tmemset(out0, 0, numInputFrames * sizeof(Z));\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ K = log001 * th.rate.invSampleRate;\n\t\t\n\t\tfor (size_t filter = 0; filter < _filters.size(); ++filter) {\n\t\t\tint framesToFill = numInputFrames;\n\t\t\tKlankFilter& kf = _filters[filter];\n\t\t\t\t\n\t\t\tZ x1 = kf.x1;\n\t\t\tZ x2 = kf.x2;\n\t\t\tZ y1 = kf.y1;\n\t\t\tZ y2 = kf.y2;\n\n\t\t\tZ* in = inputBuffer;\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp, *ringTime;\n\t\t\t\tint n, freqStride, ampStride, ringTimeStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (kf.freq(th, n, freqStride, freq) || kf.amp(th, n, ampStride, amp) || kf.ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\n\t\t\t\tif (freqStride == 0) {\n\t\t\t\t\tif (ringTimeStride == 0) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\n\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\n\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\n\t\t\t\t\t\t++in;\n\t\t\t\t\t\t++out;\n\t\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\tringTime += ringTimeStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tkf.freq.advance(n);\n\t\t\t\tkf.amp.advance(n);\n\t\t\t\tkf.ringTime.advance(n);\n\t\t\t}\n\t\t\tkf.x1 = x1;\n\t\t\tkf.x2 = x2;\n\t\t\tkf.y1 = y1;\n\t\t\tkf.y2 = y2;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\n\nstatic void resonz_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"resonz : rq\");\n\tV freq = th.popZIn(\"resonz : freq\");\n\tV in = th.popZIn(\"resonz : in\");\n\n\tth.push(new List(new Resonz(th, in, freq, rq)));\n}\n\nstatic void ringz_(Thread& th, Prim* prim)\n{\n\tV ringTime = th.popZIn(\"ringz : ringTime\");\n\tV freq = th.popZIn(\"ringz : freq\");\n\tV in = th.popZIn(\"ringz : in\");\n\n\tth.push(new List(new Ringz(th, in, freq, ringTime)));\n}\n\nstatic void formlet_(Thread& th, Prim* prim)\n{\n\tV dcyTime = th.popZIn(\"formlet : dcyTime\");\n\tV atkTime = th.popZIn(\"formlet : atkTime\");\n\tV freq = th.popZIn(\"formlet : freq\");\n\tV in = th.popZIn(\"formlet : in\");\n\n\tth.push(new List(new Formlet(th, in, freq, atkTime, dcyTime)));\n}\n\n\nstatic void klank_(Thread& th, Prim* prim)\n{\n\tV ringTimes = th.popZInList(\"klank : ringTimes\");\n\tV amps\t\t= th.popZInList(\"klank : amps\");\n\tV freqs = th.popZInList(\"klank : freqs\");\n\tV in\t\t= th.popZIn(\"klank : in\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (ringTimes.isVList() && !ringTimes.isFinite())\n\t\tindefiniteOp(\"klank : ringTimes\", \"\");\n\n\tth.push(new List(new Klank(th, in, freqs, amps, ringTimes)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakDC : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _x1, _y1;\n\t\n\tLeakDC(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_x1(0.), _y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakDC\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 - x1 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tx1 = x0;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leakdc_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leakdc : leak\");\n\tV in = th.popZIn(\"leakdc : in\");\n\n\tth.push(new List(new LeakDC(th, in, leak)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakyIntegrator : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _y1;\n\t\n\tLeakyIntegrator(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakyIntegrator\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leaky_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leaky : leak\");\n\tV in = th.popZIn(\"leaky : in\");\n\n\tth.push(new List(new LeakyIntegrator(th, in, leak)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay : public Gen\n{\n\tZIn _in;\n\tZIn _decayTime;\n\tZ _y1;\n\tZ _lagmul;\n\t\n\t\n\tDecay(Thread& th, Arg in, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, decayTime)), _in(in), _decayTime(decayTime), \n\t\t\t_y1(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *decayTime;\n\t\t\tint n, inStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (decayTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay : decayTime\");\n\tV in = th.popZIn(\"decay : in\");\n\n\tth.push(new List(new Decay(th, in, decayTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay2 : public Gen\n{\n\tZIn _in;\n\tZIn _attackTime;\n\tZIn _decayTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\t\n\t\n\tDecay2(Thread& th, Arg in, Arg attackTime, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, attackTime, decayTime)), _in(in), _attackTime(attackTime), _decayTime(decayTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *attackTime, *decayTime;\n\t\t\tint n, inStride, attackTimeStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _attackTime(th, n, attackTimeStride, attackTime) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (attackTimeStride == 0 && decayTimeStride == 0) {\n\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tattackTime += attackTimeStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_attackTime.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay2_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay2 : decayTime\");\n\tV attackTime = th.popZIn(\"decay2 : attackTime\");\n\tV in = th.popZIn(\"decay2 : in\");\n\n\tth.push(new List(new Decay2(th, in, attackTime, decayTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Phase90A : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90A(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90A\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z1;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct Phase90B : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90B(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90B\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z0;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct AmpFollow : public OneInputUGen\n{\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1a_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2a_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3a_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4a_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1a_ = 0.;\n\tZ v2a_ = 0.;\n\tZ w1a_ = 0.;\n\tZ w2a_ = 0.;\n\tZ x1a_ = 0.;\n\tZ x2a_ = 0.;\n\tZ y1a_ = 0.;\n\tZ y2a_ = 0.;\n\tZ z1a_ = 0.;\n\tZ z2a_ = 0.;\n\n\tconstexpr static Z c1b_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2b_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3b_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4b_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1b_ = 0.;\n\tZ v2b_ = 0.;\n\tZ w1b_ = 0.;\n\tZ w2b_ = 0.;\n\tZ x1b_ = 0.;\n\tZ x2b_ = 0.;\n\tZ y1b_ = 0.;\n\tZ y2b_ = 0.;\n\tZ z1b_ = 0.;\n\tZ z2b_ = 0.;\n\n\tZ b1r_;\n\tZ b1f_;\n\t\n\tZ l1a_ = 0.;\n\tZ l1b_ = 0.;\n\n\tAmpFollow(Thread& th, Arg in, Z atk, Z dcy)\n\t\t: OneInputUGen(th, in),\n\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t\tb1r_ = atk == 0. ? 0. : std::max(0., 1. + _lagmul / atk); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime)\n\t\tb1f_ = dcy == 0. ? 0. : std::max(0., 1. + _lagmul / dcy);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"AmpFollow\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1a = c1a_;\n\t\tZ c2a = c2a_;\n\t\tZ c3a = c3a_;\n\t\tZ c4a = c4a_;\n\t\t\n\t\tZ v1a = v1a_;\n\t\tZ v2a = v2a_;\n\t\tZ w1a = w1a_;\n\t\tZ w2a = w2a_;\n\t\tZ x1a = x1a_;\n\t\tZ x2a = x2a_;\n\t\tZ y1a = y1a_;\n\t\tZ y2a = y2a_;\n\t\tZ z1a = z1a_;\n\t\tZ z2a = z2a_;\n\n\t\tZ c1b = c1b_;\n\t\tZ c2b = c2b_;\n\t\tZ c3b = c3b_;\n\t\tZ c4b = c4b_;\n\t\t\n\t\tZ v1b = v1b_;\n\t\tZ v2b = v2b_;\n\t\tZ w1b = w1b_;\n\t\tZ w2b = w2b_;\n\t\tZ x1b = x1b_;\n\t\tZ x2b = x2b_;\n\t\tZ y1b = y1b_;\n\t\tZ y2b = y2b_;\n\t\tZ z1b = z1b_;\n\t\tZ z2b = z2b_;\n\t\t\n\t\tZ l1a = l1a_;\n\t\tZ l1b = l1b_;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\t{\n\t\t\t\tZ w0 = c1a * (v0 + w2a) - v2a;\n\t\t\t\tZ x0 = c2a * (w0 + x2a) - w2a;\n\t\t\t\tZ y0 = c3a * (x0 + y2a) - x2a;\n\t\t\t\tZ z0 = c4a * (y0 + z2a) - y2a;\n\t\t\t\tv2a = v1a;\n\t\t\t\tw2a = w1a;\n\t\t\t\tx2a = x1a;\n\t\t\t\ty2a = y1a;\n\t\t\t\tz2a = z1a;\n\t\t\t\tv1a = v0;\n\t\t\t\tw1a = w0;\n\t\t\t\tx1a = x0;\n\t\t\t\ty1a = y0;\n\t\t\t\tz1a = z0;\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tZ w0 = c1b * (v0 + w2b) - v2b;\n\t\t\t\tZ x0 = c2b * (w0 + x2b) - w2b;\n\t\t\t\tZ y0 = c3b * (x0 + y2b) - x2b;\n\t\t\t\tZ z0 = c4b * (y0 + z2b) - y2b;\n\t\t\t\tv2b = v1b;\n\t\t\t\tw2b = w1b;\n\t\t\t\tx2b = x1b;\n\t\t\t\ty2b = y1b;\n\t\t\t\tz2b = z1b;\n\t\t\t\tv1b = v0;\n\t\t\t\tw1b = w0;\n\t\t\t\tx1b = x0;\n\t\t\t\ty1b = y0;\n\t\t\t\tz1b = z0;\n\t\t\t}\n\t\t\t\n\t\t\tZ l0a = hypot(z1a, z1b); // vectorize this\n\n\t\t\tl1a = l0a + (l0a > l1a ? b1r_ : b1f_) * (l1a - l0a);\n\t\t\tl1b = l1a + (l1a > l1b ? b1r_ : b1f_) * (l1b - l1a);\n\t\t\tout[i] = l1b;\n\t\t}\n\t\tv1a_ = v1a;\n\t\tv2a_ = v2a;\n\t\tw1a_ = w1a;\n\t\tw2a_ = w2a;\n\t\tx1a_ = x1a;\n\t\tx2a_ = x2a;\n\t\ty1a_ = y1a;\n\t\ty2a_ = y2a;\n\t\tz1a_ = z1a;\n\t\tz2a_ = z2a;\n\n\t\tv1b_ = v1b;\n\t\tv2b_ = v2b;\n\t\tw1b_ = w1b;\n\t\tw2b_ = w2b;\n\t\tx1b_ = x1b;\n\t\tx2b_ = x2b;\n\t\ty1b_ = y1b;\n\t\ty2b_ = y2b;\n\t\tz1b_ = z1b;\n\t\tz2b_ = z2b;\n\t\t\n\t\tl1a_ = l1a;\n\t\tl1b_ = l1b;\n\t}\n};\n\nstatic void hilbert_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"hilbert : in\");\n\t\n\tth.push(new List(new Phase90A(th, in)));\n\tth.push(new List(new Phase90B(th, in)));\n}\n\nstatic void ampf_(Thread& th, Prim* prim)\n{\n\tZ dcy = th.popFloat(\"ampf : dcyTime\");\n\tZ atk = th.popFloat(\"ampf : atkTime\");\n\tV in = th.popZIn(\"ampf : in\");\n\t\n\tth.push(new List(new AmpFollow(th, in, atk, dcy)));\n}\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** filter unit generators ***\");\n\tDEFMCX(lag, 2, \"(in decayTime --> out) one pole lag filter. decayTime determines rate of convergence.\")\n\tDEFMCX(lag2, 2, \"(in decayTime --> out) cascade of two one pole lag filters. decayTime determines rate of convergence.\")\n\tDEFMCX(lag3, 2, \"(in decayTime --> out) cascade of three one pole lag filters. decayTime determines rate of convergence.\")\n\n\tDEFMCX(lagud, 3, \"(in upDecayTime, downDecayTime --> out) one pole lag filter. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud2, 3, \"(in upDecayTime, downDecayTime --> out) cascade of two one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud3, 3, \"(in upDecayTime, downDecayTime --> out) cascade of three one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\t\n\tDEFMCX(lpf1, 2, \"(in freq --> out) low pass filter. 6 dB/oct.\")\n\tDEFMCX(hpf1, 2, \"(in freq --> out) high pass filter. 6 dB/oct.\")\n\tDEFMCX(lpf, 2, \"(in freq --> out) low pass filter. 12 dB/oct.\")\n\tDEFMCX(hpf, 2, \"(in freq --> out) high pass filter. 12 dB/oct.\")\n\tDEFMCX(lpf2, 2, \"(in freq --> out) low pass filter. 24 dB/oct.\")\n\tDEFMCX(hpf2, 2, \"(in freq --> out) high pass filter. 24 dB/oct.\")\n\t\n\tDEFMCX(rlpf, 3, \"(in freq rq --> out) resonant low pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf, 3, \"(in freq rq --> out) resonant high pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2, 3, \"(in freq rq --> out) resonant low pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2, 3, \"(in freq rq --> out) resonant high pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\t\n\tDEFMCX(rlpfc, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpfc, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2c, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2c, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\n\tDEFMCX(bpf, 3, \"(in freq bw --> out) band pass filter. bw is bandwidth in octaves.\")\n\tDEFMCX(bsf, 3, \"(in freq bw --> out) band stop filter. bw is bandwidth in octaves.\")\n\tDEFMCX(apf, 3, \"(in freq bw --> out) all pass filter. bw is bandwidth in octaves.\")\n\t\n\tDEFMCX(peq, 4, \"(in freq bw gain --> out) parametric equalization filter. bw is bandwidth in octaves.\")\n\tDEFMCX(lsf, 3, \"(in freq gain --> out) low shelf filter.\")\n\tDEFMCX(hsf, 3, \"(in freq gain --> out) high shelf filter.\")\n\tDEFMCX(lsf1, 3, \"(in freq gain --> out) low shelf filter.\")\n\n\tDEFMCX(resonz, 3, \"(in freq rq --> out) resonant filter.\")\n\tDEFMCX(ringz, 3, \"(in freq ringTime --> out) resonant filter specified by a ring time in seconds.\")\n\tDEFMCX(formlet, 4, \"(in freq atkTime dcyTime --> out) a formant filter whose impulse response is a sine grain.\")\n\tDEFAM(klank, zaaa, \"(in freqs amps ringTimes --> out) a bank of ringz filters. freqs amps and ringTimes are arrays.\")\n\n\tDEFMCX(leakdc, 2, \"(in coef --> out) leaks away energy at 0 Hz.\")\n\tDEFMCX(leaky, 2, \"(in coef --> out) leaky integrator.\")\n\tDEFMCX(decay, 2, \"(in decayTime --> out) outputs an exponential decay for impulses at the input.\")\n\tDEFMCX(decay2, 3, \"(in atkTime dcyTime --> out) outputs an exponential attack and decay for impulses at the input.\")\n\n\tDEFMCX(hilbert, 1, \"(in --> outA outB) returns two signals that are 90 degrees phase shifted from each other.\")\n\tDEFMCX(ampf, 3, \"(in atkTime dcyTime --> out) amplitude follower.\")\n}\n\n\n\n"], ["/sapf/src/Midi.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Midi.hpp\"\n#include \"VM.hpp\"\n#include \"UGen.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n#include \n#include \n\n\nstruct MidiChanState\n{\n\tuint8_t control[128];\n\tuint8_t polytouch[128];\n\tuint8_t keyvel[128];\n\tuint32_t numKeysDown;\n\tuint16_t bend;\n\tuint8_t touch;\n\tuint8_t program;\n\tuint8_t lastkey;\n\tuint8_t lastvel;\n};\n\nconst int kMaxMidiPorts = 16;\nMidiChanState gMidiState[kMaxMidiPorts][16];\nbool gMidiDebug = false;\nMIDIClientRef gMIDIClient = 0;\nMIDIPortRef gMIDIInPort[kMaxMidiPorts], gMIDIOutPort[kMaxMidiPorts];\nint gNumMIDIInPorts = 0, gNumMIDIOutPorts = 0;\nbool gMIDIInitialized = false;\n\nstatic bool gSysexFlag = false;\nstatic Byte gRunningStatus = 0;\nstd::vector gSysexData;\n\nstatic void sysexBegin() {\n\tgRunningStatus = 0; // clear running status\n\t//gSysexData.clear();\n\tgSysexFlag = true;\n}\n\nstatic void sysexEnd(int lastUID) {\n\tgSysexFlag = false;\n}\n\nstatic void sysexEndInvalid() {\n\tgSysexFlag = false;\n}\n\nstatic int midiProcessSystemPacket(MIDIPacket *pkt, int chan) {\n\tint index, data;\n\tswitch (chan) {\n\tcase 7: // added cp: Sysex EOX must be taken into account if first on data packet\n\tcase 0:\n\t\t{\n\t\tint last_uid = 0;\n\t\tint m = pkt->length;\n\t\tByte* p_pkt = pkt->data;\n\t\tByte pktval;\n\n\t\twhile(m--) {\n\t\t\tpktval = *p_pkt++;\n\t\t\tif(pktval & 0x80) { // status byte\n\t\t\t\tif(pktval == 0xF7) { // end packet\n\t\t\t\t\tgSysexData.push_back(pktval); // add EOX\n\t\t\t\t\tif(gSysexFlag)\n\t\t\t\t\t\tsysexEnd(last_uid); // if last_uid != 0 rebuild the VM.\n\t\t\t\t\telse\n\t\t\t\t\t\tsysexEndInvalid(); // invalid 1 byte with only EOX can happen\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if(pktval == 0xF0) { // new packet\n\t\t\t\t\tif(gSysexFlag) {// invalid new one/should not happen -- but handle in case\n\t\t\t\t\t\t// store the last uid value previous to invalid data to rebuild VM after sysexEndInvalid call\n\t\t\t\t\t\t// since it may call sysexEnd() just after it !\n\t\t\t\t\t\tsysexEndInvalid();\n\t\t\t\t\t}\n\t\t\t\t\tsysexBegin(); // new sysex in\n\t\t\t\t\t//gSysexData.push_back(pktval); // add SOX\n\t\t\t\t}\n\t\t\t\telse {// abnormal data in middle of sysex packet\n\t\t\t\t\t//gSysexData.push_back(pktval); // add it as an abort message\n\t\t\t\t\tsysexEndInvalid(); // flush invalid\n\t\t\t\t\tm = 0; // discard all packet\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(gSysexFlag) {\n\t\t\t\t//gSysexData.push_back(pktval); // add Byte\n\t\t\t} else { // garbage - handle in case - discard it\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn (pkt->length-m);\n\t\t}\n\tbreak;\n\n\tcase 1 :\n\t\tindex = pkt->data[1] >> 4;\n\t\tdata = pkt->data[1] & 0xf;\n\t\tswitch (index) { case 1: case 3: case 5: case 7: { data = data << 4; } }\n\t\treturn 2;\n\n\tcase 2 : \t//songptr\n\t\treturn 3;\n\n\tcase 3 :\t// song select\n\t\treturn 2;\n\n\tcase 8 :\t//clock\n\tcase 10:\t//start\n\tcase 11:\t//continue\n\tcase 12: \t//stop\n\tcase 15:\t//reset\n\t\tgRunningStatus = 0; // clear running status\n\t\treturn 1;\n\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn (1);\n}\n\n\n\n\nstatic void midiProcessPacket(MIDIPacket *pkt, int srcIndex)\n{\n\tif(pkt) {\n\t\tint i = 0; \n\t\twhile (i < pkt->length) {\n\t\t\tuint8_t status = pkt->data[i] & 0xF0;\n\t\t\tuint8_t chan = pkt->data[i] & 0x0F;\n\t\t\tuint8_t a, b;\n\n\t\t\tif(status & 0x80) // set the running status for voice messages\n\t\t\t\tgRunningStatus = ((status >> 4) == 0xF) ? 0 : pkt->data[i]; // keep also additional info\n\t\tL:\n\t\t\tswitch (status) {\n\t\t\tcase 0x80 : //noteOff\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note off %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = 0;\n\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0x90 : //noteOn\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note on %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tif (b) {\n\t\t\t\t\tgMidiState[srcIndex][chan].lastkey = a;\n\t\t\t\t\tgMidiState[srcIndex][chan].lastvel = b;\n\t\t\t\t\t++gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t} else {\n\t\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t}\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xA0 : //polytouch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi poly %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].polytouch[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xB0 : //control\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi control %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].control[a] = b;\n\t\t\t\tif (a == 120 || (a >= 123 && a <= 127)) {\n\t\t\t\t\t// all notes off\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].keyvel, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].numKeysDown = 0;\n\t\t\t\t} else if (a == 121) {\n\t\t\t\t\t// reset ALL controls to zero, don't follow MMA recommended practices.\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].control, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].bend = 0x4000;\n\t\t\t\t}\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xC0 : //program\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tgMidiState[srcIndex][chan].program = a;\n\t\t\t\tif (gMidiDebug) printf(\"midi program %d %d %d\\n\", srcIndex, chan+1, a);\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xD0 : //touch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tprintf(\"midi touch %d %d\\n\", chan+1, a);\n\t\t\t\tgMidiState[srcIndex][chan].touch = a;\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xE0 : //bend\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi bend %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].bend = ((b << 7) | a) - 8192;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xF0 :\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\tdefault :\t// data byte => continuing sysex message\n\t\t\t\tif(gRunningStatus && !gSysexFlag) { // modified cp: handling running status. may be we should here\n\t\t\t\t\tstatus = gRunningStatus & 0xF0; // accept running status only inside a packet beginning\n\t\t\t\t\tchan = gRunningStatus & 0x0F;\t// with a valid status byte ?\n\t\t\t\t\t--i;\n\t\t\t\t\tgoto L; // parse again with running status set\n\t\t\t\t}\n\t\t\t\tchan = 0;\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nstatic void midiReadProc(const MIDIPacketList *pktlist, void* readProcRefCon, void* srcConnRefCon)\n{\n\tMIDIPacket *pkt = (MIDIPacket*)pktlist->packet;\n\tint srcIndex = (int)(size_t) srcConnRefCon;\n\tfor (uint32_t i=0; inumPackets; ++i) {\n\t\tmidiProcessPacket(pkt, srcIndex);\n\t\tpkt = MIDIPacketNext(pkt);\n\t}\n}\n\nstatic void midiNotifyProc(const MIDINotification *message, void *refCon)\n{\n\tprintf(\"midi notification %d %d\\n\", (int)message->messageID, (int)message->messageSize);\n}\n\nstatic struct mach_timebase_info machTimebaseInfo() {\n struct mach_timebase_info info;\n mach_timebase_info(&info);\n return info;\n}\n\nstatic MIDITimeStamp midiTime(float latencySeconds)\n{\n // add the latency expressed in seconds, to the current host time base.\n static struct mach_timebase_info info = machTimebaseInfo(); // cache the timebase info.\n Float64 latencyNanos = 1000000000 * latencySeconds;\n MIDITimeStamp latencyMIDI = (latencyNanos / (Float64)info.numer) * (Float64)info.denom;\n return (MIDITimeStamp)mach_absolute_time() + latencyMIDI;\n}\n\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late);\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late)\n{\n\tMIDIPacketList mpktlist;\n\tMIDIPacketList * pktlist = &mpktlist;\n\tMIDIPacket * pk = MIDIPacketListInit(pktlist);\n\tByteCount nData = (ByteCount) length;\n\tpk->data[0] = (Byte) (hiStatus & 0xF0) | (loStatus & 0x0F);\n\tpk->data[1] = (Byte) aval;\n\tpk->data[2] = (Byte) bval;\n\tpk = MIDIPacketListAdd(pktlist, sizeof(struct MIDIPacketList) , pk, midiTime(late), nData, pk->data);\n\t/*OSStatus error =*/ MIDISend(gMIDIOutPort[port], dest, pktlist );\n}\n\n\nstatic int midiCleanUp()\n{\n\t/*\n\t* do not catch errors when disposing ports\n\t* MIDIClientDispose should normally dispose the ports attached to it\n\t* but clean up the pointers in case\n\t*/\n\tint i = 0;\n\tfor (i=0; i= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\t//pass the uid to the midiReadProc to identify the src\n\tvoid* p = (void*)(uintptr_t)inputIndex;\n\tMIDIPortConnectSource(gMIDIInPort[inputIndex], src, p);\n\n\treturn errNone;\n}\n\n\nstatic int prDisconnectMIDIIn(int uid, int inputIndex)\n{\n\tif (inputIndex < 0 || inputIndex >= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\tMIDIPortDisconnectSource(gMIDIInPort[inputIndex], src);\n\n\treturn errNone;\n}\n\n\nstatic void midiStart_(Thread& th, Prim* prim)\n{\n\tmidiInit(16, 19);\n}\n\nstatic void midiRestart_(Thread& th, Prim* prim)\n{\n\tMIDIRestart();\n}\n\nstatic void midiStop_(Thread& th, Prim* prim)\n{\n\tmidiCleanUp();\n}\n\nstatic void midiList_(Thread& th, Prim* prim)\n{\n\tprListMIDIEndpoints();\n}\n\nstatic void midiConnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiConnectInput : port\");\n\tint uid = (int)th.popInt(\"midiConnectInput : sourceUID\");\n\tprConnectMIDIIn(uid, index);\n}\n\nstatic void midiDisconnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiDisconnectInput : port\");\n\tint uid = (int)th.popInt(\"midiDisconnectInput : sourceUID\");\n\tprDisconnectMIDIIn(uid, index);\n}\n\nstatic void midiDebug_(Thread& th, Prim* prim)\n{\n gMidiDebug = th.popFloat(\"midiDebug : onoff\") != 0.;\n}\n\nconst Z kOneOver127 = 1./127.;\nconst Z kOneOver8191 = 1./8191.;\n\nstatic void mctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl1 : hi\");\n\tZ lo = th.popFloat(\"mctl1 : lo\");\n\n\tint cnum = th.popInt(\"mctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl1 : hi\");\n\tZ lo = th.popFloat(\"xmctl1 : lo\");\n\n\tint cnum = th.popInt(\"xmctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly1 : hi\");\n\tZ lo = th.popFloat(\"mpoly1 : lo\");\n\n\tint key = th.popInt(\"mpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"mpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly1 : hi\");\n\tZ lo = th.popFloat(\"xmpoly1 : lo\");\n\n\tint key = th.popInt(\"xmpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mgate1_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate1 : key\") & 127;\n\tint chan = (th.popInt(\"mgate1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mgate1 : srcIndex\") & 15;\n\n\tth.pushBool(gMidiState[srcIndex][chan].keyvel[key] > 0);\n}\n\nstatic void mtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch1 : hi\");\n\tZ lo = th.popFloat(\"mtouch1 : lo\");\n\n\tint chan = (th.popInt(\"mtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch1 : hi\");\n\tZ lo = th.popFloat(\"xmtouch1 : lo\");\n\n\tint chan = (th.popInt(\"xmtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mprog1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mprog1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].touch);\n}\n\nstatic void mlastkey1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastkey1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].lastkey);\n}\n\nstatic void mlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel1 : hi\");\n\tZ lo = th.popFloat(\"mlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"mlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel1 : hi\");\n\tZ lo = th.popFloat(\"xmlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"xmlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nstatic void mbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend1 : hi\");\n\tZ lo = th.popFloat(\"mbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo + z * (hi - lo));\n}\nstatic void xmbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend1 : hi\");\n\tZ lo = th.popFloat(\"xmbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nZ gMidiLagTime = .1;\nZ gMidiLagMul = log001 / gMidiLagTime;\n\nstruct MCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct XMLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastKey : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMLastKey(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastKey\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastkey;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MProg : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMProg(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MProg\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].program;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MGate : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n int _key;\n\t\n\tMGate(Thread& th, int srcIndex, int chan, int key)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan), _key(key)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MGate\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].keyvel[_key];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl > 0 ? 1. : 0.;\n\t\t}\n\t}\n};\n\n\nstruct ZCtl : public ZeroInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n P zref;\n\t\n\tZCtl(Thread& th, P const& inZRef)\n : ZeroInputUGen(th, false), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n zref(inZRef)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ZCtl\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n Z& ctl = zref->z;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = ctl;\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void zctl_(Thread& th, Prim* prim)\n{\n\tP zref = th.popZRef(\"mctl : zref\");\n\n\tth.push(new List(new ZCtl(th, zref)));\n}\n\n\nstatic void mctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl : hi\");\n\tZ lo = th.popFloat(\"mctl : lo\");\n\n\tint cnum = th.popInt(\"mctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void xmctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl : hi\");\n\tZ lo = th.popFloat(\"xmctl : lo\");\n\n\tint cnum = th.popInt(\"xmctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void mpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly : hi\");\n\tZ lo = th.popFloat(\"mpoly : lo\");\n\n\tint key = th.popInt(\"mpoly : key\") & 127;\n\tint chan = (th.popInt(\"mpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void xmpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly : hi\");\n\tZ lo = th.popFloat(\"xmpoly : lo\");\n\n\tint key = th.popInt(\"xmpoly : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void mtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch : hi\");\n\tZ lo = th.popFloat(\"mtouch : lo\");\n\n\tint chan = (th.popInt(\"mtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch : hi\");\n\tZ lo = th.popFloat(\"xmtouch : lo\");\n\n\tint chan = (th.popInt(\"xmtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend : hi\");\n\tZ lo = th.popFloat(\"mbend : lo\");\n\n\tint chan = (th.popInt(\"mbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MBend(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend : hi\");\n\tZ lo = th.popFloat(\"xmbend : lo\");\n\n\tint chan = (th.popInt(\"xmbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMBend(th, srcIndex, chan, lo, hi)));\n}\n\n\nstatic void mprog_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MProg(th, srcIndex, chan)));\n}\n\nstatic void mgate_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate : key\") & 127;\n\tint chan = (th.popInt(\"mgate : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MGate(th, srcIndex, chan, key)));\n}\n\n\nstatic void mlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel : hi\");\n\tZ lo = th.popFloat(\"mlastvel : lo\");\n\n\tint chan = (th.popInt(\"mlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastVel(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mlastkey_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastKey(th, srcIndex, chan)));\n}\n\nstatic void xmlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel : hi\");\n\tZ lo = th.popFloat(\"xmlastvel : lo\");\n\n\tint chan = (th.popInt(\"xmlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMLastVel(th, srcIndex, chan, lo, hi)));\n}\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMidiOps()\n{\n\tvm.addBifHelp(\"\\n*** MIDI control ***\");\n\tDEF(midiStart, 0, 0, \"(-->) start up MIDI services\");\n\tDEF(midiRestart, 0, 0, \"(-->) rescan MIDI services\");\n\tDEF(midiStop, 0, 0, \"(-->) stop MIDI services\");\n\tDEF(midiList, 0, 0, \"(-->) list MIDI endpoints\");\n\tDEF(midiConnectInput, 2, 0, \"(sourceUID index -->) connect a MIDI source\");\n\tDEF(midiDisconnectInput, 2, 0, \"(sourceUID index -->) disconnect a MIDI source\");\n\tDEF(midiDebug, 1, 0, \"(onoff -->) turn on or off midi input monitoring\");\n\t\n\tvm.addBifHelp(\"\\n*** MIDI instantaneous value ***\");\n\tDEFMCX(mctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mprog1, 2, \"(srcIndex chan --> out) value of midi channel program 0-127.\");\n\tDEFMCX(mgate1, 3, \"(srcIndex chan key --> out) value of midi key state. 1 if key is down, 0 if key is up.\");\n\tDEFMCX(mlastkey1, 2, \"(srcIndex chan --> out) value of key of most recent midi note on.\");\n\tDEFMCX(mlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(xmctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** MIDI control signal ***\");\n\tDEFMCX(mctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mlastkey, 2, \"(srcIndex chan --> out) signal of key of most recent midi note on.\");\n\tDEFMCX(mlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(mprog, 2, \"(srcIndex chan --> out) signal of midi channel program 0-127.\");\n\tDEFMCX(mgate, 3, \"(srcIndex chan key --> out) signal of midi key state. 1 if key is down, 0 if key is up.\");\n\n\tDEFMCX(xmctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** ZRef control signal ***\");\n\tDEFMCX(zctl, 1, \"(zref --> out) makes a smoothed control signal from a zref.\");\n}\n\n\n"], ["/sapf/src/CoreOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Parser.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// stack shufflers\n#pragma mark STACK OPS\n\nstatic void clear_(Thread& th, Prim* prim)\n{\n\tth.clearStack();\n}\n\nstatic void cleard_(Thread& th, Prim* prim)\n{\n\tV v = th.top();\n\tth.clearStack();\n\tth.push(v);\n}\n\nstatic void stackDepth_(Thread& th, Prim* prim)\n{\n\tth.push(th.stackDepth());\n}\n\nstatic void ba_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[0] = sp[-1];\n\tsp[-1] = b;\n}\n\nstatic void bac_(Thread& th, Prim* prim) \n{\n\t// swapd\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = a;\n\tsp[0] = c;\n}\n\nstatic void cab_(Thread& th, Prim* prim)\n{\n\t// rrot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = a;\n\tsp[0] = b;\n}\n\nstatic void bca_(Thread& th, Prim* prim)\n{\n\t// rot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = c;\n\tsp[0] = a;\n}\n\nstatic void cba_(Thread& th, Prim* prim)\n{\n\t// reverse top 3\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n}\n\nstatic void aaa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n\tth.push(v);\n}\n\nstatic void aba_(Thread& th, Prim* prim)\n{\n\t// over\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tth.push(sp[-1]);\n}\n\nstatic void bab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\n\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n}\n\nstatic void aabb_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n\tth.push(b);\t\n}\n\nstatic void abab_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(a);\t\n\tth.push(b);\t\n}\n\nstatic void nip_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[-1] = b;\n\tth.pop();\n}\n\n\nstatic void pop_(Thread& th, Prim* prim)\n{\n\tth.pop();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark INHERIT\n\nstatic bool hasItem(int64_t size, Table** a, Table* item)\n{\n\tfor (int64_t i = 0; iIdentical(item))\n\t\t\treturn true;\n\t}\n\treturn false;\n}\n\nstatic void Envir_merge2(Thread& th, int64_t asize, Table** a, int64_t bsize, Table** b, int64_t& csize, Table** c0)\n{\n\n\tTable** c = c0;\n\tTable** aend = a + asize;\n\tTable** bend = b + bsize;\n\twhile (a < aend && b < bend) {\t\n\t\tif ((*a)->Identical(*b)) {\n\t\t\t*c++ = *a++;\n\t\t\tb++;\n\t\t} else if (!hasItem(bend-b-1, b+1, *a)) {\n\t\t\t*c++ = *a++;\n\t\t} else if (!hasItem(aend-a-1, a+1, *b)) {\n\t\t\t*c++ = *b++;\n\t\t} else {\n\t\t\tthrow errInconsistentInheritance;\n\t\t}\n\t}\n\twhile (a < aend) { *c++ = *a++; }\n\twhile (b < bend) { *c++ = *b++; }\n\tcsize = c - c0;\n}\n\t\nstatic int64_t Envir_toVec(O list, int64_t maxSize, Table** vec)\n{\n\tint64_t i = 0;\n\tfor (; list && i < maxSize-1;) {\n\t\tvec[i++] = ((Form*)list)->mTable();\n\t\tlist = ((Form*)list)->mNextForm();\n\t}\n\treturn i;\n}\n\nstatic P Envir_fromVec(int64_t size, Table** a)\n{\n\tif (size == 0) return vm._ee;\n\t\n\tP list;\n\tfor (int64_t i = size-1; i >= 0; --i) {\n\t\tlist = consForm(a[i], list);\n\t}\n\treturn list;\n}\n\n\nP linearizeInheritance(Thread& th, size_t numArgs, V* args)\n{\n\tif (numArgs == 0) return vm._ee;\n\tif (numArgs == 1) {\n\t\tif (args[0].isForm()) {\n\t\t\treturn (Form*)args[0].asObj();\n\t\t} else {\n\t\t\treturn vm._ee;\n\t\t}\n\t}\n\t\n\tconst size_t maxSize = 1024;\n\tTable* t[3][maxSize];\n\t\n\tint ai = 0;\n\tint bi = 1;\n\tint ci = 2;\n\n\tint64_t asize = Envir_toVec(args[0].asObj(), maxSize, t[ai]);\n\tfor (size_t i = 1; i < numArgs; ++i) {\n\t\tint64_t bsize = Envir_toVec(args[i].asObj(), maxSize, t[bi]);\n\t\tint64_t csize;\n\t\tEnvir_merge2(th, asize, t[ai], bsize, t[bi], csize, t[ci]);\n\t\tint temp = ci;\n\t\tci = ai;\n\t\tai = temp;\n\t\tasize = csize;\n\t}\n\treturn Envir_fromVec(asize, t[ai]);\n}\n\nP asParent(Thread& th, V& v)\n{\n\tP parent;\n\tif (v.isReal()) {\n\t\tparent = nullptr;\n\t} else if (v.isForm()) {\n\t\tif (v.o() == vm._ee()) parent = nullptr;\n\t\telse parent = (Form*)v.o();\n\t} else if (v.isFunOrPrim()) {\n\t\tSaveStack save(th);\n\t\tv.apply(th);\n\t\t\n\t\tsize_t n = th.stackDepth();\n\t\tV* args = &th.top() - (n - 1);\n\n\t\tparent = linearizeInheritance(th, n, args);\n\t\n\t\tth.popn(n);\n\t} else if (v.isVList()) {\n\t\tif (!v.isFinite())\n\t\t\tindefiniteOp(\"\", \"{} : parent\");\n\t\t\t\n\t\tP const& a = ((List*)v.o())->mArray;\n\t\tsize_t n = a->size();\n\t\tparent = linearizeInheritance(th, n, a->v());\n\t} else {\n\t\twrongType(\"new : parent\", \"Form, Fun or VList\", v);\n\t\treturn NULL; // never gets here, but otherwise gcc warns about parent uninitialized.\n\t}\n\treturn parent;\n}\n\nstruct Binding\n{\n\tV key;\n\tBothIn value;\n};\n\nstruct Bind : public Gen\n{\n\tP mMap;\n\tP mParent;\n\tstd::vector _bindings;\n\t\n\tBind(Thread& th, P& parent, P const& bindings, bool inIsFinite) \n\t\t: Gen(th, itemTypeV, inIsFinite), mParent(parent)\n\t{\n\t\tint64_t m = bindings->length(th);\n\t\tfor (int64_t i = 0; i+1 < m; i += 2) {\n\t\t\tBinding b;\n\t\t\tb.key = bindings->at(i);\n\t\t\tb.value.set(bindings->at(i+1));\n\t\t\t_bindings.push_back(b);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Bind\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tint n = framesToFill;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tP e = consForm(new Table(mMap), mParent);\n\t\t\t\n\t\t\tint64_t m = _bindings.size();\n\t\t\tfor (int64_t j = 0; j < m; ++j) {\n\t\t\t\tBinding& b = _bindings[j];\n\t\t\t\tV val;\n\t\t\t\tif (b.value.one(th, val)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\te->put(j, val); // ok, single threaded mutation\n\t\t\t}\n\t\t\t\n\t\t\tout[i] = e;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark REF OPS\n\n\nstatic void ref_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tV ref = new Ref(value);\n\tth.push(ref);\n}\n\nstatic void zref_(Thread& th, Prim* prim)\n{\n\tZ z = th.popFloat(\"zref : value\");\n\tth.push(new ZRef(z));\n}\n\n\nstatic void set_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tif (ref.isRef()) {\n\t\tV value = th.pop();\n\t\t((Ref*)ref.o())->set(value);\n\t} else if (ref.isZRef()) {\n\t\tZ value = th.popFloat(\"set : value\");\n\t\t((ZRef*)ref.o())->set(value);\n\t} else if (ref.isPlug()) {\n\t\tV value = th.pop();\n\t\t((Plug*)ref.o())->setPlug(value);\n\t} else if (ref.isZPlug()) {\n\t\tV value = th.popZIn(\"set : value\");\n\t\t((ZPlug*)ref.o())->setPlug(value);\n\t} else if (ref.isVList() && ref.isFinite()) {\n\t\tV value = th.pop();\n\t\tP refList = ((List*)ref.o())->pack(th);\n\t\tP refArray = refList->mArray;\n\t\tV* refs = refArray->v();\n\t\tif (value.isVList() && value.isFinite()) {\n\t\t\tP valueList = ((List*)value.o())->pack(th);\n\t\t\tP valueArray = valueList->mArray;\n\t\t\tV* vals = valueArray->v();\n\t\t\tsize_t n = std::min(refArray->size(), valueArray->size());\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(vals[i]);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t} else {\n\t\t\tsize_t n = refArray->size();\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(value);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"set : ref\", \"Ref, ZRef, Plug or ZPlug\", ref);\n\t}\n}\n\nstatic void get_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tth.push(ref.deref());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// printing ops\n#pragma mark PRINTING\n\nstatic void pr_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().print(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void prdebug_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().printDebug(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void cr_(Thread& th, Prim* prim)\n{\n\tpost(\"\\n\");\n}\n\nstatic void tab_(Thread& th, Prim* prim)\n{\n\tpost(\"\\t\");\n}\n\nstatic void sp_(Thread& th, Prim* prim)\n{\n\tpost(\" \");\n}\n\nstatic void prstk_(Thread& th, Prim* prim)\n{\n\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n}\n\n\nstatic void printLength_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printLength);\n}\n\nstatic void printDepth_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printDepth);\n}\n\nstatic void printTotalItems_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printTotalItems);\n}\n\nstatic void setPrintLength_(Thread& th, Prim* prim)\n{\n\tvm.printLength = (int)th.popInt(\"setPrintLength : length\");\n}\n\nstatic void setPrintDepth_(Thread& th, Prim* prim)\n{\n\tvm.printDepth = (int)th.popInt(\"setPrintDepth : depth\");\n}\n\nstatic void setPrintTotalItems_(Thread& th, Prim* prim)\n{\n\tvm.printTotalItems = (int)th.popInt(\"setPrintTotalItems : numItems\");\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// string ops\n#pragma mark STRINGS\n\nstatic void str_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.print(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void debugstr_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.printDebug(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void strcat_(Thread& th, Prim* prim)\n{\n\tP sep = th.popString(\"strcat : separator\");\n\tP list = th.popVList(\"strcat : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strcat : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tif (i != 0) s += sep->s;\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\nstatic void strlines_(Thread& th, Prim* prim)\n{\n\tP list = th.popVList(\"strlines : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strlines : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t\ts += \"\\n\";\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// loops\n#pragma mark LOOPS\n\nstatic void while_(Thread& th, Prim* prim)\n{\n\tV body = th.pop();\n\tV test = th.pop();\n\twhile (1) {\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\ttest.apply(th);\n\t\t\tif (th.pop().isTrue()) break;\n\t\t}\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\tbody.apply(th);\n\t\t}\n\t}\n}\n\n\nstatic void eachDoer(Thread& th, int level, uint32_t mask, BothIn& in, V& fun)\n{\n\tint nextLevel = level - 1;\n\tif (level == 0) {\n\t\twhile (1) {\n\t\t\tSaveStack ss(th);\n\t\t\tV v;\n\t\t\tif (in.one(th, v)) \n\t\t\t\treturn;\n\n\t\t\tth.push(v);\n\t\t\tfun.apply(th);\n\t\t}\n\t} else {\n\t\tint bit = 1 << level;\n\n\t\twhile (1) {\n\t\t\tV argv;\n\t\t\tif (in.one(th, argv))\n\t\t\t\treturn;\n\n\t\t\tbool isConstant = !(argv.isList() && (mask & bit));\n\t\t\t\n\t\t\tif (isConstant) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(argv);\n\t\t\t\tfun.apply(th);\n\t\t\t} else {\n\t\t\t\tBothIn subin;\n\t\t\t\tV v = argv;\n\t\t\t\tif (mask & bit) {\n\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\t\t\t\n\t\t\t\t\tsubin.set(v);\n\t\t\t\t} else {\n\t\t\t\t\tsubin.setConstant(v);\n\t\t\t\t}\n\t\t\t\n\t\t\t\teachDoer(th, nextLevel, mask, subin, fun);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstatic void do_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tV item = th.pop();\n\t\n\tif (item.isEachOp()) {\n\t\tP p = (EachOp*)item.o();\n\t\tif (!p->v.isFinite())\n\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\n\t\tBothIn in(p->v);\n\t\tint numLevels = p->mask <= 1 ? 0 : LOG2CEIL(p->mask) - 1;\n\t\teachDoer(th, numLevels, p->mask, in, f);\n\t} else if (item.isList()) {\n\t\n\t\tP s = (List*)item.o();\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"do\", \"\");\n\n\t\tif (s->isVList()) {\n\t\t\tVIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = kDefaultVBlockSize;\n\t\t\t\tint astride;\n\t\t\t\tV *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tZIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = th.rate.blockSize;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"do : list\", \"List\", item);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark CONDITIONALS\n\nstatic void equals_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(a.Equals(th, b));\n}\n\nstatic void less_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) < 0);\n}\n\nstatic void greater_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) > 0);\n}\n\nstatic void if_(Thread& th, Prim* prim)\n{\n\tV elseCode = th.pop();\n\tV thenCode = th.pop();\n\tV test = th.pop();\n\tif (test.isTrue()) {\n\t\tthenCode.apply(th);\n\t} else {\n\t\telseCode.apply(th);\n\t}\n}\n\nstatic void dip_(Thread& th, Prim* prim)\n{\n V temp = th.pop();\n V fun = th.pop();\n fun.apply(th);\n th.push(temp);\n}\n\nstatic void not_(Thread& th, Prim* prim)\n{\n\tV p = th.pop();\n\tth.pushBool(p.isFalse());\n}\n\nstatic void protect_(Thread& th, Prim* prim)\n{\n\tV protectCode = th.pop();\n\tV tryCode = th.pop();\n\n\t\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tprotectCode.apply(th);\n\t\tthrow;\n\t}\n\n\tprotectCode.apply(th);\n}\n\nstatic void try_(Thread& th, Prim* prim)\n{\n\tV catchCode = th.pop();\n\tV tryCode = th.pop();\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tcatchCode.apply(th);\n\t\tthrow;\n\t}\n}\n\nstatic void throw_(Thread& th, Prim* prim)\n{\n\tthrow -1;\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ENVIR OPS\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.push(asParent(th, v));\n}\n\nstatic void pushWorkspace_(Thread& th, Prim* prim)\n{\n\tth.mWorkspace = consForm(new GTable(), th.mWorkspace);\n}\n\nstatic void popWorkspace_(Thread& th, Prim* prim)\n{\n if (!th.mWorkspace->mNextForm()) {\n post(\"Must not pop top level workspace!\\n\");\n return;\n }\n\tth.mWorkspace = th.mWorkspace->mNextForm;\n}\n\n\nstatic void has_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV list = th.pop();\n\t\n\tV value;\n\tbool has = list.get(th, key, value);\n\tth.pushBool(has);\n}\n\nstatic void keys_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(keys[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\nstatic void values_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(vals[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\n\nstatic void kv_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"values : e\")->mTable;\n\t\n\tP ka = new Array(itemTypeV, t->mMap->mSize);\n\tP va = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\tka->add(keys[i]);\n\t\tva->add(vals[i]);\n\t}\n\n\tth.push(new List(ka));\n\tth.push(new List(va));\n}\n\nstatic void local_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"local : e\")->mTable;\n\t\n\tth.push(new Form(t));\n}\n\nstatic void parent_(Thread& th, Prim* prim)\n{\n\tP form = th.popForm(\"values : e\");\n\t\n\tth.push(form->mNextForm ? form->mNextForm : vm._ee);\n}\n\nstatic void dot_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV e = th.pop();\n\t\t\n\tif (!key.isVList()) {\n\t\tV v;\n\t\te.dot(th, key, v);\n\t\tth.push(v);\n\t} else {\n\t\tif (!key.isFinite())\n\t\t\tindefiniteOp(\"dot : key\", \"\");\n\t\tList* ks = (List*)key.o();\n\t\tks = ks->pack(th);\n\n\t\tP ka = ks->mArray;\n\t\tint64_t size = ka->size();\n\t\tP va = new Array(itemTypeV, size);\n\t\tva->setSize(size);\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tV v;\n\t\t\te.dot(th, key, v);\n\t\t\tth.push(v);\n\t\t}\n\t\tth.push(new List(va));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark APPLY\n\nstatic void noeach_(Thread& th, Prim* prim)\n{\n\tV fun = th.top();\n\t\n\tfun.SetNoEachOps();\n}\n\nstatic void apply_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tv.apply(th);\n}\n\nstatic void applyEvent_(Thread& th, Prim* prim)\n{\n\tP fun = th.popFun(\"!e : fun\");\n\tP form = th.popForm(\"!e : form\");\n\t\n\tfor (auto const& name : fun->mDef->mArgNames) {\n\t\tV argValue;\n\t\tif (!form->dot(th, name, argValue)) {\n\t\t\tnotFound(name);\n\t\t}\n\t\tth.push(argValue);\n\t}\n\t\n\tfun->apply(th);\n}\n\nstatic void type_(Thread& th, Prim* prim)\n{\n\tth.push(getsym(th.pop().TypeName()));\n}\n\nstatic void load_(Thread& th, Prim* prim)\n{\n\tP filename = th.popString(\"load : filename\");\n\tloadFile(th, filename->s);\n}\n\nstatic void compile_(Thread& th, Prim* prim)\n{\n\tP s = th.popString(\"compile : string\");\n\tconst char* ss = s->s;\n\t\n\tP fun;\n\tif (!th.compile(ss, fun, false)) {\n\t\tth.push(0.);\n\t} else {\n\t\tth.push(fun);\n\t}\n}\n\nstatic void y_combinator_call_(Thread& th, Prim* prim)\n{\n\tth.push(prim);\n\tprim->v.apply(th);\n}\n\nstatic void Y_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tif (f.takes() < 1) {\n\t\tpost(\"Y : fun. function must take at least one argument.\\n\");\n\t\tthrow errFailed;\n\t}\n\tth.push(new Prim(y_combinator_call_, f, f.takes()-1, f.leaves(), NULL, NULL));\n}\n\n\nstatic void* gofun(void* ptr)\n{\n Thread* th = (Thread*)ptr;\n th->fun->run(*th);\n delete th;\n return NULL;\n}\n\nstatic void go_(Thread& th, Prim* prim)\n{\n P fun = th.popFun(\"go : fun\");\n \n Thread* newThread = new Thread (th, fun); \n \n pthread_t pt;\n pthread_create(&pt, NULL, gofun, newThread);\n}\n\nstatic void sleep_(Thread& th, Prim* prim)\n{\n Z t = th.popFloat(\"sleep : secs\");\n \n usleep((useconds_t)floor(1e6 * t + .5));\n}\n\n#if COLLECT_MINFO\nstatic void minfo_(Thread& th, Prim* prim)\n{\n\tpost(\"signal generators %qd\\n\", vm.totalSignalGenerators.load());\n\tpost(\"stream generators %qd\\n\", vm.totalStreamGenerators.load());\n\tpost(\"objects live %qd\\n\", vm.totalObjectsAllocated.load() - vm.totalObjectsFreed.load());\n\tpost(\"objects allocated %qd\\n\", vm.totalObjectsAllocated.load());\n\tpost(\"objects freed %qd\\n\", vm.totalObjectsFreed.load());\n\tpost(\"retains %qd\\n\", vm.totalRetains.load());\n\tpost(\"releases %qd\\n\", vm.totalReleases.load());\n}\n#endif\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark SAMPLE RATES\n\nstatic void sr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate);\n}\n\nstatic void nyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate * .5);\n}\n\nstatic void isr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invSampleRate);\n}\n\nstatic void rps_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.radiansPerSample);\n}\n\nstatic void inyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invNyquistRate);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark HELP\n\nstatic void listdump_(Thread& th, Prim* prim)\n{\t\n\tP list = th.popList(\"listdump : seq\");\n\t\n\tpost(\"[\\n\");\n\twhile (list()) {\n\t\tpost(\"list %p %p %d\\n\", list(), list->mArray(), list->mArray() ? (int)list->mArray->size() : -1);\n\t\tlist = list->next();\n\t}\n\tpost(\"]\\n\");\n}\n\nstatic void help_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\n\tconst char* mask = v.GetAutoMapMask();\n\tconst char* help = v.OneLineHelp();\n\t\n\tif (mask) {\n\t\tpost(\"@%s \", mask);\n\t}\n\tif (help) {\n\t\tpost(\"%s\\n\", help);\n\t} else {\n\t\tpost(\"no help available.\\n\");\n\t}\n\n}\n\nstatic void helpbifs_(Thread& th, Prim* prim)\n{\n post(\"\\nBUILT IN FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.bifHelp.size(); ++i) {\n\t\tstd::string& s = vm.bifHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpLine_(Thread& th, Prim* prim)\n{\n\tP str = th.popString(\"helpLine : string\");\n\tvm.addUdfHelp(str->s);\n}\n\nstatic void helpudfs_(Thread& th, Prim* prim)\n{\n post(\"\\nUSER DEFINED FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.udfHelp.size(); ++i) {\n\t\tstd::string& s = vm.udfHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpall_(Thread& th, Prim* prim)\n{\n helpbifs_(th, prim);\n helpudfs_(th, prim);\n}\n\n\nstatic void prelude_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.prelude_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.prelude_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no prelude file.\\n\");\n\t}\n}\n\nstatic void examples_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* examples_file = getenv(\"SAPF_EXAMPLES\");\n\tif (examples_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", examples_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no examples file.\\n\");\n\t}\n}\n\nstatic void readme_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* readme_file = getenv(\"SAPF_README\");\n\tif (readme_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", readme_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no readme file.\\n\");\n\t}\n}\n\nstatic void logfile_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.log_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.log_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no log file.\\n\");\n\t}\n}\n\nstatic void trace_(Thread& th, Prim* prim)\n{\n\tvm.traceon = th.pop().isTrue();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PLUGS\n\nstruct PlugOut : Gen\n{\n\tP _plug;\n\t\n\tPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeV, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"PlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tVIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\nstruct ZPlugOut : Gen\n{\n\tP _plug;\n\t\n\tZPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeZ, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"ZPlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\n\nstatic void plug_(Thread& th, Prim* prim)\n{\n\tV in = th.pop();\n\tP plug = new Plug(in);\n\tth.push(new List(new PlugOut(th, plug)));\n\tth.push(plug);\n}\n\nstatic void zplug_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tif (value.isVList() && value.isFinite()) {\n\t\tP valueList = ((List*)value.o())->pack(th);\n\t\tP valueArray = valueList->mArray;\n\t\tV* vals = valueArray->v();\n\t\tsize_t n = valueArray->size();\n\t\t\n\t\tP plugList = new List(itemTypeV, n);\n\t\tP outList = new List(itemTypeV, n);\n\t\t\n\t\tP plugArray = plugList->mArray;\n\t\tP outArray = outList->mArray;\n\t\t\n\t\tplugArray->setSize(n);\n\t\toutArray->setSize(n);\n\t\t\n\t\tV* plugItems = plugArray->v();\n\t\tV* outItems = outArray->v();\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(vals[i]);\n\t\t\tzplug_(th, prim);\n\t\t\tplugItems[i] = th.pop();\n\t\t\toutItems[i] = th.pop();\n\t\t}\n\t\t\n\t\tth.push(outList);\n\t\tth.push(plugList);\n\t} else if (value.isZIn()) {\n\t\tP plug = new ZPlug(value);\n\t\tth.push(new List(new ZPlugOut(th, plug)));\n\t\tth.push(plug);\n\t} else {\n\t\twrongType(\"zplug : ref\", \"VList or UGen input\", value);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark GLOB\n\n#include \n\nstatic void glob_(Thread& th, Prim* prim)\n{\n\tP pat = th.popString(\"glob : pattern\");\n\t\n\tglob_t g;\n\tmemset(&g, 0, sizeof(g));\n\tglob(pat->s, GLOB_MARK, nullptr, &g);\n\t\n\tP a = new Array(itemTypeV, g.gl_matchc);\n\tfor (int i = 0; i < g.gl_matchc; ++i) {\n\t\ta->add(new String(g.gl_pathv[i]));\n\t}\n\tglobfree(&g);\n\t\n\tth.push(new List(a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD CORE OPS\n\n\n#define DEFN(NAME, N, FUN, HELP) \tvm.def(NAME, N, 1, FUN, HELP);\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEF2(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddCoreOps();\nvoid AddCoreOps()\n{\n\t// stack ops\n\tvm.addBifHelp(\"\\n*** stack ops ***\");\n\tDEFnoeach(clear, 0, 0, \"(... -->) clears everything off the stack.\");\n\tDEFnoeach(cleard, 0, 1, \"(... a --> a) clears all but the top item from the stack.\")\n\tDEFnoeach(stackDepth, 0, 1, \"(--> n) returns the size of the stack.\")\n\t\n\tDEFnoeach(aa, 1, 2, \"(a --> a a) push the top item on stack again.\")\n\tDEFnoeach(aaa, 1, 3, \"(a --> a a a) push the top item on stack two more times.\")\n\tDEFnoeach(ba, 2, 2, \"(a b --> b a) swap top two items.\")\n\t\n\tDEFnoeach(bac, 3, 3, \"(a b c --> b a c) reorder items on stack.\")\n\tDEFnoeach(cba, 3, 3, \"(a b c --> c b a) reorder items on stack.\")\n\tDEFnoeach(bca, 3, 3, \"(a b c --> b c a) reorder items on stack.\")\n\tDEFnoeach(cab, 3, 3, \"(a b c --> c a b) reorder items on stack.\")\n\n\tDEFnoeach(bab, 2, 3, \"(a b --> b a b) reorder items on stack.\")\n\tDEFnoeach(aba, 2, 3, \"(a b --> a b a) reorder items on stack.\")\n\n\tDEFnoeach(aab, 2, 3, \"(a b --> a a b) reorder items on stack.\")\n\tDEFnoeach(aabb, 2, 4, \"(a b --> a a b b) reorder items on stack.\")\n\tDEFnoeach(abab, 2, 4, \"(a b --> a b a b) reorder items on stack.\")\n\n\tDEFnoeach(nip, 2, 1, \"(a b --> b) remove second item on stack.\")\n\tDEFnoeach(pop, 1, 0, \"(a -->) remove top item on stack.\")\n\t\n\t// loops\n\tvm.addBifHelp(\"\\n*** loops ***\");\n\t//DEFnoeach(while, 2, \"(A B --> ..) While applying A returns true, apply B.\")\n\tDEFnoeach(do, 2, 0, \"(list \\\\item[..] -->) applies the function to each item of a finite list. Useful for side effects like printing or file writing.\")\n\n\t// conditional ops\n\tvm.addBifHelp(\"\\n*** conditional ops ***\");\n\tDEF(equals, 2, \"(a b --> bool) returns 1 if a and b are structurally equivalent. If the data structures are cyclic then this may never terminate.\")\n\tDEF(less, 2, \"(a b --> bool) returns 1 if a is less than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF(greater, 2, \"(a b --> bool) returns 1 if a is greater than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF2(if, 3, -1, \"(A B C --> ..) if A is true then apply B else apply C.\")\n\n\tDEF(not, 1, \"(A --> bool) returns 0 if A is true and 1 if A is false.\")\n\t//DEF2(dip, 1, -1, \"(x A --> ..) pops x from stack, applies A, pushes x back on stack.\")\n\n\tDEFnoeach(try, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied.\")\n\tDEFnoeach(throw, 0, 0, \"(a -->) throw an exception.\")\n\tDEFnoeach(protect, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied and the exception is rethrown. Otherwise function B is applied and control continues as normal.\")\n\n\t// form ops\n\tvm.addBifHelp(\"\\n*** form ops ***\");\n\tDEFAM(has, kk, \"(form key --> bool) return whether a form contains the key.\")\n \n\tDEFAM(keys, k, \"(form --> keys) return an array of the keys of the form.\")\n\tDEFAM(values, k, \"(form --> values) return an array of the values of the form.\")\n\tDEFAM(kv, k, \"(form --> keys values) return two arrays of the keys and values of the form.\") /// !!!! returns two values. can't be auto mapped.\n\tDEFAM(local, k, \"(form --> local) return the head of the prototype inheritance list.\")\n\tDEFAM(parent, k, \"(form --> parent) return the tail of the prototype inheritance list.\")\n\tDEFAM(dot, ka, \"(form key --> item) return the value for the key.\")\n \n DEFnoeach(pushWorkspace, 0, 0, \"(-->) pushes a new outer scope onto the workspace. New bindings will be made in the new outer scope.\");\n DEFnoeach(popWorkspace, 0, 0, \"(-->) pops a scope from the workspace. All bindings in the outer scope will be forgotten.\");\n\t\n\tvm.addBifHelp(\"\\n*** ref ops ***\");\n\tDEFAM(get, k, \"(r --> a) return the value store in a ref.\")\n\tDEFnoeach(set, 1, 0, \"(a r -->) store the value a in the ref r.\")\n\tvm.def(\"R\", 1, 1, ref_, \"(a --> r) create a new Ref with the inital value a\");\n\tvm.def(\"ZR\", 1, 1, zref_, \"(z --> r) create a new ZRef with the inital value z. A ZRefs is a mutable reference to a real number.\");\n\tvm.def(\"P\", 1, 2, plug_, \"(a --> out in) create a new stream plug pair with the inital value a\");\n\tvm.def(\"ZP\", 1, 2, zplug_, \"(a --> out in) create a new signal plug pair with the inital value a.\");\n\t\n\t\n\t//DEF(bind, 2, \"deprecated\")\n\t\n\t// apply ops\n\tvm.addBifHelp(\"\\n*** function ops ***\");\n\tDEF(Y, 1, \"(funA --> funB) Y combinator. funB calls funA with the last argument being funB itself. Currently the only way to do recursion. \\n\\t\\te.g. \\\\x f [x 2 < \\\\[1] \\\\[ x x -- f *] if] Y = factorial 7 factorial --> 5040\")\n\tDEF(noeach, 1, \"(fun --> fun) sets a flag in the function so that it will pass through arguments with @ operators without mapping them.\")\n\tvm.def(\"!\", 1, -1, apply_, \"(... f --> ...) apply the function to its arguments, observing @ arguments as appropriate.\");\n\tvm.def(\"!e\", 2, -1, applyEvent_, \"(form fun --> ...) for each argument in the function, find the same named fields in the form and push those values as arguments to the function.\");\n\tDEF(compile, 1, \"(string --> fun) compile the string and return a function.\")\n\t\n\tvm.addBifHelp(\"\\n*** printing ops ***\");\n\tDEFnoeach(printLength, 0, 1, \"(--> length) return the number of items printed for lists.\");\n\tDEFnoeach(printDepth, 0, 1, \"(--> depth) return the number of levels of nesting printed for lists.\");\n\tDEFnoeach(setPrintLength, 1, 0, \"(length --> ) set the number of items printed for lists.\");\n\tDEFnoeach(setPrintDepth, 1, 0, \"(depth -->) set the number of levels of nesting printed for lists.\");\n\t\n\tDEFnoeach(pr, 1, 0, \"(A -->) print the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(prdebug, 1, 0, \"(A -->) print debug version of the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(cr, 0, 0, \"(-->) print a carriage return.\")\n\tDEFnoeach(sp, 0, 0, \"(-->) print a space character.\")\n\tDEFnoeach(tab, 0, 0, \"(-->) print a tab.\")\n\tDEFnoeach(prstk, 0, 0, \"(-->) print the stack.\")\n\n#if COLLECT_MINFO\n\tDEFnoeach(minfo, 0, 0, \"(-->) print memory management info.\")\n#endif\n\tDEFnoeach(listdump, 1, 0, \"(list -->) prints information about a list.\");\n\n\tvm.addBifHelp(\"\\n*** string ops ***\");\n\tDEF(str, 1, \"(x --> string) convert x to a string.\");\n\tDEF(debugstr, 1, \"(x --> string) convert x to a debug string.\");\n\tDEFAM(strcat, ak, \"(list separator --> string) convert elements of list to a string with separator string between each.\");\n\tDEF(strlines, 1, \"(list --> string) convert elements of list to a newline separated string.\");\n\tDEFAM(glob, k, \"(pattern --> paths) return a list of file path names that match.\");\n\n\tvm.addBifHelp(\"\\n*** sample rate ops ***\");\n\tDEFnoeach(sr, 0, 1, \"(--> sampleRate) returns the sample rate. samples per second. \")\n\tDEFnoeach(nyq, 0, 1, \"(--> sampleRate/2) returns the nyquist rate\")\n\tDEFnoeach(isr, 0, 1, \"(--> 1/sampleRate) returns the inverse sample rate\")\n\tDEFnoeach(inyq, 0, 1, \"(--> 2/sampleRate) returns the inverse nyquist rate.\")\n\tDEFnoeach(rps, 0, 1, \"(--> 2pi/sampleRate) returns the radians per sample\")\n\n\n\tvm.addBifHelp(\"\\n*** help ops ***\");\n\n\tDEFnoeach(help, 1, 0, \"(fun -->) prints help for a function.\");\n\tDEFnoeach(helpbifs, 0, 0, \"(-->) prints help for all built in functions.\");\n\tDEFnoeach(helpudfs, 0, 0, \"(-->) prints help for all user defined functions.\");\n\tDEFnoeach(helpall, 0, 0, \"(-->) prints help for all built in and user defined functions.\");\n DEF(helpLine, 1, \"(string -->) add a line to the user defined function help.\");\n\t\n\tvm.addBifHelp(\"\\n*** thread ops ***\");\n DEFnoeach(go, 1, 0, \"(fun -->) launches the function in a new thread.\");\n DEFnoeach(sleep, 1, 0, \"(seconds -->) sleeps the current thread for the time given.\");\n\n\tvm.addBifHelp(\"\\n*** misc ***\");\n\tDEF(type, 1, \"(a --> symbol) return a symbol naming the type of the value a.\")\n\tDEFnoeach(trace, 1, 0, \"(bool -->) turn tracing on/off in the interpreter.\")\n\n\tvm.addBifHelp(\"\\n*** text files ***\");\n\tDEFnoeach(load, 1, 0, \"(filename -->) compiles and executes a text file.\")\t\n\tDEFnoeach(prelude, 0, 0, \"(-->) opens the prelude file in the default text editor.\")\n\tDEFnoeach(examples, 0, 0, \"(-->) opens the examples file in the default text editor.\")\n\tDEFnoeach(logfile, 0, 0, \"(-->) opens the log file in the default text editor.\")\n\tDEFnoeach(readme, 0, 0, \"(-->) opens the README file in the default text editor.\")\n\n}\n\n"], ["/sapf/src/VM.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Opcode.hpp\"\n#include \"Parser.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nVM vm;\n\npthread_mutex_t gHelpMutex = PTHREAD_MUTEX_INITIALIZER;\n\nstd::atomic randSeedCounter = 77777;\n\nuint64_t timeseed()\n{\n\tstruct timeval tv;\n\tgettimeofday(&tv, 0);\n\tint32_t counter = ++randSeedCounter;\n\treturn Hash64(tv.tv_sec) + Hash64(tv.tv_usec) + Hash64(counter);\n}\n\n\nThread::Thread()\n :rate(vm.ar), stackBase(0), localBase(0),\n\tmWorkspace(new GForm()),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent)\n :rate(inParent.rate), stackBase(0), localBase(0),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent, P const& inFun)\n :rate(vm.ar), stackBase(0), localBase(0),\n fun(inFun),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::~Thread() {}\n\n//////////////////////\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV vparent = th.pop();\n\tP form = asParent(th, vparent);\n\tth.push(form);\n}\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value)\n{\t\n\tP
table = new Table(tmap);\n\tP form = new Form(table, parent);\n\ttable->put(0, value);\n\treturn form;\n}\n\nstatic void newForm_(Thread& th, Prim* prim)\n{\n\tTableMap* tmap = (TableMap*)th.pop().o();\n\tsize_t numArgs = tmap->mSize;\n\t\n\tV* args = &th.top() - numArgs + 1;\n\t\n\tP
table = new Table(tmap);\n\tV vparent = args[-1];\n\tP parent = asParent(th, vparent);\n\t\n\tP form = new Form(table, parent);\n\t\n\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\ttable->put(i, args[i]);\n\t}\n\t\n\tth.popn(numArgs+1);\n\t\n\tth.push(form);\n}\n\nstatic void newVList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilv;\n\t} else {\n\t\tseq = new List(itemTypeV, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\tth.push(seq);\t\t\n}\n\nstatic void newZList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilz;\n\t} else {\n\t\tseq = new List(itemTypeZ, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\t\n\tth.push(seq);\t\t\n}\n\n//////////////////////\n\n\nVM::VM()\n\t:\n\tprelude_file(NULL),\n\tlog_file(NULL),\n\t_ee(0),\n\t\t\n\tprintLength(20),\n\tprintDepth(8),\n\t\n\tar(kDefaultSampleRate, kDefaultZBlockSize),\n\tkr(ar, kDefaultControlBlockSize),\n\t\n\tVblockSize(kDefaultVBlockSize),\n\t\n#if COLLECT_MINFO\n\ttotalRetains(0),\n\ttotalReleases(0),\n\ttotalObjectsAllocated(0),\n\ttotalObjectsFreed(0),\n\ttotalSignalGenerators(0),\n\ttotalStreamGenerators(0)\n#endif\n{\n\tinitElapsedTime();\n\t\n\t_ee = new Form(0, NULL);\n\t\t\n\tbuiltins = new GTable();\n\t\n\t// add built in funs\n\t\t\n\t_nilz = new List(itemTypeZ);\n\t_nilv = new List(itemTypeV);\n\t\n\t_anilz = _nilz->mArray;\n\t_anilv = _nilv->mArray;\n\t\n\tnewForm = new Prim(newForm_, 0., 0, 1, NULL, NULL);\n\tinherit = new Prim(inherit_, 0., 0, 1, NULL, NULL);\n\n\tnewVList = new Prim(newVList_, 0., 0, 1, NULL, NULL);\n\tnewZList = new Prim(newZList_, 0., 0, 1, NULL, NULL);\n}\n\nVM::~VM()\n{\n}\n\n#if USE_LIBEDIT\nstatic const char* prompt(EditLine *e) \n{\n return \"sapf> \";\n}\nstatic const char* promptParen(EditLine *e) \n{\n return \"(sapf> \";\n}\nstatic const char* promptSquareBracket(EditLine *e) \n{\n return \"[sapf> \";\n}\nstatic const char* promptCurlyBracket(EditLine *e) \n{\n return \"{sapf> \";\n}\nstatic const char* promptLambda(EditLine *e) \n{\n return \"\\\\sapf> \";\n}\nstatic const char* promptString(EditLine *e) \n{\n return \"\\\"sapf> \";\n}\n#endif\n\nvoid Thread::getLine()\n{\t\n\tif (fromString) return;\n\tswitch (parsingWhat) {\n\t\tdefault: case parsingWords : el_set(el, EL_PROMPT, &prompt); break;\n\t\tcase parsingString : el_set(el, EL_PROMPT, &promptString); break;\n\t\tcase parsingParens : el_set(el, EL_PROMPT, &promptParen); break;\n\t\tcase parsingLambda : el_set(el, EL_PROMPT, &promptLambda); break;\n\t\tcase parsingArray : el_set(el, EL_PROMPT, &promptSquareBracket); break;\n\t\tcase parsingEnvir : el_set(el, EL_PROMPT, &promptCurlyBracket); break;\n\t}\n\tline = el_gets(el, &linelen);\n\tlinepos = 0;\n\tif (strncmp(line, \"quit\", 4)==0 || strncmp(line, \"..\", 2)==0) { line = NULL; throw errUserQuit; }\n\tif (line && linelen) {\n\t\thistory(myhistory, &ev, H_ENTER, line);\n\t\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\t\tif (logfilename) {\n\t\t\tFILE* logfile = fopen(logfilename, \"a\");\n\t\t\tlogTimestamp(logfile);\n\t\t\tfwrite(line, 1, strlen(line), logfile);\n\t\t\tfclose(logfile);\n\t\t}\n\t}\n}\n\nvoid Thread::logTimestamp(FILE* logfile)\n{\n\ttimeval tv;\n\tgettimeofday(&tv, NULL);\n\tif (previousTimeStamp == 0 || tv.tv_sec - previousTimeStamp > 3600) {\n\t\tpreviousTimeStamp = tv.tv_sec;\n\t\tchar date[32];\n\t\tctime_r(&tv.tv_sec, date);\n\t\tfprintf(logfile, \";;;;;;;; %s\", date);\n\t\tfflush(logfile);\n\t}\n}\n\nchar Thread::getc() { \n\tif (fromString) {\n\t\tif (line == NULL) return 0;\n\t\treturn line[linepos++];\n\t} else {\n\t\twhile (1) {\t\n\t\t\tif (line == NULL) {\n\t\t\t\tgetLine();\n\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t} else if (line[linepos] == 0) {\n\t\t\t\tif (parsingWhat == parsingWords) {\n\t\t\t\t\treturn 0;\n\t\t\t\t} else {\n\t\t\t\t\tgetLine();\n\t\t\t\t\tif (linelen == 0 || strcmp(line, \"\\n\") == 0) {\n\t\t\t\t\t\tline = NULL;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn line[linepos++];\n\t\t\t}\n\t\t}\n\t}\n\treturn 0; // never gets here, but compiler too dumb to figure this out.\n}\n\nvoid Thread::repl(FILE* infile, const char* inLogfilename)\n{\n\tThread& th = *this;\n\n\tlogfilename = inLogfilename;\n\t\n\tpreviousTimeStamp = 0;\n\n#if USE_LIBEDIT\n\tel = el_init(\"sc\", stdin, stdout, stderr);\n\tel_set(el, EL_PROMPT, &prompt);\n\tel_set(el, EL_EDITOR, \"emacs\");\n\tel_set(el, EL_BIND, \"-s\", \"\\t\", \" \", NULL);\n\n\tmyhistory = history_init();\n\tif (myhistory == 0) {\n\t\tpost(\"history could not be initialized\\n\");\n\t\treturn;\n\t}\n\n\tconst char* envHistoryFileName = getenv(\"SAPF_HISTORY\");\n\tif (envHistoryFileName) {\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s\", envHistoryFileName);\n\t} else {\n\t\tconst char* homeDir = getenv(\"HOME\");\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s/sapf-history.txt\", homeDir);\n\t}\n\thistory(myhistory, &ev, H_SETSIZE, 800);\n\thistory(myhistory, &ev, H_LOAD, historyfilename);\n\thistory(myhistory, &ev, H_SETUNIQUE, 1);\n\tel_set(el, EL_HIST, history, myhistory);\n#endif\n\t\n\tfflush(infile);\n\tbool running = true;\n\n\tpost(\"Type 'helpall' to get a list of all built-in functions.\\n\");\n\tpost(\"Type 'quit' to quit.\\n\");\n\t\n\tdo {\n\t\ttry {\n\t\t\tif (stackDepth()) {\n\t\t\t\tprintStack();\n\t\t\t\tpost(\"\\n\");\n\t\t\t}\n\t\t} catch (int err) {\n\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"\\nunknown error\\n\");\n\t\t}\n\t\t\t\t\n\t\ttry {\n\t\t\t// PARSE\n\t\t\t{\n\t\t\t\tP compiledFun;\n\t\t\t\tif (compile(NULL, compiledFun, true)) {\n\t\t\t\t// EVAL\n\t\t\t\t\tcompiledFun->runREPL(th);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (V& v) {\n post(\"error: \");\n v.print(th);\n\t\t\tpost(\"\\n\");\n\t\t} catch (int err) {\n\t\t\tif (err == errUserQuit) {\n\t\t\t\tpost(\"good bye\\n\");\n\t\t\t\trunning = false;\n\t\t\t} else if (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"error: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"not enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"unknown error\\n\");\n\t\t}\n\n\t} while (running);\n\t\n\n#if USE_LIBEDIT\n\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\thistory_end(myhistory);\n\tel_end(el);\n#endif\n}\n\n\ntemplate \nclass AutoFree\n{\n\tT* p;\npublic:\n\tAutoFree(T* _p) : p(_p) {}\n\t~AutoFree() { free(p); }\n\t\n\tT* operator()() { return p; }\n\tT* operator*() { return p; }\n\tT* operator->() { return p; }\n};\n\nvoid loadFile(Thread& th, const char* filename)\n{\n post(\"loading file '%s'\\n\", filename);\n\tFILE* f = fopen(filename, \"r\");\n\tif (!f) {\n\t\tpost(\"could not open '%s'\\n\", filename);\n\t\treturn;\n\t}\n\n\tfseek(f, 0, SEEK_END);\n\tint64_t fileSize = ftell(f);\n\tfseek(f, 0, SEEK_SET);\n\t\n\tAutoFree buf = (char*)malloc(fileSize + 1);\n\tconst char* p = buf();\n\tfread(buf(), 1, fileSize, f);\n\tbuf()[fileSize - 1] = 0;\n\t\t\n\ttry {\n\t\t{\n\t\t\tP compiledFun;\n\t\t\tif (th.compile(p, compiledFun, true)) {\n\t\t\t\tpost(\"compiled OK.\\n\");\n\t\t\t\tcompiledFun->run(th);\n\t\t\t\tpost(\"done loading file\\n\");\n\t\t\t}\n\t\t}\n } catch (V& v) {\n post(\"error: \");\n v.print(th);\n post(\"\\n\");\n\t} catch (int err) {\n\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t} else {\n\t\t\tpost(\"error: %d\\n\", err);\n\t\t}\n\t} catch (std::bad_alloc& xerr) {\n\t\tpost(\"not enough memory\\n\");\n\t} catch (...) {\n\t\tpost(\"unknown error\\n\");\n\t}\n}\n\nvoid Thread::printStack()\n{\n\tbool between = false;\n\tsize_t n = stackDepth();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &stack[stackBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid Thread::printLocals()\n{\n\tbool between = false;\n\tsize_t n = numLocals();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &local[localBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid VM::setSampleRate(double inSampleRate)\n{\n\tar = Rate(inSampleRate, ar.blockSize);\n\tkr = Rate(ar, kDefaultControlBlockSize);\n}\n\nV VM::def(Arg key, Arg value)\n{\n\tbuiltins->putImpure(key, value); \n V dummy;\n assert(builtins->getInner(key, dummy));\n\treturn value;\n}\n\nV VM::def(const char* name, Arg value)\n{\n\tdef(V(getsym(name)), value);\n\treturn value;\n}\n\nV VM::def(const char* name, int takes, int leaves, PrimFun pf, const char* help, Arg value, bool setNoEach)\n{\n\tV aPrim = new Prim(pf, value, takes, leaves, name, help);\n\tdef(name, aPrim);\n\t\n\tif (setNoEach) aPrim.SetNoEachOps();\n\t\n\tif (help)\n\t\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\t\t\n\treturn aPrim;\n}\n\nV VM::defmcx(const char* name, int numArgs, PrimFun pf, const char* help, Arg value)\n{\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = mcx(numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\nV VM::defautomap(const char* name, const char* mask, PrimFun pf, const char* help, Arg value)\n{\n\tint numArgs = (int)strlen(mask);\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = automap(mask, numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\n\n#pragma mark STACK\n\n#define POPREFTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPFUNTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\nPOPREFTYPEDEF(Ref);\nPOPTYPEDEF(ZRef);\nPOPTYPEDEF(String);\nPOPTYPEDEF(List);\nPOPFUNTYPEDEF(Fun);\nPOPTYPEDEF(Form);\n\nvoid Thread::ApplyIfFun(V& v)\n{\n if (v.isFunOrPrim()) {\n SaveStack ss(*this);\n v.apply(*this);\n v = pop();\n }\n}\n\n\nV Thread::popZInList(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn() && !p.isVList()) {\n\t\twrongType(msg, \"Real or Signal or List of Reals or Signals\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popZIn(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef() || p.isZRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn()) {\n\t\twrongType(msg, \"Real or Signal\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popValue()\n{\n\tV p = pop().deref();\n ApplyIfFun(p);\n\treturn p;\n}\n\nP Thread::popVList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isVList()) {\n\t\twrongType(msg, \"Stream\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nP Thread::popZList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isZList()) {\n\t\twrongType(msg, \"Signal\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nint64_t Thread::popInt(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Real\", v);\n\t\n\tdouble f = v.f;\n\tint64_t i;\n\tif (f >= (double)LLONG_MAX) i = LLONG_MAX;\n\telse if (f <= (double)LLONG_MIN) i = LLONG_MIN;\n\telse i = (int64_t)f;\n\treturn i;\n}\n\ndouble Thread::popFloat(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Float\", v);\n\treturn v.f;\n}\n\nvoid Thread::tuck(size_t n, Arg v)\n{\n\tstack.push_back(V(0.));\n\tV* sp = &stack.back();\n\t\n\tfor (size_t i = 0; i < n; ++i)\n\t\tsp[-i] = sp[-i-1];\n\t\n\tsp[-n] = v;\n}\n\n///////////////////////////////////////\n\nbool Thread::compile(const char* inString, P& compiledFun, bool inTopLevel)\n{\t\n\tThread& th = *this;\n\tSaveCompileScope scs(th);\n\tif (inTopLevel) {\n\t\tmCompileScope = new TopCompileScope();\n\t} else {\n\t\tmCompileScope = new InnerCompileScope(new TopCompileScope());\n\t}\n\t\n\tP code;\n\tsetParseString(inString);\n\tgetLine();\n\tbool ok = parseElems(th, code);\n\tif (!ok || !code) {\n\t\tpost(\"parse error. %d\\n\", ok);\n\t\treturn false;\n\t}\n\t\t\n\tcompiledFun = new Fun(*this, new FunDef(*this, code, 0, th.mCompileScope->numLocals(), th.mCompileScope->numVars(), NULL));\n\t\n\treturn true;\n}\n\nint TopCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = CompileScope::directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) return scope;\n\n\tfor (size_t i = 0; i < mWorkspaceVars.size(); ++i) {\n\t\tif (mWorkspaceVars[i].mName() == inName()) {\n\t\t\treturn scopeWorkspace;\n\t\t}\n\t}\n\t\n\tV value;\n\tif (th.mWorkspace->get(th, inName(), value)) {\n\t\treturn scopeWorkspace;\n\t} else if (vm.builtins->get(th, inName, value)) {\n\t\toutBuiltIn = value;\n\t\treturn scopeBuiltIn;\n\t}\n\n\treturn scopeUndefined;\n}\n\n\nint CompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tfor (size_t i = 0; i < mLocals.size(); ++i) {\n\t\tif (mLocals[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeLocal;\n\t\t}\n\t}\n\tfor (size_t i = 0; i < mVars.size(); ++i) {\n\t\tif (mVars[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeFunVar;\n\t\t}\n\t}\n\t\n\treturn scopeUndefined;\n}\n\n\nint TopCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint InnerCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) \n\t\treturn scope;\n\n\tsize_t outerIndex;\n\tscope = mNext->indirectLookup(th, inName, outerIndex, outBuiltIn);\n\tif (scope == scopeUndefined) \n\t\treturn scopeUndefined;\n\t\n\tif (scope == scopeLocal || scope == scopeFunVar) {\n\t\tVarDef def;\n\t\tdef.mName = inName;\n\t\tdef.mIndex = mVars.size();\n\t\tdef.mFromScope = scope;\n\t\tdef.mFromIndex = outerIndex;\n\t\toutIndex = mVars.size();\n\t\tmVars.push_back(def);\n\t\treturn scopeFunVar;\n\t}\n\t\n\treturn scope;\n}\n\nint TopCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope != scopeUndefined && scope != scopeBuiltIn) \n\t\treturn scope; // already defined\n\t\t\n\tWorkspaceDef def;\n\tdef.mName = inName;\n\tmWorkspaceVars.push_back(def);\n\n\treturn scopeWorkspace;\n}\n\nint CompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope == scopeFunVar) {\n\t\tpost(\"Name %s is already in use in this scope as a free variable.\\n\", inName->cstr());\n\t\tthrow errSyntax;\n\t}\n\t\n\tif (scope == scopeUndefined) {\t\t\n\t\tLocalDef def;\n\t\tdef.mName = inName;\n\t\toutIndex = def.mIndex = mLocals.size();\n\t\tmLocals.push_back(def);\n\t}\n\treturn scopeLocal;\n}\n\nint InnerCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn innerBindVar(th, inName, outIndex);\n}\n\nCompileScope* ParenCompileScope::nextNonParen() const\n{\n\tCompileScope* scope = mNext();\n\twhile (scope->isParen()) {\n\t\tscope = scope->mNext();\n\t}\n\treturn scope;\n}\n\nint ParenCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->indirectLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\nint ParenCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\n//////////////////////\n\n\n\n\n"], ["/sapf/src/dsp.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"dsp.hpp\"\n#include \n#include \n#include \n\n\nFFTSetupD fftSetups[kMaxFFTLogSize+1];\n\nvoid initFFT()\n{\n\tfor (int i = kMinFFTLogSize; i <= kMaxFFTLogSize; ++i) {\n\t\tfftSetups[i] = vDSP_create_fftsetupD(i, kFFTRadix2);\n\t}\n}\n\nvoid fft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid ifft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid fft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\nvoid ifft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\n\nvoid rfft(int n, double* inReal, double* outReal, double* outImag)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\n vDSP_ctozD((DSPDoubleComplex*)inReal, 1, &in, 1, n2);\n\t\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zropD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n2);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n2);\n \n out.realp[n2] = out.imagp[0];\n out.imagp[0] = 0.;\n out.imagp[n2] = 0.;\n}\n\n\nvoid rifft(int n, double* inReal, double* inImag, double* outReal)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\t\n //in.imagp[0] = in.realp[n2];\n in.imagp[0] = 0.;\n\n\tvDSP_fft_zripD(fftSetups[log2n], &in, 1, log2n, FFT_INVERSE);\n\n vDSP_ztocD(&in, 1, (DSPDoubleComplex*)outReal, 2, n2);\n\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n); \n}\n\n\n#define USE_VFORCE 1\n\ninline void complex_expD_conj(double& re, double& im)\n{\n\tdouble rho = expf(re);\n\tre = rho * cosf(im);\n\tim = rho * sinf(im);\n}\n\n"], ["/sapf/src/Parser.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Parser.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PARSER\n\nbool parseElem(Thread& th, P& code);\nbool parseWord(Thread& th, P& code);\nstatic void bindVar(Thread& th, P const& name, P& code);\n\nclass ParsingWhat\n{\n\tThread& th;\n\tint what;\npublic:\t\n\tParsingWhat(Thread& inThread, int newMode) : th(inThread), what(th.parsingWhat)\n\t{\n\t\tth.parsingWhat = newMode;\n\t} \n\t~ParsingWhat()\n\t{\n\t\tth.parsingWhat = what;\n\t}\n};\n\n\nstatic bool skipSpace(Thread& th)\n{\n\t//ScopeLog sl(\"skipSpace\");\n\tfor (;;) {\n\t\tint c = th.getc();\n\t\tif (c == ';') {\n\t\t\tc = th.getc();\n\t\t\twhile (c && c != '\\n') { c = th.getc(); }\n\t\t\tif (c == 0) { th.unget(1); return true; }\n\t\t}\n\t\tif (c == 0) { th.unget(1); return true; }\n\t\tbool skip = isspace(c) || iscntrl(c);\n\t\tif (!skip) { th.unget(1); break; }\n\t}\n\treturn false;\n}\n\nconst char* nonnamechars = \";()[]{}.`,:\\\"\\n\";\n\nstatic bool endOfWord(int c)\n{\n\treturn c == 0 || isspace(c) || strchr(nonnamechars, c) != nullptr;\n}\n\nstatic bool parseHexNumber(Thread& th, P& code)\n{\n\tconst char* start = th.curline();\n\tint64_t z = 0;\n\t\n\tth.getc();\n\tth.getc();\n\tint c = th.getc();\n\twhile(isxdigit(c)) {\n\t\tif (isdigit(c)) z = z*16 + c - '0';\n\t\telse z = z*16 + toupper(c) - 'A' + 10;\n\t\tc = th.getc();\n\t}\n\n\tif (!endOfWord(c)) {\n\t\t// even though it starts out like a number it continues as some other token\n\t\tth.unget(start);\n\t\treturn false;\n\t} else {\n\t\tth.unget(1);\n\t}\n\t\n\tcode->add(opPushImmediate, z);\n\t\n\treturn true;\n}\n\n\nstatic bool parseFloat(Thread& th, Z& result)\n{\t\n\t//ScopeLog sl(\"parseFloat\");\n\tconst char* start = th.curline();\n\tint c = th.getc();\n \n if (c == 'p' && th.c() == 'i') {\n th.getc();\n result = M_PI;\n return true;\n }\n \n\tif (c == '+' || c == '-') \n\t\tc = th.getc();\n\n\tint digits = 0;\n\tbool sawdot = false;\n\tfor ( ; ; ) {\n\t\tif (isdigit(c)) digits++;\n\t\telse if (c == '.') {\n\t\t\tif (sawdot) break;\n\t\t\tsawdot = true; \n\t\t}\n\t\telse break;\n\t\tc = th.getc(); \n\t}\n\tif (digits == 0) {\n\t\tth.unget(start);\n\t\treturn false;\n\t}\n\t\n\tif (c == 'e' || c == 'E') {\n\t\tc = th.getc();\n\t\tif (c == '+' || c == '-') \n\t\t\tc = th.getc();\n\t\twhile (isdigit(c)) { c = th.getc(); }\n\t}\n\n\tth.toToken(start, (int)(th.curline() - start));\n\t\n\tbool sawpi = false;\n\tbool sawmega = false;\n\tbool sawkilo = false;\n\tbool sawhecto = false;\n\tbool sawcenti = false;\n\tbool sawmilli = false;\n\tbool sawmicro = false;\n\t\n\t\n\tif (c == 'p' && th.c() == 'i') {\n\t\tsawpi = true;\n\t\tth.getc();\n\t} else if (c == 'M') {\n\t\tsawmega = true;\n\t} else if (c == 'k') {\n\t\tsawkilo = true;\n\t} else if (c == 'h') {\n\t\tsawhecto = true;\n\t} else if (c == 'c') {\n\t\tsawcenti = true;\n\t} else if (c == 'm') {\n\t\tsawmilli = true;\n\t} else if (c == 'u') {\n\t\tsawmicro = true;\n\t} else {\n\t\tth.unget(1);\n\t}\n\n\tdouble x = strtod(th.token, nullptr);\n\tif (sawpi) x *= M_PI;\n\telse if (sawmega) x *= 1e6;\n\telse if (sawkilo) x *= 1e3;\n\telse if (sawhecto) x *= 1e2;\n\telse if (sawcenti) x *= 1e-2;\n\telse if (sawmilli) x *= 1e-3;\n\telse if (sawmicro) x *= 1e-6;\n\n\tresult = x;\n\treturn true;\n}\n\nstatic bool parseNumber(Thread& th, Z& result)\n{\n\tconst char* start = th.curline();\n\n\tZ a, b;\n\tif (parseFloat(th, a)) {\n\t\tif (th.c() == '/') {\n\t\t\tth.getc();\n\t\t\tif (parseFloat(th, b) && endOfWord(th.c())) {\n\t\t\t\tresult = a/b;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (endOfWord(th.c())) {\n\t\t\tresult = a;\n\t\t\treturn true;\n\t\t}\n\t}\n\tth.unget(start);\n\treturn false;\n}\n\nstatic bool parseNumber(Thread& th, P& code)\n{\n Z x;\n if (parseNumber(th, x)) {\n \t\tcode->add(opPushImmediate, x);\n return true;\n }\n return false;\n}\n\nstatic bool parseSymbol(Thread& th, P& result);\nstatic bool parseItemList(Thread& th, P& code, int endbrace);\n\n\nstatic bool parseQuote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after quote\");\n\t\n\tV vname(name);\n\tcode->add(opPushImmediate, vname);\n\n\treturn true; \n}\n\nstatic bool parseBackquote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after backquote\");\n\n\n\tV vname(name);\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\tswitch (scope) {\n\t\tcase scopeLocal :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushLocalVar, val);\n\t\t\tbreak;\n\t\tcase scopeFunVar :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushFunVar, val);\n\t\t\tbreak;\n\t\tcase scopeBuiltIn :\n\t\t\tcode->add(opPushImmediate, val);\n\t\t\tbreak;\n\t\tcase scopeWorkspace :\n\t\t\tcode->add(opPushWorkspaceVar, vname);\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tpost(\"backquote error: \\\"%s\\\" is an undefined word\\n\", name->s);\n\t\t\tsyntaxError(\"undefined word\");\n\t}\n\n\treturn true; \n}\n\nstatic bool parseDot(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opDot, vname);\n\n\treturn true; \n}\n\nstatic bool parseComma(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opComma, vname);\n\n\treturn true; \n}\n\nstatic bool parseColon(Thread& th, P& code)\n{\n\tth.getc();\n\n P name;\n\n if (!parseSymbol(th, name)) \n syntaxError(\"expected symbol after colon\");\n \n code->keys.push_back(name);\n\n\treturn true;\n}\n\nstatic bool parseEachOp(Thread& th, P& code)\n{\n\t\n\tint64_t mask = 0;\n\tint level = 0;\n\n\tth.getc();\n\tint c = th.getc();\n\t\n\tif (c == '@') {\n\t\tmask = 1; \n\t\t++level;\n\t\tdo {\n\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '@');\n\t} else if (c >= '2' && c <= '9') {\n\t\tmask = 1LL << (c - '1');\n\t\tc = th.getc();\n\t} else if (c == '0' || c == '1') {\n\t\tdo { \n\t\t\tif (c == '1')\n\t\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '0' || c == '1');\n\t} else {\n\t\tmask = 1;\n\t}\n\tif (isdigit(c)) {\n\t\tsyntaxError(\"unexpected extra digit after @\");\n\t}\n\t\n\tth.unget(1);\n\n\tV v;\n\tv.i = mask;\n\t\n\tcode->add(opEach, v);\n\t\n\t\n\treturn true; \n}\n\n\nstatic bool parseNewForm(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingEnvir);\n\tP code2 = new Code(8);\n\tth.getc();\n\t\n\tparseItemList(th, code2, '}');\n\t\n\tif (code2->keys.size()) {\n\n\t\tP tmap = new TableMap(code2->keys.size());\n\t\t\n\t\tint i = 0;\n\t\tfor (Arg key : code2->keys) {\n tmap->put(i, key, key.Hash());\n\t\t\t++i;\n\t\t}\n\n\t\tcode2->keys.clear();\n\t\tcode2->add(opPushImmediate, V(tmap));\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\n\t\tcode->add(opNewForm, V(code2));\n\t} else {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opInherit, V(code2));\n\t}\n\t\t\t\n\treturn true;\n}\n\nstatic String* parseString(Thread& th);\n\nstatic bool parseStackEffect(Thread& th, int& outTakes, int& outLeaves)\n{\n\toutTakes = 0;\n\toutLeaves = 1;\n\tskipSpace(th);\n\tint c = th.c();\n\tif (!isdigit(c)) return true;\n\toutLeaves = 0;\n\t\n\twhile(isdigit(c)) {\n\t\toutTakes = outTakes * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\tif (c != '.') return false;\n\tc = th.getc();\n\twhile(isdigit(c)) {\n\t\toutLeaves = outLeaves * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\treturn true;\n}\n\nstatic bool parseLambda(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseLambda\");\n\tParsingWhat pw(th, parsingLambda);\n\tth.getc();\n\tstd::vector > args;\n\t\t\n\tSaveCompileScope scs(th);\n\t\n\tP cs = new InnerCompileScope(th.mCompileScope);\n\tth.mCompileScope = cs();\n\t\n\twhile (1) {\n\t\tP name;\n\t\tif (!parseSymbol(th, name)) break;\n\t\targs.push_back(name);\n\t\t\n\t\tint takes, leaves;\n\t\tif (!parseStackEffect(th, takes, leaves)) {\n\t\t\tsyntaxError(\"incorrectly formatted function argument stack effect annotation.\");\n\t\t}\n\t\t\n\t\tLocalDef def;\n\t\tdef.mName = name;\n\t\tdef.mIndex = cs->mLocals.size();\n\t\tdef.mTakes = takes;\n\t\tdef.mLeaves = leaves;\n\t\tcs->mLocals.push_back(def);\n\t}\n\t\n\tskipSpace(th);\n\t\n\tP help = parseString(th);\n\n\tskipSpace(th);\n\t\n\tint c = th.getc();\t\n\tif (c != '[') {\n post(\"got char '%c' %d\\n\", c, c);\n\t\tsyntaxError(\"expected open square bracket after argument list\");\n\t}\n\t\t\n\tP code2 = new Code(8);\t\n\tparseItemList(th, code2, ']');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\t\n\t\t\n\t// compile code to push all fun vars\n\tfor (size_t i = 0; i < cs->mVars.size(); ++i) {\n\t\tVarDef& def = cs->mVars[i];\n\t\tV vindex;\n\t\tvindex.i = def.mFromIndex;\n\t\t\n\t\tif (def.mFromScope == scopeLocal) {\n\t\t\tcode->add(opPushLocalVar, vindex);\n\t\t} else {\n\t\t\tcode->add(opPushFunVar, vindex);\n\t\t}\n\t}\n\tif (args.size() > USHRT_MAX || cs->mLocals.size() > USHRT_MAX || cs->mVars.size() > USHRT_MAX)\n\t{\n\t\tpost(\"Too many variables!\\n\");\n\t\tthrow errSyntax;\n\t}\n\n FunDef* def = new FunDef(th, code2, args.size(), cs->mLocals.size(), cs->mVars.size(), help);\n\tdef->mArgNames = args;\n\tcode->add(opPushFun, def);\n\n\treturn true;\n}\n\n#define COMPILE_PARENS 1\n\nstatic bool parseParens(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingParens);\n\tth.getc();\n\n#if COMPILE_PARENS\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ')');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\tcode->add(opParens, V(code2));\n#else\n\tparseItemList(th, code, ')');\n#endif\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseArray(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseArray\");\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewVList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilv));\n\t}\n\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseZArray(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewZList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilz));\n\t}\n\t\t\t\n\treturn true;\n}\n\nbool parseItemList(Thread& th, P& code, int endbrace)\n{\t\n\t//ScopeLog sl(\"parseItemList\");\n\t\n\twhile (1) {\n\t\tskipSpace(th);\n\t\tint c = th.c();\n\t\tif (c == endbrace) break;\n\t\tif (!parseElem(th, code)) {\n\t\t\tif (endbrace == ']') syntaxError(\"expected ']'\");\n\t\t\tif (endbrace == '}') syntaxError(\"expected '}'\");\n\t\t\tif (endbrace == ')') syntaxError(\"expected ')'\");\n\t\t}\n\t}\n\tth.getc(); // skip end brace\n\t\n\treturn true;\n}\n\n\nbool parseSymbol(Thread& th, P& result)\n{\n\t//ScopeLog sl(\"parseSymbol\");\n\tskipSpace(th);\n\tconst char* start = th.curline();\n\tint c = th.getc();\n\t\n\twhile(!endOfWord(c)) {\n\t\tc = th.getc();\n\t}\n\tth.unget(1);\n\n\tsize_t len = th.curline() - start;\n\tif (len == 0) return false;\n\n\tth.toToken(start, (int)len);\n\t\n\tresult = getsym(th.token);\n\n\treturn true;\n}\n\nstatic void bindVar(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->bindVar(th, name, index);\n\n\tV vname(name);\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tcode->add(opBindWorkspaceVar, vname);\n\t} else {\n\t\tval.i = index;\n\t\tcode->add(opBindLocal, val);\n\t}\n}\n\nstatic void bindVarFromList(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t varIndex;\n\tint scope = th.mCompileScope->bindVar(th, name, varIndex);\n\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tV vname(name);\n\t\tcode->add(opBindWorkspaceVarFromList, vname);\n\t} else {\n\t\tval.i = varIndex;\n\t\tcode->add(opBindLocalFromList, val);\n\t}\n}\n\nbool parseWord(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseWord\");\n\tP name;\n\n\tif (!parseSymbol(th, name)) return false;\n\t\t\n\tif (strcmp(name->cstr(), \"=\")==0) {\n\n\t\tskipSpace(th);\t\t\n\t\tif (th.c() == '(') {\n\t\t\tth.getc();\n\t\t\t// parse multiple assign\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ('\\n\");\n\t\t\t}\n\t\t\tfor (int64_t i = names.size()-1; i>=0; --i) {\n\t\t\t\tbindVar(th, names[i], code);\n\t\t\t}\n\t\t\tskipSpace(th);\n\t\t\tif (th.c() != ')') {\n\t\t\t\tsyntaxError(\"expected ')' after '= ('\\n\");\n\t\t\t}\n\t\t\tth.getc();\n\t\t\tcode->add(opNone, 0.);\n\t\t} else if (th.c() == '[') {\n\t\t\tth.getc();\n\t\t\t// parse assign from array\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ['\\n\");\n\t\t\t}\n\t\t\tfor (size_t i = 0; iadd(opNone, 0.);\n\t\t} else {\n\t\t\tP name2;\n\t\t\tif (!parseSymbol(th, name2)) {\n\t\t\t\tsyntaxError(\"expected a name after '='\\n\");\n\t\t\t}\n\t\t\tbindVar(th, name2, code);\n\t\t}\n\t} else {\n\t\tV val;\n\t\tsize_t index;\n\t\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\t\tV vname(name);\n\t\tswitch (scope) {\n\t\t\tcase scopeLocal :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallLocalVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeFunVar :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallFunVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeBuiltIn :\n\t\t\t\tcode->add(opCallImmediate, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeWorkspace :\n\t\t\t\tcode->add(opCallWorkspaceVar, vname);\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"\\\"%s\\\" is an undefined word\\n\", name->cstr());\n\t\t\t\tsyntaxError(\"undefined word\");\n\t\t\t\t\n\t\t}\n\n\t}\n\t\n\treturn true;\n}\n\nstatic bool parseString(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseString\");\n\tParsingWhat pw(th, parsingString);\n\t\n\tV string = parseString(th);\t\n\tcode->add(opPushImmediate, string);\n\n\treturn true;\n}\n\nstatic String* parseString(Thread& th)\n{\n\tif (th.c() != '\"') return nullptr;\n\n\tParsingWhat pw(th, parsingString);\n\tth.getc();\n\tint c = th.getc();\n\tstd::string str;\n\t\t\n\twhile (true) {\n\t\tif (c == 0) {\n\t\t\tsyntaxError(\"end of input in string\");\n\t\t} else if (c == '\\\\' && th.c() == '\\\\') {\n\t\t\tth.getc();\n\t\t\tc = th.getc();\n\t\t\tswitch (c) {\n\t\t\t\tcase 'n' : str += '\\n'; break;\n\t\t\t\tcase 'r' : str += '\\r'; break;\n\t\t\t\tcase 'f' : str += '\\f'; break;\n\t\t\t\tcase 'v' : str += '\\v'; break;\n\t\t\t\tcase 't' : str += '\\t'; break;\n\t\t\t\tdefault : str += c; break;\n\t\t\t}\n\t\t\tc = th.getc();\n\t\t} else if (c == '\"') {\n\t\t\tif (th.c() == '\"') {\n\t\t\t\tc = th.getc();\n\t\t\t\tstr += '\"';\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tstr += c;\n\t\t\tc = th.getc();\n\t\t}\n\t}\n\t\n\treturn new String(str.c_str());\n}\n\nbool parseElem(Thread& th, P& code)\n{\t\n\tskipSpace(th);\n\tint c = th.c();\n\tif (c == 0)\n\t\treturn false;\n\tif (c == ']' || c == ')' || c == '}') {\n\t\tpost(\"unexpected '%c'.\\n\", c);\n\t\tthrow errSyntax;\n\t}\n\tif (c == '@')\n\t\t return parseEachOp(th, code);\n\tif (c == '(')\n\t\t return parseParens(th, code);\n\tif (c == '[')\n\t\t return parseArray(th, code);\n\tif (c == '{')\n\t\t return parseNewForm(th, code);\n\tif (c == '\\\\')\n\t\t return parseLambda(th, code);\n\tif (c == '\"')\n\t\treturn parseString(th, code);\n\tif (c == '\\'') \n\t\treturn parseQuote(th, code);\n\tif (c == '`') \n\t\treturn parseBackquote(th, code);\n\tif (c == ',') \n\t\treturn parseComma(th, code);\n\tif (c == ':')\n\t\treturn parseColon(th, code);\n\n\tif (c == '0' && th.d() == 'x') \n\t\treturn parseHexNumber(th, code) || parseWord(th, code);\n\n\tif (isdigit(c) || c == '+' || c == '-')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n \n if (c == 'p' && th.d() == 'i')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n\n\tif (c == '.')\n\t\treturn parseNumber(th, code) || parseDot(th, code);\n\n\n\tif (c == '#') {\n\t\tint d = th.d();\n\t\tif (!d) syntaxError(\"end of input after '#'\");\n\t\tif (d == '[') {\n\t\t\treturn parseZArray(th, code);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\treturn parseWord(th, code);\n}\n\n\nbool parseElems(Thread& th, P& code)\n{\n\tcode = new Code(8);\n\twhile (1) {\n\t\tif (!parseElem(th, code)) break;\n\t}\n\t\n\tcode->add(opReturn, 0.);\n\tcode->shrinkToFit();\n\t\t\n\treturn true;\n}\n\n/////////////////////////\n\n#pragma mark PRINTI\n\n#include \n\n///////////////////////// 1 2 3 4 5 6\n/////////////////////////1234567890123456789012345678901234567890123456789012345678901234\nconst char* s64Spaces = \" \";\nconst int kNumSpaces = 64;\n\nstatic void printSpaces(std::ostream& ost, int n)\n{\n\twhile (n >= kNumSpaces) {\n\t\tost << s64Spaces;\n\t\tn -= kNumSpaces;\n\t}\n\tif (n) {\n\t\tost << (s64Spaces + kNumSpaces - n);\n\t}\n}\n\nvoid printi(std::ostream& ost, int indent, const char* fmt, ...)\n{\n\tprintSpaces(ost, indent);\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n\nvoid prints(std::ostream& ost, const char* fmt, ...)\n{\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n//////////////////////////////////\n\n"], ["/sapf/src/Object.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Object.hpp\"\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"MathOps.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n\nvoid post(const char* fmt, ...)\n{\n va_list vargs;\n va_start(vargs, fmt);\n vprintf(fmt, vargs);\n}\n\nvoid zprintf(std::string& out, const char* fmt, ...)\n{\n\tchar s[1024];\n\tva_list args;\n\tva_start(args, fmt);\n\tvsnprintf(s, 1024, fmt, args);\n\tout += s;\n}\n\n#pragma mark ERROR HANDLING\n\n\nThread gDummyThread;\n\n[[noreturn]] void notFound(Arg key)\n{\n\tpost(\"notFound \");\n\tkey.print(gDummyThread); // keys are either symbols or numbers neither of which will use the thread argument to print.\n\tpost(\"\\n\");\n\tthrow errNotFound;\n}\n\n[[noreturn]] void wrongType(const char* msg, const char* expected, Arg got)\n{\n\tpost(\"error: wrong type for %s . expected %s. got %s.\\n\", msg, expected, got.TypeName());\n\tthrow errWrongType;\n}\n\n[[noreturn]] void syntaxError(const char* msg)\n{\n\tpost(\"syntax error: %s\\n\", msg);\n\tthrow errSyntax;\n}\n\n[[noreturn]] void indefiniteOp(const char* msg1, const char* msg2)\n{\n\tpost(\"error: operation on indefinite object %s%s\\n\", msg1, msg2);\n\tthrow errIndefiniteOperation;\n}\n\n#pragma mark OBJECT\n\n\nObject::Object()\n\t: scratch(0), elemType(0), finite(false), flags(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nObject::~Object()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\nvoid Ref::set(Arg inV)\n{\n\tO oldval = nullptr;\n\tif (inV.isObject()) {\n\t\tO newval = inV.o();\n\t\n\t\tnewval->retain();\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = newval;\n\t\t}\n\t} else {\n\t\tZ newval = inV.f;\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = nullptr;\n\t\t\tz = newval;\n\t\t}\n\t}\n\tif (oldval)\n\t\toldval->release();\n}\n\nvoid ZRef::set(Z inZ)\n{\n\tz = inZ;\n}\n\nV Ref::deref() const\n{\n\tV out;\n\t{\n\t\tSpinLocker lock(mSpinLock);\n\t\tif (o) {\n\t\t\tout = o;\n\t\t\tif (o) o->retain();\n\t\t}\n\t\telse out = z;\n\t}\n\treturn out;\n}\n\nV ZRef::deref() const\n{\n\treturn z;\n}\n\nZ Object::derefz() const\n{\n\treturn asFloat();\n}\n\nZ ZRef::derefz() const\n{\n\treturn z;\n}\n\n\nForm::Form(P
const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nvolatile int64_t gTreeNodeSerialNumber;\n\nGForm::GForm(P const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nGForm::GForm(P const& inNext)\n\t: Object(), mNextForm(inNext)\n{ \n\tmTable = new GTable();\n}\n\nP consForm(P const& inTable, P const& inNext) { return new GForm(inTable, inNext); }\nP consForm(P
const& inTable, P const& inNext) { return new Form(inTable, inNext); }\n\nvoid Object::apply(Thread& th) {\n\tth.push(this);\n}\n\nclass PushFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nclass PushREPLFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushREPLFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushREPLFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nvoid Fun::runREPL(Thread& th)\n{\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushREPLFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::run(Thread& th)\n{\t\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.setStackBase();\n\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::apply(Thread& th) \n{ \n\tint numArgs = NumArgs();\n\n\tif (th.stackDepth() < (size_t)numArgs) {\n\t\tthrow errStackUnderflow;\n\t}\n\n\tif (NoEachOps()) {\n\t\trun(th);\n\t} else {\n\t\tif (th.stackDepth()) {\n\t\t\tbool haveEachOps = false;\n\t\t\tV* args = &th.top() - numArgs + 1;\n\n\t\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, numArgs, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\trun(th);\n\t\t\t}\n\t\t} else {\n\t\t\trun(th);\n\t\t}\n\t}\n}\n\nFun::Fun(Thread& th, FunDef* def)\n\t: mDef(def), mWorkspace(def->Workspace())\n{\n\tif (NumVars()) {\n\t\tmVars.insert(mVars.end(), th.stack.end() - NumVars(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumVars(), th.stack.end());\n\t}\n}\n\nFunDef::FunDef(Thread& th, P const& inCode, uint16_t inNumArgs, uint16_t inNumLocals, uint16_t inNumVars, P const& inHelp) \n\t: mCode(inCode), mNumArgs(inNumArgs), mNumLocals(inNumLocals), mNumVars(inNumVars), \n mWorkspace(th.mWorkspace),\n mHelp(inHelp)\n{\n}\n\nFun::~Fun()\n{\n}\n\nvoid Prim::apply(Thread& th) \n{\n\tapply_n(th, mTakes);\n}\n\nvoid Prim::apply_n(Thread& th, size_t n)\n{ \n\tif (th.stackDepth() < n)\n\t\tthrow errStackUnderflow;\n\t\n\tif (NoEachOps()) {\n\t\tprim(th, this); \n\t} else {\n\t\n\t\tif (n) {\n\t\t\tV* args = &th.top() - n + 1;\n\n\t\t\tbool haveEachOps = false;\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, (int)n, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\tprim(th, this); \n\t\t\t}\n\t\t} else {\n\t\t\tprim(th, this); \n\t\t}\n\t}\n}\n\nbool Form::get(Thread& th, Arg key, V& value) const\n{\n const Form* e = this;\n\tint64_t hash = key.Hash();\n do {\n if (e->mTable->getWithHash(th, key, hash, value)) {\n return true;\n }\n e = (Form*)e->mNextForm();\n } while (e);\n return false;\n}\n\n\nV Form::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\nbool GForm::get(Thread& th, Arg key, V& value) const\n{\n const GForm* e = this;\n do {\n if (e->mTable->get(th, key, value)) {\n return true;\n }\n e = (GForm*)e->mNextForm();\n } while (e);\n return false;\n}\n\nGForm* GForm::putImpure(Arg key, Arg value)\n{\n\tif (mTable->putImpure(key, value)) return this;\n\treturn putPure(key, value);\n}\n\nGForm* GForm::putPure(Arg inKey, Arg inValue)\n{\n\tint64_t inKeyHash = inKey.Hash();\n\treturn new GForm(mTable->putPure(inKey, inKeyHash, inValue), mNextForm);\n}\n\nV GForm::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\n\nGTable* GTable::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n auto tree = mTree.load();\n\tif (tree) {\n\t\treturn new GTable(tree->putPure(inKey, inKeyHash, inValue));\n\t} else {\n\t\tint64_t serialNo = ++gTreeNodeSerialNumber;\n\t\treturn new GTable(new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n\t}\n}\n\nTreeNode* TreeNode::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n\tif (inKeyHash == mHash && inKey.Identical(mKey)) {\n\t\treturn new TreeNode(mKey, mHash, inValue, mSerialNumber, mLeft, mRight);\n\t} \n auto left = mLeft.load();\n auto right = mRight.load();\n if (inKeyHash < mHash) {\n if (left) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left->putPure(inKey, inKeyHash, inValue), right);\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr), right);\n }\n\t} else {\n if (right) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, right->putPure(inKey, inKeyHash, inValue));\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n }\n\t}\n}\n\nstatic bool TreeNodeEquals(Thread& th, TreeNode* a, TreeNode* b)\n{\n while (1) {\n if (!a) return !b;\n if (!b) return false;\n \n if (!a->mKey.Equals(th, b->mKey)) return false;\n if (!a->mValue.Equals(th, b->mValue)) return false;\n if (a->mLeft == 0) {\n if (b->mLeft != 0) return false;\n } else {\n if (b->mLeft == 0) return false;\n if (!TreeNodeEquals(th, a->mLeft, b->mLeft)) return false;\n }\n a = a->mRight;\n b = b->mRight;\n }\n}\n\nbool GTable::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isGTable()) return false;\n\tif (this == v.o()) return true;\n\tGTable* that = (GTable*)v.o();\n return TreeNodeEquals(th, mTree.load(), that->mTree.load());\n}\n\nvoid GTable::print(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tzprintf(out, \" \");\n\t\tp->mValue.print(th, out);\n\t\tzprintf(out, \" :\");\n\t\tp->mKey.print(th, out);\n\t\tzprintf(out, \"\\n\");\n\t}\n}\n\nvoid GTable::printSomethingIWant(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tif (p->mValue.leaves() != 0 && p->mValue.leaves() != 1) {\n\t\t\tzprintf(out, \" \");\n\t\t\tp->mKey.print(th, out);\n\t\t\tzprintf(out, \" : \");\n\t\t\tp->mValue.print(th, out);\n\t\t\tzprintf(out, \"\\n\");\n\t\t}\n\t}\n}\n\nbool GTable::get(Thread& th, Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nbool GTable::getInner(Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nV GTable::mustGet(Thread& th, Arg inKey) const\n{\n\tV value;\n\tif (get(th, inKey, value)) return value;\n\t\n\tthrow errNotFound;\n}\n\nbool GTable::putImpure(Arg inKey, Arg inValue)\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tvolatile std::atomic* treeNodePtr = &mTree;\n\twhile (1) {\n\t\tTreeNode* tree = treeNodePtr->load();\n\t\tif (tree == nullptr) {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n\t\t\tTreeNode* newNode = new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr);\n\t\t\tnewNode->retain();\n TreeNode* nullNode = nullptr;\n if (treeNodePtr->compare_exchange_weak(nullNode, newNode)) {\n break;\n }\n newNode->release();\n\t\t} else {\n\t\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\t\tif (treeKeyHash == inKeyHash) {\n\t\t\t\treturn false; // cannot rebind an existing value.\n\t\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\t\ttreeNodePtr = &tree->mLeft;\n\t\t\t} else {\n\t\t\t\ttreeNodePtr = &tree->mRight;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\n\nvoid TreeNode::getAll(std::vector >& vec)\n{\n\tP node = this;\n\tdo {\n\t\tvec.push_back(node);\n auto left = node->mLeft.load();\n\t\tif (left) left->getAll(vec);\n\t\tnode = node->mRight.load();\n\t} while (node());\n}\n\nstatic bool compareTreeNodes(P const& a, P const& b)\n{\n\treturn a->mSerialNumber < b->mSerialNumber;\n}\n\nstd::vector > GTable::sorted() const\n{\n\tstd::vector > vec;\n auto tree = mTree.load();\n\tif (tree) {\n\t\ttree->getAll(vec);\n\t\tsort(vec.begin(), vec.end(), compareTreeNodes);\n\t}\n\treturn vec;\n}\n\n/////////\n\n\nV List::unaryOp(Thread& th, UnaryOp* op)\n{\n\tif (isVList())\n\t\treturn new List(new UnaryOpGen(th, op, this));\n\telse\n\t\treturn new List(new UnaryOpZGen(th, op, this));\n\t\t\n}\n\nV List::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a)\n{\n\tif (isVList())\n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nV List::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a)\n{\n\treturn op->makeVList(th, _a, this);\n}\n\nV List::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a)\n{\n\tif (isVList()) \n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nvoid V::apply(Thread& th)\n{\n\tif (o) {\n\t\to->apply(th);\n\t} else {\n\t\tth.push(*this);\n\t}\n}\n\nV V::deref()\n{\n\tif (o) {\n\t\treturn o->deref();\n\t} else {\n\t\treturn *this;\n\t}\n}\n\nV V::mustGet(Thread& th, Arg key) const\n{\n\tif (o) {\n\t\treturn o->mustGet(th, key);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nbool V::get(Thread& th, Arg key, V& value) const\n{\n\tif (o) {\n\t\treturn o->get(th, key, value);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nint V::Hash() const \n{\n\tif (o) {\n\t\treturn o->Hash();\n\t} else {\n union {\n double f;\n uint64_t i;\n } u;\n u.f = f;\n\t\treturn (int)::Hash64(u.i);\n\t}\n}\n\nV V::unaryOp(Thread& th, UnaryOp* op) const\n{\n\treturn !o ? V(op->op(f)) : o->unaryOp(th, op);\n}\n\nV V::binaryOp(Thread& th, BinaryOp* op, Arg _b) const\n{\n\treturn !o ? _b.binaryOpWithReal(th, op, f) : o->binaryOp(th, op, _b);\n}\n\nV V::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a) const\n{\n\treturn !o ? V(op->op(_a, f)) : o->binaryOpWithReal(th, op, _a);\n}\n\nV V::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeVList(th, _a, *this) : o->binaryOpWithVList(th, op, _a);\n}\n\nV V::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeZList(th, _a, *this) : o->binaryOpWithZList(th, op, _a);\n}\n\nvoid Object::printDebug(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::printShort(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"#%s\", TypeName());\n\tout += s; \n}\n\nvoid Object::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %p}\", TypeName(), this);\n\tout += s; \n}\n\nvoid Prim::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\nvoid Prim::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\n\nvoid Ref::print(Thread& th, std::string& out, int depth)\n{\n\tV v = deref();\n\tv.print(th, out, depth);\n\tzprintf(out, \" R\");\n\t\n}\n\nvoid ZRef::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%g ZR\", z);\t\n}\n\nvoid String::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%s\", (char*)s);\n}\n\nvoid String::printDebug(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"\\\"%s\\\"\", (char*)s);\n}\n\nvoid GForm::print(Thread& th, std::string& out, int depth)\n{\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n zprintf(out, \"new\\n\");\n\t} else {\n\t\tzprintf(out, \"New\\n\");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n}\n\nvoid Form::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"{...} \");\n\t\treturn;\n\t}\n\t\n\tzprintf(out, \"{\");\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n\t\tzprintf(out, \" \");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n\t\n\tzprintf(out, \"}\");\n}\n\n\nvoid EachOp::print(Thread& th, std::string& out, int inDepth)\n{\n\tv.print(th, out, inDepth);\n\tzprintf(out, \" \");\n\t\n\t// try to print as concisely as possible.\n\tif (mask == 1) {\n\t\tzprintf(out, \"@\");\n\t} else if (ONES(mask) == 1 && 1 + CTZ(mask) <= 9) {\n\t\tzprintf(out, \"@%d\", 1 + CTZ(mask));\n\t} else if (CTZ(mask) == 0) {\n\t\tint n = CTZ(~mask);\n\t\twhile (n--) \n\t\t\tzprintf(out, \"@\");\n\t} else {\n\t\tzprintf(out, \"@\");\n\t\tint32_t m = mask;\n\t\twhile (m) {\n\t\t\tzprintf(out, \"%c\", '0' + (m&1));\n\t\t\tm >>= 1;\n\t\t}\n\t}\n}\n\n\nvoid Code::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"#Code{...}\");\n\t\treturn;\n\t}\n\n\tzprintf(out, \"#Code %d{\\n\", size());\n\tOpcode* items = getOps();\n\tfor (int i = 0; i < size(); ++i) {\n\t\tzprintf(out, \"%4d %s \", i, opcode_name[items[i].op]);\n\t\titems[i].v.printShort(th, out, depth+1);\n\t\tout += \"\\n\";\n\t}\n\tzprintf(out, \"}\\n\");\n}\n\nvoid List::print(Thread& th, std::string& out, int depth)\n{\n\tif (isV()) {\n\t\tzprintf(out, \"[\");\n\t} else {\n\t\tzprintf(out, \"#[\");\n\t}\n\t\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"...]\");\n\t\treturn;\n\t}\n\t\n\tbool once = true;\n\tList* list = this;\n\t\n\tfor (int i = 0; list && i < vm.printLength;) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tfor (int j = 0; j < a->size() && i < vm.printLength; ++j, ++i) {\n\t\t\tif (!once) zprintf(out, \" \");\n\t\t\tonce = false;\n\t\t\tif (a->isV()) {\n\t\t\t\ta->v()[j].print(th, out, depth+1);\n\t\t\t} else {\n\t\t\t\n\t\t\t\tzprintf(out, \"%g\", a->z()[j]);\n\t\t\t}\n\t\t}\n\t\tif (i >= vm.printLength) {\n\t\t\tzprintf(out, \" ...]\");\n\t\t\treturn;\n\t\t}\n\t\tlist = list->nextp();\n\t}\n\tif (list && list->mNext) {\n\t\tzprintf(out, \" ...]\");\n\t} else {\n\t\tzprintf(out, \"]\");\n\t}\n}\n\nvoid V::print(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->print(th, out, depth);\n}\n\nvoid V::printShort(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printShort(th, out, depth);\n}\n\nvoid V::printDebug(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printDebug(th, out, depth);\n}\n\n\nvoid V::print(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printShort(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printDebug(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nGen::Gen(Thread& th, int inItemType, bool inFinite)\n\t: mDone(false), mOut(0), mBlockSize(inItemType == itemTypeV ? vm.VblockSize : th.rate.blockSize)\n{\n\telemType = inItemType;\n\tsetFinite(inFinite);\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t++vm.totalStreamGenerators;\n\telse\n\t\t++vm.totalSignalGenerators;\n#endif\n}\n\nGen::~Gen()\n{\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t--vm.totalStreamGenerators;\n\telse\n\t\t--vm.totalSignalGenerators;\n#endif\n}\n\nvoid Gen::end() \n{\n\tsetDone();\n\tmOut->end();\n}\n\n\nvoid Gen::produce(int shrinkBy)\n{\n\tmOut->mArray->addSize(-shrinkBy);\n\tmOut = mOut->nextp();\n}\n\nvoid List::end()\n{\n\tassert(mGen);\n\tmNext = nullptr;\n\tmGen = nullptr;\n\tmArray = vm.getNilArray(elemType);\n}\n\nV* List::fulfill(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next();\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nZ* List::fulfillz(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next;\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nvoid List::link(Thread& th, List* inList)\n{\n\tassert(mGen);\n\tif (!inList) return;\n\tinList->force(th);\n\tmNext = inList->mNext;\n\tmArray = inList->mArray;\n\tmGen = nullptr;\n}\n\nvoid List::force(Thread& th)\n{\t\n\tSpinLocker lock(mSpinLock);\n\tif (mGen) {\n\t\tP gen = mGen; // keep the gen from being destroyed out from under pull().\n\t\tif (gen->done()) {\n\t\t\tgen->end();\n\t\t} else {\n\t\t\tgen->pull(th);\n\t\t}\n\t\t// mGen should be NULL at this point because one of the following should have been called: fulfill, link, end.\n\t}\n}\n\nint64_t List::length(Thread& th)\n{\n\tif (!isFinite())\n\t\tindefiniteOp(\"size\", \"\");\n\t\n\tList* list = this;\n\t\n\tint64_t sum = 0;\n\twhile (list) {\n\t\tlist->force(th);\n\t\t\n\t\tsum += list->mArray->size();\n\t\tlist = list->nextp();\n\t}\n\t\n\treturn sum;\n}\n\nArray::~Array()\n{\n\tif (isV()) {\n\t\tdelete [] vv;\n\t} else {\n\t\tfree(p);\n\t}\n}\n\nvoid Array::alloc(int64_t inCap)\n{\n\tif (mCap >= inCap) return;\n\tmCap = inCap;\n\tif (isV()) {\n\t\tV* oldv = vv;\n\t\tvv = new V[mCap];\n\t\tfor (int64_t i = 0; i < size(); ++i) \n\t\t\tvv[i] = oldv[i];\n\t\tdelete [] oldv;\n\t} else {\n\t\tp = realloc(p, mCap * elemSize());\n\t}\n}\n\nvoid Array::add(Arg inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = inItem;\n\telse zz[mSize++] = inItem.asFloat();\n}\n\nvoid Array::addAll(Array* a)\n{\n\tif (!a->mSize)\n\t\treturn;\n\t\t\n\tint64_t newSize = mSize + a->size();\n\tif (newSize > mCap)\n\t\talloc(NEXTPOWEROFTWO(newSize));\n\t\n\tif (isV()) {\n\t\tif (a->isV()) {\n\t\t\tV* x = vv + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t} else {\n\t\t\tV* x = vv + size();\n\t\t\tZ* y = a->zz;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t}\n\t} else {\n\t\tif (a->isV()) {\n\t\t\tZ* x = zz + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i].asFloat();\n\t\t} else {\n\t\t\tmemcpy(zz + mSize, a->zz, a->mSize * sizeof(Z));\n\t\t}\n\t}\n\tmSize = newSize;\n}\n\nvoid Array::addz(Z inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = V(inItem);\n\telse zz[mSize++] = inItem;\n}\n\nvoid Array::put(int64_t inIndex, Arg inItem)\n{\n\tif (isV()) vv[inIndex] = inItem;\n\telse zz[inIndex] = inItem.asFloat();\n}\n\nvoid Array::putz(int64_t inIndex, Z inItem)\n{\n\tif (isV()) vv[inIndex] = V(inItem);\n\telse zz[inIndex] = inItem;\n}\n\nIn::In()\n\t: mList(nullptr), mOffset(0), mConstant(0.), mIsConstant(true)\n{\n}\n\nVIn::VIn()\n{\n\tset(0.);\n}\n\nVIn::VIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nZIn::ZIn()\n{\n\tset(0.);\n}\n\nZIn::ZIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nBothIn::BothIn()\n{\n\tset(0.);\n}\n\nBothIn::BothIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nvoid VIn::set(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid VIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid BothIn::set(Arg inValue)\n{\n\tif (inValue.isList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setv(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid ZIn::set(Arg inValue)\n{\n\tif (inValue.isZList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nbool VIn::operator()(Thread& th, int& ioNum, int& outStride, V*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant;\n\t\treturn false;\n\t}\n\t\n\tif (mList) {\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n int num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->v() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n }\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant;\n\tmDone = true;\n\treturn true;\n}\n\nbool ZIn::operator()(Thread& th, int& ioNum, int& outStride, Z*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant.f;\n\t\treturn false;\n\t}\n\tif (mList) {\n\t\tif (mOnce) {\n\t\t\tmOnce = false;\n\t\t}\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n\t\t\tint num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->z() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n\t}\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant.f;\n ioNum = 0;\n\tmDone = true;\n\treturn true;\n}\n\nvoid dumpList(List const* list)\n{\n\tfor (int i = 0; list; ++i, list = list->nextp()) {\n\t\tprintf(\" List %d %p mGen %p\\n\", i, list, list->mGen());\n\t\tprintf(\" List %d %p mNext %p\\n\", i, list, list->nextp());\n\t\tprintf(\" List %d %p mArray %p %d\\n\", i, list, list->mArray(), (int)(list->mArray() ? list->mArray->size() : 0));\n\t}\n}\n\nbool VIn::link(Thread& th, List* inList)\n{\n\tif (!mList) return false;\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tV* out = inList->fulfill_link(n, mList->next());\n\t\t\t\tV* in = mList->mArray->v() + mOffset;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = in[i];\n\t\t\t\t}\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nbool ZIn::link(Thread& th, List* inList)\n{\t\n\tif (!mList) return false;\n\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tZ* out = inList->fulfillz_link(n, mList->next());\n\t\t\t\tZ* in = mList->mArray->z() + mOffset;\n\t\t\t\tmemcpy(out, in, n * sizeof(Z));\n\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nvoid In::advance(int inNum)\n{\n\tif (mList) {\n\t\tmOffset += inNum;\n\t\tif (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n\t\t\tmOffset = 0;\n\t\t}\n\t}\n}\n\nbool VIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::peek(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset];\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\telse\n\t\t\t\tv = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.asFloat();\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tz = mList->mArray->v()[mOffset++].asFloat();\n\t\t\telse\n\t\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onei(Thread& th, int64_t& i)\n{\n\tZ z = 0.;\n\tbool result = onez(th, z);\n\ti = (int64_t)floor(z);\n\treturn result;\n}\n\nbool ZIn::bench(Thread& th, int& ioNum)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, Z* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, float* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nvoid ZIn::hop(Thread& th, int framesToAdvance)\n{\n\tP list = mList;\n\tint offset = mOffset;\n\twhile (list && framesToAdvance) {\n\t\tlist->force(th);\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tif (avail >= framesToAdvance) {\n\t\t\toffset += framesToAdvance;\n\t\t\tmList = list;\n\t\t\tmOffset = offset;\n\t\t\treturn;\n\t\t}\n\t\tframesToAdvance -= avail;\n\t\toffset = 0;\n\t\tlist = list->next();\n\t\tif (!list) {\n\t\t\tmList = nullptr;\n\t\t\tmOffset = 0;\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nbool ZIn::fillSegment(Thread& th, int inNum, Z* outBuffer)\n{\n\tint framesToFill = inNum;\n\tif (mIsConstant) {\n\t\tZ z = mConstant.f;\n\t\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\treturn false;\n\t}\n\n\tP list = mList;\n\tint offset = mOffset;\n\tZ* out = outBuffer;\n\twhile (list) {\n\t\tlist->force(th);\n\t\tassert(list->mArray);\n\t\t\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tint numToFill = std::min(framesToFill, avail);\n\n\t\t// copy\n\t\tZ* in = list->mArray->z() + offset;\n\t\tmemcpy(out, in, numToFill * sizeof(Z));\n\t\tout += numToFill;\n\t\tframesToFill -= numToFill;\n\t\t\n\t\tif (framesToFill == 0)\n\t\t\treturn false;\n\t\t\n\t\tlist = list->next();\n\t\toffset = 0;\n\t}\n\t\n\tZ z = mConstant.f;\n\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\n\tmDone = true;\n\treturn true;\n}\n\n\nbool ZIn::mix(Thread& th, int& ioNum, Z* outBuffer)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0; i < n; ++i)\t{\n\t\t\toutBuffer[i] += *a;\n\t\t\ta += astride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nclass Comma : public Gen\n{\n\tVIn _a;\n\tV key;\npublic:\n\tComma(Thread& th, Arg a, Arg inKey) : Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {} \n\t\n\tvirtual const char* TypeName() const override { return \"Comma\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->comma(th, key);\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\nclass Dot : public Gen\n{\n\tVIn _a;\n\tV key;\n\tV defaultValue;\npublic:\n\tDot(Thread& th, Arg a, Arg inKey, Arg inDefaultValue)\n\t\t\t\t\t: Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Dot\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tV v = defaultValue;\n\t\t\t\t\t\ta->dot(th, key, v);\n\t\t\t\t\t\tout[i] = v;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\n\nV List::comma(Thread& th, Arg key)\n{\n\treturn new List(new Comma(th, this, key));\n}\n\nbool List::dot(Thread& th, Arg key, V& ioValue)\n{\n\tioValue = new List(new Dot(th, this, key, ioValue));\n\treturn true;\n}\n\nbool List::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isList()) return false;\n\tList* that = (List*)v.o();\n\tif (!isFinite())\n\t\tindefiniteOp(\"\", \"equals : a\");\n\tif (!that->isFinite())\n\t\tindefiniteOp(\"\", \"equals : b\");\n\t\n\tif (elemType != that->elemType) return false;\n\t\n\tif (isVList()) {\n\t\tVIn _a(this);\n\t\tVIn _b(that);\n\t\t\n\t\tV *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = kDefaultVBlockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n \n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (!a->Equals(th, *b)) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t\t\n\t} else {\n\t\tZIn _a(this);\n\t\tZIn _b(that);\n\t\t\n\t\tZ *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = th.rate.blockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (*a != *b) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t}\n\n}\n\nList::List(int inItemType) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, 0))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\nList::List(int inItemType, int64_t inCap) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, inCap))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\n\n\nList::List(P const& inGen) \n\t: mNext(nullptr), mGen(inGen), mArray(0)\n{\n\telemType = inGen->elemType;\n\tsetFinite(inGen->isFinite());\n\tinGen->setOut(this);\n}\n\nList::List(P const& inArray) \n\t: mNext(nullptr), mGen(nullptr), mArray(inArray)\n{\n\telemType = inArray->elemType;\n\tsetFinite(true);\n}\n\nList::List(P const& inArray, P const& inNext) \n\t: mNext(inNext), mGen(0), mArray(inArray)\n{\n\tassert(!mNext || mArray->elemType == mNext->elemType);\n\telemType = inArray->elemType;\n\tsetFinite(!mNext || mNext->isFinite());\n}\n\nList::~List()\n{\n\t// free as much tail as possible at once in order to prevent stack overflow.\n\tP list = mNext;\n\tmNext = nullptr;\n\twhile (list) {\n\t\tif (list->getRefcount() > 1) break;\n\t\tP next = list->mNext;\n\t\tlist->mNext = nullptr;\n\t\tlist = next;\n\t}\n}\n\nint64_t List::fillz(Thread& th, int64_t n, Z* z)\n{\n\tint64_t k = 0;\n\tP list = this;\n\twhile(list && k < n) {\n\t\tlist->force(th);\n\t\t\n\t\tint64_t m = std::min((n-k), list->mArray->size());\n\t\tfor (int64_t i = 0; i < m; ++i) {\n\t\t\tz[k++] = list->mArray->_atz(i);\n\t\t}\n\t\tlist = list->mNext;\n\t}\n\treturn k;\n}\n\n\nList* List::pack(Thread& th)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packz(Thread& th)\n{\n force(th);\n\tif (isPacked() && isZ())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(itemTypeZ, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::pack(Thread& th, int limit)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\t\t\n\t\tif (cap > limit) return nullptr;\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packSome(Thread& th, int64_t& limit)\n{\n force(th);\n\tif (isPacked()) {\n\t\tlimit = std::min(limit, length(th));\n\t\treturn this;\n\t}\n\t\t\n\tP list = this;\n\tint64_t count = 0;\n\twhile(list && count < limit) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcount += list->mArray->size();\t\n\t\t\t\t\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, count);\n\t\n\tlist = this;\n\tcount = 0;\n\twhile(list && count < limit) {\n\t\ta->addAll(list->mArray());\n\t\tcount += list->mArray->size();\t\n\t\tlist = list->mNext;\n\t}\n\tlimit = std::min(limit, count);\n\t\n\treturn new List(a);\n}\n\nvoid List::forceAll(Thread& th)\n{\n\tList* list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\tlist = list->nextp();\n\t}\n}\n\nV V::msgSend(Thread& th, Arg receiver)\n{\n\tif (!o) {\n\t\treturn *this;\n\t} else {\n\t\treturn o->msgSend(th, receiver);\n\t}\n}\n\nV Prim::msgSend(Thread& th, Arg receiver)\n{\n\tSaveStack ss(th, Takes());\n\tth.push(receiver);\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\nV Fun::msgSend(Thread& th, Arg receiver)\n{\n\tth.push(receiver);\n\tSaveStack ss(th, NumArgs());\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\t\nTableMap::TableMap(size_t inSize)\n\t: mSize(inSize)\n{\n\tif (inSize == 0) {\n\t\tmMask = 0;\n\t\tmIndices = nullptr;\n\t\tmKeys = nullptr;\n\t} else {\n\t\tsize_t n = 2*NEXTPOWEROFTWO((int64_t)mSize);\n\t\tmMask = n-1;\n\t\tmIndices = new size_t[n]();\n\t\tmKeys = new V[mSize];\n\t}\n}\n\nTableMap::TableMap(Arg inKey)\n\t: mSize(1)\n{\n\tmMask = 1;\n\tmIndices = new size_t[2]();\n\tmKeys = new V[mSize];\n\t\n\tmKeys[0] = inKey;\n\tmIndices[inKey.Hash() & 1] = 1;\n}\n\n\nTableMap::~TableMap()\n{\n\tdelete [] mKeys;\n\tdelete [] mIndices;\n}\n\nbool TableMap::getIndex(Arg inKey, int64_t inKeyHash, size_t& outIndex)\n{\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\tV* keys = mKeys;\n\twhile(1) {\n\t\tsize_t index = indices[i];\n\t\tif (index == 0)\n\t\t\treturn false;\n\t\tsize_t index2 = index - 1;\n\t\tif (inKey.Identical(keys[index2])) {\n\t\t\toutIndex = index2;\n\t\t\treturn true;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nvoid TableMap::put(size_t inIndex, Arg inKey, int64_t inKeyHash)\n{\n\tmKeys[inIndex] = inKey;\n\t\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\t\n\twhile(1) {\n\t\tif (indices[i] == 0) {\n\t\t\tindices[i] = inIndex + 1;\n\t\t\treturn;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nTable::Table(P const& inMap)\n\t: mMap(inMap), mValues(new V[mMap->mSize])\n{\n}\n\nTable::~Table()\n{\n\tdelete [] mValues;\n}\n\nbool Table::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isTable()) return false;\n\tif (this == v.o()) return true;\n\tTable* that = (Table*)v.o();\n\tsize_t size = mMap->mSize;\n\tif (size != that->mMap->mSize)\n\t\treturn false;\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tV key = mMap->mKeys[i];\n\t\tV thatValue;\n\t\tif (!that->getWithHash(th, key, key.Hash(), thatValue))\n\t\t\treturn false;\n\t\tif (!mValues[i].Equals(th, thatValue))\n\t\t\treturn false;\n\t}\n return true;\n}\n\nbool Table::getWithHash(Thread& th, Arg key, int64_t hash, V& value) const\n{\n\tsize_t index;\n\tif (!mMap->getIndex(key, hash, index))\n\t\treturn false;\n\tvalue = mValues[index];\n\treturn true;\n}\n\nvoid Table::put(size_t inIndex, Arg inValue)\n{\n\tmValues[inIndex] = inValue;\n}\n\nvoid Table::print(Thread& th, std::string& out, int depth)\n{\n\tfor (size_t i = 0; i < mMap->mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmMap->mKeys[i].print(th, out, depth+1);\n\t\tzprintf(out, \" \");\n\t\tmValues[i].print(th, out, depth+1);\n\t}\n}\n\nvoid TableMap::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"{\");\n\tfor (size_t i = 0; i < mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmKeys[i].print(th, out, depth+1);\n\t}\n\tzprintf(out, \"}\");\n}\n\n\nstatic P chase_z(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\n\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\n\t\t\treturn new List(a2, list->next());\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm._nilz;\n\t}\n\t\n\treturn list;\n}\n\nstatic P chase_v(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"chase : list\", \"\");\n\t}\n\t\n\tint64_t length = list->length(th);\n\t\n\tP result = new List(itemTypeV, length);\n\tP array = result->mArray;\n\tV* out = array->v();\n\t\n\tint64_t i = 0;\n\t\n\twhile (list) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tV* in = a->v();\n\t\t\n\t\tfor (int64_t j = 0; j < asize; ++j, ++i) {\n\t\t\tout[i] = in[j].chase(th, n);\n\t\t}\n\n\t\tlist = list->next();\n\t}\n\t\n\treturn list;\n}\n\nV List::chase(Thread& th, int64_t n)\n{\n\tif (isVList()) {\n\t\treturn chase_v(th, this, n);\n\t} else {\n\t\treturn chase_z(th, this, n);\n\t}\n}\n\nP Form::chaseForm(Thread& th, int64_t n)\n{\n\tP nextForm = mNextForm() ? mNextForm->chaseForm(th, n) : nullptr;\n\treturn new Form(mTable->chaseTable(th, n), nextForm);\n}\n\nP
Table::chaseTable(Thread& th, int64_t n)\n{\n\tP
result = new Table(mMap);\n\t\n\tsize_t size = mMap->mSize;\n\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tresult->mValues[i] = mValues[i].chase(th, n);\n\t}\n\t\n\treturn result;\n}\n\n\n\nvoid Plug::setPlug(Arg inV)\n{\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid Plug::setPlug(const VIn& inVIn, int inChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inVIn;\n\t}\n}\n\nvoid Plug::getPlug(VIn& outVIn, int& outChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\toutVIn = in;\n\toutChangeCount = mChangeCount;\n}\n\n\nvoid ZPlug::setPlug(Arg inV) {\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid ZPlug::setPlug(const ZIn& inZIn, int inChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inZIn;\n\t}\n}\n\nvoid ZPlug::getPlug(ZIn& outZIn, int& outChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\toutZIn = in;\n\toutChangeCount = mChangeCount;\n}\n"], ["/sapf/src/SoundFiles.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"SoundFiles.hpp\"\n#include \n\nextern char gSessionTime[256];\n\n\nclass SFReaderOutputChannel;\n\nclass SFReader : public Object\n{\n\tExtAudioFileRef mXAF;\n\tint64_t mFramesRemaining;\n\tSFReaderOutputChannel* mOutputs;\n\tint mNumChannels;\n\tAudioBufferList* mABL;\n\tbool mFinished = false;\n\t\npublic:\n\t\n\tSFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration);\n\t\n\t~SFReader();\n\n\tvirtual const char* TypeName() const override { return \"SFReader\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tbool pull(Thread& th);\n\tvoid fulfillOutputs(int blockSize);\n\tvoid produceOutputs(int shrinkBy);\n};\n\nclass SFReaderOutputChannel : public Gen\n{\n\tfriend class SFReader;\n\tP mSFReader;\n\tSFReaderOutputChannel* mNextOutput = nullptr;\n\tZ* mDummy = nullptr;\n\t\npublic:\t\n\tSFReaderOutputChannel(Thread& th, SFReader* inSFReader)\n : Gen(th, itemTypeZ, true), mSFReader(inSFReader)\n\t{\n\t}\n\t\n\t~SFReaderOutputChannel()\n\t{\n\t\tif (mDummy) free(mDummy);\n\t}\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr; \n\t\tmSFReader = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"SFReaderOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mSFReader->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nSFReader::SFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration)\n\t: mXAF(inXAF), mNumChannels(inNumChannels), mFramesRemaining(inDuration), mABL(nullptr)\n{\n\tmABL = (AudioBufferList*)calloc(1, sizeof(AudioBufferList) + (mNumChannels - 1) * sizeof(AudioBuffer));\n}\n\nSFReader::~SFReader()\n{\n\tExtAudioFileDispose(mXAF); free(mABL);\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tSFReaderOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nvoid SFReader::fulfillOutputs(int blockSize)\n{\n\tmABL->mNumberBuffers = mNumChannels;\n\tSFReaderOutputChannel* output = mOutputs;\n\tsize_t bufSize = blockSize * sizeof(Z);\n\tfor (int i = 0; output; ++i, output = output->mNextOutput){\n\t\tZ* out;\n\t\tif (output->mOut)\n\t\t\tout = output->mOut->fulfillz(blockSize);\n\t\telse {\n\t\t\tif (!output->mDummy)\n\t\t\t\toutput->mDummy = (Z*)calloc(output->mBlockSize, sizeof(Z));\n\n\t\t\tout = output->mDummy;\n\t\t}\n\t\t\t\n\t\tmABL->mBuffers[i].mNumberChannels = 1;\n\t\tmABL->mBuffers[i].mData = out;\n\t\tmABL->mBuffers[i].mDataByteSize = (UInt32)bufSize;\n\t\tmemset(out, 0, bufSize);\n\t};\n}\n\nvoid SFReader::produceOutputs(int shrinkBy)\n{\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nP SFReader::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n SFReaderOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n SFReaderOutputChannel* c = new SFReaderOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nbool SFReader::pull(Thread& th)\n{\n\tif (mFramesRemaining == 0) \n\t\tmFinished = true;\n\n\tif (mFinished) \n\t\treturn true;\n\t\n\tSFReaderOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\tif (mFramesRemaining > 0)\n\t\tblockSize = (int)std::min(mFramesRemaining, (int64_t)blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n\t// read file here.\n\tUInt32 framesRead = blockSize;\n\tOSStatus err = ExtAudioFileRead(mXAF, &framesRead, mABL);\n\t\n\tif (err || framesRead == 0) {\n\t\tmFinished = true;\n\t}\n\t\n\tproduceOutputs(blockSize - framesRead);\n\tif (mFramesRemaining > 0) mFramesRemaining -= blockSize;\n\t\n\treturn mFinished; \n}\n\nvoid sfread(Thread& th, Arg filename, int64_t offset, int64_t frames)\n{\n\tconst char* path = ((String*)filename.o())->s;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path\\n\");\n\t\treturn;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileOpenURL(url, &xaf);\n\n\tcfpathReleaser.release();\n\turlReleaser.release();\n\t\n\tif (err) {\n\t\tpost(\"failed to open file %d\\n\", (int)err);\n\t\treturn;\n\t}\n\n\tAudioStreamBasicDescription fileFormat;\n\t\n\tUInt32 propSize = sizeof(fileFormat);\n\terr = ExtAudioFileGetProperty(xaf, kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);\n\t\n\tint numChannels = fileFormat.mChannelsPerFrame;\n\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved,\n\t\tstatic_cast(sizeof(double)),\n\t\t1,\n\t\tstatic_cast(sizeof(double)),\n\t\tstatic_cast(numChannels),\n\t\t64,\n\t\t0\n\t};\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\terr = ExtAudioFileSeek(xaf, offset);\n\tif (err) {\n\t\tpost(\"seek failed %d\\n\", (int)err);\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\tSFReader* sfr = new SFReader(xaf, numChannels, -1);\n\t\n\tth.push(sfr->createOutputs(th));\n}\n\nExtAudioFileRef sfcreate(Thread& th, const char* path, int numChannels, double fileSampleRate, bool interleaved)\n{\n\tif (fileSampleRate == 0.)\n\t\tfileSampleRate = th.rate.sampleRate;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path '%s'\\n\", path);\n\t\treturn nullptr;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn nullptr;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tAudioStreamBasicDescription fileFormat = {\n\t\tfileSampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\n\tint interleavedChannels = interleaved ? numChannels : 1;\n\tUInt32 interleavedBit = interleaved ? 0 : kAudioFormatFlagIsNonInterleaved;\n\t\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | interleavedBit,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileCreateWithURL(url, kAudioFileWAVEType, &fileFormat, nullptr, kAudioFileFlags_EraseFile, &xaf);\n\t\n\tif (err) {\n\t\tpost(\"failed to create file '%s'. err: %d\\n\", path, (int)err);\n\t\treturn nullptr;\n\t}\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn nullptr;\n\t}\n\t\n\treturn xaf;\n}\n\nstd::atomic gFileCount = 0;\n\nvoid makeRecordingPath(Arg filename, char* path, int len)\n{\n\tif (filename.isString()) {\n\t\tconst char* recDir = getenv(\"SAPF_RECORDINGS\");\n\t\tif (!recDir || strlen(recDir)==0) recDir = \"/tmp\";\n\t\tsnprintf(path, len, \"%s/%s.wav\", recDir, ((String*)filename.o())->s);\n\t} else {\n\t\tint32_t count = ++gFileCount;\n\t\tsnprintf(path, len, \"/tmp/sapf-%s-%04d.wav\", gSessionTime, count);\n\t}\n}\n\nvoid sfwrite(Thread& th, V& v, Arg filename, bool openIt)\n{\n\tstd::vector in;\n\t\n\tint numChannels = 0;\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin.push_back(ZIn(v));\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin.push_back(ZIn(va));\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tchar path[1024];\n\t\n\tmakeRecordingPath(filename, path, 1024);\n\t\n\tExtAudioFileRef xaf = sfcreate(th, path, numChannels, 0., true);\n\tif (!xaf) return;\n\t\n\tstd::valarray buf(0., numChannels * kBufSize);\n\tAudioBufferList abl;\n\tabl.mNumberBuffers = 1;\n\tabl.mBuffers[0].mNumberChannels = numChannels;\n\tabl.mBuffers[0].mData = &buf[0];\n\tabl.mBuffers[0].mDataByteSize = kBufSize * sizeof(float);\n\t\n\tint64_t framesPulled = 0;\n\tint64_t framesWritten = 0;\n\tbool done = false;\n\twhile (!done) {\n\t\tint minn = kBufSize;\n\t\tmemset(&buf[0], 0, kBufSize * numChannels);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].fill(th, n, &buf[0]+i, numChannels);\n\t\t\tframesPulled += n;\n\t\t\tif (imdone) done = true;\n\t\t\tminn = std::min(n, minn);\n\t\t}\n\n\t\tabl.mBuffers[0].mDataByteSize = minn * sizeof(float);\n\t\tOSStatus err = ExtAudioFileWrite(xaf, minn, &abl);\n\t\tif (err) {\n\t\t\tpost(\"ExtAudioFileWrite failed %d\\n\", (int)err);\n\t\t\tbreak;\n\t\t}\n\n\t\tframesWritten += minn;\n\t}\n\t\n\tpost(\"wrote file '%s' %d channels %g secs\\n\", path, numChannels, framesWritten * th.rate.invSampleRate);\n\t\n\tExtAudioFileDispose(xaf);\n\t\n\tif (openIt) {\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n}\n"], ["/sapf/src/MultichannelExpansion.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n// multi channel mapping is a special case of auto mapping where the mask is all z's.\n\nclass MultichannelMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tVIn args[kMaxArgs];\npublic:\n\t\n\tMultichannelMapper(Thread& th, bool inFinite, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\targs[i].set(inArgs[i]);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"MultichannelMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nvoid mcx_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV& fun = prim->v;\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool hasVList = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tif (args[k].isVList()) {\n\t\t\thasVList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t}\n\t}\n\t\n\tif (hasVList) {\n\t\tList* s = new List(new MultichannelMapper(th, isFinite, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tfun.apply(th);\n\t}\n\n}\n\n\nconst char* kAaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";\nconst size_t kAaaLength = strlen(kAaa);\n\nconst char* kZzz = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\";\nconst size_t kZzzLength = strlen(kZzz);\n\nconst char* Prim::GetAutoMapMask() const\n{\n\t//return NoEachOps() || mNumArgs == 0 ? nullptr : kAaa + kAaaLength - mNumArgs;\n\treturn nullptr;\n}\n\nclass MultichannelMapPrim : public Prim\n{\npublic:\n\tMultichannelMapPrim(PrimFun _primFun, Arg _v, int n, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return kZzz + kZzzLength - mTakes; }\n\t\n};\n\nPrim* mcx(int n, Arg f, const char* name, const char* help)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = mcx_< 1>; break;\n\t\tcase 2 : pf = mcx_< 2>; break;\n\t\tcase 3 : pf = mcx_< 3>; break;\n\t\tcase 4 : pf = mcx_< 4>; break;\n\t\tcase 5 : pf = mcx_< 5>; break;\n\t\tcase 6 : pf = mcx_< 6>; break;\n\t\tcase 7 : pf = mcx_< 7>; break;\n\t\tcase 8 : pf = mcx_< 8>; break;\n\t\tcase 9 : pf = mcx_< 9>; break;\n\t\tcase 10 : pf = mcx_<10>; break;\n\t\tcase 11 : pf = mcx_<11>; break;\n\t\tcase 12 : pf = mcx_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new MultichannelMapPrim(pf, f, n, name, help);\n}\n\nclass AutoMapPrim : public Prim\n{\npublic:\n\tconst char* mask;\n\tAutoMapPrim(PrimFun _primFun, Arg _v, int n, const char* inMask, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp), mask(inMask)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return mask; }\n\t\n};\n\nclass AutoMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tBothIn args[kMaxArgs];\npublic:\n\t\n\tAutoMapper(Thread& th, bool inFinite, const char* inMask, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\tswitch (inMask[i]) {\n\t\t\t\tcase 'a' :\n\t\t\t\t\targs[i].setConstant(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'z' : // auto map over V lists, but not Z lists.\n\t\t\t\t\targs[i].setv(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", inMask[i]);\n\t\t\t\tcase 'k' :\n\t\t\t\t\targs[i].set(inArgs[i]);\n\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"AutoMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n/*\n\ta - as is. argument is not automapped.\n\tz - argument is expected to be a signal or scalar, streams are auto mapped.\n\tk - argument is expected to be a scalar, signals and streams are automapped.\n*/\n\ntemplate \nvoid automap_(Thread& th, Prim* prim)\n{\n\n\tconst char* mask = ((AutoMapPrim*)prim)->mask;\n\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool canMap = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tswitch (mask[k]) {\n\t\t\tcase 'a' :\n\t\t\t\tbreak;\n\t\t\tcase 'z' :\n\t\t\t\tif (args[k].isVList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", mask[k]);\n\t\t\t\tthrow errFailed;\n\t\t\t\tbreak;\n\t\t\tcase 'k' :\n\t\t\t\tif (args[k].isList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tif (canMap) {\n\t\tList* s = new List(new AutoMapper(th, isFinite, mask, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tprim->v.apply(th);\n\t}\n\n}\n\nPrim* automap(const char* mask, int n, Arg f, const char* inName, const char* inHelp)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = automap_< 1>; break;\n\t\tcase 2 : pf = automap_< 2>; break;\n\t\tcase 3 : pf = automap_< 3>; break;\n\t\tcase 4 : pf = automap_< 4>; break;\n\t\tcase 5 : pf = automap_< 5>; break;\n\t\tcase 6 : pf = automap_< 6>; break;\n\t\tcase 7 : pf = automap_< 7>; break;\n\t\tcase 8 : pf = automap_< 8>; break;\n\t\tcase 9 : pf = automap_< 9>; break;\n\t\tcase 10 : pf = automap_<10>; break;\n\t\tcase 11 : pf = automap_<11>; break;\n\t\tcase 12 : pf = automap_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new AutoMapPrim(pf, f, n, mask, inName, inHelp);\n}\n\n\n\n\n\nclass EachMapper : public Gen\n{\n\tconst int level;\n\tconst int numLevels;\n\tV fun;\n\tArgInfo args;\npublic:\n\t\n\tEachMapper(Thread& th, bool inFinite, int inLevel, int inNumLevels, const ArgInfo& inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), level(inLevel), numLevels(inNumLevels), args(inArgs), fun(inFun)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"EachMapper\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (level == 0) {\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, v)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tth.push(v);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tfun.apply(th);\n\t\t\t\t} catch (...) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tthrow;\n\t\t\t\t}\n\t\t\t\tout[i] = th.pop();\n\t\t\t\t\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t} else {\n\t\t\tArgInfo subargs;\n\t\t\tsubargs.numArgs = args.numArgs;\n\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\tsubargs.arg[j].mask = args.arg[j].mask;\n\t\t\t}\n\t\t\t\n\t\t\tint bit = 1 << (numLevels - level);\n\t\t\t\n\t\t\tbool mmIsFinite = true;\n\t\t\t\t\t\t\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tV argv[kMaxArgs];\n\t\t\t\tbool allConstant = true;\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, argv[j])) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (argv[j].isList() && (args.arg[j].mask & bit))\n\t\t\t\t\t\tallConstant = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (allConstant) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tth.push(argv[j]);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfun.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = th.pop();\n\t\t\t\t} else {\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tV v = argv[j];\n\t\t\t\t\t\tif (args.arg[j].mask & bit) {\n\t\t\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\t\t\tmmIsFinite = false;\n\t\t\t\t\t\t\tsubargs.arg[j].in.set(v);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tsubargs.arg[j].in.setConstant(v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\tout[i] = new List(new EachMapper(th, mmIsFinite, level - 1, numLevels, subargs, fun));\n\t\t\t\t}\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\n};\n\nList* handleEachOps(Thread& th, int numArgs, Arg fun)\n{\n\tArgInfo args;\n\tV argv[kMaxArgs];\n\t\n\targs.numArgs = numArgs;\n\tint32_t maxMask = 0;\n\n\tbool mmIsFinite = true;\n\n\tfor (int i = numArgs-1; i >= 0; --i) {\n\t\tV v = th.pop();\n\t\targv[i] = v;\n\t\tif (v.isEachOp()) {\n\t\t\t\n\t\t\tEachOp* adv = (EachOp*)v.o();\n\t\t\targs.arg[i].mask = adv->mask;\n\t\t\tmaxMask |= adv->mask;\n\t\t\tif (adv->mask & 1) {\n\t\t\t\tif (!adv->v.isFinite()) \n\t\t\t\t\tmmIsFinite = false;\n\t\t\t\targs.arg[i].in.set(adv->v);\n\t\t\t} else {\n\t\t\t\targs.arg[i].in.setConstant(adv->v);\n\t\t\t}\n\t\t} else {\n\t\t\targs.arg[i].in.setConstant(v);\n\t\t\targs.arg[i].mask = 0;\n\t\t}\n\t}\n\tif (maxMask > 1 && maxMask != NEXTPOWEROFTWO(maxMask) - 1) {\n\t\tpost(\"there are empty levels of iteration. mask: %x\\n\", maxMask);\n\t\tthrow errFailed;\n\t}\n\t\n\tint numLevels = maxMask <= 1 ? 1 : LOG2CEIL(maxMask);\n\treturn new List(new EachMapper(th, mmIsFinite, numLevels-1, numLevels, args, fun));\n}\n\n\nclass Flop : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlop(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flop\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nclass Flops : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlops(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tVIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flops\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flopz : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlopz(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flopz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeZ, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->addz(z);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopsNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopsNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopsNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isVList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid flop_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\nvoid flops_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flops : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flops : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flops : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flops : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopsNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nvoid flop1_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop1 : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tList* result = new List(itemTypeV, 1);\n\t\t\tresult->add(s);\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop1 : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop1 : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop1 : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nclass Lace : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLace(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), argPos(0)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lace\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (args[argPos].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Lacez : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLacez(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), argPos(0)\n\t{\n\t\tpost(\"Lacez\\n\");\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lacez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tZ z;\n\t\t\tif (args[argPos].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nvoid lace_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popList(\"lace : list\");\n\tif (!s->isVList())\n\t\twrongType(\"lace : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"lace : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Lacez(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Lace(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\nclass Sel : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSel(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sel\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = v;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Selz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSelz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Selz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = z;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sell : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSell(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sell\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tV v;\n\t\t\tif (args[k].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sellz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSellz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sellz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tZ z;\n\t\t\tif (args[k].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid sel_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sel : indices\");\n\n\tP s = th.popList(\"sel : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sel : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sel : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Selz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sel(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\nvoid sell_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sell : indices\");\n\n\tP s = th.popList(\"sell : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sell : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sell : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Sellz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sell(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\n\n\n\n\n\n"], ["/sapf/libmanta/Manta.h", "class Manta {\n public:\n Manta(void) {\n for(int i = 0; i < 53; ++i)\n {\n LastInReport[i] = 0;\n MaxSensorValues[i] = AverageMaxSensorValues[i];\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = 0xFF;\n }\n for(unsigned int i = 0; i < sizeof(CurrentOutReport); ++i)\n {\n CurrentOutReport[i] = 0;\n }\n for(unsigned int i = 0; i < sizeof(VelocityWaiting) / sizeof(VelocityWaiting[0]); ++i)\n {\n VelocityWaiting[i] = false;\n }\n}\n virtual void SetPadLED(LEDState state, int ledID) {\n int row = ledID / 8;\n int column = ledID % 8;\n\n if(ledID < 0 || ledID > 47)\n {\n throw std::invalid_argument(\"Invalid Pad Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= (1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= (1 << column);\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n break;\n case Off:\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) {\n if(row < 0 || row > 5)\n {\n throw std::invalid_argument(\"Invalid Row Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDRow(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", row, mask);\n MantaClient::DebugPrint(\"ByteReverse(0x%X) = 0x%X\", 0xA0, byteReverse(0xA0));\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= byteReverse(mask);\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n case Off:\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) {\n if(column < 0 || column > 7)\n {\n throw std::invalid_argument(\"Invalid Column Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDColumn(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", column, mask);\n switch(state)\n {\n case Amber:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[AmberIndex + i] |= (0x01 << column);\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Red:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] |= (0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Off:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) {\n switch(state)\n {\n case Amber:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Red:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Off:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case All:\n // when setting both colors we use two frames at once\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n uint8_t amberMask = mask[i];\n uint8_t redMask = mask[i+sizeof(LEDFrame)];\n // turn off any amber LEDs if there's a red LED in that position\n amberMask &= ~redMask;\n CurrentOutReport[RedIndex + i] = byteReverse(redMask);\n CurrentOutReport[AmberIndex + i] = byteReverse(amberMask);\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) {\n if(id < 0 || id > 1)\n {\n throw std::invalid_argument(\"Invalid Slider Index\");\n }\n switch(state)\n {\n case Amber:\n CurrentOutReport[SliderIndex + id] |= byteReverse(mask);\n break;\n case Red:\n /* no Red slider LEDs, do nothing */\n break;\n case Off:\n CurrentOutReport[SliderIndex + id] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetButtonLED(LEDState state, int id) {\n if(id < 0 || id > 3)\n {\n throw std::invalid_argument(\"Invalid Button Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n break;\n case Red:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n case Off:\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ResendLEDState(void) {\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearPadAndButtonLEDs(void) {\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] = 0;\n CurrentOutReport[RedIndex + i] = 0;\n }\n\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearButtonLEDs(void) {\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void Recalibrate(void) {\n if(! IsConnected())\n {\n throw MantaNotConnectedException(this);\n }\n\n /* make sure these messages get queued so that they\n * don't just cancel each other out */\n CurrentOutReport[ConfigIndex] |= 0x40;\n WriteFrame(CurrentOutReport, true);\n CurrentOutReport[ConfigIndex] &= ~0x40;\n WriteFrame(CurrentOutReport, true);\n}\n virtual void SetLEDControl(LEDControlType control, bool state) {\n uint8_t flag;\n\n switch(control)\n {\n case PadAndButton:\n flag = 0x01;\n break;\n case Slider:\n flag = 0x02;\n break;\n case Button:\n flag = 0x20;\n break;\n default:\n throw std::invalid_argument(\"Invalid Control Type\");\n }\n\n if(state)\n CurrentOutReport[ConfigIndex] |= flag;\n else\n CurrentOutReport[ConfigIndex] &= ~flag;\n if(IsConnected())\n {\n /* if we're disabling LEDControl, we want to make sure that this\n * message gets queued so that any pending LED messages get sent\n * down before we disable LEDs */\n WriteFrame(CurrentOutReport, !state);\n }\n}\n virtual void SetTurboMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x04;\n else\n CurrentOutReport[ConfigIndex] &= ~0x04;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetRawMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x08;\n else\n CurrentOutReport[ConfigIndex] &= ~0x08;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetMaxSensorValues(int *values) {\n for(int i = 0; i < 53; ++i)\n {\n MaxSensorValues[i] = values[i];\n }\n}\n private:\n virtual void FrameReceived(int8_t *frame) {\nbool hadEvent = false;\n uint8_t *uframe = (uint8_t *)frame;\n for(int i = 1; i < 53; ++i)\n {\n uframe[i] = ScaleSensorValue(frame[i] + 128, i);\n }\n /* apply the offset to the slider bytes without scaling them */\n for(int i = 53; i < 57; ++i)\n {\n uframe[i] = frame[i] + 128;\n }\n //printf(\"\\n\");\n FrameEvent(uframe);\n /* input frames have one reportID byte at the beginning */\n for(int i = 1; i < 53; ++i)\n {\n /*\n * overall pad logic:\n * if there's a velocity waiting to be calculated, send a note-on\n * if this is the first zero value, send a note-off\n * if the pad changed, send a padValue\n */\n int padIndex = i - 1;\n /* track whether this pad just went high for a single sample,\n * so we don't trigger a simultaneous note-on and note-off */\n bool singleSample = false;\n\n /* check to see if there's a previous sample waiting to have\n * the velocity algorithm run */\n if(VelocityWaiting[i])\n {\n if(uframe[i] == 0)\n {\n // we were waiting for a 2nd sample for velocity but we got zero.\n singleSample = true;\n }\n else\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n VelocityWaiting[i] = false;\n }\n\n\n if(uframe[i] != LastInReport[i])\n {\n if(padIndex < 48) {\n PadEvent(padIndex / 8, padIndex % 8, padIndex, uframe[i]);\n\t\t\t hadEvent = true;\n } else {\n ButtonEvent(padIndex - 48, uframe[i]);\n\t\t\t hadEvent = true;\n\t\t}\n\n /* check to see if this is a release */\n if(0 == uframe[i] && !singleSample)\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex, 0);\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48, 0);\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n /* check to see if this is the first nonzero sample */\n else if(0 == LastInReport[i])\n {\n VelocityWaiting[i] = true;\n }\n }\n LastInReport[i] = uframe[i];\n }\n if(uframe[53] != LastInReport[53] || uframe[54] != LastInReport[54])\n {\n\t //printf(\"slider 0 %3d %3d\\n\", (int)uframe[53], uframe[54]);\n\t int value = (uframe[53]) | ((uframe[54]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n if(uframe[55] != LastInReport[55] || uframe[56] != LastInReport[56])\n {\n\t //printf(\"slider 1 %3d %3d\\n\", (int)uframe[55], uframe[56]);\n\t int value = (uframe[55]) | ((uframe[56]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = uframe[i];\n }\n\t\n if (hadEvent) printf(\"---\\n\");\n}\n int ScaleSensorValue(int rawValue, int index) {\n float div = (float)rawValue / MaxSensorValues[index];\n return (int)((div * 210) + 0.5);\n}\n static uint8_t byteReverse(uint8_t inByte) {\n // Algorithm from Bit Twiddling Hacks\n uint8_t outByte = inByte; // first get LSB of inByte\n int s = 7; // extra shift needed at end\n\n for (inByte >>= 1; inByte; inByte >>= 1)\n {\n outByte <<= 1;\n outByte |= inByte & 1;\n s--;\n }\n outByte <<= s; // shift when inByte's highest bits are zero\n return outByte;\n}\n static int CalculateVelocity(int firstValue, int secondValue) {\n float LOG1, LOG2;\n float MAX;\n float MIN;\n float RELATIVE1, RELATIVE2;\n float LOG_RELATIVE1, LOG_RELATIVE2;\n float SUM_RAW;\n float LOG_SUM_RAW;\n float LOG_SUM_RELATIVE;\n float UP1;\n float VELOCITY = 0;\n int VELint = 0;\n\n\n // now do the velocity calculation\n LOG1 = log(1.0 + (float)LastValue);\n LOG2 = log(1.0 + (float)CurrentValue);\n\n MIN = LastValue;\n if (CurrentValue < MIN)\n {\n MIN = CurrentValue;\n }\n MAX = LastValue;\n if (CurrentValue > MAX)\n {\n MAX = CurrentValue;\n }\n RELATIVE1 = LastValue/MAX;\n RELATIVE2 = CurrentValue/MAX;\n LOG_RELATIVE1 = log(1.0 + RELATIVE1);\n LOG_RELATIVE2 = log(1.0 + RELATIVE2);\n SUM_RAW = LastValue+CurrentValue;\n LOG_SUM_RAW = log(1.0 + SUM_RAW);\n LOG_SUM_RELATIVE = log(1.0 + SUM_RAW/MAX);\n UP1 = 0;\n if (CurrentValue>LastValue) { UP1 = 1; }\n VELOCITY =\n -14.997037 +\n LastValue * 0.009361 +\n MIN * -0.014234 +\n LOG1 * 1.099763 +\n RELATIVE2 * -9.588311 +\n LOG_RELATIVE1 *-27.595303 +\n LOG_RELATIVE2 * -8.803761 +\n LOG_SUM_RELATIVE * 44.013138 +\n UP1 * 0.221622;\n //Then trim value to [0.4] range:\n if (VELOCITY < 0.)\n {\n VELOCITY = 0.;\n }\n if (VELOCITY > 4.)\n {\n VELOCITY = 4.;\n }\n //get it to 0. to 1. range\n VELOCITY = VELOCITY / 4.;\n // curve it exponentially\n VELOCITY = VELOCITY * VELOCITY;\n //get it to 0-126 range\n VELOCITY = VELOCITY * 126;\n //get it to 1-127 range\n VELOCITY = VELOCITY+ 1;\n //round to ints\n VELint = (int)VELOCITY;\n return VELint;\n}\n static const int AmberIndex = 0;\n static const int RedIndex = 10;\n static const int SliderIndex = 7;\n static const int ButtonIndex = 6;\n static const int ConfigIndex = 9;\n static const int AverageMaxSensorValues[53];\n int MaxSensorValues[53];\n uint8_t LastInReport[InPacketLen];\n uint8_t CurrentOutReport[OutPacketLen];\n bool VelocityWaiting[53];\n bool CentroidEnabled;\n bool MaximumEnabled;\n bool PadFrameEnabled;\n};"], ["/sapf/src/Play.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Play.hpp\"\n#include \n#include \n#include \n\n#include \"SoundFiles.hpp\"\n\npthread_mutex_t gPlayerMutex = PTHREAD_MUTEX_INITIALIZER;\n\nconst int kMaxChannels = 32;\n\nstruct AUPlayer* gAllPlayers = nullptr;\n\n\n\nstruct AUPlayer\n{\n\tAUPlayer(Thread& inThread, int inNumChannels, ExtAudioFileRef inXAFRef = nullptr)\n\t\t: th(inThread), count(0), done(false), prev(nullptr), next(gAllPlayers), outputUnit(nullptr), numChannels(inNumChannels), xaf(inXAFRef)\n\t{ \n\t\tgAllPlayers = this; \n\t\tif (next) next->prev = this; \n\t}\n\t\n\t~AUPlayer() {\n\t\tif (next) next->prev = prev;\n\n\t\tif (prev) prev->next = next;\n\t\telse gAllPlayers = next;\n\t\t\n\t\tif (xaf) {\n\t\t\tExtAudioFileDispose(xaf);\n\t\t\tchar cmd[1100];\n\t\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path.c_str());\n\t\t\tsystem(cmd);\n\t\t}\n\t}\n\t\n\tThread th;\n\tint count;\n\tbool done;\n\tAUPlayer* prev;\n\tAUPlayer* next;\n\tAudioComponentInstance outputUnit;\n\tint numChannels;\n\tZIn in[kMaxChannels];\n\tExtAudioFileRef xaf = nullptr;\n\tstd::string path;\n\t\n};\n\nstatic void stopPlayer(AUPlayer* player)\n{\n\tAudioComponentInstance outputUnit = player->outputUnit;\n\tplayer->outputUnit = nullptr;\n\tif (outputUnit) {\n\t\n\t\tOSStatus err = AudioOutputUnitStop(outputUnit);\n\t\tif (err) post(\"AudioOutputUnitStop err %d\\n\", (int)err);\n\t\terr = AudioComponentInstanceDispose(outputUnit);\n\t\tif (err) post(\"AudioComponentInstanceDispose outputUnit err %d\\n\", (int)err);\n\t\t\n\t}\n\tdelete player;\n}\n\nvoid stopPlaying()\n{\n\tLocker lock(&gPlayerMutex);\n\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nvoid stopPlayingIfDone()\n{\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tif (player->done)\n\t\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nstatic void* stopDonePlayers(void* x)\n{\n\twhile(1) {\n\t\tsleep(1);\n\t\tstopPlayingIfDone();\n\t}\n\treturn nullptr;\n}\n\nbool gWatchdogRunning = false;\npthread_t watchdog;\n\nstatic bool fillBufferList(AUPlayer* player, int inNumberFrames, AudioBufferList* ioData)\n{\n\tif (player->done) {\nzeroAll:\n\t\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\t\tmemset((float*)ioData->mBuffers[i].mData, 0, inNumberFrames * sizeof(float));\n\t\t}\n\t\treturn true;\n\t}\n\tZIn* in = player->in;\n\tbool done = true;\n\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\tint n = inNumberFrames;\n\t\tif (i >= player->numChannels) {\n\t\t\tmemset(ioData->mBuffers[i].mData, 0, ioData->mBuffers[i].mDataByteSize);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfloat* buf = (float*)ioData->mBuffers[i].mData;\n\t\t\t\tbool imdone = in[i].fill(player->th, n, buf, 1);\n\t\t\t\tif (n < inNumberFrames) {\n\t\t\t\t\tmemset((float*)ioData->mBuffers[i].mData + n, 0, (inNumberFrames - n) * sizeof(float));\n\t\t\t\t}\n\t\t\t\tdone = done && imdone;\n\t\t\t} catch (int err) {\n\t\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t\t} else {\n\t\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t\t}\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (std::bad_alloc& xerr) {\n\t\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (...) {\n\t\t\t\tpost(\"\\nunknown error\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn done;\n}\n\nstatic void recordPlayer(AUPlayer* player, int inNumberFrames, AudioBufferList const* inData)\n{\n\tif (!player->xaf) return;\n\t\t\n\tOSStatus err = ExtAudioFileWriteAsync(player->xaf, inNumberFrames, inData); // initialize async.\n\tif (err) printf(\"ExtAudioFileWriteAsync err %d\\n\", (int)err);\n}\n\nstatic OSStatus inputCallback(\tvoid *\t\t\t\t\t\t\tinRefCon,\n\t\t\t\t\t\tAudioUnitRenderActionFlags *\tioActionFlags,\n\t\t\t\t\t\tconst AudioTimeStamp *\t\t\tinTimeStamp,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinBusNumber,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinNumberFrames,\n\t\t\t\t\t\tAudioBufferList *\t\t\t\tioData)\n{\n\t\n\tAUPlayer* player = (AUPlayer*)inRefCon;\n\t\t\n\tbool done = fillBufferList(player, inNumberFrames, ioData);\n\trecordPlayer(player, inNumberFrames, ioData);\n\n\tif (done) {\n\t\tplayer->done = true;\n\t}\n\treturn noErr;\n}\n\n\nstatic AudioComponentInstance openAU(UInt32 inType, UInt32 inSubtype, UInt32 inManuf)\n{\n AudioComponentDescription desc;\n desc.componentType = inType;\n desc.componentSubType = inSubtype;\n desc.componentManufacturer = inManuf;\n desc.componentFlags = 0;\n desc.componentFlagsMask = 0;\n\n AudioComponent comp = AudioComponentFindNext(nullptr, &desc);\n\tif (!comp) {\n\t\treturn nullptr;\n\t}\n\n AudioComponentInstance au = nullptr;\n AudioComponentInstanceNew(comp, &au);\n\t\n\treturn au;\n}\n\nstatic OSStatus createGraph(AUPlayer* player)\n{\n OSStatus err = noErr;\n\tAudioComponentInstance outputUnit = openAU('auou', 'def ', 'appl');\n\tif (!outputUnit) {\n\t\tpost(\"open output unit failed\\n\");\n\t\treturn 'fail';\n\t}\n\t\n\tplayer->outputUnit = outputUnit;\n\t\n\tUInt32 flags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;\n\tAudioStreamBasicDescription fmt = { vm.ar.sampleRate, kAudioFormatLinearPCM, flags, 4, 1, 4, (UInt32)player->numChannels, 32, 0 };\n\t\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &fmt, sizeof(fmt));\n\tif (err) {\n\t\tpost(\"set outputUnit client format failed\\n\");\n\t\treturn err;\n\t}\n\t\n\tAURenderCallbackStruct cbs;\n\t\t\n\tcbs.inputProc = inputCallback;\n\tcbs.inputProcRefCon = player;\n\t\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &cbs, sizeof(cbs));\n\tif (err) {\n\t\tpost(\"set render callback failed\\n\");\n\t\treturn err;\n\t}\n\t\n\terr = AudioUnitInitialize(outputUnit);\n\tif (err) {\n\t\tpost(\"initialize output unit failed\\n\");\n\t\treturn err;\n\t}\n\t\n\terr = AudioOutputUnitStart(outputUnit);\n\tif (err) {\n\t\tpost(\"start output unit failed\\n\");\n\t\treturn err;\n\t}\n\t\n\tpost(\"start output unit OK\\n\");\n\t\n\treturn noErr;\n}\n\nvoid playWithAudioUnit(Thread& th, V& v)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\t\n\tif (v.isZList()) {\n\t\tplayer = new AUPlayer(th, 1);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint asize = (int)a->size();\n\t\t\n\t\tplayer = new AUPlayer(th, asize);\n\t\tfor (int i = 0; i < asize; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n \n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n\nvoid recordWithAudioUnit(Thread& th, V& v, Arg filename)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\n\tchar path[1024];\n\tExtAudioFileRef xaf = nullptr;\n\t\n\tif (v.isZList()) {\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, 1, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\n\t\tplayer = new AUPlayer(th, 1, xaf);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint numChannels = (int)a->size();\n\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, numChannels, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tplayer = new AUPlayer(th, numChannels, xaf);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n\n\tplayer->path = path;\n\n\t{\n\t\tOSStatus err = ExtAudioFileWriteAsync(xaf, 0, nullptr); // initialize async.\n\t\tif (err) printf(\"init ExtAudioFileWriteAsync err %d\\n\", (int)err);\n }\n\t\n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n"], ["/sapf/src/main.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \n#include \n#include \n#include \n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \"Manta.h\"\n\nclass MyManta : public Manta\n{\n\tvirtual void PadEvent(int row, int column, int id, int value) {\n\t\tprintf(\"pad %d %d %d %d\\n\", row, column, id, value);\n\t}\n\tvirtual void SliderEvent(int id, int value) {\n\t\tprintf(\"slider %d %d\\n\", id, value);\n\t}\n\tvirtual void ButtonEvent(int id, int value) {\n\t\tprintf(\"button %d %d\\n\", id, value);\n\t}\n\tvirtual void PadVelocityEvent(int row, int column, int id, int velocity) {\n\t\tprintf(\"pad vel %d %d %d %d\\n\", row, column, id, velocity);\n\n\t}\n\tvirtual void ButtonVelocityEvent(int id, int velocity) {\n\t\tprintf(\"button vel %d %d\\n\", id, velocity);\n\t}\n\tvirtual void FrameEvent(uint8_t *frame) {}\n\tvirtual void DebugPrint(const char *fmt, ...) {}\n};\n\nManta* manta();\nManta* manta()\n{\n\tstatic MyManta* sManta = new MyManta();\n\treturn sManta;\n}\n\n/* issue:\n\n[These comments are very old and I have not checked if they are still relevant.]\n\nTableData alloc should use new\n\nbugs:\n\nitd should have a tail time. currently the ugen stops as soon as its input, cutting off the delayed signal.\n\n+ should not stop until both inputs stop?\nother additive binops: - avg2 sumsq\n\nno, use a operator \n\n---\n\nadsrg (gate a d s r --> out) envelope generator with gate. \nadsr (dur a d s r --> out) envelope generator with duration. \nevgg - (gate levels times curves suspt --> out) envelope generator with gate. suspt is the index of the sustain level. \nevg - (dur levels times curves suspt --> out) envelope generator with duration. suspt is the index of the sustain level.\n\nblip (freq phase nharm --> out) band limited impulse oscillator.\ndsf1 (freq phase nharm lharm hmul --> out) sum of sines oscillator.\n\nformant (freq formfreq bwfreq --> out) formant oscillator\n\nsvf (in freq rq --> [lp hp bp bs]) state variable filter.\nmoogf (in freq rq --> out) moog ladder low pass filter.\n\n*/\n\nextern void AddCoreOps();\nextern void AddMathOps();\nextern void AddStreamOps();\nextern void AddLFOps();\nextern void AddUGenOps();\nextern void AddSetOps();\nextern void AddRandomOps();\nextern void AddMidiOps();\n\nconst char* gVersionString = \"0.1.21\";\n\nstatic void usage()\n{\n\tfprintf(stdout, \"sapf [-r sample-rate][-p prelude-file]\\n\");\n\tfprintf(stdout, \"\\n\");\n\tfprintf(stdout, \"sapf [-h]\\n\");\n\tfprintf(stdout, \" print this help\\n\");\n\tfprintf(stdout, \"\\n\");\t\n}\n\nint main (int argc, const char * argv[]) \n{\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"A tool for the expression of sound as pure form.\\n\");\t\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"--- version %s\\n\", gVersionString);\n\t\n\tfor (int i = 1; i < argc;) {\n\t\tint c = argv[i][0];\n\t\tif (c == '-') {\n\t\t\tc = argv[i][1];\n\t\t\tswitch (c) {\n\t\t\t\tcase 'r' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected sample rate after -r\\n\"); return 1; }\n\t\t\t\t\t\t\n\t\t\t\t\tdouble sr = atof(argv[i+1]);\n\t\t\t\t\tif (sr < 1000. || sr > 768000.) { post(\"sample rate out of range.\\n\"); return 1; }\n\t\t\t\t\tvm.setSampleRate(sr);\n\t\t\t\t\tpost(\"sample rate set to %g\\n\", vm.ar.sampleRate);\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'p' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected prelude file name after -p\\n\"); return 1; }\n\t\t\t\t\tvm.prelude_file = argv[i+1];\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'h' : {\n\t\t\t\t\tusage();\n\t\t\t\t\texit(0);\n\t\t\t\t} break;\n\t\t\t\tdefault: \n\t\t\t\t\tpost(\"unrecognized option -%c\\n\", c);\n\t\t\t}\n\t\t} else {\n\t\t\tpost(\"expected option, got \\\"%s\\\"\\n\", argv[i]);\n\t\t\t++i;\n\t\t}\n\t}\n\t\n\t\n\tvm.addBifHelp(\"Argument Automapping legend:\");\n\tvm.addBifHelp(\" a - as is. argument is not automapped.\");\n\tvm.addBifHelp(\" z - argument is expected to be a signal or scalar, streams are auto mapped.\");\n\tvm.addBifHelp(\" k - argument is expected to be a scalar, signals and streams are automapped.\");\n\tvm.addBifHelp(\"\");\n\t\n\tAddCoreOps();\n\tAddMathOps();\n\tAddStreamOps();\n AddRandomOps();\n\tAddUGenOps();\n\tAddMidiOps();\n AddSetOps();\n\t\n\t\n\tvm.log_file = getenv(\"SAPF_LOG\");\n\tif (!vm.log_file) {\n\t\tconst char* home_dir = getenv(\"HOME\");\n\t\tchar logfilename[PATH_MAX];\n\t\tsnprintf(logfilename, PATH_MAX, \"%s/sapf-log.txt\", home_dir);\n\t\tvm.log_file = strdup(logfilename);\n\t}\n\t\n\t__block Thread th;\n\n\tauto m = manta();\n\ttry {\n\t\tm->Connect();\n\t} catch(...) {\n\t}\n\tprintf(\"Manta %s connected.\\n\", m->IsConnected() ? \"is\" : \"IS NOT\");\n\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\t/*** see at bottom for better way ***/\n\t\twhile(true) {\n\t\t\ttry {\n\t\t\t\tMantaUSB::HandleEvents();\n\t\t\t\tusleep(5000);\n\t\t\t} catch(...) {\n\t\t\t\tsleep(1);\n\t\t\t}\n\t\t}\n\t});\n\t\n\tif (!vm.prelude_file) {\n\t\tvm.prelude_file = getenv(\"SAPF_PRELUDE\");\n\t}\n\tif (vm.prelude_file) {\n\t\tloadFile(th, vm.prelude_file);\n\t}\n\t\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\tth.repl(stdin, vm.log_file);\n\t\texit(0);\n\t});\n\t\n\tCFRunLoopRun();\n\t\n\treturn 0;\n}\n\n"], ["/sapf/src/SetOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n\nstruct SetPair\n{\n\tV mValue;\n\tint mIndex;\n};\n\nclass Set : public Object\n{\n\tint mSize;\n\tint mCap;\n\tint* mIndices;\n\tSetPair* mPairs;\n\t\n\tvoid grow(Thread& th);\n\tvoid alloc(int cap);\n \n\tSet(const Set& that) {}\npublic:\n\t\n\tSet(int capacity) { alloc(capacity); }\n Set(Thread& th, P list) { alloc(32); putAll(th, list); }\n \n\tvirtual ~Set();\n\t\n\tvirtual const char* TypeName() const override { return \"Set\"; }\n \n\tvirtual bool isSet() const override { return true; }\n\tvirtual bool Equals(Thread& th, Arg v) override;\n\t\n\tint size() { return mSize; }\n\t\n\tbool has(Thread& th, V& value);\n int indexOf(Thread& th, V& value);\n\t\n\tvoid put(Thread& th, V& inValue, int inIndex);\n \n void putAll(Thread& th, P& list);\n\t\n\tvirtual V at(int64_t i) override { return mPairs[i].mValue; }\n \n P asVList(Thread& th);\n P asZList(Thread& th);\n};\n\n\nbool Set::Equals(Thread& th, Arg v) \n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isSet()) return false;\n\tif (this == v.o()) return true;\n\tSet* that = (Set*)v.o();\n\tif (mSize != that->size()) return false;\n \n\tfor (int64_t i = 0; i < mSize; ++i) {\n\t\tV& value = mPairs[i].mValue;\n\t\tV u;\n\t\tif (!that->has(th, value)) return false;\n\t}\n \n\treturn true;\n}\n\nbool Set::has(Thread& th, V& value) \n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn false;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn true;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn false;\n}\n\nint Set::indexOf(Thread& th, V& value)\n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn -1;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn pairs[index2].mIndex;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn -1;\n}\n\n\nSet::~Set()\n{\n\tdelete [] mPairs;\n\tfree(mIndices);\n}\n\nvoid Set::alloc(int cap)\n{\n\tcap = NEXTPOWEROFTWO(cap);\n\tmPairs = new SetPair[cap];\n\tmIndices = (int*)calloc(2 * cap, sizeof(int));\n\tmCap = cap;\n\tmSize = 0;\n}\n\nvoid Set::grow(Thread& th)\n{\n\tfree(mIndices);\n \n\tSetPair* oldPairs = mPairs;\n\tint oldSize = mSize;\n \n\talloc(mCap * 2);\n\t\n\tfor (int i = 0; i < oldSize; ++i) {\n\t\tSetPair& pair = oldPairs[i];\n\t\tput(th, pair.mValue, pair.mIndex);\n\t}\n\t\n\tdelete [] oldPairs;\n}\n\nvoid Set::put(Thread& th, V& inValue, int inIndex)\n{\n\tif (mSize == mCap) {\n\t\tgrow(th);\n\t}\n \n\tint hash = inValue.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n \n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\tindex2 = mSize++;\n\t\t\tindices[index] = index2+1;\n\t\t\tpairs[index2].mValue = inValue;\n\t\t\tpairs[index2].mIndex = inIndex;\n\t\t\treturn;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (inValue.Equals(th, testVal)) {\n\t\t\treturn;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\n}\n\nvoid Set::putAll(Thread& th, P& in)\n{\n // caller must ensure that in is finite.\n int64_t insize = in->length(th);\n in = in->pack(th);\n for (int i = 0; i < insize; ++i) {\n V val = in->at(i);\n put(th, val, i);\n }\n}\n\n\nP Set::asVList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeV, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nP Set::asZList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeZ, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nstatic P nub(Thread& th, P in)\n{\n P set = new Set(th, in);\n \n return set->asVList(th);\n}\n\n\nstatic P set_or(Thread& th, P a, P b)\n{\n P set = new Set(32);\n\n set->putAll(th, a);\n set->putAll(th, b);\n return a->isZ() && b->isZ() ? set->asZList(th) : set->asVList(th);\n}\n\nstatic P set_and(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_minus(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_xor(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n for (int64_t i = 0; i < setB->size(); ++i) {\n V v = setB->at(i);\n if (!setA->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic bool subset(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) return false;\n }\n\t\n\treturn true;\n}\n\nstatic bool set_equals(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n\treturn setA->Equals(th, setB);\n}\n\n/* \n \n list minus values from set.\n \n \n \n\n \n \n \n*/\n\n\nstatic void nub_(Thread& th, Prim* prim)\n{\n P a = th.popList(\"nub : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"nub : a\", \"\");\n \n th.push(nub(th, a));\n}\n\nstatic void set_or_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"|| : b\");\n if (!b->isFinite())\n indefiniteOp(\"|| : b\", \"\");\n \n P a = th.popList(\"|| : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"|| : a\", \"\");\n \n th.push(set_or(th, a, b));\n}\n\nstatic void set_and_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"&& : b\");\n if (!b->isFinite())\n indefiniteOp(\"&& : b\", \"\");\n \n P a = th.popList(\"&& : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"&& : a\", \"\");\n \n th.push(set_and(th, a, b));\n}\n\n\nstatic void set_xor_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_xor : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_xor : b\", \"\");\n \n P a = th.popList(\"set_xor : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_xor : a\", \"\");\n \n th.push(set_xor(th, a, b));\n}\n\nstatic void set_minus_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_minus : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_minus : b\", \"\");\n \n P a = th.popList(\"set_minus : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_minus : a\", \"\");\n \n th.push(set_minus(th, a, b));\n}\n\nstatic void subset_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"subset : b\");\n if (!b->isFinite())\n indefiniteOp(\"subset : b\", \"\");\n \n P a = th.popList(\"subset : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"subset : a\", \"\");\n \n th.pushBool(subset(th, a, b));\n}\n\n\nstatic void set_equals_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_equals : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_equals : b\", \"\");\n \n P a = th.popList(\"set_equals : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_equals : a\", \"\");\n \n th.push(set_equals(th, a, b));\n}\n\nstruct FindV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tFindV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->indexOf(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct FindZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tFindZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeZ, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->indexOf(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct SetHasV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tSetHasV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->has(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct SetHasZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tSetHasZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->has(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic V findBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new FindZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new FindV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->indexOf(th, a);\n\t}\n\treturn result;\n}\n\nstatic void find_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"find : list\");\n if (!b->isFinite())\n indefiniteOp(\"find : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(findBase(th, a, setB));\n}\n\nstatic V hasBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new SetHasZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new SetHasV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->has(th, a);\n\t}\n\treturn result;\n}\n\nstatic void sethas_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"Shas : list\");\n if (!b->isFinite())\n indefiniteOp(\"Shas : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(hasBase(th, a, setB));\n}\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddSetOps();\nvoid AddSetOps()\n{\n\tvm.addBifHelp(\"\\n*** set operations ***\");\n vm.def(\"S\", 1, 1, nub_, \"(list --> set) removes all duplicates from a finite list.\");\n vm.def(\"S|\", 2, 1, set_or_, \"(listA listB --> set) returns the set union of the elements of lists A and B.\");\n vm.def(\"S&\", 2, 1, set_and_, \"(listA listB --> set) returns the set intersection of the elements of lists A and B.\");\n vm.def(\"Sx\", 2, 1, set_xor_, \"(listA listB --> set) returns the set of the elements which occur in list A or B, but not both.\");\n vm.def(\"S-\", 2, 1, set_minus_, \"(listA listB --> set) returns the set of the elements of listA which do not occur in listB.\");\n vm.def(\"S=\", 2, 1, set_equals_, \"(listA listB --> set) returns 1 if the set of elements in listA is equal to the set of elements in listB.\");\n vm.def(\"subset?\", 2, 1, subset_, \"(listA listB --> set) returns 1 if the set of elements of listA is a subset of the set of elements of listB. else 0.\");\n vm.def(\"find\", 2, 1, find_, \"(item(s) list --> set) returns index of item in finite list, or -1 if not in list.\");\n vm.def(\"Shas\", 2, 1, sethas_, \"(item(s) list --> set) returns 1 if finite list contains item(s), else 0.\");\n}\n\n\n\n\n\n\n"], ["/sapf/src/MathFuns.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathFuns.hpp\"\n#include \"VM.hpp\"\n\ndouble gSineTable[kSineTableSize+1];\ndouble gDBAmpTable[kDBAmpTableSize+2];\ndouble gDecayTable[kDecayTableSize+1];\ndouble gFirstOrderCoeffTable[kFirstOrderCoeffTableSize+1];\n\n\ninline double freqToTableF(double freq)\n{\n\treturn std::clamp(3. * log2(freq * .05), 0., 28.999);\n}\n\nZ gFreqToTable[20001];\n\nstatic void initFreqToTable()\n{\n\tfor (int freq = 0; freq < 20001; ++freq) {\n\t\tgFreqToTable[freq] = freqToTableF(freq);\n\t}\n}\n\ninline double freqToTable(double freq)\n{\n\tdouble findex = std::clamp(freq, 0., 20000.);\n\tdouble iindex = floor(findex);\n\treturn lut(gFreqToTable, (int)iindex, findex - iindex);\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\nvoid fillSineTable()\n{\n\tfor (int i = 0; i < kSineTableSize; ++i) {\n\t\tgSineTable[i] = sin(gSineTableOmega * i);\n\t}\n\tgSineTable[kSineTableSize] = gSineTable[0];\n}\n\nvoid fillDBAmpTable()\n{\n\tfor (int i = 0; i < kDBAmpTableSize+2; ++i) {\n\t\tdouble dbgain = i * kInvDBAmpScale - kDBAmpOffset;\n\t\tdouble amp = pow(10., .05 * dbgain);\n\t\tgDBAmpTable[i] = amp;\n\t}\n}\n\nvoid fillDecayTable()\n{\n\tfor (int i = 0; i < kDecayTableSize+1; ++i) {\n\t\tgDecayTable[i] = exp(log001 * i * .001);\n\t}\t\n}\n\nvoid fillFirstOrderCoeffTable()\n{\n\tdouble k = M_PI * kInvFirstOrderCoeffTableSize;\n\tfor (int i = 0; i < kFirstOrderCoeffTableSize+1; ++i) {\n\t\tdouble x = k * i;\n\t\tZ b = 2. - cos(x);\n\t\tgFirstOrderCoeffTable[i] = b - sqrt(b*b - 1.);\n\t}\t\n}\n\n\n"], ["/sapf/src/Opcode.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Opcode.hpp\"\n#include \"clz.hpp\"\n\nconst char* opcode_name[kNumOpcodes] = \n{\n\t\"BAD OPCODE\",\n\t\"opNone\",\n\t\"opPushImmediate\",\n\t\"opPushLocalVar\",\n\t\"opPushFunVar\",\n\t\"opPushWorkspaceVar\",\n\t\n\t\"opPushFun\",\n\n\t\"opCallImmediate\",\n\t\"opCallLocalVar\",\n\t\"opCallFunVar\",\n\t\"opCallWorkspaceVar\",\n\n\t\"opDot\",\n\t\"opComma\",\n\t\"opBindLocal\",\n\t\"opBindLocalFromList\",\n\t\"opBindWorkspaceVar\",\n\t\"opBindWorkspaceVarFromList\",\n\t\n\t\"opParens\",\n\t\"opNewVList\",\n\t\"opNewZList\",\n\t\"opNewForm\",\n\t\"opInherit\",\n\t\"opEach\",\n\t\"opReturn\"\n};\n\n\nstatic void printOpcode(Thread& th, Opcode* c)\n{\n\tV& v = c->v;\n\tpost(\"%p %s \", c, opcode_name[c->op]);\n\tswitch (c->op) {\n\t\tcase opPushImmediate :\n\t\tcase opPushWorkspaceVar :\n\t\tcase opPushFun : \n\t\tcase opCallImmediate :\n\t\tcase opCallWorkspaceVar :\n\t\tcase opDot :\n\t\tcase opComma :\n\t\tcase opInherit :\n\t\tcase opNewForm :\n\t\tcase opBindWorkspaceVar :\n\t\tcase opBindWorkspaceVarFromList :\n\t\tcase opParens :\n\t\tcase opNewVList : \n\t\tcase opNewZList : \n\t\t\tv.printShort(th);\n\t\t\tbreak;\n\t\t\t\n\t\tcase opPushLocalVar :\n\t\tcase opPushFunVar :\n\t\tcase opCallLocalVar :\n\t\tcase opCallFunVar :\n\t\tcase opBindLocal :\n\t\tcase opBindLocalFromList :\n\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\tbreak;\n\t\tcase opEach :\n\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\tbreak;\n\t\t\n\t\tcase opNone :\n\t\tcase opReturn : \n\t\t\tbreak;\n\t\t\n\t\tdefault :\n\t\t\tpost(\"BAD OPCODE\\n\");\n\t}\n\tpost(\"\\n\");\n}\n\nvoid Thread::run(Opcode* opc)\n{\n\tThread& th = *this;\n\ttry {\n\t\tfor (;;++opc) {\n\n\t\t\tV& v = opc->v;\n\n\t\t\tif (vm.traceon) {\n\t\t\t\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n\t\t\t\tprintOpcode(th, opc);\n\t\t\t}\n\n\t\t\tswitch (opc->op) {\n\t\t\t\tcase opNone :\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushImmediate :\n\t\t\t\t\tpush(v);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushLocalVar :\n\t\t\t\t\tpush(getLocal(v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFunVar :\n\t\t\t\t\tpush(fun->mVars[v.i]);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushWorkspaceVar :\n\t\t\t\t\tpush(fun->Workspace()->mustGet(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFun : {\n\t\t\t\t\t\tpush(new Fun(th, (FunDef*)v.o()));\n\t\t\t\t\t} break;\n\t\t\t\t\t\n\t\t\t\tcase opCallImmediate :\n\t\t\t\t\tv.apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallLocalVar :\n\t\t\t\t\tgetLocal(v.i).apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallFunVar :\n\t\t\t\t\tfun->mVars[v.i].apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallWorkspaceVar :\n\t\t\t\t\tfun->Workspace()->mustGet(th, v).apply(th);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase opDot : {\n\t\t\t\t\tV ioValue;\n\t\t\t\t\tif (!pop().dot(th, v, ioValue))\n\t\t\t\t\t\tnotFound(v);\n\t\t\t\t\tpush(ioValue);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase opComma :\n\t\t\t\t\tpush(pop().comma(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opBindLocal :\n\t\t\t\t\tgetLocal(v.i) = pop();\n\t\t\t\t\tbreak;\n\t\t\t\tcase opBindWorkspaceVar : {\n V value = pop();\n if (value.isList() && !value.isFinite()) {\n post(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n } else if (value.isFun()) {\n\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n } break;\n \n\t\t\t\tcase opBindLocalFromList :\n\t\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\t\t{\n\t\t\t\t\tV list = pop();\n\t\t\t\t\tBothIn in(list);\n\t\t\t\t\twhile (1) {\n\t\t\t\t\t\tif (opc->op == opNone) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tV value;\n\t\t\t\t\t\t\tif (in.one(th, value)) {\n\t\t\t\t\t\t\t\tpost(\"not enough items in list for = [..]\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (opc->op == opBindLocalFromList) {\n\t\t\t\t\t\t\t\tgetLocal(opc->v.i) = value;\n\t\t\t\t\t\t\t} else if (opc->op == opBindWorkspaceVarFromList) {\n\t\t\t\t\t\t\t\tv = opc->v;\n\t\t\t\t\t\t\t\tif (value.isList() && !value.isFinite()) {\n\t\t\t\t\t\t\t\t\tpost(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n\t\t\t\t\t\t\t\t} else if (value.isFun()) {\n\t\t\t\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++opc;\n\t\t\t\t\t}\n\t\t\t\t} break;\n\t\t\t\tcase opParens : {\n\t\t\t\t\t\tParenStack ss(th);\n\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewVList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newVList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewZList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newZList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opInherit : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tif (depth < 1) {\n\t\t\t\t\t\t\t\tresult = vm._ee;\n\t\t\t\t\t\t\t} else if (depth > 1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvm.inherit->apply_n(th, 1);\n\t\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewForm : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tTableMap* tmap = (TableMap*)th.top().o();\n\t\t\t\t\t\t\tsize_t numArgs = tmap->mSize;\n\t\t\t\t\t\t\tif (depth == numArgs+1) {\n\t\t\t\t\t\t\t\t// no inheritance, must insert zero for parent.\n\t\t\t\t\t\t\t\tth.tuck(numArgs+1, V(0.));\n\t\t\t\t\t\t\t} else if (depth < numArgs+1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"fewer arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errStackUnderflow;\n\t\t\t\t\t\t\t} else if (depth > numArgs+2) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvm.newForm->apply_n(th, numArgs+2);\n\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opEach :\n\t\t\t\t\tpush(new EachOp(pop(), (int)v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\tcase opReturn : return;\n\t\t\t\t\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t\t\t\tthrow errInternalError;\n\t\t\t}\n\t\t}\n\t} catch (...) {\n\t\tpost(\"backtrace: %s \", opcode_name[opc->op]);\n\t\topc->v.printShort(th);\n\t\tpost(\"\\n\");\n\t\tthrow;\n\t}\n}\n\nCode::~Code() { }\n\nvoid Code::shrinkToFit()\n{\n\tstd::vector(ops.begin(), ops.end()).swap(ops);\n}\n\nvoid Code::add(int _op, Arg v)\n{\n\tops.push_back(Opcode(_op, v));\n}\n\nvoid Code::add(int _op, double f)\n{\n\tadd(_op, V(f));\n}\n\nvoid Code::addAll(const P &that)\n{\n\tfor (Opcode& op : that->ops) {\n\t\tops.push_back(op);\n\t}\n}\n\nvoid Code::decompile(Thread& th, std::string& out)\n{\n\tfor (Opcode& c : ops) {\n\t\tV& v = c.v;\n\t\tswitch (c.op) {\n\t\t\tcase opPushImmediate : {\n\t\t\t\tstd::string s;\n\t\t\t\tv.printShort(th, s);\n\t\t\t\tout += s;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase opPushWorkspaceVar :\n\t\t\tcase opPushFun : \n\t\t\tcase opCallImmediate :\n\t\t\tcase opCallWorkspaceVar :\n\t\t\tcase opDot :\n\t\t\tcase opComma :\n\t\t\tcase opInherit :\n\t\t\tcase opNewForm :\n\t\t\tcase opBindWorkspaceVar :\n\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\tcase opParens :\n\t\t\tcase opNewVList : \n\t\t\tcase opNewZList : \n\t\t\t\tv.printShort(th);\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\tcase opPushLocalVar :\n\t\t\tcase opPushFunVar :\n\t\t\tcase opCallLocalVar :\n\t\t\tcase opCallFunVar :\n\t\t\tcase opBindLocal :\n\t\t\tcase opBindLocalFromList :\n\t\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\tcase opEach :\n\t\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase opNone :\n\t\t\tcase opReturn : \n\t\t\t\tbreak;\n\t\t\t\n\t\t\tdefault :\n\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t}\n\t}\n}\n\n"], ["/sapf/libmanta/MantaUSB.h", "class MantaUSB {\n public:\n MantaUSB(void) {\n mantaList.push_back(this);\n MantaIndex = int(mantaList.size());\n\n DebugPrint(\"%s-%d: Manta %d initialized\", __FILE__, __LINE__, MantaIndex);\n}\n virtual ~MantaUSB(void) {\n Disconnect();\n mantaList.remove(this);\n if(mantaList.empty())\n {\n hid_exit();\n }\n}\n void WriteFrame(uint8_t *frame, bool forceQueued) {\n if(NULL == DeviceHandle)\n {\n throw(MantaNotConnectedException(this));\n }\n MantaTxQueueEntry *queuedMessage = GetQueuedTxMessage();\n if(queuedMessage && !forceQueued)\n {\n /* replace the queued packet payload with the new one */\n for(int i = 0; i < OutPacketLen; ++i)\n {\n /* the first byte of the report is the report ID (0x00) */\n queuedMessage->OutFrame[i+1] = frame[i];\n }\n DebugPrint(\"%s-%d: (WriteFrame) Queued Transfer overwritten on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n else\n {\n /* no transfer in progress, queue up a new one */\n MantaTxQueueEntry *newMessage = new MantaTxQueueEntry;\n newMessage->OutFrame[0] = 0;\n newMessage->TargetManta = this;\n /* the first byte of the report is the report ID (0x00) */\n memcpy(newMessage->OutFrame + 1, frame, OutPacketLen);\n txQueue.push_back(newMessage);\n DebugPrint(\"%s-%d: (WriteFrame) Transfer Queued on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n}\n bool IsConnected(void) {\n return DeviceHandle != NULL;\n}\n void Connect(int connectionSerial = 0) {\n#define SERIAL_STRING_SIZE 32\n wchar_t serialString[SERIAL_STRING_SIZE];\n\n if(IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Attempting to Connect to Manta %d...\",\n __FILE__, __LINE__, connectionSerial);\n if(connectionSerial)\n {\n swprintf(serialString, SERIAL_STRING_SIZE, L\"%d\", connectionSerial);\n DeviceHandle = hid_open(VendorID, ProductID, serialString);\n }\n else\n {\n DeviceHandle = hid_open(VendorID, ProductID, NULL);\n }\n if(NULL == DeviceHandle)\n throw(MantaNotFoundException());\n hid_get_serial_number_string(DeviceHandle, serialString, SERIAL_STRING_SIZE);\n SerialNumber = int(wcstol(serialString, NULL, 10));\n int rc = hid_set_nonblocking(DeviceHandle, 1);\n printf(\"hid_set_nonblocking %d\\n\", rc);\n printf(\"SerialNumber %d\\n\", SerialNumber);\n}\n void Disconnect() {\n if(! IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Manta %d Disconnecting...\", __FILE__, __LINE__, GetSerialNumber());\n hid_close(DeviceHandle);\n DeviceHandle = NULL;\n}\n int GetSerialNumber(void) {\n return SerialNumber;\n}\n int GetHardwareVersion(void) {\n return (SerialNumber < 70) ? 1 : 2;\n}\n bool MessageQueued(void) {\n return GetQueuedTxMessage() != NULL;\n}\n static void HandleEvents(void) {\n list::iterator i = mantaList.begin();\n /* read from each manta and trigger any events */\n while(mantaList.end() != i)\n {\n MantaUSB *current = *i;\n if(current->IsConnected())\n {\n int bytesRead;\n int8_t inFrame[InPacketLen];\n\n bytesRead = hid_read(current->DeviceHandle,\n reinterpret_cast(inFrame), InPacketLen);\n if(bytesRead < 0)\n {\n current->DebugPrint(\"%s-%d: Read error on Manta %d\",\n __FILE__, __LINE__, current->GetSerialNumber());\n throw(MantaCommunicationException(current));\n }\n else if(bytesRead)\n {\n current->FrameReceived(inFrame);\n }\n }\n ++i;\n }\n\n /* pop one item off the transmit queue and send down to its target */\n if(! txQueue.empty())\n {\n int bytesWritten;\n MantaTxQueueEntry *txMessage = txQueue.front();\n txQueue.pop_front();\n bytesWritten = hid_write(txMessage->TargetManta->DeviceHandle,\n txMessage->OutFrame, OutPacketLen + 1);\n txMessage->TargetManta->DebugPrint(\"%s-%d: Frame Written to Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n for(int j = 0; j < 16; j += 8)\n {\n uint8_t *frame = txMessage->OutFrame + 1;\n txMessage->TargetManta->DebugPrint(\"\\t\\t%x %x %x %x %x %x %x %x\",\n frame[j], frame[j+1], frame[j+2], frame[j+3], frame[j+4],\n frame[j+5], frame[j+6], frame[j+7]);\n }\n delete txMessage;\n if(bytesWritten < 0)\n {\n txMessage->TargetManta->DebugPrint(\"%s-%d: Write error on Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n throw(MantaCommunicationException(txMessage->TargetManta));\n }\n }\n}\n protected:\n virtual void FrameReceived(int8_t *frame) = 0;\n static const int OutPacketLen = 16;\n static const int InPacketLen = 64;\n int SerialNumber;\n int MantaIndex;\n private:\n struct MantaTxQueueEntry\n {\n MantaUSB *TargetManta;\n uint8_t OutFrame[17];\n };\n MantaTxQueueEntry *GetQueuedTxMessage();\n static const int Interface = 0;\n static const int EndpointIn = 0x81;\n static const int EndpointOut = 0x02;\n static const int Timeout = 5000;\n static const int VendorID = 0x2424;\n static const int ProductID = 0x2424;\n hid_device *DeviceHandle;\n static list mantaList;\n static list txQueue;\n};"], ["/sapf/src/symbol.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"symbol.hpp\"\n#include \"VM.hpp\"\n#include \"Hash.hpp\"\n#include \n#include \n\nconst int kSymbolTableSize = 4096;\nconst int kSymbolTableMask = kSymbolTableSize - 1;\n\t\n// global atomic symbol table\nvolatile std::atomic sSymbolTable[kSymbolTableSize];\n\n\n\nstatic String* SymbolTable_lookup(String* list, const char* name, int32_t hash)\n{\n\twhile (list) {\n\t\tif (list->hash == hash && strcmp(list->s, name) == 0)\n\t\t\treturn list;\n\t\tlist = list->nextSymbol;\n\t}\n\treturn nullptr;\n}\n\nstatic String* SymbolTable_lookup(const char* name, int hash)\n{\n\treturn SymbolTable_lookup(sSymbolTable[hash & kSymbolTableMask].load(), name, hash);\n}\n\nstatic String* SymbolTable_lookup(const char* name)\n{\n\tuintptr_t hash = Hash(name);\n\treturn SymbolTable_lookup(name, (int)hash);\n}\n\nP getsym(const char* name)\n{\n\t// thread safe\n\n\tint32_t hash = Hash(name);\n int32_t binIndex = hash & kSymbolTableMask;\n\tvolatile std::atomic* bin = &sSymbolTable[binIndex];\n\twhile (1) {\n // get the head of the list.\n\t\tString* head = bin->load();\n // search the list for the symbol\n\t\tString* existingSymbol = head;\n\t\twhile (existingSymbol) {\n\t\t\tif (existingSymbol->hash == hash && strcmp(existingSymbol->s, name) == 0) {\n\t\t\t\treturn existingSymbol;\n\t\t\t}\n\t\t\texistingSymbol = existingSymbol->nextSymbol;\n\t\t}\n\t\tString* newSymbol = new String(name, hash, head);\n\t\tif (bin->compare_exchange_weak(head, newSymbol)) {\n\t\t\tnewSymbol->retain(); \n\t\t\treturn newSymbol;\n\t\t}\n delete newSymbol;\n\t}\t\n}\n"], ["/sapf/libmanta/extern/hidapi/hidapi/hidapi.h", "/*******************************************************\n HIDAPI - Multi-Platform library for\n communication with HID devices.\n\n Alan Ott\n Signal 11 Software\n\n 8/22/2009\n\n Copyright 2009, All Rights Reserved.\n\n At the discretion of the user of this library,\n this software may be licensed under the terms of the\n GNU Public License v3, a BSD-Style license, or the\n original HIDAPI license as outlined in the LICENSE.txt,\n LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt\n files located at the root of the source distribution.\n These files may also be found in the public source\n code repository located at:\n http://github.com/signal11/hidapi .\n********************************************************/\n\n/** @file\n * @defgroup API hidapi API\n */\n\n#ifndef HIDAPI_H__\n#define HIDAPI_H__\n\n#include \n\n#ifdef _WIN32\n #define HID_API_EXPORT __declspec(dllexport)\n #define HID_API_CALL\n#else\n #define HID_API_EXPORT /**< API export macro */\n #define HID_API_CALL /**< API call macro */\n#endif\n\n#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\t\tstruct hid_device_;\n\t\ttypedef struct hid_device_ hid_device; /**< opaque hidapi structure */\n\n\t\t/** hidapi info structure */\n\t\tstruct hid_device_info {\n\t\t\t/** Platform-specific device path */\n\t\t\tchar *path;\n\t\t\t/** Device Vendor ID */\n\t\t\tunsigned short vendor_id;\n\t\t\t/** Device Product ID */\n\t\t\tunsigned short product_id;\n\t\t\t/** Serial Number */\n\t\t\twchar_t *serial_number;\n\t\t\t/** Device Release Number in binary-coded decimal,\n\t\t\t also known as Device Version Number */\n\t\t\tunsigned short release_number;\n\t\t\t/** Manufacturer String */\n\t\t\twchar_t *manufacturer_string;\n\t\t\t/** Product string */\n\t\t\twchar_t *product_string;\n\t\t\t/** Usage Page for this Device/Interface\n\t\t\t (Windows/Mac only). */\n\t\t\tunsigned short usage_page;\n\t\t\t/** Usage for this Device/Interface\n\t\t\t (Windows/Mac only).*/\n\t\t\tunsigned short usage;\n\t\t\t/** The USB interface which this logical device\n\t\t\t represents. Valid on both Linux implementations\n\t\t\t in all cases, and valid on the Windows implementation\n\t\t\t only if the device contains more than one interface. */\n\t\t\tint interface_number;\n\n\t\t\t/** Pointer to the next device */\n\t\t\tstruct hid_device_info *next;\n\t\t};\n\n\n\t\t/** @brief Initialize the HIDAPI library.\n\n\t\t\tThis function initializes the HIDAPI library. Calling it is not\n\t\t\tstrictly necessary, as it will be called automatically by\n\t\t\thid_enumerate() and any of the hid_open_*() functions if it is\n\t\t\tneeded. This function should be called at the beginning of\n\t\t\texecution however, if there is a chance of HIDAPI handles\n\t\t\tbeing opened by different threads simultaneously.\n\t\t\t\n\t\t\t@ingroup API\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_init(void);\n\n\t\t/** @brief Finalize the HIDAPI library.\n\n\t\t\tThis function frees all of the static data associated with\n\t\t\tHIDAPI. It should be called at the end of execution to avoid\n\t\t\tmemory leaks.\n\n\t\t\t@ingroup API\n\n\t\t @returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_exit(void);\n\n\t\t/** @brief Enumerate the HID Devices.\n\n\t\t\tThis function returns a linked list of all the HID devices\n\t\t\tattached to the system which match vendor_id and product_id.\n\t\t\tIf @p vendor_id and @p product_id are both set to 0, then\n\t\t\tall HID devices will be returned.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the types of device\n\t\t\t\tto open.\n\t\t\t@param product_id The Product ID (PID) of the types of\n\t\t\t\tdevice to open.\n\n\t\t @returns\n\t\t \tThis function returns a pointer to a linked list of type\n\t\t \tstruct #hid_device, containing information about the HID devices\n\t\t \tattached to the system, or NULL in the case of failure. Free\n\t\t \tthis linked list by calling hid_free_enumeration().\n\t\t*/\n\t\tstruct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);\n\n\t\t/** @brief Free an enumeration Linked List\n\n\t\t This function frees a linked list created by hid_enumerate().\n\n\t\t\t@ingroup API\n\t\t @param devs Pointer to a list of struct_device returned from\n\t\t \t hid_enumerate().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);\n\n\t\t/** @brief Open a HID device using a Vendor ID (VID), Product ID\n\t\t\t(PID) and optionally a serial number.\n\n\t\t\tIf @p serial_number is NULL, the first device with the\n\t\t\tspecified VID and PID is opened.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the device to open.\n\t\t\t@param product_id The Product ID (PID) of the device to open.\n\t\t\t@param serial_number The Serial Number of the device to open\n\t\t\t\t (Optionally NULL).\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);\n\n\t\t/** @brief Open a HID device by its path name.\n\n\t\t\tThe path name be determined by calling hid_enumerate(), or a\n\t\t\tplatform-specific path name can be used (eg: /dev/hidraw0 on\n\t\t\tLinux).\n\n\t\t\t@ingroup API\n\t\t @param path The path name of the device to open\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);\n\n\t\t/** @brief Write an Output report to a HID device.\n\n\t\t\tThe first byte of @p data[] must contain the Report ID. For\n\t\t\tdevices which only support a single report, this must be set\n\t\t\tto 0x0. The remaining bytes contain the report data. Since\n\t\t\tthe Report ID is mandatory, calls to hid_write() will always\n\t\t\tcontain one more byte than the report contains. For example,\n\t\t\tif a hid report is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_write(), the Report ID (or 0x0, for devices with a\n\t\t\tsingle report), followed by the report data (16 bytes). In\n\t\t\tthis example, the length passed in would be 17.\n\n\t\t\thid_write() will send the data on the first OUT endpoint, if\n\t\t\tone exists. If it does not, it will send the data through\n\t\t\tthe Control Endpoint (Endpoint 0).\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Read an Input report from a HID device with timeout.\n\n\t\t\tInput reports are returned\n\t\t\tto the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\t\t\t@param milliseconds timeout in milliseconds or -1 for blocking wait.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);\n\n\t\t/** @brief Read an Input report from a HID device.\n\n\t\t\tInput reports are returned\n\t\t to the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Set the device handle to be non-blocking.\n\n\t\t\tIn non-blocking mode calls to hid_read() will return\n\t\t\timmediately with a value of 0 if there is no data to be\n\t\t\tread. In blocking mode, hid_read() will wait (block) until\n\t\t\tthere is data to read before returning.\n\n\t\t\tNonblocking can be turned on and off at any time.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param nonblock enable or not the nonblocking reads\n\t\t\t - 1 to enable nonblocking\n\t\t\t - 0 to disable nonblocking.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);\n\n\t\t/** @brief Send a Feature report to the device.\n\n\t\t\tFeature reports are sent over the Control endpoint as a\n\t\t\tSet_Report transfer. The first byte of @p data[] must\n\t\t\tcontain the Report ID. For devices which only support a\n\t\t\tsingle report, this must be set to 0x0. The remaining bytes\n\t\t\tcontain the report data. Since the Report ID is mandatory,\n\t\t\tcalls to hid_send_feature_report() will always contain one\n\t\t\tmore byte than the report contains. For example, if a hid\n\t\t\treport is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_send_feature_report(): the Report ID (or 0x0, for\n\t\t\tdevices which do not use numbered reports), followed by the\n\t\t\treport data (16 bytes). In this example, the length passed\n\t\t\tin would be 17.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send, including\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Get a feature report from a HID device.\n\n\t\t\tMake sure to set the first byte of @p data[] to the Report\n\t\t\tID of the report to be read. Make sure to allow space for\n\t\t\tthis extra byte in @p data[].\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into, including\n\t\t\t\tthe Report ID. Set the first byte of @p data[] to the\n\t\t\t\tReport ID of the report to be read.\n\t\t\t@param length The number of bytes to read, including an\n\t\t\t\textra byte for the report ID. The buffer can be longer\n\t\t\t\tthan the actual report.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Close a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);\n\n\t\t/** @brief Get The Manufacturer String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Product String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Serial Number String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string from a HID device, based on its string index.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string_index The index of the string to get.\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string describing the last error which occurred.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\n\t\t\t@returns\n\t\t\t\tThis function returns a string containing the last error\n\t\t\t\twhich occurred or NULL if none has occurred.\n\t\t*/\n\t\tHID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"], ["/sapf/src/primes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"primes.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n\n// Within a cycle of 30, there are only 8 numbers that are not multiples of 2, 3 or 5.\n// We pack these 8 into a one byte bit map.\n\nconst int gLowPrimes[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimeOffsets[8] = {1, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimesShift[30] = \n{\n\t-1, 0, -1, -1, -1, -1, -1, 1, -1, -1, \n\t-1, 2, -1, 3, -1, -1, -1, 4, -1, 5, \n\t-1, -1, -1, 6, -1, -1, -1, -1, -1, 7 \n};\n\t\nconst uint32_t gLowPrimesMask = 0x208a28ac;\n\n//const int kPrimeUpperLimit = kPrimesMaskSize * 30;\nuint8_t gPrimesMask[kPrimesMaskSize] = {\n\t0xdf, 0xef, 0x7e, 0xb6, 0xdb, 0x3d, 0xf9, 0xd5, 0x4f, 0x1e, 0xf3, 0xea, 0xa6, 0xed, 0x9e, 0xe6, \n\t0x0c, 0xd3, 0xd3, 0x3b, 0xdd, 0x59, 0xa5, 0x6a, 0x67, 0x92, 0xbd, 0x78, 0x1e, 0xa6, 0x56, 0x56, \n\t0xe3, 0xad, 0x2d, 0xde, 0x2a, 0x4c, 0x55, 0xd9, 0xa3, 0xf0, 0x9f, 0x03, 0x54, 0xa1, 0xf8, 0x2e, \n\t0xfd, 0x44, 0xe9, 0x66, 0xf6, 0x13, 0x3a, 0xb8, 0x4c, 0x2b, 0x3a, 0x45, 0x11, 0xbf, 0x54, 0x8c, \n\t0xc1, 0x7a, 0xb3, 0xc8, 0xbc, 0x8c, 0x4f, 0x21, 0x58, 0x71, 0x71, 0x9b, 0xc1, 0x17, 0xef, 0x54, \n\t0x96, 0x1a, 0x08, 0xe5, 0x83, 0x8c, 0x46, 0x72, 0xfb, 0xae, 0x65, 0x92, 0x8f, 0x58, 0x87, 0xd2, \n\t0x92, 0xd8, 0x81, 0x65, 0x26, 0xe3, 0xa0, 0x11, 0x38, 0xc7, 0x26, 0x3c, 0x81, 0xeb, 0x99, 0x8d, \n\t0x51, 0x88, 0x3e, 0x24, 0xf3, 0x33, 0x4d, 0x5a, 0x8b, 0x1c, 0xa7, 0x2a, 0xb4, 0x58, 0x4c, 0x4e, \n\t0x26, 0xf6, 0x19, 0x82, 0xdc, 0x83, 0xc3, 0x2c, 0xf1, 0x38, 0x02, 0xb5, 0xcd, 0xcd, 0x02, 0xb2, \n\t0x4a, 0x94, 0x0c, 0x57, 0x4c, 0x7a, 0x30, 0x43, 0x0b, 0xf1, 0xcb, 0x44, 0x6c, 0x24, 0xf8, 0x19, \n\t0x01, 0x95, 0xa8, 0x5c, 0x73, 0xea, 0x8d, 0x24, 0x96, 0x2b, 0x50, 0xa6, 0x22, 0x1e, 0xc4, 0xd1, \n\t0x48, 0x06, 0xd4, 0x3a, 0x2f, 0x74, 0x9c, 0x07, 0x6a, 0x05, 0x88, 0xbf, 0x68, 0x15, 0x2e, 0x60, \n\t0x55, 0xe3, 0xb7, 0x51, 0x98, 0x08, 0x14, 0x86, 0x5a, 0xaa, 0x45, 0x4d, 0x49, 0x70, 0x27, 0xd2, \n\t0x93, 0xd5, 0xca, 0xab, 0x02, 0x83, 0x61, 0x05, 0x24, 0xce, 0x87, 0x22, 0xc2, 0xa9, 0xad, 0x18, \n\t0x8c, 0x4d, 0x78, 0xd1, 0x89, 0x16, 0xb0, 0x57, 0xc7, 0x62, 0xa2, 0xc0, 0x34, 0x24, 0x52, 0xae, \n\t0x5a, 0x40, 0x32, 0x8d, 0x21, 0x08, 0x43, 0x34, 0xb6, 0xd2, 0xb6, 0xd9, 0x19, 0xe1, 0x60, 0x67, \n\t0x1a, 0x39, 0x60, 0xd0, 0x44, 0x7a, 0x94, 0x9a, 0x09, 0x88, 0x83, 0xa8, 0x74, 0x55, 0x10, 0x27, \n\t0xa1, 0x5d, 0x68, 0x1e, 0x23, 0xc8, 0x32, 0xe0, 0x19, 0x03, 0x44, 0x73, 0x48, 0xb1, 0x38, 0xc3, \n\t0xe6, 0x2a, 0x57, 0x61, 0x98, 0xb5, 0x1c, 0x0a, 0x68, 0xc5, 0x81, 0x8f, 0xac, 0x02, 0x29, 0x1a, \n\t0x47, 0xe3, 0x94, 0x11, 0x4e, 0x64, 0x2e, 0x14, 0xcb, 0x3d, 0xdc, 0x14, 0xc5, 0x06, 0x10, 0xe9, \n\t0x29, 0xb1, 0x82, 0xe9, 0x30, 0x47, 0xe3, 0x34, 0x19, 0xc3, 0x25, 0x0a, 0x30, 0x30, 0xb4, 0x6c, \n\t0xc1, 0xe5, 0x46, 0x44, 0xd8, 0x8e, 0x4c, 0x5d, 0x22, 0x24, 0x70, 0x78, 0x92, 0x89, 0x81, 0x82, \n\t0x56, 0x26, 0x1b, 0x86, 0xe9, 0x08, 0xa5, 0x00, 0xd3, 0xc3, 0x29, 0xb0, 0xc2, 0x4a, 0x10, 0xb2, \n\t0x59, 0x38, 0xa1, 0x1d, 0x42, 0x60, 0xc7, 0x22, 0x27, 0x8c, 0xc8, 0x44, 0x1a, 0xc6, 0x8b, 0x82, \n\t0x81, 0x1a, 0x46, 0x10, 0xa6, 0x31, 0x09, 0xf0, 0x54, 0x2f, 0x18, 0xd2, 0xd8, 0xa9, 0x15, 0x06, \n\t0x2e, 0x0c, 0xf6, 0xc0, 0x0e, 0x50, 0x91, 0xcd, 0x26, 0xc1, 0x18, 0x38, 0x65, 0x19, 0xc3, 0x56, \n\t0x93, 0x8b, 0x2a, 0x2d, 0xd6, 0x84, 0x4a, 0x61, 0x0a, 0xa5, 0x2c, 0x09, 0xe0, 0x76, 0xc4, 0x6a, \n\t0x3c, 0xd8, 0x08, 0xe8, 0x14, 0x66, 0x1b, 0xb0, 0xa4, 0x02, 0x63, 0x36, 0x10, 0x31, 0x07, 0xd5, \n\t0x92, 0x48, 0x42, 0x12, 0xc3, 0x8a, 0xa0, 0x9f, 0x2d, 0x74, 0xa4, 0x82, 0x85, 0x78, 0x5c, 0x0d, \n\t0x18, 0xb0, 0x61, 0x14, 0x1d, 0x02, 0xe8, 0x18, 0x12, 0xc1, 0x01, 0x49, 0x1c, 0x83, 0x30, 0x67, \n\t0x33, 0xa1, 0x88, 0xd8, 0x0f, 0x0c, 0xf4, 0x98, 0x88, 0x58, 0xd7, 0x66, 0x42, 0x47, 0xb1, 0x16, \n\t0xa8, 0x96, 0x08, 0x18, 0x41, 0x59, 0x15, 0xb5, 0x44, 0x2a, 0x52, 0xe1, 0xb3, 0xaa, 0xa1, 0x59, \n\t0x45, 0x62, 0x55, 0x18, 0x11, 0xa5, 0x0c, 0xa3, 0x3c, 0x67, 0x00, 0xbe, 0x54, 0xd6, 0x0a, 0x20, \n\t0x36, 0x6b, 0x82, 0x0c, 0x15, 0x08, 0x7e, 0x56, 0x91, 0x01, 0x78, 0xd0, 0x61, 0x0a, 0x84, 0xa8, \n\t0x2c, 0x01, 0x57, 0x0e, 0x56, 0xa0, 0x50, 0x0b, 0x98, 0x8c, 0x47, 0x6c, 0x20, 0x63, 0x10, 0xc4, \n\t0x09, 0xe4, 0x0c, 0x57, 0x88, 0x0b, 0x75, 0x0b, 0xc2, 0x52, 0x82, 0xc2, 0x39, 0x24, 0x02, 0x2c, \n\t0x56, 0x25, 0x7a, 0x31, 0x29, 0xd6, 0xa3, 0x20, 0xe1, 0xb1, 0x18, 0xb0, 0x0c, 0x8a, 0x32, 0xc1, \n\t0x11, 0x32, 0x09, 0xc5, 0xad, 0x30, 0x37, 0x08, 0xbc, 0x91, 0x82, 0xcf, 0x20, 0x25, 0x6b, 0x9c, \n\t0x30, 0x8f, 0x44, 0x26, 0x46, 0x6a, 0x07, 0x49, 0x8e, 0x09, 0x58, 0x10, 0x02, 0x25, 0xc5, 0xc4, \n\t0x42, 0x5a, 0x80, 0xa0, 0x80, 0x3c, 0x90, 0x28, 0x64, 0x14, 0xe1, 0x03, 0x84, 0x51, 0x0c, 0x2e, \n\t0xa3, 0x8a, 0xa4, 0x08, 0xc0, 0x47, 0x7e, 0xd3, 0x2b, 0x03, 0xcd, 0x54, 0x2a, 0x00, 0x04, 0xb3, \n\t0x92, 0x6c, 0x42, 0x29, 0x4c, 0x83, 0xc1, 0x92, 0xcc, 0x1c, 0x2d, 0x46, 0x21, 0xdb, 0x38, 0x59, \n\t0x84, 0x8c, 0x24, 0x12, 0x58, 0xbb, 0xe0, 0x06, 0x0d, 0x70, 0x30, 0xc9, 0x09, 0x28, 0x91, 0x41, \n\t0x44, 0x32, 0xf9, 0x8c, 0x30, 0x80, 0xc2, 0x72, 0xa4, 0x62, 0x0c, 0x7d, 0x81, 0x83, 0x14, 0xe1, \n\t0xaa, 0x0e, 0x15, 0x82, 0x0a, 0x78, 0x14, 0x70, 0x97, 0x08, 0x10, 0x6f, 0x2e, 0xf0, 0xb2, 0x1d, \n\t0x30, 0x49, 0x44, 0x32, 0x53, 0x62, 0x86, 0x65, 0x45, 0x84, 0x0a, 0x11, 0x4b, 0x36, 0xd9, 0x8c, \n\t0x69, 0x3a, 0x61, 0x80, 0x90, 0x7c, 0x19, 0xc0, 0x30, 0x95, 0x40, 0x8b, 0x0c, 0x05, 0x2d, 0x0e, \n\t0xc0, 0x71, 0xa1, 0xb4, 0x96, 0x85, 0x1a, 0x16, 0xc0, 0x15, 0x14, 0x51, 0x4c, 0x48, 0xb7, 0x79, \n\t0x95, 0x10, 0x89, 0x8a, 0x2e, 0x02, 0xa1, 0x1c, 0xd5, 0x90, 0x81, 0x10, 0x91, 0x08, 0x22, 0xb4, \n\t0x1e, 0xe9, 0x78, 0xc0, 0x33, 0x20, 0x5c, 0x8b, 0xc4, 0x0e, 0xe2, 0xaa, 0x23, 0x10, 0x47, 0xe3, \n\t0x28, 0x55, 0x7b, 0x19, 0xa1, 0x51, 0xa8, 0x06, 0x04, 0x90, 0x82, 0x2c, 0xd1, 0x61, 0x60, 0xa1, \n\t0x52, 0x06, 0x41, 0x44, 0x81, 0x54, 0x23, 0x88, 0x18, 0xa9, 0x04, 0x27, 0x22, 0x72, 0x48, 0xb6, \n\t0x40, 0x1c, 0x42, 0x12, 0x17, 0xca, 0x29, 0xa0, 0x5a, 0x01, 0x3c, 0xe1, 0x52, 0x84, 0x89, 0xda, \n\t0x01, 0x40, 0x06, 0xf1, 0x2c, 0x69, 0xd2, 0x48, 0x42, 0x63, 0xc1, 0x21, 0x34, 0x8a, 0xc8, 0x6c, \n\t0x21, 0x71, 0x26, 0x09, 0x88, 0x2e, 0x44, 0xd5, 0x28, 0x92, 0x1d, 0x98, 0x86, 0x12, 0xd1, 0x52, \n\t0xa3, 0xa0, 0x46, 0x20, 0x46, 0x14, 0x50, 0x83, 0xdc, 0xdd, 0x83, 0x50, 0x44, 0xa9, 0x8c, 0x4d, \n\t0x14, 0x2e, 0x54, 0x14, 0x89, 0x1b, 0x39, 0x42, 0x80, 0x14, 0x81, 0x29, 0x8f, 0x80, 0x02, 0x03, \n\t0x32, 0x96, 0x82, 0x83, 0xb0, 0x05, 0x0c, 0x14, 0x51, 0x88, 0x07, 0xf8, 0xd9, 0xec, 0x1a, 0x06, \n\t0x48, 0x31, 0x5c, 0x43, 0x86, 0x06, 0x23, 0xb3, 0x09, 0x44, 0x0c, 0xa5, 0x00, 0xf0, 0xb2, 0x80, \n\t0x01, 0xca, 0xe1, 0x42, 0xc2, 0x18, 0xb6, 0x2c, 0x9b, 0xc7, 0x2e, 0x52, 0x29, 0x2c, 0x61, 0x1a, \n\t0x8a, 0x26, 0x24, 0x8b, 0x84, 0x80, 0x5e, 0x60, 0x02, 0xc1, 0x53, 0x2a, 0x35, 0x45, 0x21, 0x52, \n\t0xd1, 0x42, 0xb8, 0xc5, 0x4a, 0x48, 0x04, 0x16, 0x70, 0x23, 0x61, 0xc1, 0x09, 0x50, 0xc4, 0x81, \n\t0x88, 0x18, 0xd9, 0x01, 0x16, 0x22, 0x28, 0x8c, 0x90, 0x84, 0xeb, 0x38, 0x24, 0x53, 0x09, 0xa9, \n\t0x41, 0x6a, 0x14, 0x82, 0x09, 0x86, 0x30, 0x9c, 0xa2, 0x38, 0x42, 0x00, 0x2b, 0x95, 0x5a, 0x02, \n\t0x4a, 0xc1, 0xa2, 0xad, 0x45, 0x04, 0x27, 0x54, 0xc0, 0x28, 0xa9, 0x05, 0x8c, 0x2e, 0x6e, 0x60, \n\t0xf3, 0x16, 0x90, 0x1b, 0x82, 0x1e, 0x00, 0x80, 0x26, 0x1c, 0x1d, 0x4a, 0x14, 0xc2, 0x1a, 0x22, \n\t0x3c, 0x85, 0xc1, 0x10, 0xb0, 0x48, 0x11, 0x00, 0x4a, 0xc5, 0x30, 0xf4, 0xaa, 0x30, 0x8c, 0xc8, \n\t0x49, 0x18, 0x07, 0xf0, 0x1c, 0xe9, 0x07, 0xcd, 0x0c, 0x22, 0x1b, 0x1c, 0xec, 0xc2, 0x45, 0x0a, \n\t0x50, 0x3a, 0x20, 0xe4, 0x0e, 0x6c, 0x20, 0x82, 0xc3, 0x91, 0xd9, 0xc8, 0x62, 0x4c, 0xd1, 0x80, \n\t0x85, 0x65, 0x09, 0x02, 0x30, 0x95, 0xf9, 0x10, 0x69, 0x02, 0xa6, 0x4a, 0x64, 0xc2, 0xb6, 0xf9, \n\t0x16, 0x20, 0x48, 0xa1, 0x73, 0x94, 0x31, 0x54, 0x61, 0x44, 0x07, 0x03, 0x82, 0x2c, 0x06, 0x00, \n\t0x38, 0x33, 0x09, 0x1c, 0xc1, 0x4b, 0xce, 0x12, 0x35, 0x41, 0xa4, 0x90, 0x99, 0x2d, 0x2a, 0xc0, \n\t0x59, 0x84, 0xd1, 0x4a, 0xa4, 0x72, 0x04, 0x22, 0x3c, 0x54, 0xc2, 0xa0, 0x0c, 0x01, 0x18, 0xac, \n\t0xac, 0x96, 0xe4, 0x04, 0x04, 0x03, 0x93, 0x05, 0x9b, 0x48, 0x44, 0x63, 0x32, 0x01, 0x31, 0x5f, \n\t0x60, 0x5c, 0x02, 0x00, 0x03, 0x80, 0xd1, 0x04, 0x2e, 0x34, 0xa9, 0x30, 0x49, 0xc4, 0xca, 0x1e, \n\t0x02, 0x4b, 0x32, 0x14, 0x05, 0x86, 0x22, 0xc5, 0xc2, 0x2a, 0x4c, 0xc8, 0x00, 0x08, 0xf3, 0x18, \n\t0x38, 0x65, 0x99, 0x82, 0x4a, 0x54, 0x63, 0xa1, 0x94, 0x8f, 0x44, 0x12, 0x93, 0xe9, 0x19, 0x28, \n\t0xca, 0xa1, 0x06, 0x12, 0x8a, 0x20, 0xa5, 0x51, 0x48, 0x18, 0x70, 0x31, 0xae, 0x90, 0x08, 0x43, \n\t0x68, 0x97, 0x32, 0xaf, 0x91, 0xc8, 0x0a, 0x2c, 0x02, 0x02, 0x8c, 0x0c, 0x51, 0xa5, 0x12, 0x00, \n\t0x1b, 0x1e, 0x81, 0x8a, 0x08, 0x28, 0x60, 0xd2, 0x86, 0x34, 0x44, 0x63, 0x76, 0x04, 0x43, 0x00, \n\t0xf1, 0x01, 0x04, 0x40, 0x36, 0xc8, 0xa1, 0x8c, 0xc3, 0xce, 0x32, 0x42, 0x09, 0x29, 0x55, 0x44, \n\t0x4e, 0x28, 0x43, 0x60, 0x1c, 0xa0, 0xda, 0x28, 0x0e, 0xa5, 0xf2, 0x05, 0x40, 0x59, 0x8c, 0x4e, \n\t0xa2, 0x60, 0x05, 0xe0, 0x05, 0xc5, 0x04, 0x62, 0x81, 0x26, 0xa8, 0x8a, 0xa4, 0x24, 0xb4, 0xd3, \n\t0x1a, 0x81, 0x42, 0xe4, 0x60, 0x34, 0x08, 0x2a, 0x39, 0xcc, 0x62, 0x08, 0x47, 0xd0, 0x00, 0x40, \n\t0x07, 0x02, 0x78, 0x20, 0xd9, 0xa2, 0x89, 0x50, 0x23, 0x32, 0x00, 0xb8, 0x80, 0x64, 0x11, 0xe9, \n\t0x74, 0x62, 0x0a, 0xaa, 0x44, 0x08, 0x8b, 0x16, 0x06, 0x18, 0x2d, 0xf1, 0x4c, 0x4f, 0x2a, 0x21, \n\t0x40, 0x15, 0xb4, 0x0c, 0x48, 0x22, 0xd1, 0xe1, 0x80, 0xd8, 0x17, 0xa7, 0x14, 0xa0, 0x82, 0x15, \n\t0x64, 0xc0, 0x89, 0x5a, 0x11, 0xbb, 0x8c, 0x78, 0x08, 0xcd, 0x04, 0x24, 0xa2, 0x9b, 0x9c, 0x10, \n\t0xcc, 0x42, 0xa3, 0x28, 0x3b, 0x58, 0x5f, 0xa6, 0x40, 0x90, 0x23, 0x04, 0x2c, 0xd2, 0xae, 0x52, \n\t0x51, 0x1a, 0xa4, 0x69, 0x80, 0xc1, 0x4a, 0xa3, 0xc8, 0x90, 0x19, 0x48, 0x42, 0x24, 0x22, 0x43, \n\t0x02, 0x45, 0xc1, 0x05, 0x00, 0x74, 0x11, 0x15, 0x94, 0x10, 0x0c, 0x38, 0x73, 0x8a, 0x25, 0x04, \n\t0x07, 0x28, 0x7e, 0x01, 0x40, 0x82, 0x41, 0x48, 0x6d, 0x16, 0x36, 0x29, 0x31, 0xe5, 0x81, 0xa4, \n\t0x1c, 0x81, 0xfa, 0x09, 0x00, 0x14, 0x2d, 0x10, 0x60, 0x40, 0x97, 0xdc, 0x88, 0x02, 0x4e, 0x17, \n\t0x98, 0x85, 0x44, 0x9c, 0xa2, 0x60, 0x91, 0x8a, 0x92, 0x68, 0x19, 0x0a, 0x40, 0x51, 0x80, 0x37, \n\t0x84, 0x15, 0x40, 0x62, 0x64, 0xb2, 0x0e, 0x91, 0x48, 0x2a, 0x00, 0x55, 0x48, 0x99, 0xb0, 0x08, \n\t0x85, 0x1a, 0x13, 0x10, 0x9b, 0x00, 0x5e, 0xc9, 0x50, 0x00, 0xe8, 0xa4, 0x00, 0x83, 0x45, 0x6c, \n\t0x40, 0x0b, 0x9d, 0xa0, 0x02, 0x2d, 0x34, 0x92, 0x01, 0x21, 0x81, 0x17, 0xa3, 0x46, 0xa0, 0x8a, \n\t0x85, 0xe8, 0x88, 0x47, 0x18, 0x96, 0x01, 0xb6, 0x41, 0x93, 0x84, 0x08, 0x02, 0x18, 0x02, 0x35, \n\t0x50, 0xe4, 0x3a, 0x81, 0x10, 0x11, 0xa1, 0xda, 0x82, 0x4c, 0x34, 0x32, 0x85, 0x00, 0x57, 0x4b, \n\t0x28, 0xa5, 0xa8, 0x38, 0x84, 0x1d, 0x0e, 0x30, 0xb3, 0x50, 0x22, 0x41, 0xc3, 0xc6, 0x06, 0xd0, \n\t0x20, 0x28, 0xa1, 0x05, 0x8a, 0x1a, 0x84, 0x22, 0x85, 0x0c, 0x46, 0x44, 0x72, 0x90, 0xc8, 0x17, \n\t0xd8, 0x41, 0x61, 0x64, 0x30, 0x39, 0x00, 0x0c, 0x97, 0xa3, 0x0e, 0xb2, 0x29, 0x02, 0x50, 0x88, \n\t0xa9, 0x5c, 0x22, 0xc1, 0x8e, 0x90, 0xc3, 0x47, 0x40, 0x31, 0x12, 0x2c, 0x38, 0x8c, 0x63, 0x64, \n\t0x86, 0xc0, 0xb3, 0x00, 0x4a, 0x2a, 0x38, 0x11, 0x91, 0x13, 0x38, 0x47, 0x49, 0x14, 0x81, 0x73, \n\t0x02, 0x2c, 0x4c, 0x8e, 0x52, 0xe5, 0xd1, 0x10, 0x10, 0x07, 0x4c, 0x06, 0x65, 0x61, 0x1a, 0x54, \n\t0x84, 0x01, 0x4a, 0xe2, 0x01, 0x2f, 0x10, 0x06, 0x09, 0x42, 0x44, 0x9a, 0x00, 0xa9, 0x52, 0x8c, \n\t0x28, 0x94, 0x61, 0x01, 0x99, 0x05, 0x20, 0x1c, 0x23, 0x78, 0xa2, 0x51, 0x18, 0x82, 0x3c, 0x41, \n\t0xd0, 0xb7, 0xc4, 0x43, 0x87, 0x44, 0xc6, 0x0a, 0x93, 0x68, 0xc1, 0x81, 0x30, 0x52, 0xb2, 0xa8, \n\t0xc1, 0x8a, 0x24, 0x1c, 0x21, 0x03, 0x33, 0x41, 0x14, 0x4a, 0x2e, 0x41, 0xe2, 0x82, 0x45, 0x01, \n\t0xac, 0x06, 0x40, 0x18, 0x20, 0x95, 0x4c, 0x67, 0x20, 0x26, 0x50, 0x94, 0x55, 0x92, 0x08, 0x1a, \n\t0x82, 0xe1, 0x8c, 0x10, 0x5b, 0x61, 0x02, 0x86, 0x72, 0x99, 0x30, 0x8d, 0x06, 0x2c, 0xb0, 0xa1, \n\t0x18, 0x28, 0x06, 0x27, 0x46, 0x20, 0x18, 0x82, 0x21, 0x9c, 0xeb, 0x18, 0xc4, 0x30, 0x81, 0x58, \n\t0xc1, 0x84, 0x06, 0x37, 0x9a, 0x24, 0x50, 0x0d, 0xa2, 0x40, 0x05, 0x29, 0x19, 0x09, 0x02, 0x84, \n\t0x52, 0x64, 0x11, 0x17, 0xec, 0xd1, 0x20, 0x78, 0x86, 0x63, 0x0e, 0xd1, 0x11, 0x2a, 0x60, 0x03, \n\t0xd1, 0x22, 0x60, 0x84, 0x06, 0x32, 0xa4, 0x68, 0x24, 0x81, 0xc7, 0xc0, 0x12, 0x42, 0x01, 0xbb, \n\t0xa8, 0x00, 0x41, 0x7c, 0x41, 0x21, 0x81, 0x91, 0x10, 0x85, 0x14, 0xa0, 0xa8, 0x2d, 0x5c, 0x15, \n\t0x47, 0x40, 0xd0, 0xfa, 0x2a, 0x84, 0x0e, 0x8f, 0x10, 0xd2, 0x80, 0x09, 0xd4, 0x49, 0x21, 0x26, \n\t0x32, 0xb0, 0x38, 0x20, 0x41, 0xa0, 0x4a, 0x11, 0x4b, 0xba, 0xac, 0x4e, 0x20, 0x34, 0x61, 0x60, \n\t0x15, 0x0d, 0x13, 0x6a, 0x70, 0x43, 0x42, 0x9c, 0x2d, 0x55, 0xe8, 0x00, 0x96, 0x98, 0x92, 0xe4, \n\t0xc8, 0x4c, 0x0c, 0xa5, 0x19, 0x81, 0x31, 0xca, 0x42, 0x02, 0x12, 0x4a, 0x30, 0x30, 0x51, 0x01, \n\t0x66, 0xa2, 0xe2, 0x16, 0x41, 0xcf, 0xa0, 0x2a, 0x84, 0x51, 0x18, 0x18, 0x41, 0xc6, 0x56, 0xa0, \n\t0x21, 0x8e, 0xe1, 0x96, 0x0b, 0x04, 0x60, 0x11, 0xb8, 0x4c, 0x93, 0x0d, 0x06, 0x04, 0x2a, 0x2a, \n\t0x4c, 0x04, 0x86, 0x2a, 0x51, 0x51, 0x31, 0x00, 0x01, 0x80, 0x76, 0x51, 0x98, 0x94, 0x2d, 0xcc, \n\t0x4a, 0x6a, 0xa4, 0x42, 0xb2, 0x69, 0x48, 0x01, 0x40, 0xb5, 0xd2, 0x32, 0x5c, 0x0e, 0x62, 0x20, \n\t0x16, 0x01, 0x37, 0xe4, 0xc1, 0xc2, 0x58, 0x24, 0x23, 0x08, 0x88, 0x02, 0x24, 0x14, 0x85, 0x98, \n\t0x06, 0xd0, 0x1d, 0xaa, 0x34, 0x80, 0x0a, 0x34, 0x61, 0x10, 0x4b, 0x48, 0x42, 0xc2, 0x02, 0x98, \n\t0x94, 0x00, 0x20, 0x57, 0xb3, 0xa1, 0x88, 0x1a, 0xce, 0x08, 0x05, 0xa0, 0xb0, 0x79, 0x4a, 0x01, \n\t0x14, 0x46, 0x03, 0x24, 0x24, 0x8d, 0x00, 0x44, 0x41, 0x41, 0x03, 0x6c, 0x8a, 0xc1, 0x02, 0xc1, \n\t0x59, 0x26, 0xd8, 0x41, 0x68, 0x56, 0x53, 0x43, 0x2a, 0x14, 0x04, 0x28, 0x0a, 0x25, 0x20, 0x8a, \n\t0x94, 0x47, 0x83, 0x1a, 0x85, 0xa0, 0x0f, 0x84, 0xd5, 0x08, 0x40, 0x70, 0x19, 0x06, 0x08, 0x51, \n\t0x80, 0x5a, 0x16, 0xa8, 0x08, 0x55, 0xd2, 0x28, 0x18, 0x41, 0x49, 0x09, 0x85, 0x02, 0x65, 0x50, \n\t0xb4, 0x80, 0x3d, 0x80, 0x81, 0x2a, 0x4a, 0x86, 0x80, 0x30, 0x01, 0x03, 0x86, 0x1c, 0x53, 0x93, \n\t0xa3, 0x61, 0x58, 0x2a, 0x54, 0x21, 0xb2, 0x97, 0xb0, 0x86, 0xab, 0x52, 0x44, 0xe9, 0x88, 0x59, \n\t0x00, 0x8b, 0x20, 0x10, 0xd2, 0x18, 0x18, 0x85, 0x08, 0x1c, 0x31, 0x50, 0x03, 0x64, 0x8c, 0x0a, \n\t0x40, 0x61, 0xc0, 0x0c, 0xa8, 0x08, 0x40, 0x32, 0x65, 0x0b, 0x9c, 0x88, 0x02, 0x42, 0x4c, 0x14, \n\t0x60, 0x34, 0x85, 0x13, 0x21, 0x50, 0x71, 0x48, 0xa1, 0xe5, 0x14, 0x6e, 0x48, 0x20, 0x32, 0x8a, \n\t0x18, 0x18, 0x45, 0x6a, 0x32, 0x20, 0x82, 0x71, 0x8b, 0xa3, 0x62, 0x16, 0x92, 0xbb, 0x01, 0x91, \n\t0x20, 0x76, 0x11, 0x21, 0x34, 0x54, 0x4c, 0x80, 0x16, 0xc6, 0x38, 0x10, 0xe4, 0x04, 0x84, 0x00, \n\t0x41, 0x01, 0x9a, 0x59, 0x48, 0x84, 0x1a, 0xa4, 0x68, 0x89, 0x51, 0x91, 0x48, 0x40, 0x46, 0xa9, \n\t0x09, 0x94, 0x04, 0x4d, 0x2a, 0x60, 0xb9, 0x18, 0x08, 0xc9, 0xc6, 0x40, 0xa4, 0x99, 0x34, 0x3c, \n\t0x11, 0x8d, 0x10, 0xe0, 0x20, 0xa4, 0x75, 0x0a, 0xe6, 0x44, 0x93, 0xb2, 0x94, 0x04, 0x81, 0xa0, \n\t0x48, 0x75, 0x2a, 0xa3, 0x48, 0x42, 0x05, 0x6e, 0x96, 0x0a, 0x08, 0x29, 0x91, 0x0c, 0x14, 0x05, \n\t0xf0, 0x22, 0x84, 0x01, 0x21, 0x04, 0xa1, 0x00, 0x3a, 0xd8, 0x15, 0x65, 0x10, 0x11, 0xc1, 0xa0, \n\t0x98, 0x8c, 0x2a, 0x16, 0xc1, 0x01, 0x88, 0xf5, 0x12, 0x42, 0x40, 0xa5, 0x01, 0x0b, 0xa0, 0xc2, \n\t0x09, 0x5c, 0xc4, 0x72, 0x00, 0x18, 0x06, 0xe4, 0x0c, 0x26, 0x5a, 0x3d, 0x80, 0x10, 0x40, 0x40, \n\t0x40, 0x11, 0x23, 0x30, 0x9c, 0x80, 0x74, 0x32, 0x82, 0x84, 0x85, 0x00, 0xaf, 0x20, 0x95, 0x20, \n\t0x8f, 0x51, 0x8e, 0xc3, 0x26, 0x84, 0x62, 0x03, 0xc1, 0x09, 0xa8, 0x34, 0x34, 0x83, 0x22, 0xcc, \n\t0x90, 0x23, 0x1a, 0x82, 0x22, 0x88, 0x48, 0x40, 0x6c, 0x32, 0xc5, 0x91, 0xa3, 0x35, 0x89, 0xa0, \n\t0x24, 0xa0, 0x58, 0x07, 0x21, 0x98, 0x0e, 0x0a, 0xf2, 0x6b, 0xb0, 0xac, 0x4a, 0x6c, 0x08, 0x92, \n\t0x29, 0x18, 0x40, 0x42, 0xc1, 0x2e, 0x04, 0x91, 0x30, 0xd1, 0x94, 0xa3, 0x42, 0x43, 0xd9, 0x20, \n\t0x59, 0x98, 0x2d, 0x20, 0x74, 0x00, 0x3d, 0x8c, 0x13, 0x0a, 0x46, 0x62, 0x00, 0x05, 0x34, 0x59, \n\t0x40, 0x26, 0x02, 0x58, 0x38, 0xad, 0x94, 0x2a, 0x18, 0x10, 0x0a, 0xa0, 0x69, 0x47, 0xe3, 0x18, \n\t0xe2, 0x70, 0x8c, 0x04, 0x54, 0x01, 0x24, 0x00, 0x8a, 0x10, 0x29, 0x06, 0xad, 0x02, 0x46, 0x28, \n\t0x0b, 0xd0, 0x50, 0xc5, 0x72, 0x50, 0xc1, 0xa9, 0x14, 0x14, 0x09, 0x60, 0xb0, 0x52, 0x12, 0x60, \n\t0x45, 0x20, 0x16, 0x06, 0xc3, 0x01, 0xa9, 0x93, 0xae, 0x04, 0x82, 0x1a, 0x0b, 0x58, 0x0e, 0x2c, \n\t0x64, 0x84, 0x30, 0x07, 0x55, 0x92, 0x09, 0x08, 0x90, 0xba, 0x91, 0x25, 0x02, 0x47, 0x66, 0x56, \n\t0x68, 0x21, 0x00, 0x9c, 0x06, 0x60, 0x20, 0x88, 0x34, 0x89, 0x9b, 0x88, 0x22, 0xc2, 0x52, 0x92, \n\t0x1d, 0x14, 0x80, 0x40, 0xd5, 0x19, 0x0b, 0xb4, 0xc4, 0xe0, 0x38, 0x45, 0x50, 0x1b, 0x44, 0x88, \n\t0x08, 0x08, 0x07, 0xe2, 0x0f, 0x24, 0x80, 0x65, 0x28, 0x72, 0x00, 0x0a, 0xe9, 0xc1, 0x08, 0x48, \n\t0xb0, 0x42, 0x0c, 0x41, 0x55, 0x26, 0x0e, 0x21, 0x1a, 0x84, 0xd1, 0x10, 0x42, 0x18, 0x07, 0xa1, \n\t0x13, 0x4c, 0xd0, 0xc0, 0x0c, 0x44, 0x2a, 0x83, 0x44, 0x01, 0x46, 0x06, 0x45, 0xf0, 0xbc, 0x04, \n\t0x8a, 0xa6, 0x0a, 0x30, 0x11, 0xb4, 0x61, 0xc3, 0x6b, 0x06, 0x07, 0x23, 0xb4, 0x6c, 0x19, 0x49, \n\t0x46, 0xa0, 0x18, 0x28, 0x60, 0x84, 0x8a, 0x12, 0xa5, 0x20, 0x04, 0x31, 0xda, 0x4c, 0x60, 0x21, \n\t0x0a, 0x17, 0x14, 0x02, 0x04, 0x32, 0x90, 0x92, 0x83, 0x89, 0x4b, 0x42, 0x68, 0x00, 0x53, 0x11, \n\t0x80, 0xd7, 0x88, 0x18, 0x72, 0xa1, 0x04, 0xb0, 0x00, 0x64, 0x08, 0x42, 0xc1, 0x2e, 0x54, 0x81, \n\t0x85, 0x68, 0xa4, 0x98, 0x92, 0x38, 0x59, 0x04, 0x44, 0x00, 0xa3, 0xa1, 0x64, 0x0f, 0x22, 0x3e, \n\t0x00, 0x90, 0x02, 0xdd, 0x1c, 0x8b, 0x1c, 0x60, 0xd0, 0x32, 0x84, 0x04, 0x03, 0x06, 0x74, 0x1a, \n\t0x31, 0x2d, 0xc9, 0x82, 0x22, 0xc3, 0x10, 0x82, 0x30, 0x8c, 0x41, 0x12, 0x12, 0x60, 0x35, 0x94, \n\t0x1f, 0x09, 0x32, 0xf1, 0xa8, 0x8c, 0x08, 0x90, 0x6b, 0x48, 0x20, 0x79, 0x3d, 0x54, 0x86, 0x04, \n\t0x4a, 0x71, 0xc8, 0x00, 0xcc, 0x02, 0xe9, 0x0c, 0x24, 0x21, 0x0a, 0x80, 0x52, 0xee, 0x00, 0xa4, \n\t0x32, 0x96, 0x1c, 0x92, 0x64, 0x20, 0x82, 0x8a, 0x88, 0xa1, 0x4b, 0x0e, 0x78, 0x35, 0x51, 0x00, \n\t0xa0, 0x49, 0x69, 0x72, 0x07, 0x23, 0x14, 0xa0, 0x45, 0x0a, 0x04, 0xd0, 0xd9, 0x82, 0xa1, 0x07, \n\t0xe5, 0x08, 0x03, 0x20, 0x3c, 0x70, 0xd4, 0x0c, 0x12, 0xc0, 0x49, 0x20, 0x08, 0xd1, 0x08, 0x62, \n\t0x63, 0x11, 0x02, 0x10, 0x98, 0x4f, 0x72, 0x20, 0x81, 0x11, 0xa8, 0x53, 0xab, 0x14, 0x02, 0x10, \n\t0x8e, 0x94, 0x86, 0x49, 0x20, 0x31, 0x02, 0x19, 0x41, 0x48, 0x62, 0x44, 0xc5, 0x80, 0x18, 0x14, \n\t0xd0, 0x83, 0x00, 0x57, 0x88, 0x25, 0xad, 0x42, 0x80, 0x3a, 0x30, 0x90, 0x15, 0xd5, 0x1a, 0xe1, \n\t0x4c, 0x24, 0x20, 0x80, 0xe1, 0x08, 0xc7, 0x14, 0x05, 0x8a, 0x11, 0xb0, 0x01, 0x28, 0x10, 0x33, \n\t0x21, 0x93, 0x04, 0xcf, 0x44, 0x22, 0xc0, 0xc9, 0x9a, 0x00, 0x4a, 0x0c, 0x2c, 0x01, 0xb1, 0x8e, \n\t0x10, 0x58, 0x21, 0x14, 0x96, 0x63, 0x34, 0x44, 0x43, 0x04, 0x44, 0xb0, 0x5b, 0x80, 0x28, 0x0c, \n\t0x00, 0x24, 0x33, 0x80, 0x0a, 0x1c, 0x0b, 0x65, 0x26, 0xe0, 0x2a, 0x1e, 0x09, 0x9d, 0xa5, 0x48, \n\t0x44, 0x13, 0x25, 0x2c, 0xc4, 0x22, 0x30, 0x00, 0x62, 0xa4, 0x48, 0x46, 0x40, 0x50, 0x27, 0x00, \n\t0xb8, 0xa4, 0x44, 0x0c, 0x26, 0x44, 0x98, 0x89, 0x81, 0x03, 0x0d, 0x1c, 0xc6, 0x58, 0x82, 0x40, \n\t0x18, 0x4b, 0x40, 0x85, 0x8b, 0x3b, 0x38, 0xc8, 0x2d, 0x64, 0x87, 0x61, 0x11, 0x58, 0x41, 0x88, \n\t0x16, 0x14, 0x89, 0x19, 0x9d, 0x10, 0xa0, 0x08, 0x22, 0x80, 0x02, 0x44, 0x86, 0x81, 0x04, 0x33, \n\t0x80, 0x10, 0x19, 0xc0, 0xc1, 0x48, 0x10, 0x80, 0x31, 0x40, 0x1f, 0x01, 0x24, 0x03, 0xe1, 0x3f, \n\t0x48, 0x4b, 0x8a, 0x10, 0x21, 0xd8, 0x06, 0x95, 0x19, 0x6b, 0x42, 0x80, 0x68, 0x16, 0x64, 0x48, \n\t0x22, 0x40, 0xd5, 0x18, 0xa9, 0x10, 0xc5, 0x0b, 0x1c, 0x74, 0x51, 0xb8, 0x25, 0x00, 0xc0, 0x62, \n\t0xa2, 0xa9, 0x10, 0xb4, 0x8a, 0x60, 0x2a, 0x77, 0xc1, 0x8e, 0x10, 0x83, 0x48, 0x76, 0x92, 0x42, \n\t0x25, 0x08, 0xc0, 0x2c, 0x1e, 0x30, 0x60, 0x21, 0x79, 0x02, 0x88, 0x30, 0x95, 0x30, 0x2a, 0x84, \n\t0x00, 0x4a, 0x4c, 0x43, 0x10, 0x17, 0x11, 0x94, 0xa2, 0x08, 0x80, 0x31, 0xb4, 0x6d, 0xc8, 0x80, \n\t0x6a, 0x40, 0x2b, 0x04, 0x70, 0x1b, 0x49, 0x78, 0xc0, 0x88, 0x04, 0x5c, 0x01, 0x25, 0x40, 0x44, \n\t0x41, 0x18, 0x05, 0x4f, 0x06, 0x0a, 0x20, 0x61, 0x37, 0xd0, 0x40, 0x05, 0x0a, 0x26, 0x48, 0xb8, \n\t0x88, 0x5b, 0x21, 0x10, 0x43, 0xda, 0x9e, 0x29, 0x81, 0xa3, 0x18, 0x00, 0x33, 0x09, 0x98, 0x93, \n\t0xcd, 0x52, 0x42, 0xa3, 0x25, 0x85, 0x1e, 0x28, 0x14, 0x35, 0x50, 0x01, 0xd0, 0xd0, 0x4a, 0x2c, \n\t0xa1, 0x22, 0xa0, 0x5d, 0x1c, 0xe2, 0x02, 0x54, 0x90, 0x02, 0x88, 0x5f, 0x28, 0x78, 0x04, 0x83, \n\t0x02, 0x40, 0x8c, 0x20, 0x0c, 0x82, 0x11, 0x04, 0x71, 0x4d, 0x26, 0x66, 0x32, 0x88, 0x8a, 0xa0, \n\t0x07, 0x8c, 0x00, 0xa3, 0x40, 0x09, 0x31, 0xc7, 0x81, 0x30, 0xd4, 0x43, 0x0a, 0x88, 0x9d, 0x49, \n\t0x4a, 0x81, 0x01, 0x8a, 0x18, 0x02, 0x67, 0x64, 0x36, 0x88, 0x18, 0x88, 0x05, 0xe8, 0x14, 0x40, \n\t0x79, 0x07, 0x49, 0x90, 0xc9, 0x2c, 0xd6, 0x02, 0x93, 0x80, 0x48, 0xa9, 0x0c, 0x67, 0x10, 0xa6, \n\t0x24, 0x51, 0x66, 0x04, 0x00, 0x5b, 0x13, 0xc8, 0xcd, 0x00, 0x62, 0x05, 0x2b, 0x32, 0x31, 0x19, \n\t0xc8, 0x20, 0x02, 0x90, 0x92, 0x21, 0x4d, 0xe0, 0x64, 0xc0, 0x43, 0x10, 0x84, 0x44, 0xa7, 0x1a, \n\t0x12, 0x18, 0x34, 0x01, 0x08, 0x07, 0x0a, 0xb4, 0xaa, 0x32, 0x1c, 0x16, 0x40, 0x06, 0xc1, 0xa8, \n\t0x1e, 0x21, 0x40, 0x41, 0x12, 0xb4, 0x13, 0x08, 0x85, 0x40, 0x0c, 0x02, 0xf0, 0x13, 0x28, 0x69, \n\t0x80, 0x45, 0x70, 0x75, 0x70, 0x80, 0x41, 0x02, 0x21, 0x00, 0x33, 0x88, 0xbc, 0x65, 0x80, 0x46, \n\t0x54, 0x82, 0x03, 0x13, 0x04, 0xc1, 0x08, 0x20, 0x50, 0x03, 0x23, 0x30, 0x1e, 0x82, 0x32, 0xa6, \n\t0xc8, 0x2a, 0x91, 0x48, 0x4c, 0x10, 0x94, 0xc1, 0x20, 0x9c, 0x03, 0x28, 0x34, 0x90, 0x70, 0xba, \n\t0xb1, 0x4a, 0xc4, 0x58, 0x44, 0xe0, 0xa8, 0xbc, 0x40, 0x05, 0x48, 0x35, 0x22, 0x10, 0x30, 0x16, \n\t0x27, 0x24, 0x20, 0x12, 0x38, 0x64, 0x07, 0x46, 0x08, 0xa3, 0xf0, 0x09, 0x14, 0x8a, 0xea, 0x20, \n\t0x07, 0xc3, 0x00, 0x85, 0x89, 0xc0, 0x22, 0xc0, 0x20, 0x8c, 0x68, 0x0a, 0x02, 0x26, 0x43, 0x48, \n\t0x8e, 0x4c, 0x03, 0xa2, 0x48, 0x75, 0xb2, 0x00, 0x61, 0x81, 0x60, 0x68, 0x40, 0x83, 0x90, 0xc5, \n\t0x50, 0x00, 0x50, 0x56, 0x02, 0xa3, 0x14, 0x44, 0x24, 0x3e, 0xa4, 0x49, 0x3a, 0x01, 0xd0, 0x0b, \n\t0x48, 0x63, 0x8a, 0xa4, 0x20, 0xd2, 0x4c, 0x1e, 0x44, 0x61, 0x11, 0x49, 0x44, 0x61, 0x36, 0x84, \n\t0x12, 0x38, 0xe8, 0x04, 0xa6, 0x50, 0x92, 0x69, 0x89, 0x35, 0x1c, 0xa1, 0x04, 0x75, 0x62, 0x2d, \n\t0xc0, 0x91, 0x82, 0x02, 0x32, 0x18, 0x05, 0x71, 0xc8, 0x66, 0x50, 0x06, 0x58, 0x3a, 0x04, 0x00, \n\t0x2c, 0x18, 0x21, 0x21, 0x07, 0x8c, 0x41, 0x42, 0x14, 0xc0, 0xb0, 0x2e, 0x08, 0x01, 0x0b, 0x10, \n\t0x03, 0x80, 0x91, 0x88, 0x02, 0xae, 0x0c, 0x14, 0x09, 0x84, 0x60, 0x5b, 0xc1, 0x40, 0x23, 0x63, \n\t0x08, 0x80, 0x10, 0x0d, 0x0e, 0x82, 0xc8, 0x00, 0xb9, 0xdd, 0x44, 0x2a, 0x30, 0x6a, 0x30, 0x69, \n\t0x10, 0x6c, 0x00, 0x93, 0x19, 0x82, 0xcc, 0x10, 0x80, 0x2c, 0x41, 0xd2, 0x85, 0x18, 0x88, 0x24, \n\t0x4e, 0xd7, 0x88, 0xa9, 0x0c, 0x86, 0xa1, 0x04, 0x43, 0x2a, 0x91, 0x60, 0x03, 0x04, 0x12, 0x50, \n\t0x50, 0x20, 0xb1, 0xcc, 0x02, 0x60, 0x87, 0xab, 0x16, 0x90, 0x10, 0xe4, 0x72, 0x51, 0x00, 0x2b, \n\t0x60, 0x4a, 0x05, 0x0a, 0x35, 0x00, 0x22, 0x40, 0x89, 0x8a, 0x48, 0x56, 0xc2, 0x0c, 0x00, 0xc2, \n\t0x2c, 0x40, 0x34, 0x3a, 0x08, 0x39, 0x9b, 0x85, 0x5a, 0x14, 0x53, 0x0d, 0x10, 0x01, 0x0f, 0x00, \n\t0x81, 0x93, 0x2e, 0x69, 0x94, 0x2e, 0x1c, 0x41, 0xc0, 0x17, 0x18, 0x91, 0x8e, 0x08, 0x44, 0x98, \n\t0xa3, 0x61, 0x02, 0x44, 0x26, 0x42, 0xe1, 0x80, 0x88, 0x16, 0x02, 0x00, 0x64, 0x0a, 0x30, 0x00, \n\t0x08, 0xe1, 0x04, 0x03, 0xd1, 0x38, 0x14, 0x19, 0x01, 0x72, 0x52, 0x51, 0x18, 0x05, 0x85, 0x4e, \n\t0x06, 0xa1, 0x30, 0x26, 0x84, 0x4e, 0x4b, 0x42, 0x71, 0x01, 0x98, 0x30, 0x44, 0x21, 0x0e, 0x70, \n\t0x62, 0x19, 0x11, 0x00, 0x2b, 0x10, 0x30, 0x22, 0x25, 0x6c, 0x14, 0xc0, 0x5e, 0xd2, 0xb8, 0x07, \n\t0x45, 0x90, 0x48, 0x50, 0xc5, 0xa3, 0x81, 0x85, 0x40, 0x22, 0x4a, 0x05, 0x9a, 0x16, 0x48, 0x8d, \n\t0x05, 0x32, 0x16, 0xe2, 0xa2, 0x21, 0x4c, 0x00, 0x06, 0x05, 0x60, 0xa2, 0xbd, 0x48, 0xcb, 0x50, \n\t0x04, 0x02, 0x8a, 0xe4, 0x08, 0xa0, 0x00, 0x41, 0x00, 0x19, 0x65, 0x05, 0x8d, 0x20, 0x00, 0x20, \n\t0x87, 0x30, 0x0d, 0x4a, 0x7a, 0xd3, 0x28, 0x07, 0x04, 0x84, 0x61, 0x14, 0xd0, 0x81, 0x88, 0xa1, \n\t0xde, 0x86, 0x22, 0x80, 0x69, 0x00, 0xa9, 0xc3, 0x00, 0x06, 0x33, 0xc8, 0x01, 0x51, 0x16, 0x08, \n\t0x20, 0x66, 0x10, 0x9e, 0xc4, 0x00, 0xc6, 0x44, 0xc6, 0x02, 0x02, 0x0d, 0xd1, 0x25, 0x74, 0xd2, \n\t0x41, 0x28, 0xe0, 0x18, 0x82, 0x04, 0x34, 0x52, 0xa5, 0x48, 0x84, 0x4a, 0x76, 0xa1, 0x0b, 0xb6, \n\t0x0c, 0x50, 0x20, 0x20, 0x04, 0x03, 0x88, 0xdc, 0x0c, 0x41, 0x0a, 0x06, 0x00, 0x31, 0x91, 0x02, \n\t0x89, 0x10, 0xe4, 0x23, 0x91, 0x10, 0x9f, 0x45, 0x6c, 0x54, 0xf9, 0x9f, 0x60, 0x0a, 0x80, 0x02, \n\t0x30, 0x71, 0x0d, 0x10, 0x42, 0x82, 0x46, 0x30, 0x12, 0x04, 0x0c, 0x12, 0x08, 0x70, 0xa1, 0x71, \n\t0xa2, 0x50, 0x00, 0xe4, 0x44, 0xd2, 0x28, 0x09, 0x0d, 0xda, 0x40, 0x40, 0x16, 0x78, 0x26, 0xa0, \n\t0x86, 0xa4, 0x08, 0x14, 0x90, 0x00, 0xd1, 0x0a, 0x00, 0x0a, 0xc3, 0x19, 0xac, 0xa5, 0x41, 0xc0, \n\t0x66, 0xb1, 0x50, 0x22, 0x28, 0x09, 0x04, 0x0a, 0xc6, 0x01, 0x96, 0x20, 0x5a, 0x4c, 0x08, 0x45, \n\t0xa2, 0x20, 0xac, 0x57, 0x0c, 0x20, 0x24, 0xa0, 0x81, 0x48, 0x50, 0x85, 0x4e, 0x14, 0x8a, 0x08, \n\t0x50, 0xd5, 0x4f, 0x46, 0xe3, 0x79, 0x0d, 0x0c, 0x88, 0x83, 0x10, 0x03, 0xa0, 0x0b, 0x85, 0x92, \n\t0x05, 0x60, 0xe2, 0x08, 0x20, 0x25, 0x15, 0x44, 0x1a, 0x45, 0x11, 0xbc, 0x80, 0x08, 0x80, 0x50, \n\t0x34, 0x22, 0x15, 0x80, 0x8b, 0x8a, 0x10, 0x41, 0x79, 0xa8, 0x64, 0x50, 0x4e, 0x04, 0xa4, 0x0a, \n\t0x18, 0xcc, 0x88, 0xa5, 0x04, 0xa2, 0x41, 0x8d, 0x40, 0x56, 0x00, 0x70, 0xa3, 0x41, 0x03, 0x30, \n\t0x88, 0x2c, 0x2c, 0x07, 0xcb, 0x92, 0xc1, 0x05, 0xae, 0x14, 0x82, 0xb8, 0x01, 0x58, 0x07, 0x09, \n\t0x10, 0xc2, 0x21, 0x2c, 0xf0, 0x18, 0x02, 0x40, 0x64, 0xa2, 0x29, 0x58, 0x41, 0x80, 0x28, 0xc4, \n\t0x88, 0x09, 0x64, 0x87, 0x82, 0x16, 0x90, 0x21, 0x09, 0x09, 0x5f, 0x06, 0x50, 0x00, 0xd0, 0x92, \n\t0xb8, 0x83, 0x81, 0x68, 0x01, 0x5a, 0x10, 0x3c, 0x05, 0x60, 0x20, 0xb0, 0x10, 0x80, 0x48, 0x88, \n\t0x2b, 0x04, 0x53, 0x38, 0xb3, 0x41, 0x92, 0x4c, 0x62, 0xa6, 0x21, 0x05, 0x2c, 0x48, 0x4d, 0x14, \n\t0x34, 0x32, 0x0b, 0x01, 0x1a, 0xa9, 0x48, 0x02, 0xca, 0x20, 0x21, 0x44, 0x47, 0x06, 0x40, 0x40, \n\t0x81, 0xd4, 0x12, 0x62, 0x14, 0x95, 0x61, 0xb1, 0x98, 0x00, 0x6b, 0x46, 0xa3, 0xb2, 0x1e, 0x10, \n\t0xd6, 0x21, 0x1c, 0x01, 0x88, 0x94, 0x25, 0x80, 0x80, 0x46, 0x61, 0xcb, 0xb3, 0x40, 0x84, 0x8b, \n\t0x50, 0x43, 0xd1, 0x34, 0x31, 0x1d, 0x04, 0x12, 0x15, 0x40, 0x30, 0x00, 0x48, 0xc2, 0x20, 0x95, \n\t0x19, 0x18, 0xf5, 0x8d, 0x84, 0x10, 0x31, 0x0a, 0xbc, 0x04, 0xd9, 0x20, 0x1c, 0x42, 0xf0, 0x01, \n\t0x68, 0x94, 0x2e, 0x0a, 0x86, 0xb0, 0x01, 0x4c, 0x40, 0x21, 0x4c, 0x91, 0x80, 0xaa, 0x34, 0x06, \n\t0xa4, 0x58, 0x01, 0x13, 0xa1, 0x50, 0x41, 0x43, 0x20, 0xc4, 0xa2, 0xa0, 0x20, 0x46, 0x04, 0x38, \n\t0x96, 0xaa, 0x82, 0x6c, 0x12, 0x0e, 0x4c, 0x21, 0x43, 0x13, 0x94, 0x1e, 0x02, 0x46, 0x66, 0x48, \n\t0x10, 0x44, 0x45, 0xe8, 0x06, 0x01, 0x10, 0x12, 0xcc, 0x0a, 0xcd, 0x08, 0x31, 0x10, 0x2f, 0xf0, \n\t0x19, 0x00, 0x70, 0x22, 0x63, 0x88, 0x0c, 0x13, 0x04, 0x48, 0xe0, 0x68, 0x86, 0xa8, 0xcf, 0x60, \n\t0x50, 0x00, 0xb2, 0x00, 0x81, 0x47, 0x22, 0x48, 0x40, 0x3b, 0x25, 0x40, 0x96, 0x45, 0x24, 0x62, \n\t0xa1, 0x08, 0x99, 0xc2, 0x44, 0x04, 0x32, 0x22, 0x01, 0x14, 0x96, 0xa5, 0x58, 0x16, 0x4b, 0x90, \n\t0x49, 0x01, 0x08, 0x32, 0x74, 0x61, 0x00, 0x6d, 0x17, 0x22, 0x12, 0x46, 0x41, 0x20, 0x79, 0x11, \n\t0x01, 0x56, 0xa6, 0x00, 0x02, 0x49, 0x46, 0x2f, 0x02, 0x07, 0x08, 0x0d, 0x45, 0x40, 0xc9, 0x68, \n\t0x07, 0x01, 0x98, 0x34, 0x00, 0x48, 0x28, 0x83, 0x00, 0x1c, 0x81, 0x41, 0xc8, 0x50, 0x20, 0x32, \n\t0x34, 0x95, 0x07, 0x45, 0x48, 0x60, 0x08, 0x0a, 0x54, 0x82, 0x24, 0x60, 0x37, 0xd0, 0xaa, 0xc5, \n\t0xd3, 0x42, 0x04, 0x32, 0xaa, 0x1a, 0x40, 0x05, 0xc1, 0x10, 0x44, 0x0a, 0x80, 0x2c, 0xd0, 0x88, \n\t0x4c, 0x31, 0x42, 0x06, 0x95, 0x07, 0xe2, 0x0c, 0x23, 0xdb, 0xa0, 0x81, 0x09, 0x64, 0x24, 0xf0, \n\t0x4a, 0x10, 0x30, 0x03, 0xc0, 0x1c, 0xc6, 0x40, 0x88, 0xa5, 0x5d, 0x45, 0x22, 0xc1, 0xc2, 0x03, \n\t0x20, 0x9a, 0x2c, 0x40, 0x76, 0x08, 0x14, 0x21, 0x8c, 0xe0, 0x26, 0xb4, 0xf2, 0x08, 0x74, 0x82, \n\t0x0d, 0x04, 0x90, 0x98, 0x2a, 0x48, 0x00, 0x09, 0x50, 0x31, 0xc2, 0x06, 0x08, 0x43, 0xe3, 0x22, \n\t0x14, 0x02, 0x89, 0x45, 0xc4, 0x23, 0x18, 0xd0, 0xb8, 0xa0, 0x89, 0x92, 0x2a, 0x58, 0x51, 0xa0, \n\t0x80, 0xed, 0x03, 0x2b, 0x20, 0x80, 0x18, 0x96, 0x8c, 0x08, 0x00, 0x02, 0x62, 0x83, 0x09, 0x61, \n\t0x01, 0x8d, 0x28, 0x04, 0x48, 0x85, 0x11, 0x58, 0x07, 0x50, 0x05, 0x08, 0x37, 0xb0, 0x96, 0x40, \n\t0x04, 0x05, 0x93, 0x01, 0x11, 0x0f, 0xa9, 0x74, 0x02, 0xb0, 0x04, 0xac, 0xd0, 0xa3, 0x00, 0x21, \n\t0xb0, 0x04, 0x68, 0x10, 0x63, 0x20, 0x60, 0x53, 0x98, 0x88, 0x11, 0x47, 0x28, 0x31, 0x20, 0x24, \n\t0x79, 0x03, 0x20, 0x66, 0x13, 0xa3, 0x36, 0xa1, 0x0f, 0x00, 0x42, 0x74, 0x50, 0x84, 0x70, 0x87, \n\t0x40, 0x28, 0x61, 0xd2, 0x06, 0x98, 0x18, 0x09, 0x44, 0x75, 0x88, 0x93, 0x81, 0x46, 0x82, 0x06, \n\t0xc4, 0x20, 0x8c, 0x44, 0x02, 0x8c, 0x62, 0x94, 0x4b, 0x80, 0x04, 0x0d, 0x49, 0x18, 0x80, 0x80, \n\t0x98, 0x29, 0xc0, 0x2a, 0x76, 0x80, 0x40, 0x15, 0xd1, 0x42, 0x2a, 0x0e, 0xd0, 0xe9, 0x81, 0x11, \n\t0x0a, 0x84, 0x58, 0x00, 0x00, 0x9f, 0x80, 0x80, 0x8e, 0x02, 0x45, 0x90, 0x10, 0x30, 0x53, 0x82, \n\t0x0e, 0x06, 0xa0, 0xb2, 0xa8, 0x90, 0x84, 0x04, 0x41, 0x99, 0x05, 0x11, 0x0f, 0xa1, 0x70, 0x82, \n\t0x29, 0x8e, 0xbc, 0x10, 0x41, 0x20, 0xe5, 0x5b, 0x32, 0x05, 0x86, 0x47, 0x02, 0x23, 0x20, 0x25, \n\t0xd0, 0x8c, 0x02, 0x30, 0x40, 0x4a, 0x32, 0x28, 0xc1, 0x40, 0x62, 0x52, 0x12, 0x19, 0xa8, 0x5a, \n\t0xc5, 0x78, 0x26, 0x4a, 0x0d, 0x65, 0x97, 0x08, 0x1c, 0x81, 0x03, 0x8c, 0xd1, 0x8c, 0x02, 0x0c, \n\t0xa4, 0xe1, 0x02, 0xc0, 0xc9, 0x2e, 0x20, 0x00, 0x32, 0x30, 0x59, 0x50, 0xa7, 0x20, 0xc1, 0x40, \n\t0x84, 0xe9, 0xd8, 0x08, 0x5a, 0x50, 0x91, 0x10, 0x50, 0x1a, 0xc8, 0x28, 0x80, 0x4a, 0x0a, 0x14, \n\t0x09, 0x86, 0x70, 0x80, 0x51, 0x13, 0xc8, 0x02, 0xc4, 0x34, 0x54, 0x60, 0x8a, 0x95, 0x80, 0x07, \n\t0x28, 0x64, 0x22, 0x8c, 0x1c, 0x8a, 0x25, 0x18, 0x03, 0xe2, 0x97, 0x90, 0x16, 0x61, 0x00, 0x26, \n\t0x08, 0x38, 0x24, 0xc1, 0xe8, 0x50, 0x82, 0x12, 0x00, 0x09, 0x90, 0x84, 0x4c, 0x80, 0x92, 0x01, \n\t0x04, 0x0a, 0x6f, 0x68, 0x34, 0x9a, 0xa8, 0x30, 0x58, 0x05, 0x12, 0x84, 0xa3, 0x02, 0x0c, 0xd1, \n\t0xa4, 0x2a, 0x10, 0x09, 0x03, 0x45, 0x15, 0x61, 0x30, 0xa7, 0x00, 0x98, 0x01, 0x44, 0x88, 0x16, \n\t0x13, 0x93, 0x28, 0x11, 0xc6, 0x44, 0x04, 0x77, 0x68, 0x18, 0x00, 0x8b, 0x03, 0x4a, 0xb3, 0x60, \n\t0x2e, 0x90, 0x85, 0x29, 0x42, 0x36, 0x38, 0x9c, 0xa0, 0x00, 0x2a, 0x40, 0x04, 0x2b, 0x14, 0x05, \n\t0x86, 0xa1, 0x4c, 0xd1, 0x0a, 0x27, 0xc0, 0x04, 0x4a, 0x60, 0x04, 0xb1, 0xa1, 0x04, 0x10, 0xe9, \n\t0x62, 0xb6, 0xb2, 0x04, 0x74, 0x48, 0x61, 0x4c, 0x01, 0x12, 0x87, 0x05, 0x91, 0xa4, 0x16, 0x30, \n\t0x09, 0xb4, 0x68, 0x54, 0x03, 0x04, 0x82, 0x02, 0x22, 0x45, 0x54, 0x88, 0x00, 0x81, 0xda, 0x8a, \n\t0xb5, 0x00, 0x42, 0x30, 0x41, 0x30, 0xb1, 0x04, 0x06, 0x0e, 0x1a, 0xa0, 0xe8, 0x09, 0x00, 0x48, \n\t0x40, 0x0e, 0x86, 0x10, 0x02, 0xe0, 0x0e, 0x07, 0x60, 0x10, 0x10, 0x29, 0x08, 0xd3, 0xec, 0x12, \n\t0x71, 0x88, 0x22, 0x8c, 0x92, 0xa4, 0x08, 0x20, 0x53, 0x0f, 0xc0, 0x81, 0x00, 0x0a, 0x87, 0x08, \n\t0x03, 0x0d, 0x08, 0x20, 0x7c, 0x40, 0x08, 0x2b, 0xa1, 0x46, 0x24, 0x60, 0x70, 0x22, 0x85, 0x11, \n\t0x81, 0xc1, 0x6a, 0x84, 0x80, 0x06, 0xa4, 0x14, 0xcb, 0x04, 0xa2, 0x02, 0xb8, 0x10, 0x05, 0x4b, \n\t0x30, 0x55, 0x28, 0x84, 0xc4, 0x00, 0x42, 0x2a, 0xc0, 0xc2, 0x18, 0x80, 0x04, 0x25, 0x4a, 0x65, \n\t0x13, 0x1d, 0x39, 0x90, 0x0c, 0x58, 0x84, 0xc3, 0x0c, 0x38, 0x83, 0xe2, 0x00, 0x21, 0x0a, 0x8c, \n\t0x38, 0x86, 0x4d, 0x74, 0xc2, 0x10, 0x04, 0x09, 0x4b, 0xa1, 0x40, 0xb4, 0x0a, 0xa2, 0x2c, 0x52, \n\t0x22, 0x10, 0xc0, 0x63, 0x08, 0xc1, 0x82, 0x82, 0x0e, 0x21, 0x28, 0x12, 0x94, 0xd8, 0x02, 0x0c, \n\t0x46, 0x09, 0x3a, 0x84, 0x11, 0xc8, 0x12, 0x30, 0x89, 0x90, 0x35, 0x48, 0xe8, 0x24, 0x55, 0x10, \n\t0xa7, 0x80, 0x03, 0x43, 0x02, 0x17, 0x09, 0x9a, 0x10, 0x8d, 0x28, 0x62, 0xe4, 0x2a, 0x11, 0x68, \n\t0x04, 0x20, 0x22, 0x10, 0x42, 0x01, 0xcc, 0x04, 0x88, 0x1e, 0xc1, 0x83, 0x28, 0x20, 0x0c, 0x24, \n\t0x14, 0x63, 0xa1, 0x90, 0x09, 0x19, 0x23, 0x28, 0x20, 0x2a, 0x38, 0x0c, 0x1d, 0x42, 0x4c, 0x90, \n\t0xc0, 0x0b, 0x41, 0x8f, 0x06, 0x14, 0x55, 0xb8, 0x92, 0x2d, 0xc8, 0x49, 0x42, 0xa0, 0x23, 0x92, \n\t0x48, 0x05, 0xc7, 0x74, 0x84, 0x80, 0x8b, 0x4d, 0x8d, 0x40, 0x38, 0x00, 0x20, 0x9c, 0xa1, 0x06, \n\t0x09, 0x32, 0x54, 0xa8, 0x85, 0x88, 0x41, 0x05, 0x44, 0xd3, 0x13, 0x04, 0x21, 0xd8, 0x8f, 0x02, \n\t0x90, 0xc1, 0x08, 0x78, 0x54, 0x26, 0x40, 0x50, 0x4a, 0x24, 0x39, 0x16, 0xa0, 0x00, 0x12, 0x41, \n\t0xb0, 0x14, 0x50, 0x82, 0x6c, 0xa3, 0x80, 0xa3, 0x71, 0x82, 0x03, 0x04, 0x04, 0xd9, 0x21, 0x09, \n\t0x5e, 0xa8, 0x08, 0x70, 0x82, 0x15, 0x68, 0x04, 0x8b, 0x52, 0x63, 0x29, 0x3a, 0x54, 0x51, 0x4b, \n\t0x62, 0x80, 0x99, 0x18, 0x34, 0x44, 0x2e, 0x30, 0x30, 0x40, 0xb2, 0x41, 0x4e, 0x44, 0x10, 0xc0, \n\t0xca, 0xa4, 0x10, 0x1a, 0x01, 0x40, 0x66, 0xf2, 0x8c, 0x01, 0x84, 0x2c, 0x18, 0x30, 0xaa, 0x11, \n\t0x05, 0xd0, 0x40, 0x52, 0xa1, 0x79, 0x83, 0xb0, 0x80, 0x2b, 0x64, 0x01, 0x80, 0x9e, 0x50, 0x18, \n\t0x01, 0x04, 0x00, 0xa2, 0x17, 0x28, 0xca, 0x24, 0x30, 0xd3, 0x22, 0xa2, 0x6d, 0x50, 0x20, 0x46, \n\t0x24, 0x80, 0x84, 0xe8, 0x0a, 0x00, 0x02, 0x01, 0x33, 0x8c, 0x74, 0x00, 0x07, 0x42, 0xd6, 0x13, \n\t0x11, 0x38, 0x0c, 0x8c, 0x18, 0x32, 0x49, 0x29, 0x61, 0x82, 0x8a, 0x20, 0x50, 0x41, 0x08, 0xac, \n\t0xc1, 0x41, 0x30, 0x25, 0x58, 0x8a, 0xb0, 0x42, 0x24, 0x5c, 0x02, 0x5a, 0x00, 0xc5, 0x12, 0x82, \n\t0x1c, 0x20, 0x42, 0x07, 0xad, 0x04, 0x21, 0x64, 0x52, 0x00, 0x9f, 0x48, 0x48, 0x09, 0x24, 0x31, \n\t0xa2, 0xa9, 0x14, 0x58, 0xe1, 0x72, 0x15, 0x58, 0x26, 0x89, 0x0d, 0x0e, 0x04, 0x00, 0x00, 0x26, \n\t0x84, 0x85, 0xa0, 0x26, 0x03, 0x00, 0x32, 0xb9, 0x00, 0xa2, 0x50, 0x05, 0x80, 0x11, 0x10, 0x0e, \n\t0x85, 0x00, 0x62, 0x61, 0x85, 0x74, 0x99, 0x8a, 0x00, 0x31, 0x4a, 0x01, 0x90, 0x09, 0x0c, 0x26, \n\t0xd0, 0x90, 0x07, 0xc1, 0x50, 0x41, 0x26, 0xb6, 0xd9, 0x3c, 0x19, 0x83, 0x09, 0x08, 0x71, 0x10, \n\t0x2a, 0x68, 0x88, 0x25, 0x00, 0xb2, 0xb0, 0x00, 0xc4, 0x82, 0xc1, 0x48, 0x07, 0x92, 0x16, 0x0c, \n\t0x01, 0xe4, 0x22, 0x02, 0x03, 0x88, 0x0c, 0x81, 0x24, 0x4e, 0x24, 0x48, 0x20, 0x75, 0x41, 0xa2, \n\t0x28, 0x80, 0x90, 0x12, 0x59, 0x15, 0x47, 0x52, 0x80, 0x00, 0xb1, 0x15, 0x09, 0xc0, 0x18, 0x81, \n\t0x18, 0x21, 0x44, 0x58, 0x80, 0x28, 0xc2, 0x00, 0xb6, 0xac, 0x58, 0x00, 0x50, 0x24, 0x32, 0x81, \n\t0x18, 0x15, 0x6a, 0x64, 0x84, 0xc9, 0x21, 0xd0, 0x01, 0x4e, 0x16, 0x31, 0xe8, 0x2e, 0xc1, 0x98, \n\t0x81, 0x04, 0x03, 0x30, 0xa4, 0x8c, 0xc0, 0x0f, 0x02, 0xe1, 0x08, 0x13, 0x49, 0x00, 0xe0, 0x40, \n\t0x52, 0xd2, 0x08, 0x09, 0x8c, 0x02, 0x44, 0x60, 0x89, 0xb3, 0x29, 0x93, 0x89, 0x1c, 0x24, 0x9a, \n\t0x04, 0x71, 0x18, 0x08, 0x30, 0x91, 0xc2, 0x2a, 0x51, 0x40, 0xa6, 0x02, 0x04, 0x19, 0x18, 0xc1, \n\t0xc8, 0x41, 0x12, 0x06, 0xc0, 0x05, 0x18, 0x47, 0x6c, 0x24, 0x91, 0x21, 0x08, 0x90, 0x4d, 0x6d, \n\t0x10, 0x24, 0xe0, 0x01, 0x0d, 0x92, 0x8b, 0x16, 0xc0, 0x20, 0xa1, 0x40, 0x00, 0x80, 0x24, 0xd4, \n\t0x72, 0x00, 0x88, 0x80, 0xc1, 0x20, 0x43, 0x28, 0x3a, 0x58, 0x42, 0xc5, 0x24, 0x54, 0x69, 0xa6, \n\t0x81, 0x06, 0xac, 0x2a, 0x24, 0x13, 0x12, 0x8c, 0x8a, 0x03, 0x0c, 0x80, 0x32, 0x86, 0xc5, 0x44, \n\t0xa8, 0x00, 0x30, 0x13, 0x19, 0xc8, 0x43, 0x80, 0x1e, 0x10, 0x08, 0x0b, 0x44, 0x5b, 0xc4, 0x10, \n\t0x60, 0x09, 0x25, 0x24, 0xd4, 0x45, 0x24, 0x02, 0xc0, 0x1f, 0x89, 0x14, 0x61, 0x18, 0x30, 0x48, \n\t0x25, 0xac, 0x91, 0xa4, 0x04, 0x51, 0x13, 0xa8, 0x39, 0x14, 0x48, 0x04, 0x20, 0x23, 0x1e, 0x48, \n\t0x0a, 0x83, 0x08, 0x86, 0x20, 0x35, 0x00, 0x09, 0x01, 0x48, 0x90, 0x01, 0xb6, 0xe0, 0x08, 0x08, \n\t0x44, 0x41, 0x61, 0x02, 0x50, 0x1c, 0x29, 0x62, 0x03, 0xd0, 0xaa, 0x00, 0x59, 0xad, 0x30, 0x15, \n\t0x40, 0x0a, 0xfc, 0x81, 0x80, 0x20, 0x63, 0x10, 0x1a, 0x01, 0x15, 0x41, 0x40, 0x47, 0x08, 0x21, \n\t0x00, 0x96, 0x28, 0x22, 0x92, 0x88, 0x8e, 0x80, 0x0b, 0xe8, 0x22, 0x10, 0x11, 0x00, 0x04, 0x07, \n\t0xee, 0x46, 0xb2, 0x48, 0x88, 0x01, 0x8c, 0x42, 0x7c, 0x07, 0xa0, 0x84, 0xd0, 0x82, 0xce, 0x06, \n\t0x97, 0x3a, 0xa0, 0x18, 0x43, 0x81, 0x34, 0x80, 0xa3, 0x01, 0x44, 0xca, 0x2e, 0x44, 0x01, 0x51, \n\t0x00, 0x18, 0x5d, 0x41, 0x0a, 0x84, 0x90, 0x34, 0x24, 0x00, 0xcc, 0x26, 0x03, 0x08, 0x11, 0xc8, \n\t0x0a, 0xc6, 0x20, 0x42, 0x01, 0x18, 0x11, 0xca, 0x46, 0x40, 0x51, 0x00, 0x21, 0x88, 0x0b, 0x25, \n\t0x58, 0x21, 0x80, 0x91, 0x09, 0x18, 0xc2, 0x54, 0x24, 0x41, 0x00, 0xc4, 0xd0, 0x09, 0x0a, 0x10, \n\t0xb9, 0x80, 0xb8, 0x18, 0x21, 0x24, 0x86, 0x30, 0xac, 0x40, 0xd0, 0x63, 0x64, 0xa0, 0x10, 0x10, \n\t0x69, 0x41, 0x41, 0x42, 0x11, 0xaa, 0x16, 0x8d, 0x40, 0x8c, 0x2a, 0x50, 0x8b, 0x80, 0xe1, 0x58, \n\t0x03, 0x46, 0x24, 0x52, 0x84, 0x45, 0x04, 0xa2, 0x52, 0xe6, 0x98, 0x28, 0x10, 0xcf, 0x69, 0x08, \n\t0x14, 0x48, 0x2a, 0x30, 0x83, 0xc0, 0x50, 0x83, 0x20, 0x07, 0xa4, 0x1b, 0x64, 0x52, 0x43, 0x23, \n\t0x14, 0x18, 0x01, 0xc2, 0x78, 0x30, 0x09, 0x04, 0xbc, 0x40, 0x40, 0x4c, 0xc1, 0x90, 0x04, 0x40, \n\t0x0c, 0xa2, 0x70, 0x05, 0xa2, 0x29, 0x09, 0x90, 0xc6, 0x2c, 0xd2, 0x08, 0x0e, 0x68, 0x19, 0xc4, \n\t0x26, 0xd0, 0x12, 0x00, 0x24, 0x87, 0xa0, 0x18, 0x10, 0x9a, 0x85, 0x78, 0x88, 0x60, 0x52, 0x45, \n\t0x43, 0x20, 0xdd, 0x01, 0x20, 0x32, 0x44, 0xc9, 0x9a, 0xc8, 0x4a, 0x83, 0x06, 0x25, 0x10, 0x83, \n\t0xe0, 0x56, 0x00, 0x08, 0x60, 0x2b, 0x8c, 0x28, 0x94, 0x00, 0x26, 0xd0, 0xb1, 0x80, 0x58, 0x9c, \n\t0x00, 0x32, 0x00, 0x80, 0x01, 0x48, 0x07, 0xe4, 0x44, 0x20, 0x22, 0xa6, 0x99, 0x8a, 0x0c, 0x78, \n\t0x90, 0x22, 0x15, 0x94, 0x4a, 0x80, 0x46, 0x32, 0x30, 0x37, 0x05, 0xd1, 0x22, 0x10, 0x04, 0x71, \n\t0xa4, 0x84, 0x13, 0x82, 0x50, 0x44, 0x32, 0x07, 0x50, 0x80, 0x89, 0x18, 0xe3, 0x28, 0x08, 0x91, \n\t0x5c, 0x20, 0x24, 0x24, 0x42, 0x93, 0x89, 0x80, 0x49, 0x20, 0xb4, 0x41, 0x20, 0x01, 0x00, 0x84, \n\t0x00, 0x13, 0x29, 0x8a, 0x04, 0x4c, 0x41, 0x4a, 0xc4, 0x60, 0x08, 0x08, 0x04, 0x8d, 0x48, 0xa6, \n\t0x18, 0x38, 0x0c, 0x84, 0xca, 0x08, 0xa3, 0xb0, 0x8c, 0x0c, 0x0e, 0x4f, 0x34, 0xc0, 0xc0, 0x21, \n\t0x55, 0x53, 0x04, 0x60, 0x76, 0x9a, 0x28, 0x39, 0x81, 0x83, 0x3a, 0x95, 0x43, 0xb4, 0x21, 0x05, \n\t0x82, 0x0c, 0x54, 0xb0, 0xb3, 0x80, 0x02, 0x62, 0x5c, 0x04, 0x2a, 0x2e, 0x08, 0x00, 0x65, 0x06, \n\t0x50, 0x80, 0x8b, 0x90, 0x08, 0x61, 0x12, 0x60, 0x20, 0x0f, 0x50, 0x0b, 0xc1, 0x08, 0x20, 0x41, \n\t0x10, 0x30, 0x01, 0x60, 0x0c, 0x16, 0x89, 0x01, 0x78, 0x9a, 0x68, 0x22, 0x04, 0x31, 0x30, 0x4c, \n\t0x12, 0x85, 0x18, 0x42, 0xb1, 0x81, 0x14, 0x8a, 0x05, 0x58, 0x82, 0x83, 0x34, 0x09, 0x83, 0x07, \n\t0x6e, 0x63, 0x00, 0x1d, 0x00, 0x18, 0xc4, 0x3a, 0xc1, 0x98, 0x3a, 0x2d, 0x41, 0x02, 0x64, 0x15, \n\t0xa8, 0x26, 0x08, 0x0b, 0x68, 0x48, 0x24, 0x03, 0x16, 0x94, 0x4c, 0x86, 0x46, 0x65, 0x82, 0x8a, \n\t0xc8, 0x4d, 0x48, 0x34, 0x71, 0x30, 0x2a, 0x20, 0xd4, 0x8b, 0x00, 0xf0, 0x8a, 0x9e, 0xa4, 0x43, \n\t0x48, 0x1c, 0x02, 0x10, 0x84, 0x01, 0xc5, 0x63, 0x34, 0x16, 0x13, 0x25, 0xc1, 0x10, 0x48, 0x54, \n\t0xc1, 0xc3, 0x00, 0xd0, 0x10, 0x22, 0x04, 0x84, 0xc1, 0x38, 0x01, 0x02, 0x09, 0x02, 0xa0, 0x00, \n\t0x8c, 0x24, 0x0c, 0x03, 0x08, 0x11, 0xc8, 0x2d, 0x48, 0x58, 0x0e, 0x00, 0x04, 0xb2, 0x84, 0x30, \n\t0x80, 0x49, 0x62, 0x00, 0xb8, 0x20, 0x30, 0x08, 0xa7, 0x74, 0x32, 0x08, 0x02, 0x8c, 0xc9, 0x46, \n\t0x12, 0x91, 0x31, 0x33, 0xa0, 0xc7, 0x85, 0x32, 0x24, 0x68, 0x84, 0x90, 0xc0, 0x09, 0x30, 0x50, \n\t0x49, 0x8e, 0xa8, 0x90, 0x84, 0x6a, 0x92, 0x39, 0x14, 0x0d, 0x10, 0xa8, 0x48, 0x21, 0x13, 0x2a, \n\t0x74, 0x98, 0x84, 0x40, 0x96, 0x82, 0x81, 0x00, 0x11, 0x44, 0x00, 0x62, 0xa8, 0xb3, 0x28, 0xd9, \n\t0x02, 0x30, 0xc5, 0xf2, 0x19, 0x80, 0x57, 0x04, 0x02, 0x41, 0x73, 0x00, 0x0c, 0x90, 0x28, 0x00, \n\t0x07, 0x32, 0xa8, 0x2c, 0x58, 0x64, 0x42, 0x03, 0x43, 0x18, 0xb4, 0x04, 0x85, 0x2c, 0x21, 0x19, \n\t0x21, 0x80, 0x02, 0x43, 0x32, 0x54, 0xc0, 0x16, 0x30, 0x8e, 0x21, 0x4a, 0x55, 0x08, 0x02, 0xc0, \n\t0x8b, 0x20, 0x4c, 0x80, 0x32, 0x38, 0x14, 0xd4, 0xa3, 0x40, 0x63, 0xd3, 0x00, 0x49, 0x10, 0xe4, \n\t0x18, 0xe0, 0x01, 0x81, 0x04, 0x52, 0x81, 0x6e, 0x33, 0x28, 0x04, 0x05, 0xce, 0x46, 0x72, 0x82, \n\t0xc2, 0x8d, 0x60, 0x58, 0x0a, 0x36, 0x51, 0x6a, 0x26, 0x04, 0xda, 0x80, 0x0e, 0x06, 0xb1, 0x2a, \n\t0x89, 0x15, 0x08, 0x30, 0x83, 0x10, 0xa1, 0x01, 0x00, 0x84, 0x1c, 0xa1, 0x70, 0xa4, 0x34, 0x4a, \n\t0x4e, 0x28, 0x00, 0xa1, 0x2b, 0x10, 0x90, 0x00, 0x28, 0xc2, 0x70, 0x05, 0xf9, 0x41, 0x67, 0x74, \n\t0x02, 0x18, 0x08, 0xb0, 0xd4, 0x8a, 0x4a, 0xc1, 0x03, 0x0a, 0x91, 0x08, 0x02, 0x3c, 0x25, 0x22, \n\t0x05, 0x44, 0x50, 0x40, 0x08, 0x55, 0x32, 0x07, 0x49, 0x02, 0x27, 0x00, 0x00, 0x02, 0x9a, 0xa4, \n\t0x02, 0x80, 0x44, 0x65, 0x4b, 0xa4, 0x20, 0x13, 0x8b, 0x48, 0x81, 0x0a, 0x88, 0xc0, 0x44, 0x08, \n\t0x56, 0xa7, 0x40, 0x22, 0x05, 0x4e, 0x2e, 0x04, 0xd1, 0x19, 0x88, 0x34, 0x0c, 0x03, 0x00, 0xa2, \n\t0x21, 0x22, 0xa8, 0x1c, 0x01, 0x06, 0x72, 0x91, 0x15, 0x39, 0xd8, 0x8c, 0x2a, 0x22, 0xc8, 0x38, \n\t0x48, 0x05, 0x47, 0x48, 0x12, 0x30, 0x0a, 0x2c, 0x16, 0x89, 0x30, 0xd3, 0x02, 0x06, 0x09, 0x18, \n\t0x24, 0x22, 0x04, 0x02, 0x28, 0x45, 0x46, 0x25, 0x32, 0xc6, 0x00, 0x00, 0x01, 0xc2, 0x0a, 0x78, \n\t0x51, 0xa8, 0x32, 0xa0, 0x03, 0xe8, 0x58, 0xc6, 0x0a, 0x84, 0x65, 0x01, 0x80, 0x10, 0xd4, 0x12, \n\t0xa1, 0x60, 0x0e, 0x89, 0x00, 0x96, 0x01, 0x31, 0x80, 0x09, 0x00, 0x08, 0xf4, 0x0b, 0xb3, 0x1c, \n\t0x8d, 0x20, 0x14, 0x90, 0xe3, 0x12, 0x30, 0x48, 0x0d, 0x1e, 0x04, 0x60, 0x21, 0x88, 0x82, 0x8a, \n\t0x5a, 0x00, 0x4b, 0x89, 0x44, 0x0e, 0xe0, 0x64, 0x01, 0x72, 0x1c, 0x58, 0x11, 0x04, 0x0c, 0x30, \n\t0xa0, 0x1a, 0x1d, 0x9d, 0x03, 0x12, 0x02, 0xd0, 0x12, 0x25, 0x43, 0x2a, 0x3a, 0x50, 0x21, 0x35, \n\t0x69, 0x44, 0x43, 0x08, 0xc0, 0x4a, 0x2c, 0x01, 0x18, 0x41, 0x04, 0x12, 0xd2, 0x0b, 0x48, 0xc7, \n\t0x40, 0x0a, 0xa4, 0x18, 0x9e, 0x80, 0x88, 0x40, 0x18, 0x55, 0xe1, 0x0c, 0x94, 0x5d, 0x01, 0x70, \n\t0x83, 0x48, 0x12, 0x90, 0x59, 0x29, 0x24, 0x22, 0x0a, 0x20, 0x38, 0x80, 0x08, 0x08, 0x03, 0x08, \n\t0x09, 0x64, 0x10, 0x43, 0x20, 0x85, 0x00, 0x2a, 0x1d, 0xda, 0x20, 0x06, 0xe0, 0x22, 0x3c, 0x24, \n\t0x43, 0x40, 0x26, 0xc0, 0x78, 0x94, 0x08, 0x17, 0x0e, 0x58, 0x20, 0x29, 0x07, 0xa4, 0xcc, 0x80, \n\t0x54, 0x42, 0xa2, 0x18, 0x91, 0x01, 0xc4, 0x00, 0x80, 0x10, 0x23, 0x7c, 0x05, 0x87, 0x02, 0xc0, \n\t0x58, 0xaa, 0x01, 0x1e, 0x0b, 0x68, 0x41, 0x03, 0x83, 0xa0, 0x57, 0x01, 0x10, 0x34, 0x19, 0x14, \n\t0x80, 0x02, 0xa0, 0x28, 0x82, 0x61, 0x2c, 0x61, 0x42, 0x40, 0x0e, 0xa3, 0x92, 0x84, 0x81, 0x10, \n\t0x43, 0x2c, 0x94, 0x02, 0x04, 0xcc, 0x48, 0x60, 0x2a, 0x51, 0x92, 0x01, 0x18, 0x49, 0xe6, 0x38, \n\t0x81, 0xa3, 0x2d, 0x60, 0x44, 0x20, 0x10, 0x21, 0x71, 0xb0, 0x04, 0x07, 0xaa, 0x0c, 0xc4, 0x2a, \n\t0x18, 0x14, 0x00, 0x8e, 0x54, 0xf2, 0x01, 0x18, 0x19, 0x48, 0x23, 0x22, 0xc0, 0x18, 0x0c, 0x35, \n\t0x06, 0x49, 0x32, 0x10, 0x63, 0x32, 0xac, 0x44, 0x60, 0x08, 0xe1, 0x48, 0x96, 0x88, 0x84, 0x08, \n\t0x24, 0x00, 0xfb, 0x25, 0x80, 0x81, 0xce, 0x16, 0x02, 0xb9, 0x00, 0xc1, 0x00, 0x0c, 0x44, 0x06, \n\t0x10, 0x83, 0x40, 0x51, 0xc2, 0x60, 0x23, 0x1a, 0xb8, 0x41, 0x80, 0x42, 0x0c, 0x11, 0xe2, 0x12, \n\t0xa4, 0x0d, 0x8a, 0x2e, 0x41, 0x98, 0x20, 0x0d, 0x14, 0xe0, 0x6a, 0x41, 0x10, 0x10, 0xc1, 0x54, \n\t0x05, 0x16, 0x42, 0x18, 0x28, 0x55, 0x0d, 0x03, 0x0a, 0x43, 0x40, 0x00, 0xe0, 0x96, 0x80, 0x10, \n\t0xa1, 0x48, 0x01, 0xa4, 0x12, 0x40, 0x34, 0xe5, 0x30, 0x00, 0x39, 0x06, 0x23, 0x08, 0x94, 0x21, \n\t0x19, 0xc8, 0x41, 0x06, 0x14, 0x82, 0x82, 0x80, 0x4c, 0x90, 0x41, 0x3c, 0x03, 0x12, 0xa6, 0xc4, \n\t0x40, 0x4b, 0x24, 0x44, 0x32, 0x97, 0x7c, 0x02, 0x64, 0x66, 0x52, 0x29, 0x06, 0x85, 0x1c, 0xa2, \n\t0x34, 0x00, 0x18, 0x21, 0x09, 0x90, 0x21, 0x62, 0x06, 0xcb, 0x00, 0x01, 0x45, 0xa0, 0x20, 0x12, \n\t0x41, 0x33, 0x94, 0x08, 0x62, 0x1e, 0x82, 0x50, 0x84, 0xb0, 0x10, 0x8d, 0x50, 0x23, 0x8b, 0x14, \n\t0x00, 0x10, 0x04, 0x48, 0x70, 0x8b, 0x80, 0x88, 0x8f, 0x4d, 0x5c, 0xb0, 0xa1, 0x01, 0x00, 0x84, \n\t0xa8, 0x04, 0x12, 0xf9, 0x00, 0x08, 0x00, 0x8f, 0x30, 0x41, 0x62, 0x90, 0x05, 0x8a, 0xa3, 0x6a, \n\t0x90, 0x02, 0x14, 0x58, 0x4d, 0x00, 0x40, 0x04, 0x80, 0xa5, 0xc1, 0x17, 0x02, 0x76, 0x04, 0x83, \n\t0x07, 0x50, 0x98, 0x49, 0x04, 0x22, 0x90, 0x88, 0x01, 0x5d, 0x04, 0x30, 0x11, 0x58, 0x11, 0x68, \n\t0x80, 0x4c, 0x28, 0x51, 0x61, 0x15, 0x11, 0x4d, 0x42, 0x02, 0x92, 0x22, 0x02, 0x34, 0x5e, 0x49, \n\t0x5a, 0xa2, 0xe2, 0x80, 0x98, 0x0a, 0x0f, 0x40, 0x04, 0x60, 0x08, 0x50, 0x12, 0x60, 0x40, 0x90, \n\t0x1b, 0x8d, 0xd4, 0x86, 0x0e, 0x40, 0x40, 0x70, 0x2b, 0x99, 0xc9, 0x65, 0x00, 0x87, 0x88, 0x2e, \n\t0x10, 0xd3, 0x84, 0x42, 0x01, 0x58, 0x98, 0x05, 0x80, 0x00, 0x20, 0x60, 0xd8, 0x03, 0x80, 0x92, \n\t0xcb, 0x0c, 0x40, 0x98, 0x06, 0x29, 0x40, 0x23, 0x20, 0x36, 0x90, 0x91, 0x50, 0x83, 0x0d, 0x16, \n\t0x24, 0x48, 0xaa, 0x95, 0x0f, 0xc7, 0x60, 0xa0, 0x48, 0x2d, 0xa0, 0x41, 0x28, 0x30, 0x45, 0x82, \n\t0x02, 0x40, 0x55, 0x0e, 0x2e, 0x90, 0x52, 0x20, 0xa5, 0x03, 0x20, 0x5a, 0x41, 0x71, 0xa1, 0x18, \n\t0x90, 0x8e, 0x40, 0xf1, 0xe0, 0xad, 0x40, 0x90, 0x21, 0x06, 0x52, 0x32, 0xa4, 0x20, 0x90, 0x02, \n\t0x0a, 0x90, 0x11, 0x0e, 0x0c, 0x1c, 0xa4, 0x40, 0x21, 0x40, 0x90, 0xa8, 0x4c, 0x8b, 0x3a, 0x20, \n\t0x53, 0x3a, 0x45, 0x01, 0xa5, 0x14, 0x82, 0xc8, 0xb8, 0x11, 0x8c, 0xa2, 0x10, 0x33, 0x08, 0x86, \n\t0xe4, 0x11, 0x07, 0x02, 0xb2, 0x28, 0x1b, 0x24, 0x43, 0x04, 0x66, 0x66, 0x62, 0x8e, 0x60, 0x53, \n\t0x8a, 0x70, 0x90, 0x01, 0x1d, 0x11, 0x14, 0x27, 0x58, 0x10, 0x80, 0x21, 0x89, 0x04, 0xe0, 0x24, \n\t0x44, 0xc0, 0x99, 0x98, 0x00, 0xcf, 0x08, 0x03, 0x10, 0xa0, 0x5d, 0x18, 0x20, 0x0c, 0xd2, 0xb8, \n\t0x15, 0x44, 0xc3, 0xa8, 0x60, 0x40, 0x50, 0x91, 0xc0, 0x03, 0x88, 0x4c, 0x82, 0x60, 0x0e, 0x0d, \n\t0x19, 0x03, 0x26, 0x15, 0x80, 0xba, 0x01, 0xce, 0xa0, 0x10, 0xa0, 0x10, 0x84, 0x50, 0x05, 0x43, \n\t0x38, 0x62, 0x00, 0x19, 0x00, 0x88, 0x08, 0x64, 0x52, 0x23, 0x14, 0x00, 0xc6, 0x0a, 0x50, 0x84, \n\t0x0b, 0x01, 0x00, 0x10, 0x05, 0x52, 0x71, 0xd1, 0x0a, 0x80, 0x94, 0xe0, 0x08, 0x22, 0x83, 0xac, \n\t0x40, 0xc9, 0x2a, 0x4a, 0x34, 0xa2, 0xa2, 0x41, 0x13, 0x80, 0x14, 0x05, 0xc8, 0x18, 0xa0, 0x4c, \n\t0xa6, 0x00, 0x40, 0x13, 0x01, 0x24, 0x54, 0x22, 0x14, 0xa1, 0x78, 0x98, 0x38, 0x4d, 0x29, 0x06, \n\t0x60, 0x43, 0x22, 0x2c, 0x8a, 0x40, 0x22, 0x00, 0x49, 0x25, 0xc0, 0xd4, 0x8c, 0x32, 0x85, 0x81, \n\t0x18, 0x24, 0x5b, 0x04, 0x68, 0x61, 0x39, 0x16, 0x61, 0x42, 0x41, 0x60, 0x10, 0x0a, 0x00, 0x44, \n\t0x12, 0x40, 0x4c, 0x61, 0x03, 0xa0, 0xc4, 0x90, 0x22, 0x2c, 0xe4, 0x10, 0x98, 0x45, 0x1a, 0x05, \n\t0x48, 0x02, 0x02, 0x28, 0x74, 0x40, 0x42, 0x06, 0x06, 0x4a, 0x0b, 0xa8, 0x94, 0x28, 0x0c, 0x40, \n\t0x02, 0x05, 0xd9, 0x8a, 0xc2, 0x00, 0x43, 0x60, 0x20, 0xb0, 0x10, 0x2c, 0x06, 0x05, 0x01, 0x89, \n\t0x08, 0x8c, 0x03, 0x12, 0x74, 0x21, 0x88, 0x44, 0x87, 0x47, 0x20, 0x25, 0x82, 0x35, 0x10, 0x0a, \n\t0x0d, 0x0a, 0x22, 0x01, 0x07, 0xd0, 0x80, 0xe3, 0x44, 0x04, 0xf0, 0x38, 0x3d, 0x92, 0xa5, 0x50, \n\t0xa0, 0x30, 0x80, 0x39, 0x80, 0x40, 0x14, 0x17, 0xd2, 0x02, 0x45, 0xc0, 0xa0, 0x00, 0x34, 0x18, \n\t0xa0, 0x41, 0x04, 0x82, 0x1e, 0x16, 0x2b, 0x04, 0x41, 0x8a, 0x80, 0x02, 0x00, 0x50, 0x25, 0x71, \n\t0xd2, 0x21, 0x60, 0x87, 0x81, 0x24, 0x39, 0x15, 0x06, 0x74, 0x22, 0x41, 0xa2, 0xe8, 0x42, 0x02, \n\t0x08, 0xc3, 0x71, 0x31, 0xc5, 0x44, 0x8b, 0x48, 0x20, 0x02, 0x0a, 0x04, 0x46, 0x0d, 0x40, 0x95, \n\t0x30, 0x18, 0x19, 0x44, 0x6a, 0x02, 0x92, 0xaa, 0x30, 0xf0, 0x10, 0x87, 0x1e, 0xb2, 0xa8, 0x06, \n\t0x25, 0x14, 0xcf, 0x74, 0xe0, 0x01, 0x0a, 0x00, 0x08, 0xc7, 0x22, 0x10, 0x08, 0x20, 0x15, 0x0a, \n\t0x67, 0x64, 0x05, 0x82, 0x01, 0x8c, 0xca, 0xa8, 0x40, 0x00, 0x58, 0xa3, 0x04, 0x12, 0x69, 0x06, \n\t0x84, 0xb9, 0x9e, 0x2c, 0x40, 0x00, 0x04, 0xa2, 0x5b, 0x01, 0x80, 0x0c, 0xae, 0x2a, 0x05, 0x41, \n\t0x13, 0x00, 0xc0, 0x0d, 0x50, 0x95, 0x22, 0xb0, 0x10, 0x43, 0x0c, 0x38, 0x03, 0xfa, 0x12, 0x08, \n\t0x52, 0x86, 0x40, 0x84, 0x00, 0x1d, 0xb0, 0xc6, 0x8c, 0x0a, 0x70, 0x92, 0x0d, 0x38, 0x00, 0x82, \n\t0x60, 0xd4, 0x32, 0xa3, 0x88, 0x10, 0x04, 0x28, 0x51, 0x18, 0x10, 0x29, 0x98, 0x20, 0x50, 0x04, \n\t0xc0, 0x2e, 0x88, 0x51, 0x0a, 0x28, 0x55, 0x32, 0xb1, 0x90, 0x0d, 0x62, 0x60, 0x04, 0x00, 0xb6, \n\t0xdc, 0x58, 0xc9, 0x34, 0x14, 0x41, 0xa8, 0xc1, 0x44, 0x82, 0x38, 0x90, 0x00, 0x19, 0x90, 0x11, \n\t0x01, 0x3a, 0x04, 0xc0, 0x2f, 0x00, 0x88, 0x21, 0x28, 0x20, 0x51, 0x93, 0x01, 0x89, 0x61, 0x14, \n\t0x26, 0x29, 0x15, 0xe4, 0x12, 0x64, 0x00, 0xc1, 0x28, 0x0b, 0x45, 0x02, 0xa8, 0x44, 0x63, 0x80, \n\t0x8a, 0x94, 0x8a, 0x04, 0x42, 0x04, 0x28, 0x95, 0x25, 0x86, 0x42, 0x40, 0x02, 0xb3, 0xa0, 0xc8, \n\t0x1e, 0x00, 0x1e, 0x51, 0xb0, 0x02, 0x7c, 0x4c, 0x00, 0x06, 0x86, 0xe8, 0x38, 0x80, 0x0c, 0xad, \n\t0x02, 0xc4, 0x02, 0x89, 0xb1, 0x81, 0xa4, 0x20, 0x21, 0x20, 0x2d, 0xd1, 0x54, 0x02, 0x08, 0x62, \n\t0x68, 0x81, 0xa8, 0x11, 0x05, 0x42, 0x50, 0x10, 0x92, 0x91, 0x50, 0x4c, 0x18, 0x04, 0x71, 0x04, \n\t0x24, 0xd5, 0x2a, 0x14, 0x00, 0x89, 0xaa, 0x78, 0x08, 0x04, 0x5c, 0x50, 0x00, 0x04, 0x11, 0x08, \n\t0x64, 0x0c, 0xd1, 0x92, 0x91, 0x0c, 0x13, 0x61, 0x00, 0x40, 0xd3, 0x22, 0xc1, 0x8e, 0x86, 0x1c, \n\t0x34, 0xd9, 0x31, 0x4c, 0xc1, 0xa2, 0x08, 0x80, 0x02, 0x82, 0x60, 0x08, 0x00, 0x06, 0x62, 0x48, \n\t0x20, 0x11, 0x4a, 0x26, 0x00, 0x71, 0x49, 0x14, 0x84, 0x07, 0xc7, 0x40, 0xa0, 0x43, 0xa7, 0x80, \n\t0x8f, 0x20, 0x56, 0x35, 0x12, 0x10, 0x50, 0x1c, 0x43, 0x38, 0x20, 0xab, 0x1c, 0xcd, 0xc0, 0xc1, \n\t0x08, 0x12, 0x00, 0x09, 0xd8, 0x18, 0xa5, 0x58, 0x72, 0x43, 0x20, 0x41, 0x41, 0xe8, 0x48, 0xa0, \n\t0x90, 0xa2, 0x70, 0xc1, 0x45, 0x36, 0x00, 0x69, 0x93, 0xec, 0x87, 0x28, 0x36, 0x00, 0x0a, 0xb0, \n\t0x8c, 0x41, 0x02, 0x62, 0x26, 0x53, 0x2a, 0x80, 0x48, 0x2b, 0x42, 0xc5, 0x91, 0x99, 0x78, 0x00, \n\t0x61, 0x26, 0x14, 0x20, 0x1d, 0x10, 0x01, 0x4a, 0x48, 0xa0, 0x08, 0x2f, 0x90, 0x8a, 0x4c, 0x04, \n\t0xe0, 0xa1, 0x82, 0x31, 0x45, 0x22, 0x30, 0x04, 0x20, 0x10, 0x08, 0x81, 0xe3, 0x50, 0xb1, 0x22, \n\t0xa0, 0x4c, 0x8c, 0x49, 0x60, 0x66, 0xa1, 0x0e, 0x09, 0x11, 0xa4, 0x00, 0x80, 0xa0, 0x9c, 0x21, \n\t0x43, 0x61, 0x18, 0x03, 0x58, 0x80, 0xc1, 0xc5, 0x22, 0x08, 0x31, 0x12, 0x80, 0x00, 0x18, 0x08, \n\t0x1a, 0x85, 0xc3, 0x34, 0x90, 0x48, 0x20, 0x06, 0x13, 0x49, 0x28, 0xa1, 0x01, 0x0d, 0x02, 0x65, \n\t0x50, 0x15, 0x95, 0x10, 0x0c, 0x02, 0x04, 0x80, 0x09, 0x18, 0x8c, 0x49, 0x04, 0x25, 0x91, 0x18, \n\t0x38, 0x1b, 0x01, 0x72, 0x02, 0x90, 0x20, 0x80, 0x03, 0xa4, 0x06, 0xc1, 0x78, 0x08, 0x98, 0x10, \n\t0x00, 0x10, 0x85, 0x01, 0x8f, 0x81, 0x48, 0x82, 0x08, 0xc2, 0x08, 0xa5, 0x14, 0x5f, 0x83, 0x20, \n\t0x55, 0x70, 0x0d, 0x41, 0x00, 0x04, 0x5e, 0x20, 0xb1, 0x03, 0xb1, 0x88, 0xc0, 0x48, 0x40, 0xcb, \n\t0x20, 0xe5, 0x41, 0xc6, 0x40, 0x12, 0x91, 0xb3, 0x78, 0x40, 0x23, 0x24, 0x03, 0x20, 0x87, 0x04, \n\t0x0d, 0x88, 0x30, 0x90, 0x20, 0x10, 0x80, 0x03, 0x68, 0x68, 0xc6, 0x10, 0x15, 0x01, 0xcc, 0x20, \n\t0x08, 0x06, 0x78, 0x0c, 0x20, 0x94, 0x85, 0x02, 0x91, 0x10, 0x06, 0xc8, 0x12, 0x86, 0x48, 0x02, \n\t0xb0, 0x04, 0x04, 0x1a, 0xe8, 0x00, 0x96, 0x82, 0x20, 0x35, 0x98, 0x82, 0x48, 0x80, 0x10, 0x29, \n\t0x84, 0xcb, 0x22, 0x6c, 0x50, 0x00, 0xb0, 0x9d, 0x02, 0x02, 0x4c, 0x24, 0x48, 0x8e, 0x01, 0x50, \n\t0xcf, 0x40, 0x42, 0x10, 0x1b, 0x29, 0x09, 0x29, 0x24, 0x00, 0x10, 0x82, 0x00, 0x42, 0x05, 0x22, \n\t0x01, 0xc8, 0x15, 0x98, 0x18, 0x05, 0x04, 0x34, 0x0a, 0x85, 0x80, 0x1e, 0xa6, 0x34, 0x80, 0xe9, \n\t0x00, 0x75, 0x05, 0xcb, 0x12, 0x03, 0x51, 0x25, 0x6c, 0x10, 0x8a, 0x44, 0x87, 0xa0, 0x11, 0x08, \n\t0x01, 0xa2, 0x42, 0xc5, 0x38, 0x22, 0x24, 0x81, 0xc6, 0x70, 0x82, 0xe1, 0x10, 0x04, 0x1a, 0x88, \n\t0x14, 0x20, 0x12, 0x26, 0x04, 0x5c, 0x49, 0x12, 0x60, 0x12, 0x38, 0xd0, 0x05, 0x81, 0x20, 0x67, \n\t0x92, 0x12, 0x49, 0x01, 0xa1, 0x0c, 0x43, 0x60, 0x18, 0xc4, 0xc3, 0x08, 0x60, 0x52, 0x82, 0x16, \n\t0xbc, 0x88, 0x64, 0x24, 0x61, 0xd0, 0x00, 0x70, 0x19, 0x20, 0x74, 0x24, 0x00, 0x19, 0xc0, 0xc4, \n\t0x02, 0x04, 0xb1, 0x42, 0x85, 0x10, 0x94, 0x6a, 0x28, 0x10, 0x21, 0xa9, 0xcc, 0x08, 0xc8, 0x02, \n\t0x42, 0x92, 0xb5, 0x08, 0x12, 0x81, 0x0a, 0x82, 0xe0, 0x05, 0x49, 0x5b, 0x0c, 0x0c, 0x24, 0xc9, \n\t0x20, 0x1c, 0x8a, 0x83, 0x0e, 0x60, 0x99, 0x06, 0x91, 0x00, 0x4d, 0x56, 0x10, 0x5b, 0x98, 0x25, \n\t0xc9, 0x89, 0x00, 0xb0, 0x48, 0xa1, 0x10, 0x0d, 0x06, 0x42, 0xc6, 0x80, 0x20, 0x10, 0xc3, 0x28, \n\t0x74, 0x62, 0xa1, 0x09, 0x01, 0x44, 0xe6, 0x22, 0x26, 0x88, 0x11, 0xa8, 0xd2, 0x00, 0x58, 0x02, \n\t0x19, 0x00, 0xa1, 0x04, 0x01, 0x18, 0xa5, 0x91, 0x16, 0xd0, 0xd0, 0x60, 0x00, 0x05, 0x08, 0x02, \n\t0x0d, 0x1d, 0xe4, 0x02, 0xd6, 0x08, 0x3a, 0x48, 0x19, 0x0c, 0x3c, 0x00, 0x20, 0xa3, 0xa0, 0x54, \n\t0x21, 0x14, 0x41, 0x88, 0x28, 0x49, 0x00, 0x86, 0x24, 0x33, 0x82, 0x30, 0x58, 0x01, 0x4f, 0x28, \n\t0x93, 0x69, 0x29, 0x54, 0x45, 0x82, 0x50, 0xc3, 0x8a, 0x38, 0x30, 0x46, 0x45, 0x2a, 0x14, 0x08, \n\t0x8e, 0x99, 0x06, 0x60, 0x02, 0x10, 0xe8, 0x00, 0x19, 0x82, 0x21, 0x5c, 0x20, 0x00, 0xa7, 0x24, \n\t0x86, 0x00, 0x28, 0x36, 0x02, 0x1c, 0xc4, 0x0b, 0x0c, 0x0e, 0xb4, 0x08, 0x0d, 0x64, 0xd4, 0xc4, \n\t0x00, 0x81, 0x09, 0xb1, 0x01, 0x41, 0x2e, 0x14, 0x20, 0x08, 0x82, 0x0d, 0x51, 0xca, 0x0a, 0x07, \n\t0x23, 0xb0, 0x28, 0x05, 0x09, 0x20, 0x60, 0x90, 0x99, 0x90, 0x82, 0x0e, 0x0e, 0xc1, 0x70, 0x24, \n\t0x60, 0xcb, 0xc3, 0x00, 0xa0, 0xea, 0x17, 0x24, 0x14, 0x04, 0x70, 0x22, 0x00, 0x01, 0x48, 0xc1, \n\t0xa4, 0x20, 0x24, 0x70, 0x28, 0x8d, 0xc4, 0x44, 0x00, 0xa1, 0x51, 0x20, 0x7d, 0x88, 0x01, 0x1c, \n\t0xa3, 0xa0, 0x85, 0x8c, 0x50, 0xa8, 0x44, 0x60, 0x02, 0x3c, 0x44, 0x55, 0xa3, 0x30, 0x06, 0xb3, \n\t0x0c, 0x44, 0x12, 0xac, 0x0a, 0x14, 0x21, 0x03, 0x15, 0x59, 0x20, 0x58, 0xa0, 0x9a, 0x94, 0x11, \n\t0x08, 0x63, 0x62, 0xe0, 0x42, 0x23, 0xb5, 0xce, 0x00, 0x00, 0x15, 0x10, 0x82, 0xa0, 0x1a, 0x4e, \n\t0x00, 0x23, 0x63, 0x18, 0x10, 0x94, 0x04, 0x52, 0x82, 0xbb, 0x08, 0x70, 0xc6, 0x41, 0x68, 0x02, \n\t0x90, 0x14, 0x08, 0x93, 0x88, 0x10, 0x51, 0x78, 0x05, 0x44, 0x18, 0x8e, 0x50, 0xd6, 0x43, 0x84, \n\t0x08, 0x8a, 0x80, 0x00, 0xc0, 0x22, 0x14, 0x40, 0x04, 0xc0, 0x48, 0x05, 0xa0, 0x01, 0x08, 0x40, \n\t0x80, 0x40, 0x40, 0xcb, 0x94, 0x0d, 0xd2, 0x8a, 0x46, 0x86, 0x80, 0x80, 0xb9, 0x48, 0x40, 0x74, \n\t0x95, 0x10, 0xa8, 0x34, 0x8f, 0x0d, 0x0e, 0x16, 0x08, 0x2a, 0x50, 0x90, 0x0b, 0x5a, 0xc5, 0x6a, \n\t0x14, 0x80, 0x8d, 0x48, 0x02, 0x03, 0x02, 0x81, 0x21, 0x4c, 0x86, 0x5a, 0x82, 0x83, 0x09, 0x99, \n\t0x02, 0x20, 0x04, 0x60, 0x6b, 0x89, 0x48, 0x08, 0x6a, 0x68, 0x84, 0x40, 0xa5, 0xc4, 0x0a, 0x81, \n\t0x40, 0x21, 0x28, 0x16, 0x04, 0x02, 0x61, 0x16, 0x94, 0x00, 0x3a, 0x80, 0xd6, 0x2c, 0x22, 0x64, \n\t0x48, 0x80, 0x08, 0xc1, 0x40, 0x38, 0x00, 0x80, 0x18, 0x08, 0x10, 0xc1, 0x34, 0x03, 0xda, 0x82, \n\t0x44, 0x03, 0x4b, 0x0a, 0x74, 0x38, 0x85, 0x41, 0x42, 0xc5, 0x32, 0x65, 0x40, 0x26, 0xb4, 0x90, \n\t0x21, 0x6a, 0x94, 0x0b, 0x09, 0x20, 0x14, 0x21, 0x72, 0x80, 0x82, 0x25, 0x20, 0x80, 0x2a, 0x0a, \n\t0x12, 0x81, 0x81, 0x10, 0x02, 0x08, 0x18, 0x62, 0x80, 0x88, 0x55, 0x58, 0x09, 0x0e, 0xe2, 0x22, \n\t0x31, 0x61, 0x53, 0x62, 0x68, 0x54, 0x12, 0x9b, 0xc0, 0x9d, 0x82, 0x2e, 0x00, 0x88, 0x20, 0x45, \n\t0xc0, 0x40, 0x72, 0x62, 0x0b, 0x04, 0x31, 0x18, 0xe6, 0x22, 0x60, 0x48, 0x1a, 0x40, 0x80, 0xa7, \n\t0x12, 0x72, 0x10, 0x9d, 0x80, 0x8d, 0x82, 0x08, 0x66, 0xc2, 0xb4, 0x24, 0x00, 0x20, 0x54, 0x90, \n\t0x28, 0x0c, 0x08, 0x81, 0xe9, 0x10, 0x04, 0xb3, 0x28, 0x60, 0x05, 0x22, 0x0c, 0x10, 0x81, 0x09, \n\t0x01, 0x98, 0x0c, 0x24, 0x12, 0x41, 0x02, 0x88, 0xc2, 0x42, 0x04, 0x95, 0x80, 0xa1, 0x48, 0x1b, \n\t0x85, 0x0c, 0x85, 0x03, 0x9a, 0x88, 0x8e, 0x20, 0x04, 0x04, 0x91, 0x10, 0x31, 0x1e, 0x01, 0x40, \n\t0x03, 0x10, 0xbe, 0x48, 0x04, 0x0a, 0x74, 0x60, 0x01, 0x03, 0xf4, 0x46, 0x46, 0x10, 0x41, 0x09, \n\t0x8a, 0xb0, 0x43, 0x88, 0x58, 0xd1, 0x20, 0x26, 0x94, 0xc4, 0x04, 0x5e, 0x83, 0x18, 0x1b, 0x59, \n\t0x88, 0xc2, 0x10, 0x02, 0x11, 0x30, 0xa0, 0x56, 0xa5, 0x08, 0x00, 0x20, 0x0c, 0xf4, 0x0a, 0xad, \n\t0x00, 0x14, 0x20, 0x21, 0x80, 0x13, 0x25, 0x2c, 0x80, 0x12, 0x13, 0x50, 0x88, 0x67, 0x12, 0x15, \n\t0x4a, 0x04, 0x0d, 0xc9, 0x06, 0x02, 0x10, 0xd8, 0x10, 0xcc, 0x0b, 0x02, 0x24, 0x04, 0x02, 0xa4, \n\t0x75, 0x04, 0x28, 0x00, 0xa2, 0x40, 0x90, 0x3c, 0x44, 0xc3, 0x00, 0xe2, 0x61, 0x83, 0x20, 0x06, \n\t0x03, 0x58, 0x50, 0x09, 0x31, 0x80, 0xce, 0x08, 0x04, 0xa5, 0x98, 0x1c, 0x89, 0x95, 0x04, 0x02, \n\t0x30, 0x00, 0x28, 0x05, 0x05, 0xc1, 0x52, 0xa0, 0x10, 0x2e, 0x19, 0x80, 0x28, 0x50, 0x56, 0x21, \n\t0x0f, 0x08, 0x52, 0x21, 0x46, 0x26, 0x08, 0x02, 0x14, 0x10, 0x80, 0x5c, 0x10, 0x82, 0xa1, 0xc0, \n\t0xd5, 0x0e, 0x50, 0x10, 0x43, 0x05, 0x48, 0x95, 0x21, 0x26, 0x41, 0xa0, 0x20, 0x2d, 0x4c, 0x42, \n\t0x02, 0xc3, 0x03, 0x99, 0xc8, 0x03, 0x0c, 0x22, 0x40, 0x50, 0x26, 0x90, 0x02, 0x81, 0x08, 0x42, \n\t0x2b, 0xa5, 0x00, 0x46, 0x65, 0x22, 0x72, 0x4a, 0x08, 0x80, 0x98, 0xc5, 0x0a, 0x80, 0xc9, 0x19, \n\t0x54, 0x94, 0x05, 0x16, 0x02, 0xc0, 0x82, 0x01, 0x88, 0xc3, 0x38, 0xa1, 0x51, 0x1d, 0x08, 0x8a, \n\t0xc1, 0x44, 0x45, 0x3a, 0xb0, 0x00, 0x05, 0xc0, 0x28, 0x41, 0xe9, 0x04, 0x09, 0x50, 0x08, 0x02, \n\t0x30, 0x28, 0x86, 0x21, 0x8b, 0x00, 0x02, 0xe4, 0xaa, 0x0e, 0xb1, 0x00, 0xe5, 0x20, 0xa1, 0x11, \n\t0x1b, 0x11, 0x80, 0x0c, 0x2a, 0xd5, 0x40, 0x02, 0x35, 0x1d, 0x40, 0x38, 0x00, 0x61, 0x1a, 0x24, \n\t0x49, 0x0c, 0x1c, 0x27, 0xd0, 0x01, 0x00, 0xc0, 0xa3, 0x12, 0x14, 0x2a, 0x15, 0x4d, 0x01, 0x01, \n\t0x06, 0xc2, 0x38, 0x2e, 0xec, 0x94, 0xc2, 0x50, 0x00, 0x21, 0x24, 0x1d, 0x40, 0xac, 0x04, 0x15, \n\t0x30, 0xb0, 0x01, 0x81, 0x00, 0x62, 0x40, 0x43, 0x3f, 0x25, 0x80, 0x02, 0x06, 0x31, 0x18, 0xb4, \n\t0x54, 0x1a, 0xcb, 0x10, 0x22, 0x00, 0x02, 0x6c, 0x10, 0x6a, 0x72, 0x20, 0x83, 0x13, 0x44, 0x88, \n\t0xcd, 0x2c, 0xa1, 0x19, 0x0f, 0x95, 0x54, 0x8d, 0x3a, 0x37, 0xc0, 0xb3, 0x08, 0x55, 0x61, 0x50, \n\t0xd2, 0x8b, 0x84, 0x01, 0x48, 0xc0, 0x28, 0x04, 0x48, 0x08, 0xa1, 0x06, 0x42, 0x46, 0x03, 0x40, \n\t0x00, 0x40, 0x80, 0x20, 0x50, 0xb3, 0x13, 0x08, 0x50, 0x50, 0x04, 0x08, 0x64, 0x32, 0x2f, 0x7c, \n\t0x0c, 0x41, 0x62, 0x13, 0xe0, 0x38, 0xa8, 0xd1, 0x20, 0x10, 0x05, 0xf2, 0xa4, 0x15, 0x03, 0x01, \n\t0x52, 0x05, 0x7a, 0xa8, 0x05, 0x09, 0xc0, 0x62, 0xc4, 0x10, 0x0a, 0x45, 0x08, 0x69, 0x24, 0x61, \n\t0x01, 0x00, 0x81, 0x16, 0x88, 0x0a, 0x14, 0x81, 0x83, 0x0c, 0x02, 0x4d, 0x1a, 0x84, 0xaa, 0x81, \n\t0x91, 0xc6, 0x0a, 0x24, 0x10, 0x51, 0x0d, 0x88, 0x90, 0x4e, 0x5a, 0x21, 0xc1, 0xa2, 0xa4, 0x90, \n\t0x0c, 0x34, 0x44, 0x21, 0x80, 0x48, 0x43, 0x0b, 0x48, 0x43, 0x92, 0x90, 0x30, 0xc0, 0x06, 0x14, \n\t0x45, 0xb9, 0x00, 0x08, 0x1b, 0x88, 0x20, 0x44, 0xa9, 0x11, 0x60, 0x0c, 0x8a, 0x30, 0x03, 0x48, \n\t0x28, 0x88, 0x11, 0x86, 0x64, 0x23, 0x8a, 0x22, 0x30, 0xc1, 0xa1, 0x28, 0x40, 0x00, 0x05, 0xe4, \n\t0x0d, 0x86, 0x3a, 0x22, 0x62, 0xaf, 0x8c, 0x56, 0x60, 0x10, 0x10, 0xb8, 0x18, 0x41, 0x04, 0x24, \n\t0x48, 0x30, 0x82, 0x15, 0x70, 0x00, 0x88, 0x42, 0x53, 0x20, 0xad, 0x81, 0x98, 0x4b, 0x50, 0x86, \n\t0x02, 0x0b, 0x40, 0x88, 0x2d, 0x4c, 0xa0, 0x02, 0x00, 0x08, 0x42, 0x40, 0x16, 0x84, 0x00, 0x99, \n\t0x4c, 0x00, 0xa2, 0x22, 0x40, 0x52, 0x14, 0x10, 0x84, 0xa9, 0x0c, 0x26, 0x92, 0x08, 0x24, 0x49, \n\t0x8e, 0x42, 0x93, 0x49, 0x8a, 0x54, 0x04, 0x88, 0x06, 0x40, 0x08, 0x1d, 0x21, 0x90, 0x00, 0x60, \n\t0x21, 0x02, 0x94, 0x98, 0x89, 0x04, 0x1a, 0x94, 0x5b, 0x87, 0x20, 0x44, 0x47, 0x48, 0x90, 0x2a, \n\t0x18, 0x80, 0xd1, 0x43, 0x14, 0x02, 0x29, 0xa0, 0x8c, 0x10, 0xe1, 0x60, 0xf0, 0x81, 0x09, 0xc5, \n\t0xc0, 0x2d, 0x08, 0x95, 0x82, 0xa4, 0x04, 0x4a, 0x40, 0x12, 0x00, 0x11, 0xaf, 0xc1, 0x94, 0x26, \n\t0x3e, 0x60, 0x41, 0x10, 0x41, 0x87, 0xa0, 0x16, 0x42, 0x60, 0x9a, 0x8c, 0x04, 0xe0, 0x14, 0x62, \n\t0x12, 0x18, 0xf4, 0xc0, 0x02, 0x0c, 0x10, 0x21, 0x98, 0x01, 0xde, 0x82, 0x08, 0xb3, 0x60, 0x11, \n\t0x18, 0x01, 0x49, 0x32, 0x00, 0xd0, 0x0a, 0x58, 0x91, 0x29, 0x26, 0x04, 0x48, 0x00, 0x35, 0x00, \n\t0xc8, 0x08, 0x31, 0x32, 0x0e, 0x70, 0x0a, 0x46, 0x00, 0x17, 0x70, 0x88, 0x90, 0xc0, 0x8b, 0x00, \n\t0x04, 0x28, 0x22, 0x45, 0x11, 0x64, 0x38, 0x10, 0xb1, 0x1a, 0xa4, 0x00, 0x24, 0x4a, 0x50, 0x08, \n\t0x82, 0xa0, 0x0f, 0xc0, 0x0e, 0x85, 0x9b, 0x04, 0x31, 0x11, 0x4c, 0x02, 0xf4, 0xc2, 0x90, 0xc5, \n\t0x03, 0x02, 0x04, 0xc3, 0x10, 0x08, 0xa0, 0x57, 0xc0, 0x42, 0x05, 0x80, 0x00, 0x94, 0x42, 0x00, \n\t0x52, 0x45, 0x81, 0x01, 0x09, 0x1d, 0x4b, 0x2a, 0xa6, 0xa0, 0x30, 0x04, 0x95, 0x00, 0x0a, 0x52, \n\t0x08, 0x28, 0x24, 0x12, 0x65, 0x14, 0x24, 0x70, 0xa4, 0x00, 0x98, 0xe2, 0x68, 0x10, 0x0a, 0x33, \n\t0x41, 0x80, 0x01, 0x44, 0x90, 0x0a, 0x36, 0xc1, 0x5b, 0x22, 0x40, 0x71, 0x23, 0xa4, 0x01, 0x14, \n\t0x8a, 0x64, 0x62, 0xab, 0x9a, 0x10, 0x48, 0xc8, 0x04, 0x10, 0xc1, 0x82, 0x11, 0xca, 0xc1, 0x14, \n\t0x96, 0x58, 0x04, 0xe0, 0x01, 0x00, 0x20, 0xa6, 0x8b, 0x81, 0x1c, 0xcf, 0x08, 0x30, 0x12, 0x53, \n\t0x1b, 0xb8, 0x12, 0x0a, 0x5c, 0x22, 0x61, 0x25, 0xc0, 0x84, 0x0f, 0x42, 0x12, 0x00, 0xa4, 0x09, \n\t0x94, 0x0e, 0x20, 0xd0, 0x71, 0x22, 0x04, 0x0b, 0x00, 0x60, 0xa3, 0x10, 0x00, 0x75, 0x5b, 0x00, \n\t0x70, 0x90, 0x50, 0x86, 0x24, 0x1e, 0x80, 0x18, 0x35, 0x02, 0x81, 0x38, 0xc7, 0x60, 0x4c, 0x06, \n\t0x00, 0x92, 0x08, 0x00, 0x20, 0x50, 0x01, 0x42, 0x30, 0x25, 0x44, 0x6c, 0x34, 0x34, 0x20, 0x12, \n\t0x04, 0xc1, 0xc1, 0x1a, 0x83, 0x09, 0x20, 0x90, 0x86, 0x40, 0x08, 0x35, 0x48, 0x94, 0xe1, 0x09, \n\t0x05, 0x5e, 0x34, 0x08, 0x01, 0x91, 0x12, 0xca, 0x10, 0xd2, 0x30, 0x23, 0x45, 0x0e, 0x48, 0x34, \n\t0x24, 0xc3, 0xbf, 0x50, 0xd8, 0x2c, 0x02, 0x31, 0x12, 0x90, 0x20, 0x42, 0x21, 0x24, 0xc5, 0x21, \n\t0x85, 0x24, 0x14, 0x04, 0x3c, 0x11, 0x08, 0x10, 0x00, 0x09, 0x6b, 0x10, 0xc6, 0xb8, 0x80, 0x8c, \n\t0x0d, 0x0b, 0x32, 0x85, 0x5a, 0x01, 0x98, 0x01, 0x01, 0x00, 0x62, 0x70, 0xa6, 0xc0, 0x4c, 0x40, \n\t0x20, 0x40, 0x81, 0x00, 0x28, 0x80, 0x04, 0x08, 0x30, 0x19, 0x15, 0xb8, 0xda, 0x28, 0x5c, 0x80, \n\t0xe1, 0x08, 0x41, 0x52, 0x45, 0x4c, 0x23, 0x09, 0x81, 0x08, 0x00, 0x02, 0x40, 0x63, 0x00, 0x32, \n\t0xd0, 0x12, 0xa6, 0x2a, 0x81, 0x38, 0xa3, 0x15, 0x54, 0x03, 0x58, 0x00, 0x22, 0x00, 0x0d, 0x90, \n\t0x82, 0x10, 0x21, 0x80, 0x25, 0x01, 0x11, 0xc0, 0x44, 0x81, 0x5b, 0x02, 0xc4, 0x00, 0x02, 0x42, \n\t0x60, 0x91, 0x20, 0x10, 0x80, 0xe5, 0x10, 0x13, 0x48, 0x1a, 0xa0, 0xc1, 0x48, 0x0a, 0x14, 0x29, \n\t0xb0, 0x24, 0x0b, 0x00, 0x70, 0xe1, 0x02, 0x0c, 0x51, 0x40, 0xca, 0x0c, 0x02, 0x8a, 0x11, 0xa8, \n\t0x87, 0xad, 0x18, 0xe0, 0xb1, 0x85, 0x65, 0x08, 0x6c, 0x48, 0xa3, 0xc0, 0x24, 0x11, 0x8a, 0xc8, \n\t0x22, 0x04, 0x88, 0x98, 0x18, 0x50, 0x22, 0x00, 0x56, 0x61, 0x21, 0x00, 0xde, 0x84, 0x02, 0x10, \n\t0x53, 0x22, 0xdd, 0x13, 0x08, 0x2a, 0x06, 0xc1, 0xa4, 0xc8, 0x00, 0x00, 0x12, 0xa6, 0xc8, 0xa0, \n\t0x1c, 0x8c, 0x22, 0x2e, 0x02, 0x18, 0x1f, 0xf0, 0x03, 0x07, 0x02, 0x03, 0x09, 0x33, 0xa4, 0x10, \n\t0x08, 0x60, 0xd1, 0x0a, 0x0e, 0x90, 0x5c, 0x40, 0x70, 0xa4, 0x02, 0x18, 0xd1, 0x00, 0xa3, 0x1e, \n\t0x80, 0x70, 0x02, 0xc5, 0x84, 0xe2, 0x00, 0x20, 0x30, 0x91, 0x05, 0x43, 0x81, 0x04, 0x62, 0x98, \n\t0x92, 0x41, 0x00, 0x64, 0x02, 0x13, 0xa2, 0x0d, 0x40, 0x13, 0x0c, 0x40, 0x25, 0x42, 0xa4, 0x40, \n\t0x19, 0x09, 0x10, 0xa1, 0x6b, 0x10, 0x25, 0x19, 0x04, 0x06, 0xd4, 0xc8, 0x13, 0x28, 0x42, 0x23, \n\t0x26, 0x22, 0x20, 0x09, 0xe0, 0x08, 0x04, 0x00, 0xd5, 0xc2, 0x30, 0x38, 0x54, 0x01, 0x2e, 0x00, \n\t0xa1, 0x14, 0x80, 0x08, 0xc5, 0x4a, 0x10, 0x40, 0x00, 0x60, 0xc6, 0x24, 0x06, 0xd1, 0x20, 0x0a, \n\t0x09, 0x06, 0x0c, 0x28, 0x00, 0x11, 0xa8, 0xc9, 0xc8, 0x02, 0x08, 0x86, 0xb2, 0x21, 0x19, 0x87, \n\t0x62, 0x3c, 0x56, 0x40, 0x0b, 0x24, 0x94, 0xa0, 0x28, 0x44, 0x00, 0x80, 0xb4, 0x08, 0x08, 0x04, \n\t0x47, 0xeb, 0x24, 0xa0, 0x50, 0x64, 0x70, 0xa0, 0x13, 0xb8, 0xc0, 0x01, 0x29, 0x08, 0x90, 0x21, \n\t0x92, 0x54, 0xc1, 0x08, 0x0a, 0x02, 0xe3, 0x21, 0x00, 0x18, 0x44, 0x06, 0x05, 0x00, 0x08, 0x68, \n\t0x10, 0xa4, 0x12, 0x20, 0x5b, 0x3d, 0x2c, 0xd0, 0x45, 0x08, 0x13, 0x03, 0x89, 0x90, 0x82, 0x40, \n\t0x44, 0xd1, 0xe1, 0x22, 0x00, 0xca, 0x02, 0x00, 0x06, 0xb8, 0xb8, 0x00, 0x8f, 0x07, 0x10, 0xc4, \n\t0x58, 0xa8, 0x65, 0x0e, 0x86, 0x4e, 0x00, 0x80, 0x25, 0x81, 0x1d, 0x60, 0x20, 0x63, 0x42, 0x08, \n\t0x25, 0x04, 0x40, 0x56, 0x20, 0x10, 0x80, 0x14, 0x0b, 0x21, 0x32, 0xc3, 0x48, 0x00, 0x24, 0xdb, \n\t0x84, 0x40, 0x91, 0x02, 0x82, 0x98, 0x41, 0x09, 0x64, 0x06, 0x41, 0x86, 0x41, 0xc5, 0x08, 0x2a, \n\t0x00, 0xb8, 0x11, 0x4d, 0x12, 0x41, 0x18, 0xe2, 0x60, 0xa0, 0x11, 0x04, 0x0a, 0x08, 0x80, 0xe0, \n\t0x14, 0x05, 0x91, 0x8f, 0x48, 0x30, 0x82, 0x31, 0x54, 0x01, 0x02, 0x50, 0x00, 0x28, 0x33, 0x68, \n\t0x90, 0x0a, 0x12, 0x24, 0x43, 0x20, 0x04, 0x03, 0x63, 0x70, 0x61, 0x31, 0x10, 0x3c, 0x44, 0x23, \n\t0x30, 0x40, 0x0a, 0x08, 0x8d, 0x45, 0x29, 0x14, 0x10, 0x40, 0x06, 0xc5, 0x40, 0x85, 0x4a, 0x52, \n\t0x08, 0x88, 0xa0, 0x90, 0x09, 0x0e, 0xe4, 0x02, 0x82, 0x71, 0x19, 0x02, 0x42, 0x26, 0x08, 0x3d, \n\t0x01, 0x90, 0x6c, 0x40, 0x31, 0x4b, 0x81, 0xe9, 0x86, 0xa2, 0x0c, 0x94, 0x62, 0x80, 0x41, 0x1b, \n\t0x42, 0x22, 0xc3, 0x00, 0x18, 0x29, 0x0e, 0x24, 0x1e, 0x02, 0x88, 0x8c, 0x0c, 0xc1, 0x28, 0x62, \n\t0x71, 0x01, 0x01, 0x70, 0x85, 0xc2, 0x62, 0x41, 0x01, 0x2e, 0x60, 0x08, 0x0d, 0x12, 0x56, 0xca, \n\t0x80, 0xbc, 0x00, 0x08, 0x00, 0x44, 0x08, 0x8e, 0x41, 0x03, 0xc4, 0x32, 0x22, 0x00, 0x80, 0x94, \n\t0x88, 0x40, 0x50, 0x00, 0xd9, 0x9b, 0x20, 0x42, 0x04, 0x44, 0x90, 0x22, 0x05, 0x5c, 0x43, 0xc4, \n\t0x14, 0xa1, 0xab, 0xae, 0x60, 0x88, 0x83, 0x60, 0x03, 0x02, 0x02, 0x10, 0xd9, 0x4a, 0x06, 0xb7, \n\t0x20, 0x05, 0x68, 0x1c, 0xa0, 0x0e, 0x55, 0x38, 0x38, 0xe0, 0x49, 0x86, 0x10, 0x41, 0x92, 0x20, \n\t0x21, 0x12, 0x83, 0x40, 0x62, 0xa9, 0x38, 0x25, 0x10, 0xcc, 0x40, 0x54, 0xc0, 0x20, 0x0c, 0x84, \n\t0x4a, 0x0c, 0xe3, 0x30, 0x26, 0x55, 0xc6, 0x01, 0x22, 0x44, 0x09, 0x82, 0xa8, 0x54, 0x25, 0x0a, \n\t0x31, 0x62, 0x1e, 0xd8, 0x84, 0x01, 0x6e, 0x82, 0x40, 0x2d, 0x19, 0x00, 0xa0, 0x54, 0x10, 0x11, \n\t0xa0, 0xcc, 0x02, 0x6f, 0x24, 0xf4, 0x02, 0x09, 0x09, 0x59, 0xc5, 0x40, 0x00, 0x30, 0xac, 0x45, \n\t0x08, 0xa1, 0x56, 0x00, 0x52, 0x02, 0x81, 0xc4, 0x24, 0x40, 0x01, 0xa9, 0x32, 0x8c, 0x80, 0x6a, \n\t0x00, 0x81, 0xb1, 0x92, 0x90, 0x15, 0xca, 0x44, 0x63, 0x41, 0x32, 0x00, 0x48, 0x81, 0x1c, 0xa2, \n\t0x08, 0x81, 0x34, 0x1a, 0xcb, 0x28, 0x74, 0x00, 0xa1, 0x0c, 0x90, 0x4c, 0x24, 0xc2, 0x31, 0x01, \n\t0xc8, 0xdb, 0x04, 0x30, 0x14, 0xb1, 0x08, 0x04, 0x05, 0xc4, 0x0a, 0xd0, 0x20, 0x2e, 0x21, 0x0e, \n\t0x41, 0x20, 0x00, 0x50, 0x89, 0x0c, 0x89, 0x20, 0x20, 0x40, 0x12, 0x05, 0x44, 0x93, 0x66, 0x00, \n\t0xc0, 0x80, 0x08, 0xcc, 0x5b, 0x20, 0x08, 0x44, 0x12, 0x82, 0xb5, 0x13, 0x61, 0x12, 0x84, 0x41, \n\t0x04, 0x49, 0x00, 0x09, 0x64, 0x82, 0x03, 0x22, 0xf8, 0x04, 0xa0, 0x2e, 0x83, 0x60, 0x31, 0x15, \n\t0x52, 0x08, 0x08, 0xa5, 0x63, 0x1c, 0x80, 0x06, 0x09, 0x18, 0xa6, 0x49, 0x8c, 0x21, 0x8b, 0xc0, \n\t0x02, 0x16, 0x50, 0x14, 0xa0, 0x11, 0x09, 0x1c, 0x82, 0x80, 0x03, 0x90, 0x80, 0xc3, 0x00, 0x07, \n\t0x33, 0x80, 0x14, 0xc0, 0x0b, 0x48, 0x41, 0x08, 0x8e, 0x10, 0xc8, 0x62, 0x24, 0x07, 0xd0, 0x16, \n\t0x01, 0x42, 0x08, 0x18, 0x75, 0x03, 0x25, 0xe1, 0x01, 0xc3, 0x04, 0x86, 0x20, 0x92, 0x54, 0x01, \n\t0x80, 0x44, 0x42, 0xd8, 0x0a, 0x10, 0x80, 0x6c, 0x28, 0x23, 0x41, 0x22, 0x50, 0x08, 0x00, 0x38, \n\t0x37, 0xc0, 0x00, 0x28, 0x1e, 0x0c, 0x3a, 0x00, 0x19, 0x03, 0x30, 0x11, 0x00, 0x54, 0x04, 0xc2, \n\t0x19, 0xcc, 0x14, 0x01, 0x04, 0xf0, 0x63, 0x8d, 0x2c, 0x0c, 0x69, 0x44, 0x56, 0x02, 0x21, 0x80, \n\t0x12, 0x4c, 0x2c, 0x71, 0x08, 0x38, 0x2c, 0x52, 0xc2, 0x20, 0x80, 0x51, 0x90, 0x80, 0x0f, 0xa6, \n\t0x28, 0x14, 0x00, 0x83, 0x70, 0x4e, 0x00, 0x26, 0x24, 0x8a, 0x16, 0x4d, 0x41, 0xa3, 0x00, 0x00, \n\t0x03, 0x12, 0x68, 0xc7, 0xca, 0x30, 0xa4, 0x20, 0x97, 0x41, 0x0a, 0x80, 0x60, 0xe0, 0x22, 0x8d, \n\t0xa4, 0x5f, 0x04, 0x60, 0x02, 0x9a, 0x82, 0x89, 0xc0, 0x6a, 0x1e, 0x20, 0xa0, 0x34, 0x80, 0x43, \n\t0x44, 0x02, 0x43, 0xc2, 0x20, 0x75, 0x18, 0x05, 0x40, 0x66, 0x10, 0x35, 0x50, 0x02, 0x81, 0x40, \n\t0x52, 0x18, 0x28, 0x0c, 0x92, 0x42, 0x2a, 0x02, 0x80, 0x29, 0x08, 0x96, 0x04, 0x08, 0x20, 0x99, \n\t0x30, 0x91, 0x15, 0x09, 0x36, 0xa6, 0xe0, 0x18, 0x09, 0x14, 0x0f, 0x60, 0x81, 0x40, 0x21, 0x14, \n\t0xcc, 0x02, 0x22, 0x13, 0x08, 0x1c, 0x51, 0x92, 0xc0, 0x08, 0x62, 0x69, 0x8c, 0x04, 0x07, 0x61, \n\t0x48, 0x44, 0xa8, 0x88, 0xc1, 0x03, 0x01, 0x56, 0x00, 0x99, 0x0c, 0x75, 0x02, 0xa8, 0x4a, 0x31, \n\t0xd0, 0x21, 0x99, 0x10, 0x07, 0x44, 0x25, 0x42, 0x33, 0x40, 0x80, 0xa4, 0x22, 0x02, 0xba, 0x00, \n\t0x5c, 0x4c, 0x81, 0x24, 0xc3, 0xc0, 0x09, 0x20, 0x0a, 0xae, 0x06, 0x44, 0x41, 0x95, 0x0d, 0xdc, \n\t0x02, 0x26, 0x02, 0x42, 0x0c, 0xf0, 0x19, 0x43, 0x00, 0x10, 0x18, 0x12, 0xc4, 0xc5, 0x61, 0x22, \n\t0xb5, 0x69, 0x32, 0x10, 0x98, 0x44, 0x52, 0x40, 0x08, 0xb0, 0x24, 0x81, 0x44, 0x74, 0x45, 0xd0, \n\t0x01, 0x89, 0x4b, 0x41, 0x2c, 0x36, 0x20, 0x20, 0x04, 0x96, 0x26, 0x18, 0x72, 0xa2, 0x08, 0x45, \n\t0x82, 0xa0, 0x40, 0x63, 0x03, 0x26, 0xd1, 0x89, 0xaa, 0x24, 0x14, 0x92, 0x15, 0x20, 0xc0, 0x27, \n\t0x70, 0x52, 0x00, 0xb4, 0x21, 0x40, 0x86, 0x16, 0x50, 0x89, 0x91, 0x59, 0x0c, 0x2b, 0x6c, 0x20, \n\t0xe0, 0x30, 0x70, 0x4c, 0xa2, 0x00, 0x32, 0x11, 0x21, 0x54, 0x40, 0x29, 0x0c, 0x84, 0x11, 0xb2, \n\t0xd0, 0x08, 0x84, 0x02, 0x01, 0x69, 0x15, 0x20, 0x99, 0x09, 0x00, 0x12, 0x53, 0x18, 0x21, 0x40, \n\t0x28, 0x6a, 0x94, 0x02, 0x20, 0xed, 0x85, 0x46, 0x4a, 0xc2, 0x30, 0x80, 0x00, 0x8a, 0x43, 0x34, \n\t0x11, 0x21, 0x30, 0x49, 0x83, 0x20, 0x6e, 0x06, 0x20, 0x05, 0x30, 0x41, 0x65, 0x30, 0xd3, 0x98, \n\t0x81, 0x80, 0x41, 0x88, 0x3a, 0x05, 0x80, 0xa2, 0x01, 0xd0, 0x62, 0x60, 0x00, 0x69, 0xa2, 0xcc, \n\t0x51, 0x8e, 0x20, 0x80, 0x10, 0x92, 0x0d, 0x02, 0xa0, 0x14, 0x85, 0x21, 0x29, 0xf0, 0x10, 0x08, \n\t0x5a, 0x41, 0x23, 0x00, 0x14, 0xc8, 0x41, 0x00, 0xc0, 0xa1, 0x0f, 0x28, 0x0c, 0x0e, 0x30, 0x90, \n\t0x90, 0x35, 0x08, 0x07, 0x80, 0x16, 0x80, 0x82, 0x8e, 0x10, 0x80, 0x60, 0x58, 0x14, 0x10, 0x04, \n\t0x41, 0x8a, 0xc6, 0x44, 0x85, 0xa0, 0x8b, 0x04, 0xc0, 0xa1, 0x04, 0x01, 0x8b, 0xb6, 0x61, 0x54, \n\t0x2a, 0x10, 0x70, 0x30, 0x16, 0x89, 0x12, 0x48, 0x4a, 0xa5, 0x81, 0x82, 0x61, 0x01, 0x65, 0x70, \n\t0xa7, 0x43, 0x89, 0x09, 0x40, 0x48, 0x34, 0xb1, 0x21, 0x04, 0xb4, 0xc8, 0x80, 0x00, 0x85, 0x6a, \n\t0x12, 0x18, 0x0e, 0x04, 0x12, 0x46, 0x50, 0x9d, 0x28, 0x8e, 0x0e, 0x0a, 0x20, 0xd1, 0x05, 0x61, \n\t0x03, 0x2a, 0x08, 0x50, 0x98, 0x29, 0xfc, 0x84, 0x88, 0x00, 0x03, 0x80, 0x08, 0x8c, 0x00, 0x00, \n\t0x26, 0x22, 0x0a, 0xb0, 0x1c, 0x99, 0x43, 0x70, 0x54, 0x03, 0x06, 0x28, 0x00, 0x04, 0x78, 0x41, \n\t0x88, 0x07, 0xc8, 0x57, 0x80, 0x24, 0x00, 0x0a, 0x88, 0xc8, 0x01, 0x46, 0x22, 0x36, 0x1b, 0x00, \n\t0xb4, 0x49, 0xe8, 0x2c, 0x23, 0x38, 0x8d, 0xa0, 0x10, 0x8b, 0x10, 0x31, 0x82, 0xb0, 0xb8, 0x8c, \n\t0x25, 0x50, 0x44, 0x62, 0x10, 0x50, 0x1d, 0xc8, 0x34, 0x00, 0x03, 0x08, 0x28, 0x54, 0x09, 0x4e, \n\t0xc2, 0x11, 0xa5, 0x00, 0x04, 0x2c, 0x08, 0xa0, 0x81, 0x39, 0x11, 0x82, 0x04, 0x08, 0x36, 0x88, \n\t0x32, 0x40, 0x87, 0x05, 0x04, 0x81, 0x10, 0x28, 0x2c, 0x45, 0x08, 0x12, 0x35, 0x48, 0x32, 0xb9, \n\t0x46, 0x02, 0x50, 0x21, 0x01, 0x8c, 0x88, 0x08, 0x03, 0x56, 0xb2, 0x50, 0x1b, 0xd4, 0x00, 0xa9, \n\t0x0c, 0x00, 0x58, 0x24, 0x00, 0x97, 0xc2, 0x30, 0x56, 0x03, 0x0a, 0xac, 0x10, 0x60, 0x72, 0x03, \n\t0x31, 0x8c, 0x91, 0xc0, 0x60, 0x2e, 0x20, 0x80, 0x00, 0xd0, 0x10, 0x46, 0x4c, 0xe1, 0x8a, 0x85, \n\t0x10, 0x0e, 0x8c, 0x38, 0x92, 0x12, 0x08, 0x40, 0x42, 0x46, 0x08, 0x21, 0x10, 0x2b, 0x09, 0x1a, \n\t0xa5, 0x50, 0x94, 0xb8, 0x30, 0x24, 0x08, 0x06, 0x20, 0x65, 0x7a, 0xb0, 0x68, 0x00, 0x09, 0x1c, \n\t0x81, 0x88, 0x06, 0x21, 0x0c, 0xc4, 0x32, 0x51, 0x52, 0xb0, 0x81, 0x88, 0x84, 0x18, 0x90, 0x61, \n\t0x9d, 0x01, 0x49, 0xc2, 0x02, 0x00, 0xc0, 0x14, 0x14, 0x9f, 0x60, 0x00, 0x74, 0x00, 0x0b, 0x01, \n\t0x90, 0x84, 0x28, 0x22, 0x09, 0x10, 0x41, 0x43, 0x44, 0x06, 0x70, 0xe0, 0x25, 0x04, 0x1e, 0x24, \n\t0x04, 0x92, 0x50, 0x88, 0x99, 0x40, 0x27, 0x42, 0x82, 0xaa, 0x83, 0x5c, 0xc2, 0x40, 0x24, 0x40, \n\t0x11, 0x2a, 0xc5, 0x11, 0xa2, 0x4e, 0x04, 0x10, 0x01, 0xc4, 0x84, 0x88, 0x02, 0xc5, 0x22, 0x28, \n\t0x50, 0x10, 0xab, 0x00, 0x11, 0x81, 0x82, 0x8c, 0x88, 0x4a, 0x3c, 0x02, 0x50, 0x0e, 0x34, 0x01, \n\t0x88, 0x50, 0x15, 0x29, 0x16, 0x2c, 0x5b, 0x00, 0x08, 0x91, 0x03, 0x04, 0x48, 0x8e, 0x64, 0x16, \n\t0x26, 0x5a, 0x21, 0x0d, 0x50, 0x81, 0x44, 0x21, 0x08, 0x03, 0x0c, 0x94, 0xe0, 0x18, 0x90, 0x22, \n\t0x92, 0x84, 0x40, 0xc9, 0x64, 0xa0, 0x18, 0x04, 0x70, 0x49, 0x82, 0x18, 0x02, 0x19, 0x80, 0x80, \n\t0x85, 0x20, 0x6c, 0x41, 0x0b, 0x21, 0x9d, 0x4e, 0x00, 0x12, 0x40, 0x09, 0x8a, 0x10, 0x08, 0x64, \n\t0x74, 0x44, 0xd3, 0x08, 0x69, 0xc6, 0x08, 0x02, 0x76, 0x68, 0x38, 0x50, 0x91, 0x85, 0x00, 0xd1, \n\t0x42, 0xa5, 0x20, 0x15, 0x04, 0x08, 0x20, 0x79, 0x00, 0x71, 0x45, 0xe2, 0x34, 0x10, 0x11, 0x18, \n\t0x30, 0x94, 0x0e, 0x40, 0x30, 0x2a, 0x25, 0x15, 0x04, 0x25, 0x44, 0x10, 0xc2, 0x0f, 0x9d, 0x80, \n\t0x62, 0x20, 0x52, 0x00, 0x00, 0x20, 0xc6, 0x47, 0x5a, 0x14, 0xb9, 0x9a, 0x8c, 0x83, 0x28, 0x4e, \n\t0x21, 0x19, 0x02, 0x44, 0xd8, 0x81, 0x00, 0xa0, 0x18, 0x12, 0x51, 0x19, 0x09, 0x20, 0x13, 0x88, \n\t0x10, 0x20, 0xc0, 0x40, 0x20, 0x06, 0x19, 0x33, 0x45, 0x02, 0x89, 0x52, 0x20, 0x42, 0x05, 0x88, \n\t0x40, 0x08, 0x10, 0x04, 0x92, 0x10, 0x28, 0x19, 0xe3, 0x2c, 0x10, 0x82, 0x25, 0x20, 0x97, 0x41, \n\t0x10, 0x02, 0x88, 0x00, 0x11, 0x96, 0xce, 0x40, 0x37, 0x80, 0x08, 0x05, 0x02, 0x43, 0x02, 0x31, \n\t0x20, 0x9b, 0x20, 0x0e, 0x06, 0x20, 0x84, 0x78, 0x85, 0xc8, 0x06, 0x8a, 0x08, 0x10, 0x72, 0x25, \n\t0xa0, 0x90, 0xea, 0x3e, 0x82, 0x20, 0x12, 0x71, 0x18, 0x40, 0x04, 0x24, 0x89, 0x0a, 0x60, 0x4b, \n\t0xcd, 0x12, 0x00, 0x40, 0x98, 0x11, 0x15, 0x41, 0x22, 0x52, 0x2a, 0x23, 0x14, 0x81, 0x28, 0x1c, \n\t0x40, 0x23, 0x89, 0x00, 0x11, 0x6e, 0x48, 0x00, 0xb2, 0x1d, 0x14, 0x44, 0x80, 0x56, 0xc1, 0x11, \n\t0x8c, 0x20, 0x9e, 0xac, 0x40, 0x81, 0x31, 0x11, 0x14, 0x8a, 0xc0, 0x02, 0xd0, 0x28, 0x03, 0x08, \n\t0x06, 0x64, 0x44, 0xc3, 0xa1, 0x80, 0x20, 0x84, 0x80, 0x10, 0x45, 0x03, 0x10, 0xc9, 0xc2, 0x20, \n\t0x4a, 0x83, 0x78, 0x1a, 0xc0, 0x0d, 0x49, 0x00, 0x24, 0x90, 0x99, 0xe1, 0x05, 0xa6, 0x14, 0x82, \n\t0x10, 0x80, 0x91, 0xd9, 0x01, 0x00, 0x47, 0x68, 0x09, 0x10, 0x86, 0x08, 0x08, 0x14, 0x40, 0x9f, \n\t0x70, 0xd5, 0x6b, 0x0c, 0x14, 0x4a, 0x01, 0xd0, 0x40, 0x60, 0x02, 0x40, 0x10, 0x22, 0xa5, 0x08, \n\t0x4d, 0x20, 0xe0, 0x00, 0x97, 0x41, 0x4a, 0x8a, 0x06, 0xf1, 0x10, 0x35, 0x14, 0x82, 0x20, 0x68, \n\t0x00, 0x09, 0x34, 0x60, 0x01, 0x86, 0x00, 0x20, 0x40, 0x04, 0xcd, 0x02, 0x43, 0x06, 0x87, 0x03, \n\t0x9a, 0xa8, 0x14, 0xae, 0x62, 0x44, 0x0b, 0x88, 0x34, 0x42, 0x42, 0x20, 0x42, 0x60, 0x81, 0x14, \n\t0xc3, 0x83, 0x10, 0x53, 0x80, 0x11, 0x28, 0x95, 0x64, 0x3c, 0xe6, 0x8b, 0x00, 0x81, 0xd8, 0x81, \n\t0x14, 0xa2, 0x33, 0x20, 0x85, 0x44, 0x40, 0x00, 0x21, 0x1a, 0x09, 0x68, 0x0c, 0x40, 0x40, 0xf5, \n\t0x81, 0x80, 0x0d, 0x5b, 0x26, 0x2a, 0x03, 0x32, 0x22, 0x21, 0x00, 0x05, 0x0a, 0x80, 0xe0, 0x28, \n\t0x8c, 0x86, 0x24, 0x04, 0x01, 0x92, 0x91, 0x2c, 0x44, 0x81, 0x40, 0x26, 0x60, 0xb4, 0x7c, 0x15, \n\t0x49, 0x50, 0x02, 0x80, 0x08, 0x85, 0x86, 0xab, 0x10, 0x42, 0x40, 0x82, 0x94, 0x5d, 0x0f, 0x02, \n\t0x10, 0x6a, 0x19, 0x90, 0x0a, 0x05, 0x20, 0x24, 0xaa, 0x00, 0xd1, 0x04, 0x28, 0x74, 0x22, 0x80, \n\t0x11, 0x60, 0x81, 0xa9, 0x44, 0x00, 0x9b, 0x06, 0x04, 0x00, 0x49, 0x54, 0xe2, 0xf3, 0x09, 0x00, \n\t0xcb, 0xa2, 0x40, 0xa2, 0x08, 0x10, 0x18, 0x90, 0x22, 0x28, 0x50, 0xa9, 0x27, 0x04, 0xd8, 0xae, \n\t0x18, 0x41, 0xe0, 0x00, 0x70, 0x06, 0x82, 0x20, 0xc1, 0x90, 0x02, 0x09, 0x00, 0x06, 0x06, 0xc4, \n\t0xdb, 0x00, 0x08, 0x81, 0x0c, 0x0a, 0x26, 0x50, 0x82, 0xa4, 0x17, 0xc6, 0x28, 0x40, 0x21, 0x27, \n\t0x00, 0x43, 0x2d, 0x44, 0xd7, 0x31, 0x02, 0x09, 0x83, 0x00, 0x2a, 0xb0, 0x70, 0x05, 0x9c, 0x41, \n\t0x47, 0x12, 0xa2, 0x50, 0x22, 0x44, 0x90, 0x00, 0x48, 0x03, 0x11, 0x8e, 0xc9, 0x50, 0x21, 0x66, \n\t0x10, 0xa8, 0x81, 0x04, 0x11, 0xc1, 0x62, 0x91, 0x49, 0x00, 0x44, 0x91, 0x22, 0x0e, 0x24, 0x8a, \n\t0x36, 0xe1, 0x0d, 0x61, 0x6c, 0x44, 0x28, 0xa0, 0x94, 0x18, 0x04, 0x04, 0x81, 0x19, 0x01, 0x38, \n\t0x47, 0x42, 0x30, 0xa4, 0x41, 0x04, 0x05, 0x9a, 0x84, 0x50, 0x32, 0x29, 0x0c, 0x10, 0x08, 0x08, \n\t0x66, 0x21, 0x20, 0x85, 0xc8, 0x8c, 0x04, 0x06, 0x12, 0x40, 0x35, 0x19, 0x96, 0x04, 0x12, 0x52, \n\t0xd2, 0x08, 0xb0, 0x14, 0xa7, 0x40, 0x00, 0x53, 0x1f, 0x08, 0x03, 0xe1, 0x28, 0x81, 0x00, 0x3e, \n\t0x01, 0xdb, 0x42, 0x5c, 0x05, 0x61, 0xad, 0x00, 0xc0, 0x0c, 0x14, 0x20, 0x18, 0x93, 0x0c, 0x52, \n\t0x89, 0x24, 0xe0, 0x82, 0x0e, 0x04, 0x40, 0x6d, 0x32, 0xb6, 0x4a, 0xaa, 0x91, 0x00, 0x41, 0x04, \n\t0x00, 0x01, 0x12, 0x65, 0x8c, 0x00, 0x12, 0x51, 0x88, 0xbb, 0xa4, 0x0c, 0x21, 0x48, 0xa1, 0x10, \n\t0x0e, 0x48, 0x8a, 0x24, 0x54, 0x02, 0x61, 0x38, 0x31, 0x00, 0x88, 0x00, 0x42, 0xc9, 0x0e, 0x0c, \n\t0x82, 0x40, 0x0c, 0x22, 0x51, 0x04, 0x90, 0x00, 0x6c, 0x22, 0x24, 0x88, 0x9c, 0x04, 0x04, 0x42, \n\t0x40, 0x01, 0x23, 0x01, 0x88, 0x05, 0x20, 0x0a, 0x70, 0xa2, 0xa6, 0x00, 0x11, 0x68, 0x38, 0x24, \n\t0xa0, 0x30, 0xa1, 0x41, 0x4d, 0x20, 0xf0, 0x90, 0x00, 0x15, 0x40, 0xc0, 0x02, 0xe4, 0x59, 0x2c, \n\t0xe0, 0xd7, 0x08, 0x3a, 0x90, 0x8b, 0xaa, 0x20, 0x08, 0x08, 0x00, 0xd2, 0x02, 0x04, 0xe1, 0xc0, \n\t0x00, 0x38, 0x04, 0xe9, 0x08, 0xb8, 0x47, 0x86, 0x40, 0x00, 0x32, 0x23, 0x99, 0x00, 0x05, 0x0c, \n\t0x57, 0x10, 0x30, 0x55, 0x59, 0x8a, 0x48, 0x84, 0x90, 0x33, 0x3c, 0x04, 0xc1, 0x6a, 0x12, 0xc1, \n\t0x00, 0x85, 0x5a, 0x06, 0x30, 0x44, 0x98, 0x34, 0x19, 0x18, 0x22, 0x32, 0x24, 0x70, 0x24, 0xa0, \n\t0x0c, 0x23, 0x44, 0x51, 0x00, 0x29, 0x51, 0x43, 0x00, 0x10, 0x21, 0x10, 0x21, 0x00, 0x14, 0x42, \n\t0x62, 0x84, 0x01, 0x00, 0x38, 0x1b, 0x68, 0x10, 0x73, 0x52, 0x02, 0x00, 0x11, 0x21, 0x06, 0x90, \n\t0x01, 0x05, 0x60, 0x04, 0x62, 0x00, 0x00, 0x80, 0xa0, 0x41, 0x1e, 0xcc, 0x00, 0x03, 0xf0, 0xb8, \n\t0x4c, 0x08, 0x20, 0x0c, 0x01, 0x20, 0x08, 0x7c, 0x06, 0x24, 0x40, 0x93, 0x4b, 0x80, 0x45, 0xc7, \n\t0x84, 0x46, 0x25, 0x11, 0x00, 0xd0, 0x89, 0x02, 0x18, 0xc2, 0xf0, 0x02, 0x08, 0x1c, 0xac, 0x42, \n\t0xd4, 0x48, 0x10, 0xac, 0xc4, 0x02, 0x1a, 0x11, 0x49, 0x19, 0x00, 0xcd, 0xc0, 0x5a, 0x47, 0xa2, \n\t0xa9, 0x08, 0x00, 0x01, 0x24, 0x21, 0x60, 0x10, 0x40, 0x52, 0xec, 0x00, 0x04, 0x00, 0x19, 0x50, \n\t0x11, 0x8d, 0x1a, 0x30, 0x9a, 0x03, 0x80, 0x80, 0xc7, 0x20, 0x03, 0x90, 0x03, 0x98, 0x88, 0x2f, \n\t0x0e, 0x34, 0x08, 0x15, 0x68, 0xd5, 0x26, 0x24, 0x80, 0x50, 0x81, 0x04, 0x57, 0xa0, 0x60, 0x01, \n\t0x31, 0x15, 0xb4, 0x92, 0x00, 0x06, 0xe0, 0x40, 0x30, 0x01, 0x59, 0x48, 0x04, 0x86, 0x49, 0x99, \n\t0xc0, 0x08, 0x4b, 0x26, 0x81, 0x48, 0x0e, 0x44, 0x14, 0x43, 0x22, 0x26, 0x82, 0x2e, 0x00, 0x81, \n\t0x40, 0x68, 0xa1, 0x51, 0x84, 0x58, 0x86, 0xc0, 0x20, 0xa2, 0x92, 0x28, 0x44, 0x84, 0x03, 0x5c, \n\t0x50, 0x90, 0x02, 0x6c, 0x04, 0xaf, 0x70, 0x16, 0x32, 0x06, 0x91, 0x81, 0xa8, 0x00, 0xb0, 0x28, \n\t0x23, 0x30, 0x01, 0x40, 0x60, 0x81, 0x08, 0xa9, 0x41, 0x10, 0x0a, 0x2a, 0x74, 0x29, 0x97, 0xa0, \n\t0x52, 0x8a, 0x1c, 0x40, 0xa2, 0x38, 0x9c, 0x10, 0x07, 0x02, 0xc0, 0x02, 0x01, 0x50, 0x4e, 0x0b, \n\t0x00, 0x06, 0x21, 0xad, 0x24, 0x53, 0x44, 0x4a, 0x96, 0x8b, 0x20, 0x10, 0x9c, 0x40, 0x24, 0xa3, \n\t0x89, 0x19, 0x70, 0x01, 0x22, 0x14, 0x10, 0x98, 0x00, 0x21, 0x95, 0x09, 0x4a, 0x91, 0x49, 0x22, \n\t0xc5, 0x04, 0x27, 0x60, 0x65, 0xe2, 0x20, 0x80, 0x02, 0x00, 0x24, 0x22, 0xaa, 0x96, 0x64, 0x84, \n\t0x02, 0x4e, 0xc0, 0x0a, 0x18, 0xe0, 0x80, 0x04, 0x58, 0x04, 0x51, 0x25, 0x81, 0x98, 0x40, 0x0e, \n\t0x20, 0x90, 0x0a, 0xc8, 0x0d, 0x08, 0x42, 0x21, 0x81, 0x12, 0x00, 0xca, 0x00, 0x36, 0x82, 0x58, \n\t0x20, 0x15, 0x01, 0xca, 0x48, 0x21, 0x41, 0x01, 0xb0, 0x00, 0x20, 0x06, 0x80, 0x18, 0x04, 0x00, \n\t0x92, 0x09, 0x28, 0x24, 0x01, 0x0c, 0x74, 0x05, 0x42, 0x18, 0x90, 0x61, 0x2b, 0x09, 0x16, 0x45, \n\t0x44, 0xa2, 0xc0, 0x1a, 0x14, 0x01, 0x00, 0x00, 0x40, 0x22, 0x9d, 0x45, 0x4b, 0x84, 0x12, 0x05, \n\t0xea, 0x04, 0xcc, 0x0a, 0x08, 0x20, 0x40, 0x09, 0x02, 0x6c, 0x83, 0x80, 0x00, 0x00, 0x30, 0x90, \n\t0x99, 0x00, 0x4d, 0x30, 0x41, 0x9a, 0x03, 0x65, 0xc5, 0x29, 0x38, 0x10, 0x50, 0x24, 0x61, 0x80, \n\t0x44, 0x02, 0xd2, 0xc0, 0x80, 0x20, 0x02, 0x20, 0x02, 0x54, 0x63, 0x10, 0xb0, 0x15, 0x85, 0x48, \n\t0xa2, 0x03, 0x10, 0x95, 0xd0, 0x00, 0x08, 0xc1, 0xe3, 0x0c, 0x40, 0x16, 0x66, 0x40, 0x45, 0x11, \n\t0x89, 0x00, 0x00, 0x8e, 0x42, 0x93, 0xb0, 0x28, 0x69, 0xd0, 0xe2, 0x22, 0x07, 0x11, 0x0c, 0x2c, \n\t0x98, 0x80, 0x48, 0x04, 0x10, 0x14, 0xdd, 0x8e, 0x01, 0x08, 0x07, 0xe2, 0x8e, 0x08, 0x00, 0x6a, \n\t0x30, 0x11, 0x40, 0x03, 0x40, 0x85, 0x26, 0x08, 0x06, 0x18, 0x0a, 0x40, 0x82, 0x01, 0x28, 0x50, \n\t0x29, 0xa3, 0xa0, 0xc3, 0x68, 0x54, 0xa2, 0x98, 0x88, 0x20, 0x00, 0x2e, 0x46, 0x26, 0xa0, 0x00, \n\t0x1c, 0x41, 0x04, 0x14, 0x02, 0x42, 0x80, 0x89, 0x1e, 0xa9, 0x44, 0xc5, 0x92, 0xb0, 0x80, 0xca, \n\t0xa0, 0x08, 0x76, 0xb0, 0xa8, 0x40, 0xcf, 0x83, 0x2a, 0xc0, 0x58, 0x3e, 0x0c, 0x04, 0x84, 0x0e, \n\t0x51, 0xc0, 0x13, 0x81, 0x59, 0xe8, 0x40, 0x42, 0x19, 0x0a, 0x38, 0x40, 0xc6, 0x22, 0x40, 0x11, \n\t0x80, 0x41, 0x01, 0x66, 0x2e, 0xa1, 0x08, 0x31, 0x50, 0x0a, 0x89, 0x00, 0x07, 0x40, 0x13, 0x00, \n\t0x41, 0x28, 0x02, 0xc0, 0x0b, 0x85, 0x11, 0xd8, 0x28, 0x2e, 0x82, 0xa2, 0x24, 0xb0, 0x50, 0x67, \n\t0x56, 0x80, 0x03, 0x8f, 0x28, 0x00, 0x05, 0x24, 0x81, 0xc0, 0x12, 0x4c, 0x82, 0x04, 0x0a, 0x16, \n\t0xb0, 0x8a, 0x51, 0x00, 0x80, 0x14, 0x41, 0x53, 0x0e, 0x29, 0x4a, 0x08, 0x14, 0x14, 0x22, 0xa5, \n\t0x24, 0x46, 0x41, 0x02, 0x01, 0x40, 0x84, 0x64, 0x04, 0xc4, 0x04, 0x92, 0x99, 0x08, 0xa8, 0x89, \n\t0x2a, 0x10, 0x40, 0x21, 0x14, 0xa0, 0x18, 0xc8, 0x48, 0xa4, 0x49, 0xa1, 0x00, 0x47, 0x41, 0x28, \n\t0x86, 0x88, 0x0e, 0x80, 0x48, 0xa1, 0x64, 0x12, 0x72, 0x28, 0x40, 0x53, 0x48, 0x52, 0xb2, 0x02, \n\t0x00, 0xd8, 0x90, 0x48, 0x20, 0x36, 0xc2, 0x25, 0x80, 0x09, 0x25, 0x2c, 0x12, 0x88, 0x98, 0x69, \n\t0x1c, 0x04, 0x12, 0x14, 0xe2, 0x90, 0x68, 0x06, 0x88, 0x38, 0x00, 0x23, 0x01, 0x90, 0x15, 0xa0, \n\t0x1e, 0x04, 0x31, 0xa6, 0x71, 0x40, 0x0a, 0x50, 0xd4, 0x41, 0x08, 0x08, 0x0a, 0x04, 0x2c, 0x15, \n\t0x00, 0x8a, 0x40, 0x10, 0x8a, 0x70, 0xb0, 0x81, 0x22, 0x14, 0x0b, 0x25, 0x12, 0x15, 0x0a, 0x00, \n\t0x30, 0x81, 0xcc, 0x08, 0x30, 0x61, 0x18, 0xdc, 0xc4, 0x60, 0x14, 0x83, 0x78, 0xa1, 0x00, 0x82, \n\t0x83, 0x08, 0x52, 0xb0, 0x06, 0x0c, 0x02, 0x29, 0x00, 0x14, 0x2a, 0x90, 0x0d, 0x11, 0x64, 0x42, \n\t0x02, 0x40, 0x21, 0x80, 0x45, 0x06, 0x08, 0x04, 0x4b, 0x04, 0x30, 0x50, 0x40, 0x26, 0x64, 0xe2, \n\t0x04, 0xc5, 0x0c, 0xc8, 0x30, 0xc6, 0x02, 0x0b, 0x18, 0x4f, 0x80, 0x28, 0x84, 0x20, 0x29, 0x85, \n\t0x8e, 0x0b, 0x58, 0x24, 0x80, 0x01, 0x14, 0x55, 0x04, 0x02, 0xc1, 0xb0, 0x80, 0xc0, 0x80, 0x8b, \n\t0x42, 0x82, 0x59, 0x34, 0x4c, 0xc0, 0xc0, 0x12, 0x53, 0x39, 0x20, 0x84, 0x0a, 0xc5, 0x18, 0x91, \n\t0x20, 0xa3, 0x50, 0x48, 0x43, 0x4a, 0x10, 0x3a, 0xb2, 0x11, 0x89, 0x42, 0x18, 0x10, 0xe0, 0x93, \n\t0x40, 0x02, 0xa6, 0x64, 0x04, 0x08, 0x87, 0x18, 0xc3, 0x00, 0x16, 0x07, 0x20, 0x2a, 0x04, 0x09, \n\t0x44, 0x22, 0xa2, 0x83, 0xb0, 0x29, 0xc1, 0x40, 0x20, 0xa3, 0x01, 0x07, 0x81, 0x5c, 0x42, 0x00, \n\t0x45, 0x21, 0x83, 0xac, 0x13, 0x25, 0x0e, 0x80, 0x80, 0x01, 0x49, 0x14, 0x8b, 0x10, 0x16, 0x62, \n\t0x10, 0x14, 0x82, 0x07, 0x48, 0xb0, 0xe9, 0x09, 0x80, 0x9a, 0x88, 0x70, 0xe0, 0xc0, 0x0d, 0x8d, \n\t0x03, 0x84, 0x04, 0xd1, 0x20, 0x82, 0x25, 0x07, 0x62, 0x68, 0x11, 0x10, 0x20, 0x20, 0x01, 0x06, \n\t0x14, 0x40, 0x72, 0x12, 0x11, 0xd4, 0x20, 0x10, 0x65, 0x72, 0x10, 0xc8, 0x04, 0x8a, 0x04, 0x04, \n\t0x0a, 0x98, 0x08, 0xc8, 0x20, 0x04, 0x12, 0x48, 0x85, 0x70, 0x10, 0xc3, 0x08, 0x25, 0x80, 0x18, \n\t0x00, 0x1c, 0x40, 0x1e, 0x20, 0x00, 0x13, 0xa1, 0x43, 0xe0, 0x1e, 0x04, 0xc3, 0x18, 0xc4, 0x00, \n\t0x69, 0x44, 0x00, 0x20, 0xaf, 0xa0, 0x04, 0x0a, 0x00, 0x01, 0x43, 0x3c, 0x11, 0x10, 0x66, 0x48, \n\t0x82, 0x20, 0x0f, 0x1c, 0x0c, 0x44, 0x38, 0x13, 0xa8, 0x14, 0x24, 0x8f, 0x80, 0x06, 0x60, 0x72, \n\t0x00, 0x90, 0x84, 0x01, 0x12, 0x61, 0x50, 0x2e, 0xbc, 0x04, 0x24, 0x64, 0x90, 0x48, 0x28, 0x49, \n\t0x83, 0xa0, 0x10, 0x54, 0x19, 0x1b, 0xa5, 0x01, 0x08, 0x52, 0xf6, 0x00, 0x07, 0xac, 0x09, 0x40, \n\t0x24, 0x42, 0xd8, 0x8a, 0xd1, 0x99, 0x88, 0x6e, 0x90, 0x08, 0x04, 0x00, 0x50, 0x0c, 0x18, 0x73, \n\t0x09, 0x85, 0x24, 0x84, 0x6a, 0x00, 0xc0, 0x83, 0xa1, 0x85, 0x5a, 0x40, 0x42, 0x64, 0x82, 0x30, \n\t0x31, 0x48, 0x05, 0x14, 0xd1, 0x7a, 0x00, 0x0d, 0x10, 0x20, 0x42, 0x20, 0xc0, 0x26, 0x84, 0x0c, \n\t0xc3, 0x1c, 0x20, 0x51, 0x10, 0xa9, 0x19, 0x21, 0x14, 0x22, 0x41, 0xa8, 0x90, 0x0d, 0xe9, 0x10, \n\t0x64, 0x29, 0xbd, 0x31, 0xc4, 0x46, 0x28, 0x40, 0x0a, 0x9a, 0x88, 0xc4, 0x20, 0x28, 0x21, 0xc2, \n\t0x80, 0x40, 0x86, 0x03, 0x38, 0x96, 0x83, 0x08, 0x39, 0xd0, 0x0c, 0x1a, 0x81, 0x78, 0x2a, 0x51, \n\t0x06, 0xc7, 0x00, 0x13, 0x91, 0x05, 0x01, 0x59, 0x4c, 0x00, 0xc1, 0x02, 0x86, 0x15, 0x5f, 0x84, \n\t0x22, 0x56, 0x62, 0xa3, 0x84, 0x10, 0x00, 0x7a, 0x01, 0xa1, 0x11, 0x91, 0x92, 0xa0, 0x48, 0x20, \n\t0x28, 0x98, 0x10, 0x45, 0xa4, 0x04, 0x81, 0x02, 0x3a, 0x88, 0x01, 0x08, 0x24, 0xc3, 0x20, 0x34, \n\t0x84, 0x5c, 0x40, 0x20, 0xf6, 0x22, 0x10, 0xbc, 0x02, 0x21, 0x02, 0x44, 0x38, 0x0b, 0x98, 0x82, \n\t0x60, 0x2e, 0x96, 0x88, 0x05, 0x44, 0x45, 0xca, 0x0c, 0x00, 0x0a, 0x82, 0xe9, 0x00, 0x61, 0x58, \n\t0x00, 0x11, 0x15, 0x10, 0x13, 0x21, 0x26, 0x02, 0x08, 0x80, 0x41, 0x96, 0x04, 0x28, 0x01, 0x81, \n\t0x0d, 0x21, 0x99, 0x00, 0x42, 0x71, 0x82, 0xa2, 0xc0, 0x45, 0x60, 0x38, 0x40, 0xd2, 0x80, 0x80, \n\t0x58, 0x43, 0x06, 0xe1, 0x13, 0x22, 0xe8, 0x08, 0x00, 0x00, 0x40, 0x00, 0x1d, 0x20, 0x5b, 0x44, \n\t0x42, 0x12, 0x4b, 0x28, 0x10, 0x0c, 0x0c, 0x54, 0xc2, 0xc0, 0x0e, 0x10, 0xc7, 0x00, 0x70, 0xa0, \n\t0x60, 0x30, 0x3c, 0x82, 0x03, 0x48, 0x40, 0x12, 0x2c, 0x7c, 0x80, 0x86, 0x20, 0x02, 0x12, 0x21, \n\t0x49, 0x01, 0xe9, 0x68, 0x12, 0xb8, 0x28, 0x04, 0xd0, 0x82, 0x54, 0x42, 0x89, 0x9b, 0x40, 0x52, \n\t0x84, 0x1e, 0x21, 0xe0, 0x22, 0x85, 0x15, 0x80, 0x4c, 0x84, 0x81, 0x04, 0xc0, 0x09, 0x0a, 0x42, \n\t0x46, 0x81, 0x22, 0x40, 0x89, 0x26, 0x16, 0x94, 0x49, 0x11, 0x94, 0x41, 0x0f, 0x00, 0x40, 0xa0, \n\t0x2d, 0x28, 0x40, 0x2d, 0x18, 0x11, 0x1b, 0x19, 0x18, 0x92, 0x81, 0x26, 0x26, 0x0b, 0x00, 0x0c, \n\t0x91, 0x0c, 0x46, 0xe0, 0x20, 0x0c, 0x31, 0x8a, 0x08, 0x14, 0x90, 0x12, 0x3a, 0x11, 0x53, 0x25, \n\t0x00, 0x85, 0x22, 0x11, 0x05, 0x40, 0x80, 0x20, 0x96, 0x40, 0x83, 0x41, 0x8d, 0x28, 0x00, 0x40, \n\t0xe2, 0x04, 0x08, 0xc6, 0x08, 0x10, 0xa2, 0x98, 0x12, 0x29, 0x00, 0x29, 0x24, 0x54, 0x80, 0x82, \n\t0x25, 0x03, 0x45, 0x16, 0x00, 0x18, 0x90, 0x30, 0x11, 0x0a, 0x30, 0x84, 0x21, 0x06, 0x08, 0x0c, \n\t0x60, 0x22, 0x14, 0xc2, 0x82, 0x38, 0x54, 0xc0, 0x6a, 0x84, 0x11, 0x3c, 0x00, 0x10, 0x8c, 0x48, \n\t0x82, 0x8a, 0x8d, 0x65, 0x88, 0x40, 0x00, 0x42, 0x33, 0x25, 0x5c, 0x09, 0x01, 0x00, 0x03, 0x20, \n\t0x3f, 0x50, 0x0a, 0xe6, 0x04, 0x40, 0x38, 0x00, 0x0d, 0xd0, 0x8e, 0x50, 0x40, 0x61, 0x04, 0x20, \n\t0x4c, 0x83, 0x24, 0x26, 0x28, 0x06, 0xc0, 0x00, 0x88, 0x04, 0x72, 0x12, 0x19, 0x81, 0x84, 0x43, \n\t0x26, 0x10, 0x18, 0x90, 0x21, 0x93, 0x04, 0x08, 0xa3, 0x89, 0x27, 0x04, 0x84, 0x68, 0x00, 0x93, \n\t0x43, 0x81, 0x71, 0x84, 0x0c, 0x10, 0xb4, 0xe0, 0x21, 0xc1, 0x52, 0x2e, 0x02, 0x10, 0x00, 0x00, \n\t0xc1, 0x08, 0x00, 0x68, 0x80, 0xd2, 0x01, 0x00, 0x00, 0xa5, 0x0e, 0x85, 0x32, 0x8c, 0x01, 0x40, \n\t0x82, 0x20, 0x95, 0x8b, 0x92, 0x40, 0x1c, 0x08, 0x54, 0x30, 0x40, 0x36, 0x34, 0x09, 0x82, 0x06, \n\t0x84, 0xf2, 0xac, 0x84, 0x18, 0x21, 0x32, 0xd0, 0x41, 0x11, 0xb0, 0x82, 0x43, 0x12, 0x50, 0x08, \n\t0x0a, 0x80, 0x0b, 0x02, 0x50, 0x06, 0x60, 0xa6, 0x04, 0x51, 0x08, 0x02, 0x84, 0x1b, 0x91, 0x79, \n\t0x01, 0x8c, 0x44, 0x30, 0xa2, 0x00, 0x20, 0x16, 0x82, 0x48, 0x10, 0x00, 0x21, 0x09, 0x08, 0x22, \n\t0x08, 0x20, 0x62, 0x30, 0x99, 0x89, 0x4a, 0x26, 0x07, 0xb2, 0x0a, 0x01, 0x02, 0xc4, 0x2c, 0x03, \n\t0xd0, 0x22, 0xc4, 0x94, 0x80, 0x5a, 0x14, 0xc0, 0x15, 0x49, 0x86, 0x28, 0x0a, 0xa2, 0x43, 0x24, \n\t0x24, 0x14, 0x01, 0x16, 0x60, 0xd0, 0x2b, 0x45, 0x09, 0x04, 0x16, 0xa1, 0x48, 0x1e, 0xa4, 0x14, \n\t0xc0, 0x48, 0x00, 0x42, 0x8b, 0x90, 0xcd, 0x40, 0x68, 0xc2, 0x02, 0x91, 0x00, 0x4c, 0xc8, 0x24, \n\t0x12, 0x4b, 0x28, 0x21, 0x04, 0x48, 0x12, 0x10, 0x82, 0x87, 0x01, 0x9a, 0xa1, 0x14, 0x60, 0x41, \n\t0x8b, 0xd0, 0x08, 0xa8, 0x22, 0x20, 0x02, 0x8c, 0x69, 0x88, 0x06, 0x58, 0x05, 0xa3, 0x27, 0x48, \n\t0x15, 0xaa, 0x20, 0x40, 0x50, 0x30, 0x2c, 0x0c, 0x08, 0x6c, 0x82, 0x21, 0x8a, 0x29, 0x58, 0x0d, \n\t0x40, 0x91, 0xd3, 0x00, 0x05, 0x02, 0x2e, 0x24, 0x11, 0x11, 0xb5, 0xc0, 0x94, 0x08, 0x02, 0x60, \n\t0x20, 0x08, 0x88, 0x0f, 0x25, 0x46, 0xc4, 0x42, 0x12, 0x18, 0x41, 0x2d, 0x10, 0x04, 0x12, 0x25, \n\t0x20, 0xc1, 0xe0, 0x44, 0x30, 0xd0, 0x2a, 0x1c, 0x06, 0x62, 0x38, 0x73, 0x81, 0xa0, 0x4c, 0x01, \n\t0x08, 0x60, 0x16, 0x02, 0x95, 0x3c, 0x51, 0xa1, 0x58, 0x12, 0x71, 0x2d, 0x60, 0x98, 0x08, 0x68, \n\t0x00, 0x12, 0x01, 0x50, 0x54, 0x00, 0x02, 0x87, 0xa9, 0x32, 0x19, 0x00, 0x82, 0x00, 0x41, 0x02, \n\t0xa1, 0x00, 0x0d, 0xe0, 0x10, 0x82, 0x50, 0x88, 0x75, 0x8c, 0x8c, 0x42, 0x16, 0x48, 0x19, 0x28, \n\t0x00, 0x08, 0x00, 0x94, 0x08, 0x11, 0x00, 0x1b, 0x83, 0x12, 0x20, 0x08, 0x2c, 0x2c, 0xc2, 0x60, \n\t0x10, 0x82, 0xb8, 0x02, 0x09, 0x04, 0x04, 0x38, 0x61, 0x51, 0x36, 0x04, 0x82, 0xe0, 0x06, 0xa1, \n\t0x0a, 0x8c, 0x11, 0xc3, 0x42, 0x0c, 0x17, 0x42, 0x84, 0x28, 0x03, 0x86, 0x4c, 0x70, 0x3b, 0x15, \n\t0xf8, 0xc8, 0x40, 0x10, 0xe1, 0xc8, 0xa0, 0x14, 0x41, 0x24, 0x64, 0x92, 0x41, 0x2b, 0x31, 0x09, \n\t0x41, 0x0c, 0x80, 0x40, 0x80, 0x85, 0x10, 0x82, 0x22, 0x52, 0xc8, 0x12, 0x38, 0x46, 0x65, 0x16, \n\t0x26, 0x20, 0x98, 0x61, 0x00, 0x29, 0x04, 0x94, 0xab, 0x28, 0x09, 0x00, 0x23, 0x02, 0xf0, 0x02, \n\t0x84, 0xe0, 0x0a, 0x05, 0x40, 0x20, 0xf0, 0x3b, 0x8c, 0x18, 0x4f, 0x44, 0xc0, 0x08, 0x2c, 0x20, \n\t0x42, 0x20, 0x00, 0x01, 0x02, 0xa9, 0x41, 0x03, 0x00, 0x52, 0x20, 0x72, 0x02, 0x80, 0xc2, 0x0a, \n\t0x64, 0x47, 0x92, 0x04, 0x49, 0x14, 0x03, 0x74, 0x80, 0x10, 0x83, 0x8c, 0x09, 0x29, 0x0e, 0x50, \n\t0x29, 0x04, 0x81, 0x1f, 0x49, 0x08, 0x85, 0xc0, 0x8c, 0x00, 0xd5, 0x41, 0x32, 0x46, 0xe1, 0x82, \n\t0x20, 0x90, 0xa6, 0x22, 0x80, 0xa8, 0x08, 0xf5, 0x43, 0x05, 0x18, 0x22, 0x41, 0x04, 0xc0, 0x00, \n\t0x0e, 0x1c, 0x12, 0xa0, 0x84, 0x44, 0xd9, 0x2c, 0x2a, 0xc7, 0x20, 0x2b, 0x04, 0x1b, 0x00, 0x3e, \n\t0x10, 0x00, 0x14, 0xc5, 0x05, 0x84, 0x04, 0x55, 0x22, 0x04, 0x08, 0xd1, 0xa8, 0x5a, 0x41, 0x12, \n\t0x9e, 0xf4, 0x08, 0x04, 0x50, 0x05, 0x48, 0x90, 0x0d, 0x07, 0x40, 0x08, 0x74, 0x28, 0x80, 0x81, \n\t0x16, 0x08, 0x0a, 0x80, 0x08, 0x0c, 0x04, 0xc9, 0x41, 0x7a, 0x65, 0x43, 0x82, 0x21, 0x92, 0x61, \n\t0x04, 0x94, 0xc1, 0x08, 0x00, 0x54, 0x01, 0x54, 0xa2, 0xe1, 0x01, 0x3c, 0x80, 0xa0, 0x04, 0x12, \n\t0xa2, 0x98, 0x80, 0x49, 0x4c, 0x62, 0x26, 0x02, 0x04, 0x28, 0x48, 0xa4, 0x04, 0x91, 0x4a, 0xa8, \n\t0x49, 0x11, 0x80, 0x00, 0x30, 0x69, 0x06, 0xf4, 0x93, 0x01, 0x08, 0x03, 0x11, 0x00, 0x51, 0x40, \n\t0x40, 0x12, 0x20, 0xd1, 0xba, 0x8d, 0x06, 0x40, 0x28, 0xe4, 0x10, 0x86, 0x85, 0xc8, 0x42, 0x02, \n\t0xc1, 0x20, 0x00, 0x90, 0x5b, 0x01, 0x14, 0x10, 0x20, 0x07, 0xe0, 0x81, 0x0a, 0x02, 0xb6, 0x39, \n\t0x19, 0x80, 0x10, 0x29, 0x48, 0x43, 0x2b, 0x0b, 0xc0, 0x84, 0x64, 0x34, 0xb6, 0x42, 0x14, 0x80, \n\t0x48, 0x26, 0x2e, 0xd1, 0x00, 0x33, 0x14, 0x11, 0x20, 0x02, 0x52, 0x82, 0xa9, 0x45, 0x08, 0xaa, \n\t0x18, 0x00, 0x21, 0x91, 0x9d, 0x12, 0x80, 0x4c, 0xa6, 0xd2, 0x90, 0x40, 0x19, 0x0f, 0x40, 0x64, \n\t0x01, 0x10, 0x68, 0x04, 0x45, 0x20, 0xb2, 0x18, 0x06, 0x20, 0x94, 0x8a, 0x30, 0x90, 0x03, 0xb4, \n\t0x2c, 0x83, 0x69, 0x20, 0x14, 0x50, 0x90, 0x30, 0x09, 0x43, 0x30, 0x80, 0x12, 0x18, 0xc1, 0x95, \n\t0x62, 0x40, 0x52, 0x70, 0x0c, 0x8c, 0x84, 0x89, 0x08, 0xc4, 0x00, 0x09, 0x04, 0x09, 0x00, 0x60, \n\t0xc5, 0x30, 0xa7, 0x60, 0x81, 0x20, 0x32, 0x06, 0x00, 0x99, 0x09, 0x04, 0x0c, 0x18, 0x61, 0x08, \n\t0x10, 0x25, 0x41, 0xc0, 0x14, 0x03, 0x20, 0x02, 0x10, 0x4d, 0x08, 0x04, 0x07, 0x01, 0x33, 0x74, \n\t0xce, 0x22, 0x00, 0x61, 0x61, 0x38, 0x05, 0x0c, 0x46, 0x60, 0xf0, 0x41, 0x02, 0x84, 0x04, 0x08, \n\t0x3e, 0x60, 0x30, 0x0a, 0xa1, 0x41, 0xee, 0x16, 0x02, 0xd8, 0x04, 0x20, 0x83, 0x01, 0x00, 0x01, \n\t0x5b, 0x04, 0x34, 0x08, 0xa0, 0x70, 0xc0, 0xa0, 0x33, 0x5c, 0xd8, 0x03, 0x48, 0x00, 0x3a, 0x1b, \n\t0x00, 0x87, 0x41, 0x70, 0x80, 0x88, 0x00, 0x85, 0x00, 0x8c, 0x28, 0x24, 0xbb, 0x00, 0xe0, 0x50, \n\t0x4b, 0x00, 0x85, 0x10, 0x36, 0x48, 0x49, 0x20, 0x00, 0x14, 0x02, 0x12, 0x08, 0x40, 0xa4, 0x32, \n\t0x04, 0x11, 0x1b, 0x21, 0x0f, 0x80, 0x30, 0x83, 0x62, 0x86, 0x38, 0xd2, 0x25, 0x46, 0xb4, 0x00, \n\t0x89, 0x79, 0x84, 0x0e, 0x40, 0x14, 0x1a, 0x0c, 0xb4, 0x97, 0x4b, 0x0c, 0xf1, 0x00, 0x06, 0x0d, \n\t0x84, 0x02, 0x40, 0x00, 0x80, 0xb2, 0x88, 0x48, 0x02, 0x08, 0x51, 0x08, 0x90, 0x1c, 0x48, 0xa4, \n\t0x0c, 0x80, 0x08, 0xb4, 0x88, 0x8f, 0xa8, 0x64, 0x14, 0x69, 0x33, 0x81, 0x82, 0x23, 0x26, 0x46, \n\t0x8a, 0x02, 0x54, 0x08, 0xc9, 0x10, 0x33, 0x12, 0xa1, 0xc0, 0x86, 0xc0, 0x34, 0x20, 0x40, 0x09, \n\t0x10, 0x51, 0x07, 0x70, 0x41, 0x82, 0x81, 0x10, 0x1e, 0x0c, 0x3a, 0x47, 0x61, 0x02, 0x48, 0x43, \n\t0xcb, 0x0a, 0x02, 0xf1, 0x1c, 0x60, 0x10, 0x05, 0x16, 0x51, 0xaa, 0x88, 0x45, 0x98, 0x82, 0x64, \n\t0x91, 0xb0, 0x32, 0x08, 0x83, 0x01, 0x40, 0xd3, 0x00, 0x39, 0x40, 0x92, 0x40, 0x42, 0x81, 0xe1, \n\t0x08, 0x88, 0xc5, 0x2a, 0x0a, 0x05, 0x50, 0x83, 0xe4, 0x07, 0xa1, 0x10, 0x67, 0x28, 0xa4, 0x88, \n\t0x01, 0x0b, 0x20, 0x14, 0x10, 0x2a, 0xcd, 0x41, 0x28, 0x22, 0x16, 0x18, 0x90, 0xd1, 0x00, 0x44, \n\t0x18, 0x81, 0xa1, 0x00, 0x14, 0x1e, 0x04, 0x22, 0x25, 0xd1, 0x14, 0x58, 0x09, 0x4a, 0x3a, 0x06, \n\t0x83, 0x25, 0x24, 0x01, 0x4c, 0x18, 0x01, 0x22, 0xa8, 0x30, 0x08, 0x41, 0x58, 0xa7, 0x52, 0x81, \n\t0xdc, 0x52, 0x26, 0x00, 0x86, 0x00, 0x38, 0x64, 0x85, 0x07, 0x0c, 0x52, 0x1a, 0x12, 0xa8, 0x04, \n\t0x8e, 0x32, 0x01, 0x41, 0x20, 0xe9, 0x4b, 0x60, 0x76, 0x21, 0x20, 0x2c, 0xa9, 0x00, 0x82, 0x32, \n\t0x64, 0x4a, 0x30, 0x48, 0x4a, 0x02, 0x04, 0x17, 0x10, 0x16, 0x05, 0x10, 0x41, 0x68, 0x71, 0x40, \n\t0x02, 0x20, 0x92, 0x60, 0x0e, 0xc2, 0x31, 0x04, 0x11, 0x83, 0x41, 0x0a, 0xb2, 0x11, 0x00, 0x25, \n\t0x45, 0x84, 0x40, 0x00, 0xda, 0x28, 0x41, 0x00, 0x4b, 0x0c, 0xe6, 0x00, 0x85, 0x50, 0xc8, 0x0a, \n\t0x04, 0x54, 0x30, 0x09, 0x00, 0x0e, 0xa6, 0x6a, 0x02, 0x02, 0x20, 0x0d, 0x56, 0xa0, 0x48, 0x04, \n\t0xa0, 0x90, 0x14, 0x81, 0x08, 0x2a, 0x02, 0x91, 0x30, 0x00, 0x01, 0x4c, 0x20, 0x40, 0x49, 0x29, \n\t0x15, 0x89, 0x04, 0x10, 0xa5, 0x60, 0x90, 0x20, 0x5e, 0x84, 0x20, 0x45, 0x03, 0x07, 0x14, 0x09, \n\t0x24, 0x08, 0x70, 0x8a, 0x92, 0x08, 0x46, 0xe3, 0x30, 0x00, 0x08, 0x01, 0x48, 0x51, 0x89, 0x10, \n\t0x40, 0xa8, 0x08, 0xa0, 0x12, 0x81, 0x34, 0x61, 0x41, 0x24, 0x84, 0x5a, 0x44, 0x24, 0x14, 0x9a, \n\t0x28, 0x68, 0x95, 0x44, 0x60, 0x43, 0x89, 0x80, 0x64, 0x85, 0x88, 0x02, 0x50, 0x01, 0x81, 0x74, \n\t0x18, 0x23, 0x24, 0x41, 0xe1, 0x02, 0xe9, 0x00, 0x0d, 0x04, 0x36, 0xd2, 0xb1, 0x01, 0x00, 0x8d, \n\t0x0e, 0x54, 0x41, 0x09, 0x30, 0x85, 0x08, 0x48, 0x81, 0x29, 0x38, 0x84, 0x4c, 0x28, 0x74, 0x03, \n\t0xa2, 0x0e, 0x20, 0x56, 0x04, 0x22, 0xa0, 0x01, 0x08, 0xc1, 0x84, 0x20, 0x1a, 0xd2, 0x10, 0x2a, \n\t0x11, 0x02, 0x4a, 0x10, 0x01, 0x32, 0xb1, 0x01, 0x12, 0x4a, 0x42, 0x04, 0xb8, 0x0e, 0x24, 0x90, \n\t0x84, 0x16, 0x47, 0x93, 0x0a, 0x44, 0x81, 0x0a, 0x18, 0x30, 0x80, 0x92, 0xb0, 0x11, 0x03, 0x3c, \n\t0xa4, 0x08, 0x00, 0x64, 0x44, 0xca, 0x26, 0xd2, 0x0b, 0x21, 0x88, 0x00, 0xcc, 0x16, 0x83, 0x71, \n\t0x22, 0xd0, 0xd0, 0x87, 0x08, 0xd7, 0x48, 0x0d, 0x00, 0xcb, 0x20, 0x6a, 0x43, 0x82, 0x04, 0x48, \n\t0x1d, 0xc6, 0x20, 0x20, 0x30, 0x05, 0xe1, 0x15, 0x01, 0x10, 0xf1, 0xa9, 0x82, 0x09, 0x98, 0x83, \n\t0x18, 0xa0, 0x60, 0x07, 0xd1, 0x83, 0x00, 0x08, 0x75, 0x02, 0x3c, 0x00, 0x0c, 0xc1, 0x6c, 0x02, \n\t0xba, 0x9a, 0x20, 0x42, 0x26, 0x14, 0x44, 0x20, 0x10, 0x4c, 0x43, 0xe1, 0x5a, 0x81, 0x42, 0x26, \n\t0x84, 0x0d, 0x20, 0x56, 0x00, 0x91, 0x98, 0x80, 0x00, 0x65, 0x12, 0x21, 0x08, 0x00, 0x50, 0x4a, \n\t0x82, 0x02, 0x06, 0xca, 0x82, 0x8c, 0x02, 0x64, 0x00, 0x83, 0xa1, 0x82, 0x50, 0x54, 0x01, 0x54, \n\t0x30, 0xc0, 0x00, 0x09, 0x14, 0xc4, 0x04, 0xa0, 0x03, 0x07, 0xcc, 0x88, 0x48, 0x48, 0xb0, 0x11, \n\t0x14, 0x19, 0x08, 0x88, 0x24, 0xd0, 0x00, 0x12, 0x00, 0x18, 0xc1, 0x0a, 0x80, 0x22, 0x08, 0x8d, \n\t0x45, 0x84, 0x08, 0x25, 0x40, 0x22, 0x94, 0x18, 0xc0, 0x18, 0x47, 0x72, 0x00, 0x64, 0x41, 0x00, \n\t0x24, 0xe2, 0x19, 0x81, 0x14, 0x81, 0x01, 0x14, 0x06, 0x50, 0x0c, 0xc0, 0x82, 0x0c, 0x3a, 0x21, \n\t0x4a, 0x03, 0x08, 0x41, 0x49, 0x06, 0x52, 0x08, 0x85, 0xb1, 0xd2, 0x02, 0x24, 0x00, 0x68, 0x01, \n\t0xd9, 0x12, 0x04, 0x04, 0x00, 0x20, 0x01, 0x01, 0x12, 0x0e, 0x10, 0x52, 0x50, 0x81, 0x40, 0x83, \n\t0xc8, 0x6e, 0x10, 0x22, 0x20, 0x78, 0x01, 0x04, 0x4a, 0x92, 0x61, 0x0d, 0x2c, 0xc2, 0x2c, 0x62, \n\t0x45, 0x4a, 0x84, 0x34, 0x86, 0x08, 0x00, 0xc0, 0x3a, 0x84, 0x24, 0x48, 0xe7, 0x00, 0x84, 0x4a, \n\t0x12, 0x09, 0x81, 0x00, 0x24, 0x65, 0x31, 0xa5, 0x00, 0x56, 0x4c, 0x12, 0x24, 0xa8, 0x9a, 0x30, \n\t0xd2, 0x05, 0x28, 0x53, 0x49, 0x05, 0xc1, 0x4b, 0x60, 0x50, 0x94, 0x11, 0x2c, 0x10, 0x91, 0x02, \n\t0x14, 0xf2, 0xa3, 0x23, 0xdc, 0x98, 0x28, 0x04, 0x43, 0x20, 0x23, 0xd8, 0x00, 0x20, 0x0e, 0x03, \n\t0x20, 0x30, 0x6c, 0x54, 0x04, 0x12, 0x81, 0x01, 0x84, 0x60, 0x54, 0x20, 0x24, 0x11, 0xba, 0xa5, \n\t0x08, 0x0a, 0xc9, 0x40, 0x83, 0x28, 0x2e, 0x39, 0x14, 0x82, 0x52, 0x01, 0x1a, 0x00, 0x81, 0x05, \n\t0x45, 0x2a, 0xa0, 0x18, 0x20, 0x40, 0x42, 0x01, 0x48, 0x00, 0x82, 0xbd, 0x80, 0x12, 0x61, 0x00, \n\t0x31, 0x01, 0x81, 0x08, 0x52, 0x05, 0x62, 0x00, 0x08, 0x18, 0x28, 0xc0, 0x40, 0x08, 0x90, 0x58, \n\t0x06, 0xb1, 0x92, 0x82, 0x60, 0x95, 0x10, 0x36, 0x00, 0x01, 0x05, 0x00, 0x10, 0xa8, 0x81, 0x11, \n\t0x8f, 0x46, 0x38, 0x10, 0x02, 0x30, 0x48, 0x06, 0x22, 0x4a, 0x21, 0x51, 0x21, 0x2d, 0x8c, 0x80, \n\t0x00, 0x25, 0x88, 0xac, 0x51, 0x10, 0x4a, 0x04, 0x87, 0x82, 0x02, 0x0c, 0x08, 0x0b, 0x1c, 0x30, \n\t0x28, 0x12, 0xc0, 0x80, 0x0d, 0x60, 0x82, 0x40, 0xb8, 0x80, 0x91, 0x45, 0x70, 0x44, 0x41, 0x0a, \n\t0xc0, 0x40, 0xa0, 0x16, 0x84, 0x1a, 0x2c, 0x84, 0xc6, 0x09, 0x44, 0x23, 0x0b, 0xad, 0x41, 0x16, \n\t0xc2, 0x70, 0x10, 0x22, 0x1c, 0x15, 0x02, 0xc1, 0x20, 0x86, 0x08, 0x21, 0x44, 0x89, 0xe2, 0x4a, \n\t0x12, 0x01, 0xb1, 0x80, 0x11, 0x08, 0x48, 0x01, 0x48, 0x80, 0x60, 0x12, 0x28, 0x22, 0x07, 0x60, \n\t0xaa, 0x38, 0x15, 0x4e, 0x74, 0x60, 0x02, 0x12, 0x38, 0x84, 0x05, 0x00, 0x87, 0x41, 0xa0, 0x20, \n\t0x4d, 0xc1, 0x02, 0x36, 0x82, 0x0c, 0x28, 0x89, 0x44, 0x36, 0x90, 0x28, 0x18, 0x79, 0x45, 0xa0, \n\t0x00, 0x16, 0xd0, 0x04, 0x30, 0x41, 0xe5, 0x12, 0x81, 0x10, 0xa0, 0x98, 0x02, 0x84, 0x48, 0x40, \n\t0x80, 0x83, 0x90, 0xda, 0x00, 0x60, 0x00, 0xa8, 0x93, 0x20, 0x00, 0x80, 0x5a, 0x50, 0x82, 0x03, \n\t0x20, 0x50, 0x04, 0x4c, 0x70, 0x28, 0xa5, 0xc4, 0x08, 0xa1, 0x10, 0x80, 0x93, 0x80, 0x88, 0x14, \n\t0x26, 0x72, 0x57, 0xca, 0x13, 0x80, 0x41, 0x02, 0x30, 0x81, 0x68, 0x10, 0x41, 0x19, 0x4e, 0x58, \n\t0x02, 0x43, 0xb8, 0x80, 0x0c, 0x00, 0x40, 0x66, 0x31, 0x14, 0x09, 0x80, 0x08, 0x44, 0x22, 0x03, \n\t0x08, 0xc8, 0x02, 0x01, 0x40, 0x20, 0xc9, 0x27, 0x11, 0x12, 0x25, 0x14, 0x11, 0x82, 0x06, 0x90, \n\t0xc0, 0xca, 0x02, 0x44, 0x02, 0x00, 0x09, 0x85, 0xa0, 0x5a, 0x42, 0x90, 0x05, 0x00, 0x53, 0x88, \n\t0x0c, 0x04, 0xd9, 0x90, 0xe1, 0x87, 0x03, 0x2c, 0x40, 0x21, 0x18, 0x44, 0x11, 0x28, 0x62, 0xb0, \n\t0x5a, 0x20, 0x44, 0x0e, 0x0e, 0x22, 0x10, 0x01, 0x24, 0xe1, 0x90, 0x08, 0x72, 0x12, 0x00, 0x00, \n\t0x8c, 0x40, 0x04, 0x06, 0x46, 0x10, 0x0b, 0x08, 0x04, 0x2a, 0x6a, 0x84, 0x00, 0x25, 0x84, 0x40, \n\t0x01, 0x06, 0x03, 0x19, 0xa4, 0x51, 0x10, 0x2d, 0x20, 0x93, 0x23, 0x82, 0xcc, 0x1a, 0xc2, 0x2a, \n\t0x40, 0x00, 0x10, 0x45, 0x95, 0x05, 0x52, 0x40, 0x08, 0x0c, 0x00, 0x48, 0x00, 0x10, 0x24, 0x2a, \n\t0x33, 0x41, 0xcb, 0x61, 0x08, 0x22, 0x40, 0x3e, 0x08, 0x4d, 0x23, 0x20, 0x40, 0xca, 0x88, 0x08, \n\t0x03, 0x4b, 0x14, 0xc2, 0x21, 0x8b, 0x91, 0x81, 0x48, 0x4a, 0x45, 0x82, 0x24, 0xa0, 0x0f, 0x0c, \n\t0x46, 0x10, 0x8b, 0x85, 0x11, 0x04, 0x0d, 0x28, 0x92, 0x62, 0x00, 0xb1, 0x06, 0x46, 0x06, 0x42, \n\t0x90, 0x00, 0x74, 0x1e, 0xec, 0x40, 0x82, 0x90, 0x9a, 0x4d, 0xc8, 0x2e, 0x04, 0xb7, 0x90, 0x08, \n\t0x7d, 0x82, 0x01, 0x20, 0xc7, 0x30, 0x03, 0x68, 0x90, 0x08, 0x28, 0x00, 0x28, 0x05, 0x14, 0x04, \n\t0xa9, 0x20, 0x04, 0x61, 0x04, 0xb1, 0x44, 0x01, 0x50, 0x91, 0x11, 0x90, 0xa0, 0x4a, 0xe4, 0x06, \n\t0x84, 0x08, 0x0d, 0x01, 0x18, 0x4b, 0x08, 0x25, 0x62, 0x80, 0x08, 0x05, 0x08, 0x10, 0x52, 0x2b, \n\t0x88, 0x90, 0x41, 0x00, 0x6a, 0x06, 0x12, 0x21, 0xc0, 0x00, 0xe2, 0x00, 0x03, 0xd0, 0x06, 0x40, \n\t0x0c, 0x61, 0x14, 0x44, 0x62, 0x30, 0x04, 0x18, 0x62, 0x08, 0x81, 0x10, 0x13, 0x3c, 0x1b, 0xc6, \n\t0x02, 0x06, 0x73, 0x95, 0xa5, 0x88, 0x2a, 0x48, 0x40, 0x0a, 0xb0, 0x79, 0x10, 0x49, 0x02, 0xa5, \n\t0xa0, 0x26, 0x70, 0x19, 0x43, 0x26, 0x80, 0x09, 0x23, 0x60, 0xc0, 0x84, 0x00, 0x21, 0x49, 0xac, \n\t0x10, 0x14, 0xc6, 0x68, 0x54, 0x43, 0xab, 0x30, 0x44, 0x41, 0x06, 0xa5, 0xf8, 0x08, 0x40, 0x4a, \n\t0x20, 0x14, 0x20, 0x20, 0x14, 0x89, 0x40, 0xa2, 0x46, 0x62, 0x08, 0x05, 0xb9, 0x10, 0xa1, 0x10, \n\t0x10, 0x81, 0x0c, 0xc1, 0x40, 0x86, 0x42, 0x06, 0x0a, 0x9a, 0x50, 0x45, 0x24, 0x30, 0x91, 0x20, \n\t0xa2, 0x08, 0x84, 0x20, 0x3e, 0x00, 0x61, 0x23, 0xf4, 0x42, 0x89, 0x70, 0x42, 0x22, 0xa0, 0x9c, \n\t0x58, 0x8d, 0x44, 0x25, 0x81, 0xb8, 0x14, 0xce, 0x20, 0x24, 0x21, 0x60, 0x81, 0x14, 0x18, 0x47, \n\t0x50, 0x33, 0xc0, 0x02, 0x04, 0x89, 0x05, 0x30, 0xc4, 0x8a, 0x02, 0x29, 0x8e, 0x09, 0x40, 0x80, \n\t0x19, 0x20, 0x11, 0xc3, 0xc4, 0x08, 0x61, 0x32, 0xa4, 0x5c, 0x8a, 0x81, 0x20, 0x45, 0x02, 0x0b, \n\t0x41, 0xc3, 0xa9, 0x00, 0x82, 0x02, 0x1b, 0x40, 0xd9, 0x64, 0x60, 0x00, 0x70, 0x89, 0xa4, 0x8c, \n\t0x20, 0x2c, 0x05, 0x90, 0x02, 0x40, 0x8c, 0x09, 0x02, 0x64, 0x20, 0x96, 0x05, 0x45, 0xc0, 0x10, \n\t0x93, 0x40, 0x30, 0x31, 0x08, 0x88, 0x14, 0x00, 0x20, 0x11, 0x94, 0x0a, 0x8f, 0x02, 0x82, 0x0a, \n\t0x15, 0x0c, 0x0e, 0x24, 0x4c, 0x34, 0xda, 0x8e, 0x80, 0x10, 0x43, 0x22, 0x00, 0xe0, 0x0c, 0x81, \n\t0x00, 0x28, 0x16, 0x22, 0xb9, 0x0c, 0x95, 0x90, 0xaa, 0x18, 0x84, 0x52, 0x29, 0x10, 0x09, 0x41, \n\t0x20, 0x26, 0x9a, 0xa0, 0x41, 0x58, 0x80, 0x74, 0x40, 0x93, 0x0d, 0xa0, 0x90, 0x06, 0x30, 0x10, \n\t0xa3, 0x82, 0x81, 0x12, 0x80, 0x56, 0xa7, 0x50, 0x00, 0x10, 0x41, 0xcd, 0x00, 0xa7, 0x00, 0xa2, \n\t0x08, 0xcc, 0x06, 0x0e, 0xb1, 0x41, 0x36, 0x91, 0x08, 0xc4, 0x20, 0x40, 0xc2, 0xb1, 0xa0, 0x1d, \n\t0x24, 0x6c, 0x62, 0x42, 0x87, 0xb0, 0x1a, 0x0b, 0x42, 0x94, 0xb8, 0x21, 0x34, 0x07, 0x0a, 0x42, \n\t0x80, 0xd8, 0x80, 0x20, 0x02, 0xc6, 0x04, 0xe3, 0x00, 0x32, 0xd0, 0x00, 0x80, 0x66, 0xc1, 0x22, \n\t0x0c, 0x29, 0xca, 0x40, 0x08, 0x84, 0x29, 0x06, 0x25, 0x00, 0x26, 0x3c, 0x11, 0x18, 0x01, 0x84, \n\t0x08, 0x80, 0x24, 0x20, 0x42, 0x98, 0x84, 0x41, 0x20, 0x20, 0x24, 0x10, 0x8b, 0x1c, 0x43, 0x60, \n\t0x02, 0x14, 0x00, 0x27, 0x30, 0x94, 0x8d, 0x52, 0x84, 0x08, 0x14, 0x18, 0x05, 0x20, 0x38, 0x22, \n\t0xa1, 0x90, 0xa1, 0x0a, 0xcc, 0x0c, 0x00, 0x61, 0x01, 0x64, 0x57, 0x2d, 0x4c, 0x40, 0x01, 0xac, \n\t0x08, 0x16, 0x81, 0x10, 0xb1, 0xc3, 0x10, 0x4d, 0x49, 0x25, 0x46, 0x56, 0x18, 0x24, 0x38, 0x01, \n\t0x04, 0x00, 0x53, 0x80, 0x25, 0x65, 0x18, 0xa2, 0x12, 0x10, 0x13, 0xa0, 0x05, 0x89, 0x62, 0x48, \n\t0x24, 0x29, 0xa8, 0x00, 0x00, 0x01, 0x60, 0x55, 0x42, 0x29, 0x84, 0xc5, 0x80, 0x1c, 0x01, 0x78, \n\t0xb8, 0x05, 0x55, 0x48, 0x32, 0xc0, 0x00, 0x00, 0x90, 0x90, 0x2c, 0x6a, 0xa1, 0x82, 0x0d, 0xe0, \n\t0x56, 0xc9, 0x18, 0x00, 0x10, 0x01, 0x50, 0x94, 0x44, 0x42, 0x90, 0x08, 0x04, 0xa4, 0x86, 0xa2, \n\t0x2c, 0x41, 0x51, 0x9a, 0x48, 0x1b, 0x87, 0x06, 0x21, 0x00, 0x1e, 0x40, 0xc8, 0x82, 0x42, 0x82, \n\t0x20, 0x09, 0x21, 0x94, 0x80, 0x28, 0x51, 0x39, 0x04, 0x8c, 0x10, 0x0b, 0x3a, 0x63, 0x20, 0x20, \n\t0x08, 0x10, 0xe6, 0x04, 0xc1, 0x51, 0x00, 0xa0, 0x48, 0x4e, 0x08, 0x81, 0x08, 0x26, 0xd1, 0x4b, \n\t0x06, 0x40, 0xf4, 0x22, 0x20, 0x18, 0x54, 0x61, 0x38, 0x36, 0xc9, 0x8a, 0x88, 0x12, 0x4c, 0x30, \n\t0x02, 0x13, 0x01, 0x10, 0x01, 0x05, 0x02, 0x22, 0x98, 0x80, 0xe5, 0x06, 0x24, 0x50, 0x12, 0x92, \n\t0x32, 0x48, 0x10, 0x65, 0x08, 0x55, 0x02, 0xa4, 0x28, 0x04, 0xa2, 0x0a, 0x57, 0x82, 0xb1, 0xc8, \n\t0x08, 0x82, 0x42, 0x04, 0x81, 0x12, 0x94, 0x04, 0x2b, 0x0c, 0x45, 0x83, 0x88, 0x40, 0x0c, 0x22, \n\t0x64, 0x10, 0x83, 0x32, 0x70, 0x00, 0x09, 0x10, 0x72, 0x61, 0x00, 0x44, 0x50, 0xc4, 0x12, 0x80, \n\t0x40, 0x02, 0x00, 0x02, 0x01, 0x22, 0x24, 0x69, 0x04, 0x49, 0x03, 0x07, 0x34, 0x00, 0x08, 0x00, \n\t0x01, 0x46, 0x29, 0x54, 0x12, 0x20, 0xa2, 0x40, 0x10, 0xca, 0x00, 0x12, 0x21, 0x91, 0x41, 0x10, \n\t0x80, 0x0e, 0x00, 0xa8, 0x08, 0x21, 0x42, 0x40, 0x4e, 0x05, 0x89, 0x28, 0x88, 0x49, 0x0c, 0x02, \n\t0x44, 0xca, 0x25, 0xb0, 0x13, 0xc8, 0x00, 0xc5, 0x91, 0xa0, 0x28, 0x11, 0x4e, 0x76, 0x42, 0x01, \n\t0x32, 0x11, 0xc6, 0x80, 0x00, 0xc2, 0x38, 0x14, 0x51, 0x81, 0xc3, 0x28, 0x41, 0x00, 0x1a, 0x2c, \n\t0x10, 0x41, 0x58, 0x80, 0x08, 0x17, 0x38, 0xd2, 0x27, 0x02, 0x00, 0x81, 0x1c, 0x90, 0x03, 0xc5, \n\t0x52, 0x91, 0x68, 0xa4, 0x09, 0x88, 0x03, 0x48, 0xc0, 0xd0, 0x05, 0x94, 0x00, 0x20, 0x68, 0x05, \n\t0x3a, 0xae, 0x0c, 0xc2, 0xe7, 0x0a, 0x84, 0x33, 0x84, 0x08, 0x48, 0x20, 0x50, 0x40, 0xd3, 0x05, \n\t0x30, 0xd5, 0xa8, 0x20, 0x03, 0x0b, 0x84, 0x98, 0x04, 0x22, 0x44, 0x25, 0x48, 0x01, 0x64, 0x0a, \n\t0x86, 0x14, 0x82, 0x51, 0x88, 0x80, 0x0a, 0x83, 0x30, 0xa6, 0x82, 0x0a, 0xa0, 0x1c, 0x01, 0x08, \n\t0xc1, 0xb8, 0x01, 0x48, 0x04, 0x6c, 0x4a, 0x86, 0x11, 0x0d, 0x8c, 0x91, 0x8c, 0x0c, 0x02, 0x50, \n\t0x07, 0xa4, 0x08, 0x43, 0x34, 0x56, 0x60, 0x20, 0x10, 0x08, 0x06, 0x68, 0xc4, 0x20, 0xae, 0x3c, \n\t0x81, 0x46, 0x0c, 0x10, 0x40, 0x81, 0x09, 0x80, 0xa2, 0x10, 0x41, 0x93, 0x33, 0x4c, 0x80, 0x21, \n\t0x0c, 0x80, 0xa2, 0x06, 0xc4, 0x00, 0xc5, 0x30, 0xf0, 0x19, 0x03, 0xd0, 0x00, 0xc1, 0x0e, 0x36, \n\t0x00, 0x0d, 0xd1, 0x8c, 0x02, 0x22, 0x13, 0xc8, 0x82, 0x18, 0x53, 0x20, 0x08, 0x84, 0x0a, 0x9a, \n\t0xd0, 0x53, 0x48, 0x00, 0x00, 0x00, 0x10, 0x1c, 0xc4, 0x20, 0x00, 0x90, 0x6a, 0x05, 0x18, 0x06, \n\t0x09, 0x44, 0x10, 0xb1, 0x95, 0x0c, 0x90, 0x05, 0x2e, 0x21, 0x80, 0x08, 0x49, 0x05, 0x00, 0x22, \n\t0x44, 0xc3, 0x10, 0x88, 0xdd, 0xa2, 0x42, 0x35, 0x29, 0x30, 0x45, 0x08, 0x21, 0x78, 0x40, 0x52, \n\t0x04, 0x40, 0x05, 0x6a, 0x10, 0x43, 0x02, 0x88, 0x65, 0x02, 0x42, 0x1e, 0xc0, 0x18, 0x82, 0x34, \n\t0xd0, 0x08, 0x28, 0x85, 0x4a, 0x83, 0x14, 0x02, 0x41, 0x10, 0x33, 0x03, 0x12, 0xa9, 0x1c, 0x0a, \n\t0x0c, 0x04, 0x82, 0x21, 0x1c, 0x86, 0x86, 0x06, 0xd3, 0x68, 0xab, 0xc1, 0x08, 0xc0, 0x40, 0x60, \n\t0xd2, 0x20, 0x10, 0x10, 0x0e, 0x06, 0xe0, 0xa8, 0x05, 0x21, 0x05, 0x81, 0x22, 0x43, 0x9a, 0x95, \n\t0x44, 0x99, 0x06, 0x04, 0x11, 0xf0, 0x31, 0xbc, 0x12, 0x22, 0x54, 0x80, 0x63, 0x36, 0x34, 0x04, \n\t0xc2, 0x40, 0xd1, 0x4a, 0x90, 0x20, 0xc9, 0x00, 0x18, 0x40, 0x50, 0x84, 0x81, 0xc0, 0x4b, 0x68, \n\t0x00, 0x21, 0x90, 0x28, 0xd7, 0x04, 0x20, 0x60, 0x20, 0x04, 0x20, 0x43, 0x41, 0x42, 0x20, 0x18, \n\t0x24, 0x94, 0xc7, 0x80, 0x08, 0x30, 0x03, 0x87, 0x40, 0x1c, 0x46, 0x14, 0x02, 0x20, 0xa6, 0xd5, \n\t0x88, 0x04, 0x20, 0x54, 0x20, 0x29, 0x35, 0x11, 0x87, 0x52, 0x40, 0x60, 0x23, 0xa5, 0x06, 0x0c, \n\t0x44, 0x24, 0x71, 0x20, 0x20, 0xd0, 0xe2, 0x08, 0x40, 0x89, 0x8c, 0x40, 0x18, 0x81, 0x10, 0x30, \n\t0x01, 0x01, 0x09, 0x03, 0x2f, 0x20, 0x34, 0x18, 0x1c, 0x14, 0x8a, 0x0c, 0x58, 0xa0, 0x01, 0xa8, \n\t0x94, 0x47, 0x40, 0x30, 0x04, 0x42, 0x13, 0x99, 0x00, 0x2b, 0x18, 0x20, 0xf2, 0x35, 0x2c, 0x84, \n\t0x40, 0x52, 0x20, 0x83, 0x0c, 0x54, 0x88, 0x20, 0x4c, 0x62, 0xa0, 0x04, 0x15, 0x99, 0xec, 0x0e, \n\t0xa3, 0x02, 0x14, 0x21, 0x40, 0x60, 0x0a, 0x42, 0xe2, 0x80, 0x20, 0x91, 0x08, 0x2e, 0x40, 0x3a, \n\t0x22, 0xbc, 0x02, 0x22, 0x46, 0xc1, 0x60, 0x18, 0x89, 0x4c, 0xa4, 0x02, 0x90, 0x42, 0x20, 0x00, \n\t0xc3, 0xe8, 0x04, 0x10, 0x31, 0x24, 0x44, 0x87, 0x4d, 0x1a, 0x02, 0xa9, 0x0b, 0x90, 0x08, 0x2d, \n\t0x42, 0xd6, 0x6a, 0x10, 0x91, 0x10, 0x0c, 0x42, 0xa4, 0x02, 0x09, 0x48, 0x01, 0x40, 0x42, 0x51, \n\t0x82, 0x00, 0x9d, 0x04, 0xa0, 0x40, 0x36, 0x41, 0x20, 0x04, 0x51, 0x06, 0x46, 0x60, 0x8a, 0x0b, \n\t0x44, 0x01, 0x05, 0x10, 0x92, 0x11, 0x04, 0x21, 0x00, 0x88, 0x24, 0x05, 0x90, 0x13, 0x68, 0x00, \n\t0x43, 0x4c, 0x21, 0x62, 0x22, 0x80, 0x15, 0xa2, 0x14, 0x41, 0x80, 0x11, 0x44, 0x40, 0x82, 0x08, \n\t0x02, 0x40, 0x93, 0x00, 0x52, 0x8e, 0x10, 0x52, 0x82, 0xa4, 0x2c, 0x4a, 0x45, 0x40, 0x04, 0xc0, \n\t0x09, 0xa8, 0x0d, 0x4a, 0x00, 0x12, 0x48, 0x34, 0x89, 0x03, 0xa3, 0x00, 0xb1, 0xe2, 0x28, 0x15, \n\t0x10, 0x09, 0x08, 0xe1, 0x03, 0x93, 0x04, 0x82, 0xa0, 0x46, 0xe2, 0xb0, 0x08, 0x00, 0xc6, 0x00, \n\t0x1c, 0x42, 0xc0, 0x32, 0x01, 0x57, 0x00, 0x02, 0x10, 0x32, 0x06, 0x1c, 0x43, 0x81, 0x5a, 0xc2, \n\t0x01, 0x8e, 0x55, 0x14, 0xab, 0x30, 0x14, 0x09, 0x03, 0x70, 0xc4, 0x23, 0x32, 0xa0, 0x21, 0xa2, \n\t0x44, 0x4d, 0x82, 0x08, 0xd4, 0x68, 0x2a, 0x8c, 0x11, 0x60, 0x06, 0x64, 0x00, 0x16, 0x90, 0x82, \n\t0xa4, 0x00, 0x00, 0x02, 0x09, 0x29, 0x11, 0x4c, 0x44, 0x00, 0x29, 0x05, 0xf0, 0x16, 0x44, 0x50, \n\t0xa0, 0x21, 0x15, 0x1c, 0x49, 0xac, 0x20, 0x42, 0xb8, 0x80, 0x09, 0x48, 0x23, 0x50, 0x44, 0x6a, \n\t0x21, 0x41, 0xc8, 0x80, 0x20, 0x34, 0xe8, 0xb0, 0x09, 0x18, 0x02, 0x00, 0x20, 0x99, 0xb0, 0x45, \n\t0x04, 0x05, 0x04, 0x74, 0x08, 0x10, 0xe1, 0x02, 0x05, 0x0a, 0xc3, 0x40, 0x82, 0xd1, 0x94, 0x00, \n\t0x08, 0x33, 0x42, 0x25, 0xa0, 0x19, 0x40, 0x56, 0x20, 0x20, 0x11, 0xc8, 0x8a, 0x0c, 0x06, 0x86, \n\t0x58, 0x08, 0xc0, 0x04, 0xa3, 0x18, 0xa1, 0x72, 0x80, 0x51, 0x04, 0x88, 0x10, 0x00, 0xa1, 0x14, \n\t0x14, 0x02, 0xec, 0x44, 0x67, 0x02, 0x18, 0x48, 0x11, 0x41, 0x32, 0x00, 0x08, 0x23, 0x08, 0x1b, \n\t0x22, 0x60, 0x60, 0x98, 0x24, 0x10, 0x40, 0xc1, 0x6a, 0x45, 0x48, 0x2a, 0xf4, 0x40, 0x07, 0x42, \n\t0x06, 0x58, 0x98, 0x80, 0x85, 0x62, 0x20, 0x02, 0x31, 0xbb, 0x04, 0x13, 0x82, 0x60, 0x52, 0x0b, \n\t0x91, 0x24, 0x01, 0x61, 0x0c, 0x80, 0x0b, 0x01, 0x20, 0x8c, 0x2c, 0x3c, 0x00, 0x50, 0x31, 0x00, \n\t0x51, 0x48, 0x1a, 0x02, 0x20, 0x22, 0x0d, 0x80, 0xc4, 0x28, 0x06, 0x82, 0x09, 0xcc, 0x43, 0x4d, \n\t0x0a, 0xa1, 0x02, 0x1a, 0x05, 0x86, 0x82, 0x5a, 0x12, 0x62, 0xa4, 0x68, 0x09, 0x0e, 0x20, 0x44, \n\t0x09, 0x10, 0x50, 0x05, 0x89, 0x0a, 0x23, 0x28, 0x0c, 0x94, 0x05, 0x22, 0x40, 0x01, 0x12, 0x02, \n\t0x10, 0x80, 0x21, 0x02, 0x45, 0x08, 0x20, 0xa0, 0x08, 0x02, 0x1a, 0x55, 0xe0, 0x9d, 0x04, 0x51, \n\t0x09, 0x1c, 0x14, 0x23, 0x8a, 0xc1, 0x00, 0x64, 0x36, 0x20, 0xa2, 0x19, 0xd5, 0x42, 0x2c, 0x14, \n\t0x72, 0x40, 0x80, 0x90, 0x0a, 0x2e, 0x54, 0x06, 0x92, 0x26, 0xc0, 0x81, 0x61, 0x00, 0x40, 0x00, \n\t0x25, 0x68, 0x83, 0xa6, 0x34, 0x01, 0xa0, 0x01, 0x85, 0x50, 0x0a, 0x10, 0x65, 0x81, 0x87, 0x49, \n\t0x1a, 0x02, 0x12, 0xa1, 0x38, 0x94, 0x60, 0x48, 0x86, 0x20, 0x62, 0x08, 0x80, 0xe8, 0x09, 0x05, \n\t0x00, 0xf1, 0x21, 0x01, 0xc1, 0x97, 0x48, 0x60, 0xd5, 0x8a, 0x08, 0xa8, 0x10, 0x00, 0x00, 0x01, \n\t0x30, 0x04, 0x68, 0x08, 0x01, 0x1e, 0x80, 0x08, 0x09, 0x94, 0x07, 0x81, 0x00, 0x10, 0x90, 0x20, \n\t0x88, 0x12, 0x85, 0x4c, 0x56, 0x01, 0x06, 0x5d, 0x48, 0x60, 0x46, 0x02, 0x2a, 0x85, 0x40, 0x50, \n\t0x60, 0x10, 0x01, 0x02, 0xaf, 0xa8, 0x58, 0x0e, 0x4a, 0x60, 0xa0, 0x15, 0x11, 0x9d, 0x22, 0x28, \n\t0x86, 0x41, 0xb0, 0x74, 0x48, 0xa8, 0x64, 0x03, 0x02, 0x08, 0xa5, 0x02, 0x0b, 0x06, 0xb1, 0x38, \n\t0x09, 0x40, 0xd4, 0x07, 0x20, 0x84, 0x2a, 0x96, 0x2c, 0x93, 0x08, 0x50, 0x50, 0x69, 0x03, 0xb0, \n\t0x95, 0x0f, 0x70, 0x94, 0xea, 0x30, 0x00, 0x00, 0xe7, 0x02, 0x00, 0x50, 0x01, 0x19, 0x84, 0x86, \n\t0x10, 0x25, 0x02, 0x32, 0x88, 0xc9, 0xc3, 0x24, 0x31, 0xb8, 0x04, 0x24, 0x11, 0x01, 0x30, 0x94, \n\t0x11, 0x0e, 0x20, 0x49, 0x80, 0x12, 0x05, 0x10, 0xa0, 0x90, 0x9e, 0x23, 0x7c, 0x04, 0x18, 0x08, \n\t0x41, 0x08, 0x2c, 0x04, 0x03, 0xc2, 0x93, 0x05, 0x05, 0x08, 0x32, 0x92, 0x18, 0x03, 0xe0, 0x4c, \n\t0x41, 0x0a, 0x02, 0xa2, 0x9c, 0x0c, 0x16, 0x24, 0x18, 0x42, 0x49, 0x18, 0x20, 0x5a, 0x02, 0x40, \n\t0x24, 0x72, 0x19, 0x84, 0x82, 0x45, 0x58, 0x40, 0x29, 0x04, 0x40, 0x08, 0x04, 0x20, 0x73, 0xa0, \n\t0xae, 0x89, 0x59, 0x06, 0x00, 0x80, 0x30, 0x86, 0x30, 0x8d, 0x80, 0x64, 0x06, 0x62, 0x10, 0x08, \n\t0x46, 0x82, 0x40, 0x41, 0x3a, 0x81, 0x8c, 0x47, 0x00, 0x22, 0x42, 0x3b, 0x04, 0x44, 0x11, 0xa1, \n\t0x22, 0xf0, 0xc2, 0x81, 0x10, 0x44, 0x8b, 0x3a, 0x13, 0x41, 0x00, 0xb1, 0x41, 0x42, 0x68, 0x92, \n\t0xe1, 0x04, 0xa4, 0x53, 0x28, 0x00, 0xc4, 0x10, 0x92, 0x69, 0x40, 0x02, 0x16, 0x24, 0xf1, 0x24, \n\t0x2c, 0x50, 0x02, 0x4c, 0x61, 0xa0, 0xa0, 0x10, 0x0e, 0x89, 0x00, 0x41, 0x82, 0xb9, 0x98, 0x90, \n\t0x0e, 0x02, 0xb1, 0x18, 0x1d, 0x20, 0x98, 0x81, 0x10, 0x85, 0x00, 0x98, 0x20, 0x80, 0x02, 0x2a, \n\t0x00, 0x01, 0x12, 0x88, 0x03, 0x42, 0x52, 0x60, 0x70, 0x24, 0x4c, 0x1c, 0x0a, 0x34, 0x72, 0x01, \n\t0x22, 0x61, 0x43, 0x81, 0x10, 0x12, 0x18, 0x92, 0x20, 0x12, 0x00, 0x5a, 0x95, 0x68, 0x20, 0x84, \n\t0x8e, 0x45, 0x26, 0x82, 0x00, 0x8f, 0x30, 0x8c, 0x40, 0x00, 0xb2, 0x01, 0x00, 0x2c, 0x40, 0x80, \n\t0x0c, 0x03, 0x09, 0x80, 0x0c, 0x06, 0x6a, 0x28, 0xc4, 0xf3, 0x8d, 0x99, 0x08, 0x00, 0x04, 0x52, \n\t0x1a, 0xac, 0x04, 0x1b, 0x80, 0x08, 0xc0, 0x39, 0x23, 0x2c, 0x16, 0x0c, 0x62, 0x01, 0xc9, 0x02, \n\t0x24, 0x14, 0xe2, 0x26, 0x60, 0x81, 0x82, 0x80, 0x51, 0x48, 0x72, 0x61, 0x00, 0x92, 0x79, 0x02, \n\t0x86, 0x30, 0xe0, 0x48, 0x21, 0xc4, 0x13, 0x00, 0x50, 0x17, 0x28, 0x29, 0x88, 0x05, 0x09, 0x4c, \n\t0x84, 0x9a, 0x93, 0xc1, 0xc2, 0x61, 0x06, 0x80, 0xc3, 0x04, 0x60, 0x54, 0x0b, 0x18, 0x00, 0xd8, \n\t0x85, 0xc0, 0x88, 0x29, 0x38, 0x10, 0x41, 0x05, 0x50, 0x0a, 0xc6, 0x26, 0x54, 0x80, 0x10, 0x08, \n\t0x0a, 0x65, 0x58, 0x00, 0x81, 0x81, 0x64, 0x80, 0xa8, 0x40, 0x21, 0x91, 0x24, 0x01, 0x5c, 0x09, \n\t0x4c, 0x00, 0x13, 0x16, 0x18, 0x14, 0x0a, 0x42, 0xa0, 0x98, 0x00, 0x48, 0xcd, 0x08, 0x20, 0x86, \n\t0x11, 0x20, 0x00, 0xc4, 0x81, 0x2a, 0xb1, 0x00, 0x88, 0x24, 0x4d, 0x40, 0x0e, 0x84, 0x10, 0x0e, \n\t0x19, 0xda, 0x01, 0x50, 0x36, 0x18, 0x0c, 0x88, 0x86, 0x0c, 0x54, 0xc2, 0x02, 0x09, 0x0d, 0x00, \n\t0x21, 0x38, 0x11, 0x30, 0x88, 0x90, 0x42, 0x8f, 0x08, 0x07, 0x00, 0xae, 0x10, 0x04, 0x00, 0x2a, \n\t0xc6, 0x23, 0x16, 0x45, 0x50, 0x80, 0x0a, 0x50, 0x2a, 0x92, 0x95, 0x58, 0xe0, 0x28, 0x60, 0x81, \n\t0x18, 0x00, 0x54, 0xae, 0x10, 0xf0, 0x00, 0xa9, 0x40, 0x0d, 0x4d, 0x0a, 0x12, 0x58, 0x27, 0x10, \n\t0x01, 0x82, 0x2a, 0x50, 0x08, 0x24, 0x0c, 0x49, 0x68, 0x50, 0xa0, 0x48, 0x94, 0x00, 0xdb, 0x40, \n\t0x00, 0x00, 0x02, 0x11, 0x04, 0x86, 0x25, 0x4c, 0x03, 0x8a, 0x04, 0x04, 0x00, 0x28, 0x5c, 0x53, \n\t0x03, 0x25, 0x00, 0xd0, 0x26, 0x0a, 0x24, 0x28, 0x00, 0x69, 0xd8, 0x00, 0x24, 0x53, 0x50, 0x8e, \n\t0xc0, 0x44, 0x86, 0x0e, 0x20, 0xc1, 0x13, 0x01, 0x9c, 0x29, 0x28, 0x86, 0xc0, 0x14, 0x2d, 0x45, \n\t0x60, 0x02, 0x90, 0x80, 0x01, 0xe9, 0x41, 0x4c, 0x22, 0x84, 0x20, 0x92, 0xc1, 0x92, 0x0e, 0x50, \n\t0x16, 0x48, 0xa1, 0x08, 0xd0, 0x00, 0x20, 0xc0, 0x40, 0x09, 0x40, 0x01, 0x41, 0x6c, 0x12, 0x10, \n\t0x24, 0x15, 0x82, 0x8a, 0x14, 0xe0, 0xe1, 0xaa, 0xb8, 0x18, 0x45, 0x10, 0x50, 0x60, 0x21, 0x09, \n\t0x08, 0xc7, 0x04, 0x06, 0x18, 0x24, 0x40, 0x04, 0x21, 0x08, 0x07, 0x93, 0xb3, 0x05, 0x12, 0x20, \n\t0x00, 0x20, 0x91, 0x15, 0x28, 0x48, 0x29, 0x04, 0xc0, 0x18, 0x04, 0x60, 0x48, 0xa4, 0x44, 0xa2, \n\t0x0a, 0x08, 0x88, 0x88, 0x05, 0x26, 0x00, 0x00, 0xb4, 0xc4, 0x10, 0x8c, 0x30, 0x12, 0xe8, 0x90, \n\t0x10, 0x15, 0x49, 0x04, 0xa0, 0x21, 0x80, 0x70, 0x52, 0x24, 0x0a, 0xb4, 0x90, 0x05, 0x34, 0x80, \n\t0xc9, 0x4a, 0xd0, 0x0b, 0x09, 0x18, 0x82, 0x42, 0x7c, 0x23, 0x61, 0x0c, 0x0c, 0x88, 0x44, 0x04, \n\t0x93, 0xb0, 0x28, 0x3c, 0x0d, 0xa0, 0x32, 0x84, 0x6a, 0x0a, 0xa1, 0xc7, 0x06, 0x26, 0x01, 0x4a, \n\t0x22, 0x15, 0x44, 0x81, 0x14, 0x02, 0x19, 0x28, 0x4c, 0x00, 0x00, 0x10, 0x10, 0x82, 0x98, 0x04, \n\t0x02, 0x29, 0x28, 0xe0, 0x60, 0x0b, 0x01, 0x0b, 0x8a, 0x28, 0x04, 0x00, 0x85, 0x80, 0xc1, 0x08, \n\t0x1e, 0x76, 0x80, 0x01, 0xb0, 0x42, 0x2e, 0x0c, 0x12, 0x30, 0x09, 0x10, 0x15, 0xec, 0x40, 0xa3, \n\t0x02, 0x81, 0x01, 0x90, 0x8d, 0x44, 0xa3, 0xd1, 0x04, 0x14, 0x00, 0x67, 0x00, 0xc2, 0x80, 0x02, \n\t0x60, 0x8f, 0xc4, 0x06, 0x90, 0x18, 0x34, 0xc8, 0x8d, 0x06, 0x20, 0x01, 0x30, 0x20, 0x3c, 0x08, \n\t0x40, 0x00, 0xe4, 0x49, 0x12, 0xcc, 0x08, 0x41, 0x02, 0xf0, 0x08, 0x31, 0x04, 0x02, 0x40, 0x00, \n\t0x04, 0x21, 0x84, 0xa1, 0xd2, 0x43, 0x42, 0x84, 0x09, 0x03, 0x38, 0xda, 0x01, 0x18, 0x24, 0x80, \n\t0x83, 0x31, 0x92, 0xac, 0x00, 0xb0, 0x4b, 0x00, 0xe1, 0xc1, 0x08, 0x44, 0x03, 0x03, 0x00, 0x81, \n\t0x14, 0x82, 0x04, 0x12, 0x60, 0x09, 0x44, 0x11, 0x23, 0x46, 0x24, 0xa0, 0x2c, 0x05, 0x82, 0x82, \n\t0x08, 0xc6, 0x3b, 0xb4, 0x40, 0x04, 0x26, 0x28, 0x15, 0x60, 0x87, 0x10, 0x83, 0x80, 0x04, 0x02, \n\t0x11, 0x2e, 0x1c, 0x48, 0x4d, 0x74, 0x65, 0xc2, 0x92, 0x10, 0x0d, 0x29, 0x08, 0x00, 0x01, 0x01, \n\t0x14, 0xc3, 0x82, 0x38, 0x93, 0x62, 0x00, 0x00, 0x58, 0x68, 0x10, 0x45, 0x03, 0x15, 0x40, 0x04, \n\t0xcd, 0x06, 0x94, 0xb0, 0x00, 0x01, 0x42, 0xe4, 0x0e, 0x42, 0x5a, 0x29, 0xb4, 0x0e, 0xe4, 0x60, \n\t0x10, 0x02, 0x08, 0xd0, 0x80, 0x0c, 0x40, 0x17, 0x82, 0xa5, 0x58, 0x00, 0x60, 0x1e, 0x11, 0x39, \n\t0x3b, 0x85, 0x00, 0x06, 0x76, 0x05, 0x00, 0xb0, 0xe8, 0x00, 0x8b, 0x40, 0x80, 0x38, 0x00, 0x00, \n\t0x50, 0x60, 0x20, 0x04, 0x13, 0x19, 0x28, 0x00, 0x44, 0x06, 0x11, 0x20, 0x1e, 0x30, 0x45, 0x0a, \n\t0x02, 0xf1, 0x8a, 0x12, 0x8c, 0x00, 0x68, 0x50, 0x70, 0x10, 0x0d, 0x81, 0x48, 0x24, 0x12, 0x04, \n\t0x20, 0x00, 0x11, 0x80, 0x2a, 0x58, 0x02, 0xcb, 0x81, 0xa0, 0x06, 0x47, 0x00, 0x44, 0xb1, 0x88, \n\t0x01, 0x42, 0x48, 0x28, 0xe3, 0x22, 0x00, 0x31, 0x51, 0x06, 0x2e, 0x90, 0xc1, 0x10, 0xc1, 0x49, \n\t0x28, 0x50, 0x64, 0x0b, 0x01, 0x00, 0x94, 0x80, 0x08, 0x82, 0x98, 0x38, 0x09, 0x55, 0xa1, 0x24, \n\t0x00, 0x01, 0x00, 0xe1, 0x44, 0x20, 0x1a, 0x13, 0x10, 0x11, 0x04, 0x5a, 0xc4, 0x00, 0x01, 0xc0, \n\t0x26, 0x0c, 0x05, 0x01, 0x6e, 0x32, 0x01, 0x09, 0xd9, 0x89, 0x82, 0x52, 0xa4, 0x62, 0x0c, 0x81, \n\t0x10, 0xcb, 0x10, 0x70, 0x61, 0x84, 0x24, 0x00, 0x03, 0x60, 0x80, 0xa0, 0xa8, 0x50, 0x48, 0x80, \n\t0x44, 0x63, 0x08, 0x84, 0x08, 0x46, 0xc1, 0x52, 0xc4, 0x81, 0x8c, 0x49, 0x92, 0x04, 0x28, 0x10, \n\t0x53, 0x22, 0x60, 0x45, 0x01, 0x5e, 0x25, 0xd8, 0x10, 0x58, 0x00, 0x6d, 0x02, 0x84, 0x03, 0xa1, \n\t0x3c, 0x48, 0x24, 0x32, 0x04, 0x68, 0x01, 0x20, 0x09, 0xc5, 0x00, 0xc1, 0x43, 0x8e, 0x30, 0x42, \n\t0x2c, 0x42, 0xd5, 0xb8, 0x11, 0x00, 0xc2, 0x40, 0x0a, 0x04, 0x2a, 0x30, 0x30, 0x82, 0x4c, 0x00, \n\t0xb3, 0xc0, 0x26, 0x0c, 0x04, 0xe2, 0x20, 0x10, 0xa1, 0x00, 0x90, 0x93, 0x21, 0x28, 0x45, 0x10, \n\t0x30, 0x15, 0x8f, 0x44, 0x46, 0x50, 0x20, 0x0d, 0x8d, 0x01, 0x28, 0x30, 0x65, 0x58, 0x92, 0xe0, \n\t0xc0, 0x8a, 0x08, 0x20, 0x92, 0x0c, 0x20, 0x11, 0x85, 0x42, 0x14, 0x42, 0x08, 0xc1, 0x88, 0xe0, \n\t0x22, 0x13, 0x00, 0x2c, 0x61, 0xd8, 0x49, 0x0a, 0x64, 0xc0, 0x04, 0x80, 0x53, 0x64, 0x04, 0x85, \n\t0xd1, 0x80, 0x59, 0x12, 0x80, 0x08, 0x82, 0x61, 0x09, 0x11, 0x44, 0x20, 0x0e, 0x00, 0x60, 0x0d, \n\t0x19, 0x08, 0x2c, 0x04, 0xa0, 0x10, 0x38, 0x84, 0x03, 0x8e, 0x44, 0x23, 0x98, 0x18, 0x00, 0x44, \n\t0x41, 0x50, 0x53, 0x78, 0x88, 0x09, 0x45, 0x86, 0x60, 0x30, 0x20, 0x00, 0x29, 0x00, 0xc3, 0x52, \n\t0x05, 0x9a, 0x28, 0xc9, 0x15, 0xc2, 0x10, 0x63, 0x50, 0xb2, 0x20, 0x04, 0x22, 0x0a, 0x86, 0x09, \n\t0x0c, 0x45, 0x03, 0x04, 0x32, 0xd0, 0x02, 0xa6, 0x30, 0x18, 0x28, 0x68, 0x02, 0x02, 0x0a, 0x30, \n\t0x51, 0x02, 0x08, 0x06, 0x60, 0x10, 0xd1, 0xc1, 0x82, 0x06, 0xd1, 0xa2, 0x0b, 0xf9, 0x00, 0x2e, \n\t0x18, 0xa4, 0x02, 0x80, 0x4c, 0x58, 0xa3, 0x40, 0x10, 0x80, 0x04, 0x1c, 0x52, 0x03, 0x22, 0x41, \n\t0x81, 0x21, 0x04, 0x06, 0x0c, 0x10, 0x60, 0x00, 0x02, 0x55, 0x13, 0x60, 0x14, 0x00, 0x38, 0x18, \n\t0x01, 0x00, 0x45, 0x02, 0x10, 0x53, 0x31, 0x48, 0x08, 0x20, 0x06, 0xa4, 0x48, 0xaf, 0x40, 0x47, \n\t0x41, 0x60, 0x00, 0x21, 0x1a, 0x28, 0x82, 0x68, 0x74, 0x22, 0x81, 0x9e, 0x18, 0xc9, 0xe4, 0x74, \n\t0xa4, 0x43, 0x01, 0x64, 0x12, 0x23, 0x56, 0xb1, 0x50, 0x00, 0xc0, 0x00, 0x06, 0x00, 0x64, 0xc1, \n\t0xa4, 0x80, 0x03, 0x40, 0x28, 0xc1, 0x80, 0x19, 0x51, 0x04, 0xc1, 0x40, 0x41, 0x90, 0x9d, 0xa1, \n\t0x0c, 0x04, 0x0e, 0x64, 0x10, 0x00, 0x14, 0x92, 0x40, 0x42, 0x61, 0xa1, 0x90, 0xd0, 0x08, 0x0d, \n\t0x30, 0x22, 0x08, 0x00, 0x44, 0x07, 0xe2, 0x34, 0xe4, 0x41, 0x98, 0x84, 0x08, 0x41, 0x08, 0x05, \n\t0x22, 0x0f, 0x30, 0xc0, 0x44, 0x08, 0x13, 0x28, 0x06, 0x80, 0x11, 0x29, 0x48, 0x10, 0x0a, 0x3d, \n\t0x89, 0x10, 0xc2, 0x40, 0x32, 0x10, 0x04, 0xa4, 0x08, 0xcc, 0x34, 0x55, 0x03, 0xac, 0xd0, 0xc2, \n\t0x80, 0x02, 0x86, 0x0a, 0xa5, 0x50, 0x54, 0x20, 0x50, 0x04, 0xaa, 0x02, 0x6c, 0x5a, 0xa2, 0x2c, \n\t0x51, 0xfb, 0x00, 0x39, 0x03, 0x09, 0x40, 0x04, 0x92, 0xb4, 0x0d, 0x44, 0x05, 0x10, 0x86, 0x89, \n\t0x28, 0x21, 0x42, 0x47, 0x0a, 0x12, 0x68, 0x1e, 0xa0, 0x81, 0x02, 0x20, 0xd0, 0x61, 0x2f, 0x00, \n\t0x44, 0x25, 0x20, 0x04, 0x02, 0x0a, 0x98, 0x9a, 0xa0, 0x20, 0x04, 0x00, 0x24, 0x2c, 0x80, 0x02, \n\t0x00, 0x02, 0x48, 0x08, 0x14, 0x92, 0xa0, 0x00, 0x00, 0x52, 0x19, 0x49, 0x92, 0x41, 0x00, 0x44, \n\t0x20, 0x82, 0x44, 0x01, 0x81, 0x4c, 0x57, 0x98, 0x07, 0xe0, 0x96, 0x20, 0x42, 0x31, 0x02, 0xb0, \n\t0x51, 0x0d, 0x69, 0x6c, 0x85, 0x68, 0x24, 0x08, 0x05, 0x04, 0x26, 0xc4, 0xd8, 0x92, 0x85, 0x07, \n\t0x86, 0x38, 0x61, 0x40, 0x82, 0x80, 0x08, 0x02, 0x10, 0x34, 0x02, 0x3d, 0x30, 0x82, 0x0c, 0x40, \n\t0x05, 0x2a, 0x08, 0x50, 0x00, 0x40, 0x18, 0x10, 0x60, 0x15, 0x21, 0x13, 0x60, 0x02, 0x91, 0x18, \n\t0xa4, 0x81, 0x0a, 0x8a, 0x48, 0x14, 0x70, 0x94, 0x81, 0x4b, 0xc0, 0x0e, 0xb5, 0x90, 0x1a, 0x14, \n\t0x48, 0x00, 0x40, 0x12, 0x48, 0x26, 0x6c, 0x00, 0x84, 0x18, 0x10, 0x00, 0x85, 0x70, 0x82, 0xe8, \n\t0x42, 0xa0, 0x22, 0x80, 0x11, 0x40, 0x2b, 0x02, 0x96, 0xc9, 0x88, 0x58, 0x84, 0x0f, 0x30, 0xc5, \n\t0x28, 0x36, 0xe0, 0xc6, 0x4a, 0x10, 0x15, 0x00, 0x18, 0x80, 0x51, 0x08, 0x20, 0x82, 0xb1, 0x11, \n\t0xc0, 0x10, 0x09, 0x12, 0x22, 0x03, 0x21, 0x69, 0x44, 0x0e, 0x40, 0x00, 0x09, 0x02, 0x50, 0x98, \n\t0x4f, 0x00, 0x00, 0xf1, 0x1b, 0x00, 0xc2, 0x28, 0x46, 0x73, 0x82, 0x02, 0x01, 0x09, 0x83, 0x00, \n\t0x81, 0x42, 0x93, 0x0c, 0xc1, 0x02, 0x16, 0x41, 0x80, 0x83, 0x00, 0x50, 0x02, 0x60, 0x00, 0xd2, \n\t0x14, 0xa0, 0x11, 0x2a, 0x70, 0x80, 0x00, 0x03, 0xe1, 0x8b, 0x80, 0x10, 0x95, 0x08, 0x21, 0x51, \n\t0x8f, 0x00, 0x3a, 0x21, 0x83, 0x8a, 0x20, 0x94, 0x40, 0x4c, 0x73, 0x03, 0x07, 0xa8, 0x08, 0x80, \n\t0x18, 0x06, 0xc0, 0x09, 0x45, 0x40, 0x24, 0x10, 0xa0, 0x42, 0xa2, 0xa4, 0x08, 0x04, 0x18, 0x42, \n\t0x41, 0x10, 0x59, 0x01, 0x88, 0x66, 0x05, 0x1a, 0x0f, 0x14, 0x86, 0x81, 0x66, 0xd0, 0x39, 0x00, \n\t0x0c, 0x80, 0x00, 0x70, 0x11, 0x21, 0x12, 0x08, 0xc0, 0xe1, 0x0a, 0x60, 0x09, 0x9c, 0x91, 0x0c, \n\t0xe2, 0x64, 0x25, 0x5a, 0x90, 0x10, 0x08, 0x89, 0x3c, 0x74, 0x71, 0x24, 0x44, 0x05, 0x46, 0x08, \n\t0x00, 0x80, 0x80, 0xa8, 0xd9, 0x01, 0x1c, 0xb6, 0xb1, 0x8a, 0x10, 0x09, 0xaa, 0x56, 0x82, 0x58, \n\t0x00, 0x01, 0x94, 0x2d, 0x14, 0x21, 0xa2, 0x03, 0x85, 0x94, 0x20, 0x28, 0x41, 0x52, 0x80, 0xc5, \n\t0x01, 0x23, 0x08, 0x25, 0x20, 0xb1, 0x40, 0x08, 0x03, 0x00, 0x05, 0xe0, 0x0c, 0x08, 0xc2, 0xa0, \n\t0x06, 0x25, 0xaa, 0x05, 0x54, 0x1f, 0x08, 0x28, 0x60, 0x00, 0x18, 0xed, 0x50, 0x02, 0x02, 0x71, \n\t0x10, 0x28, 0x21, 0x41, 0x6d, 0x10, 0x90, 0x70, 0x22, 0x25, 0x83, 0x81, 0x50, 0xb3, 0xe0, 0x3c, \n\t0x98, 0x06, 0x20, 0x10, 0x55, 0x4b, 0x90, 0xc1, 0xd0, 0xc1, 0x40, 0x02, 0x11, 0x00, 0xb4, 0x40, \n\t0x8c, 0x10, 0x00, 0x4a, 0xa2, 0x90, 0x0c, 0x64, 0x20, 0x10, 0xc3, 0x9b, 0x19, 0x90, 0x01, 0x00, \n\t0x12, 0x28, 0x81, 0x30, 0x0e, 0x86, 0x22, 0x46, 0x99, 0x81, 0x44, 0x1a, 0x08, 0x0c, 0x05, 0xa1, \n\t0x10, 0xf0, 0x0c, 0x21, 0x00, 0xe1, 0x32, 0x00, 0x58, 0x08, 0xe8, 0x00, 0x62, 0x83, 0x18, 0x00, \n\t0x82, 0x47, 0x12, 0x62, 0x59, 0x01, 0xa0, 0x19, 0x80, 0x00, 0x50, 0xa8, 0x38, 0x80, 0x50, 0x48, \n\t0x12, 0xe0, 0x43, 0x18, 0xc8, 0xc4, 0x07, 0x40, 0x02, 0xa0, 0x01, 0x91, 0x05, 0xa8, 0x48, 0x00, \n\t0xc3, 0x0d, 0x09, 0x86, 0xe2, 0x54, 0x50, 0x10, 0x01, 0x91, 0x1a, 0x48, 0x0c, 0x71, 0x10, 0xa9, \n\t0x25, 0x80, 0x84, 0x04, 0x95, 0x48, 0x1f, 0x00, 0xd0, 0x28, 0x04, 0x30, 0x01, 0x27, 0x64, 0x88, \n\t0xe8, 0x0c, 0x06, 0x18, 0xb2, 0xd4, 0x0c, 0xe7, 0x22, 0x06, 0x00, 0x00, 0xac, 0x00, 0x28, 0x12, \n\t0x30, 0x48, 0x38, 0x11, 0x09, 0x8e, 0x42, 0x20, 0xa0, 0x24, 0x10, 0x8e, 0x09, 0x32, 0x10, 0x58, \n\t0x09, 0xd8, 0x93, 0x88, 0x44, 0x32, 0x10, 0x00, 0x84, 0x14, 0x84, 0x12, 0x21, 0x2a, 0xa6, 0x34, \n\t0x82, 0x01, 0x24, 0x43, 0x42, 0x10, 0x01, 0x42, 0x69, 0x00, 0x11, 0xb0, 0x13, 0x48, 0x81, 0x23, \n\t0x44, 0xd2, 0x2a, 0x18, 0x48, 0xd3, 0x04, 0x22, 0x70, 0xa1, 0x04, 0xb0, 0x88, 0x63, 0x06, 0x01, \n\t0x0a, 0x30, 0x81, 0x54, 0x40, 0x60, 0xd0, 0x08, 0x80, 0x30, 0x80, 0x64, 0x1e, 0x04, 0x41, 0x20, \n\t0x30, 0x0a, 0x41, 0x70, 0xe6, 0xc1, 0x19, 0x8c, 0x4e, 0x08, 0x54, 0x11, 0xca, 0x80, 0x20, 0x84, \n\t0x4e, 0x02, 0x30, 0x4b, 0x04, 0x0c, 0x80, 0x09, 0x40, 0xc0, 0x18, 0x29, 0x81, 0x00, 0x0d, 0x64, \n\t0xc6, 0x81, 0x02, 0x00, 0x13, 0x88, 0x60, 0x11, 0x10, 0x2e, 0x48, 0x0e, 0x43, 0x72, 0x50, 0x0a, \n\t0x8a, 0x84, 0xc5, 0x22, 0x20, 0x11, 0x20, 0x83, 0xa1, 0x01, 0x2a, 0x5c, 0x06, 0x32, 0x0c, 0x48, \n\t0x49, 0x8d, 0x42, 0x86, 0x98, 0x08, 0x01, 0x83, 0x43, 0x30, 0x82, 0x50, 0x98, 0x81, 0x49, 0x0a, \n\t0x22, 0x41, 0x6a, 0x84, 0x04, 0x0b, 0x0c, 0x1c, 0x03, 0x42, 0x80, 0x30, 0x56, 0xc1, 0x1c, 0x06, \n\t0x80, 0x30, 0x00, 0x04, 0xa1, 0x0a, 0x23, 0xa0, 0x01, 0x45, 0x10, 0x41, 0x28, 0x90, 0x81, 0x17, \n\t0x5c, 0x89, 0x04, 0x2c, 0x90, 0x00, 0x23, 0x4d, 0xd0, 0x05, 0x20, 0x02, 0x90, 0x8a, 0x25, 0x8a, \n\t0x22, 0x2a, 0x05, 0x30, 0x11, 0xd4, 0x06, 0xa2, 0x44, 0x65, 0x0a, 0x10, 0xc8, 0x05, 0x63, 0x10, \n\t0x50, 0x88, 0x2a, 0x01, 0xc4, 0x29, 0x28, 0x10, 0x20, 0x15, 0x51, 0x58, 0x84, 0x00, 0x44, 0x42, \n\t0x08, 0x80, 0x84, 0x41, 0x00, 0x32, 0xd2, 0x94, 0x10, 0x0c, 0x20, 0x04, 0x06, 0xea, 0x14, 0x60, \n\t0xc2, 0x6a, 0x02, 0x92, 0x21, 0x80, 0xe8, 0x10, 0x0b, 0x44, 0xc5, 0x60, 0x2f, 0x1d, 0xd0, 0x84, \n\t0x08, 0x20, 0x02, 0x84, 0x29, 0x18, 0x06, 0x42, 0x41, 0x50, 0x14, 0x48, 0x02, 0x86, 0x56, 0x21, \n\t0x48, 0x14, 0x01, 0xdb, 0x82, 0x24, 0x80, 0x5b, 0xae, 0x3c, 0x40, 0x80, 0x22, 0x10, 0x53, 0x02, \n\t0xad, 0x0a, 0x20, 0x08, 0x02, 0x18, 0xa5, 0x80, 0x1c, 0x42, 0x60, 0x70, 0xc1, 0x01, 0x0c, 0x96, \n\t0x2c, 0x0e, 0x90, 0x08, 0x09, 0x81, 0x50, 0x2d, 0x26, 0x04, 0xaa, 0x29, 0xc5, 0x01, 0x46, 0x5c, \n\t0x10, 0x53, 0x2b, 0xa8, 0x84, 0x00, 0x38, 0x53, 0x00, 0x01, 0x15, 0x98, 0x86, 0x0a, 0xc2, 0xaa, \n\t0x89, 0x60, 0x4e, 0xa0, 0x52, 0x04, 0x73, 0x8c, 0x40, 0x8a, 0x08, 0x16, 0x50, 0xa2, 0xb1, 0x24, \n\t0x0a, 0x69, 0x42, 0x05, 0x71, 0x24, 0xa0, 0x11, 0x42, 0x04, 0x90, 0xc1, 0x0a, 0x18, 0x08, 0xc9, \n\t0x26, 0x80, 0x01, 0x20, 0x35, 0x4a, 0x08, 0x58, 0xd0, 0x00, 0x91, 0x00, 0x47, 0x04, 0x76, 0x10, \n\t0x00, 0x83, 0x08, 0x80, 0x89, 0x60, 0x34, 0x2a, 0x0d, 0x88, 0x03, 0x86, 0x02, 0x82, 0x80, 0x0c, \n\t0x45, 0x82, 0x01, 0x60, 0x35, 0x60, 0x00, 0x01, 0x03, 0x6c, 0x48, 0x86, 0x90, 0x19, 0x08, 0x09, \n\t0x00, 0x18, 0x54, 0x01, 0x83, 0xe0, 0x47, 0x04, 0x14, 0x40, 0xb9, 0x80, 0x1c, 0x50, 0xaa, 0x02, \n\t0x03, 0x80, 0x00, 0x50, 0x50, 0xa8, 0x10, 0xb3, 0x00, 0x38, 0x44, 0x04, 0xe2, 0x28, 0x10, 0x20, \n\t0x2c, 0x60, 0x18, 0x40, 0x40, 0xa3, 0x41, 0x16, 0x0c, 0x09, 0x40, 0x20, 0x31, 0x31, 0x04, 0x10, \n\t0x19, 0x45, 0x22, 0xa0, 0x08, 0x28, 0x84, 0x45, 0xe0, 0x08, 0x21, 0xe0, 0x83, 0x04, 0x10, 0x43, \n\t0x54, 0x01, 0x82, 0x08, 0x80, 0x82, 0x46, 0x22, 0xe4, 0x10, 0x80, 0x70, 0x02, 0x81, 0x38, 0x51, \n\t0x33, 0x0e, 0x20, 0xcc, 0x28, 0x12, 0x11, 0x91, 0x26, 0xe1, 0x0c, 0x09, 0x18, 0x63, 0x40, 0x00, \n\t0x68, 0x19, 0x8a, 0x24, 0x50, 0x4a, 0x20, 0x25, 0x0d, 0x24, 0x2c, 0x64, 0x70, 0x0e, 0x45, 0x1c, \n\t0x0c, 0x08, 0x94, 0x83, 0x30, 0x28, 0xd7, 0x24, 0x40, 0x52, 0x70, 0x07, 0x20, 0x06, 0x00, 0x52, \n\t0x00, 0x20, 0x29, 0x60, 0x40, 0x84, 0x52, 0x40, 0x12, 0x00, 0x99, 0x10, 0x8f, 0x48, 0x11, 0x01, \n\t0x9d, 0x8c, 0x80, 0x22, 0x0e, 0x83, 0x32, 0x20, 0x4d, 0xc4, 0x03, 0x10, 0x46, 0x22, 0x22, 0xa1, \n\t0x41, 0x08, 0x3c, 0x10, 0xa0, 0x94, 0xc1, 0x91, 0x08, 0x70, 0x62, 0x1b, 0xaa, 0x31, 0x0c, 0x83, \n\t0x50, 0x17, 0xc9, 0x28, 0xc9, 0x01, 0x01, 0x0c, 0x04, 0x68, 0x30, 0x34, 0x40, 0x02, 0x00, 0xc2, \n\t0x43, 0x01, 0x00, 0x13, 0x08, 0x18, 0x00, 0xe2, 0x1f, 0x81, 0x14, 0xaa, 0x4c, 0x30, 0x98, 0x20, \n\t0x20, 0x46, 0xc7, 0x0c, 0x02, 0xc1, 0x80, 0x60, 0x00, 0x81, 0x18, 0x10, 0xe0, 0x2a, 0x49, 0xc8, \n\t0x41, 0x02, 0x26, 0xa2, 0x08, 0x25, 0x8f, 0x20, 0x72, 0x41, 0x1a, 0x00, 0xe1, 0x08, 0x00, 0x1e, \n\t0x20, 0x80, 0x84, 0xc8, 0x01, 0x03, 0x60, 0x43, 0xb9, 0x18, 0x41, 0x10, 0x8c, 0x24, 0xe6, 0x08, \n\t0x8a, 0xbc, 0x02, 0x00, 0x36, 0x41, 0x58, 0xa8, 0xa0, 0xc1, 0x00, 0x02, 0x12, 0x80, 0x83, 0x28, \n\t0x18, 0x65, 0x70, 0xa0, 0x00, 0x01, 0x18, 0x08, 0xa8, 0x22, 0x94, 0x52, 0x30, 0x01, 0x06, 0x04, \n\t0x40, 0xc0, 0x23, 0x07, 0x35, 0x00, 0xaa, 0x10, 0x44, 0x52, 0x09, 0x0c, 0x58, 0xe3, 0x0c, 0x80, \n\t0x10, 0x10, 0x78, 0x00, 0x41, 0x44, 0x41, 0xc1, 0x04, 0x29, 0x99, 0xaa, 0x00, 0x30, 0xc1, 0x10, \n\t0x05, 0x54, 0x29, 0x50, 0xc4, 0x29, 0x84, 0x60, 0x08, 0x44, 0x22, 0x24, 0xd0, 0x21, 0xc8, 0x04, \n\t0x48, 0x0c, 0x25, 0x00, 0x30, 0x40, 0xc6, 0x83, 0x68, 0x36, 0x82, 0x07, 0x1c, 0x89, 0x29, 0x02, \n\t0x22, 0x90, 0x02, 0x41, 0x85, 0x88, 0x0e, 0x02, 0x01, 0x04, 0x58, 0x11, 0x6e, 0x00, 0xb1, 0x69, \n\t0x00, 0x75, 0x94, 0x08, 0x10, 0x02, 0x70, 0x23, 0x95, 0x42, 0xe3, 0x28, 0x82, 0x10, 0x89, 0x14, \n\t0x10, 0x02, 0x0c, 0x80, 0x11, 0x04, 0x21, 0x12, 0x02, 0x66, 0x01, 0x6b, 0x21, 0xc8, 0x0a, 0xc0, \n\t0x24, 0x01, 0xe0, 0x12, 0xdc, 0x04, 0x4e, 0x20, 0x06, 0x0b, 0xb2, 0x90, 0x47, 0x05, 0x0a, 0x05, \n\t0x41, 0xb1, 0x44, 0x41, 0x01, 0x58, 0x94, 0x02, 0x32, 0x9c, 0xc8, 0x28, 0x04, 0x25, 0x50, 0x86, \n\t0x20, 0x06, 0x8b, 0x4c, 0x10, 0x10, 0x0d, 0x8c, 0x40, 0xc4, 0x12, 0x10, 0x08, 0x24, 0x20, 0x80, \n\t0x05, 0x44, 0x12, 0x42, 0x2c, 0xd9, 0x00, 0x4a, 0x04, 0xa2, 0x80, 0xa4, 0x24, 0x0d, 0x46, 0x2e, \n\t0xc4, 0x7b, 0x33, 0x80, 0x54, 0x04, 0x6a, 0x00, 0x00, 0x00, 0x21, 0x40, 0xaa, 0x10, 0xe1, 0xe0, \n\t0xa4, 0x10, 0x51, 0x01, 0x06, 0x90, 0x90, 0xa0, 0xe8, 0x80, 0x05, 0x30, 0x71, 0x28, 0x14, 0xe5, \n\t0x82, 0x43, 0x10, 0xa4, 0x42, 0x90, 0x8c, 0x84, 0x01, 0x58, 0x10, 0x1a, 0x01, 0xb9, 0x06, 0x80, \n\t0x68, 0x82, 0x40, 0x0d, 0x08, 0x14, 0x2a, 0x4c, 0x41, 0xf8, 0xa2, 0x01, 0x10, 0x22, 0x00, 0xa0, \n\t0x20, 0x90, 0xd4, 0x8a, 0x44, 0x0a, 0x52, 0x90, 0xa7, 0x70, 0x41, 0x05, 0x40, 0x01, 0x08, 0x07, \n\t0x80, 0x4d, 0x04, 0x60, 0x40, 0xc8, 0x00, 0x58, 0x94, 0xa0, 0x34, 0x02, 0xe8, 0x08, 0x00, 0x5d, \n\t0x02, 0x04, 0xe1, 0x52, 0x80, 0x28, 0x88, 0x07, 0x1e, 0xd0, 0x18, 0x9d, 0x30, 0x5e, 0x84, 0x28, \n\t0x60, 0x01, 0xbc, 0xb4, 0x0a, 0x00, 0x0e, 0x00, 0x41, 0x10, 0x21, 0x48, 0x80, 0x02, 0x30, 0x51, \n\t0x1c, 0x81, 0x00, 0x68, 0x0a, 0xc1, 0x20, 0x2d, 0x15, 0x0c, 0x61, 0x00, 0xb0, 0xd0, 0x11, 0x11, \n\t0x51, 0x00, 0x60, 0x70, 0x80, 0xb2, 0x69, 0xc5, 0x81, 0x44, 0x82, 0x03, 0x00, 0x8d, 0x41, 0xa8, \n\t0x42, 0x01, 0xaa, 0x82, 0x80, 0x44, 0x4b, 0x72, 0x00, 0x0b, 0xb2, 0x00, 0x18, 0x26, 0x54, 0xc0, \n\t0xc8, 0xa0, 0x54, 0x89, 0x2a, 0x0a, 0x82, 0x29, 0x1b, 0x51, 0x04, 0xc2, 0x52, 0x01, 0xe1, 0x3b, \n\t0x04, 0x48, 0x24, 0x40, 0x83, 0xc1, 0x04, 0x20, 0x12, 0xce, 0x00, 0xa0, 0x03, 0x04, 0x08, 0x01, \n\t0x08, 0x50, 0xd0, 0xb0, 0x08, 0xa4, 0x04, 0x26, 0x00, 0x84, 0xa2, 0x92, 0x00, 0x41, 0xcc, 0x62, \n\t0x80, 0x28, 0x15, 0x61, 0xc4, 0x41, 0x1c, 0xd1, 0x3a, 0x32, 0xc1, 0x09, 0x22, 0x08, 0x51, 0x90, \n\t0x05, 0x0d, 0x13, 0x80, 0x50, 0x00, 0x8a, 0x18, 0x48, 0x00, 0x60, 0x24, 0xe4, 0x42, 0x02, 0xc4, \n\t0x07, 0x42, 0x04, 0x11, 0x41, 0x82, 0x40, 0x00, 0x0d, 0x3a, 0xc0, 0x42, 0x94, 0x9c, 0xc2, 0x44, \n\t0x2e, 0x47, 0x70, 0x98, 0x60, 0x09, 0x2a, 0x60, 0x00, 0x33, 0x25, 0x5c, 0x14, 0x20, 0x00, 0x11, \n\t0x01, 0x08, 0x28, 0x0c, 0x2a, 0x24, 0xc0, 0x12, 0x09, 0x94, 0x0b, 0x8b, 0x22, 0xc0, 0x10, 0x16, \n\t0x70, 0x80, 0x04, 0x30, 0x00, 0xc9, 0xa6, 0xa8, 0x59, 0xa2, 0x02, 0x10, 0x1a, 0x01, 0x94, 0xc7, \n\t0xc1, 0x42, 0xa0, 0x18, 0x32, 0x18, 0x55, 0x20, 0x40, 0x63, 0x00, 0x9a, 0x24, 0xc1, 0x08, 0x00, \n\t0x32, 0x29, 0x00, 0x45, 0x41, 0x89, 0x58, 0x72, 0x80, 0x00, 0x90, 0x1c, 0x44, 0x00, 0x12, 0x18, \n\t0x02, 0x50, 0x08, 0x46, 0x2c, 0x80, 0xcb, 0x30, 0x59, 0x91, 0xec, 0x08, 0x00, 0xc2, 0x09, 0x89, \n\t0x12, 0x40, 0x0c, 0x20, 0x51, 0x02, 0x1c, 0x10, 0x05, 0x02, 0x60, 0xa8, 0xa0, 0x08, 0x0e, 0xa2, \n\t0x4c, 0x96, 0xc0, 0x9c, 0x84, 0x10, 0x82, 0x52, 0x00, 0x31, 0x20, 0xe5, 0x55, 0x28, 0x74, 0x80, \n\t0x18, 0x22, 0x24, 0x04, 0x0a, 0x02, 0xe1, 0x40, 0xa3, 0x99, 0x05, 0xe6, 0x08, 0x91, 0x50, 0x03, \n\t0x14, 0x8e, 0xc1, 0x60, 0x24, 0xeb, 0x12, 0xa0, 0x02, 0x60, 0x60, 0x40, 0x2a, 0x91, 0xf8, 0x80, \n\t0x2c, 0x14, 0x22, 0x48, 0x05, 0x34, 0x91, 0x2c, 0x12, 0xa2, 0x51, 0x81, 0x01, 0x9c, 0x62, 0x08, \n\t0xd1, 0xe1, 0x10, 0x85, 0x50, 0x2e, 0x20, 0x15, 0x80, 0x02, 0x00, 0x16, 0xe6, 0x72, 0x81, 0x13, \n\t0xa5, 0x40, 0xc2, 0x02, 0x02, 0x64, 0x09, 0x80, 0x65, 0x40, 0x80, 0x04, 0x44, 0x20, 0x30, 0x98, \n\t0x11, 0xc5, 0x32, 0x11, 0x50, 0x31, 0x08, 0x80, 0x04, 0x22, 0x77, 0x20, 0x0a, 0x24, 0x98, 0x00, \n\t0x00, 0x20, 0x48, 0xb3, 0x08, 0x88, 0x04, 0x24, 0xb3, 0x0a, 0x96, 0x00, 0x83, 0xa0, 0x34, 0x02, \n\t0x50, 0x39, 0x68, 0x04, 0x48, 0x14, 0x00, 0x00, 0x03, 0x04, 0x0a, 0xc9, 0x58, 0x01, 0x22, 0x0b, \n\t0x81, 0x49, 0x41, 0x2e, 0x25, 0x02, 0x22, 0x01, 0x90, 0x63, 0x60, 0x04, 0x80, 0x14, 0x80, 0x45, \n\t0x06, 0x3a, 0x05, 0x50, 0x23, 0x64, 0x4a, 0x89, 0x06, 0x03, 0x91, 0x84, 0xb4, 0x40, 0x88, 0x52, \n\t0x61, 0x10, 0x89, 0x1c, 0x40, 0x87, 0x20, 0x82, 0x61, 0x12, 0x84, 0x9a, 0x89, 0x40, 0x42, 0x68, \n\t0x00, 0x00, 0x9a, 0x21, 0x20, 0x11, 0xda, 0x84, 0x80, 0x46, 0x45, 0x00, 0x14, 0x01, 0x08, 0xb4, \n\t0x05, 0x24, 0x0e, 0xa1, 0xa2, 0x20, 0x44, 0x80, 0x49, 0x48, 0x06, 0x40, 0xa2, 0xc0, 0x51, 0xc4, \n\t0x68, 0x34, 0x32, 0x00, 0x3c, 0x10, 0x44, 0x1c, 0x11, 0x30, 0x08, 0x00, 0x4e, 0xa8, 0x30, 0x15, \n\t0xd8, 0x31, 0x28, 0x80, 0x28, 0x04, 0x46, 0x08, 0x20, 0xa1, 0x04, 0x42, 0x12, 0xd2, 0x0a, 0x31, \n\t0x01, 0x02, 0x00, 0x04, 0x20, 0x01, 0xac, 0x65, 0x14, 0x0d, 0x58, 0x51, 0x03, 0x10, 0x00, 0x15, \n\t0x08, 0x04, 0x46, 0x89, 0x8f, 0xf0, 0x88, 0x06, 0x08, 0x20, 0xb1, 0x09, 0x68, 0x52, 0x2a, 0x02, \n\t0x33, 0x82, 0x82, 0xa8, 0x08, 0xe4, 0x60, 0x25, 0x03, 0xac, 0x11, 0x00, 0x85, 0x40, 0xb1, 0x92, \n\t0x86, 0x01, 0xc2, 0x03, 0x28, 0x42, 0x30, 0x17, 0x28, 0xd6, 0xa0, 0x26, 0x00, 0x10, 0x00, 0x59, \n\t0x12, 0x08, 0x0a, 0xc2, 0x61, 0x80, 0x95, 0x08, 0x43, 0x62, 0x90, 0x40, 0x31, 0x90, 0x00, 0x04, \n\t0x2a, 0x92, 0x08, 0x80, 0x21, 0x57, 0x0e, 0x30, 0x00, 0x40, 0x22, 0x24, 0x03, 0x45, 0x60, 0x62, \n\t0xa0, 0x90, 0x41, 0x44, 0x00, 0x18, 0x90, 0x98, 0x15, 0x20, 0x05, 0x00, 0x4a, 0x43, 0x62, 0x00, \n\t0x08, 0x90, 0x80, 0x28, 0x00, 0xb1, 0x3f, 0x40, 0x58, 0x4d, 0x24, 0x45, 0x22, 0x18, 0x04, 0x02, \n\t0x26, 0x6a, 0x10, 0x10, 0x84, 0xcc, 0x85, 0x24, 0x28, 0x14, 0x12, 0x94, 0x41, 0x81, 0x60, 0x70, \n\t0x01, 0x88, 0x80, 0x05, 0x01, 0x23, 0x40, 0x34, 0x8a, 0x0b, 0x20, 0x89, 0x40, 0x36, 0x01, 0x21, \n\t0x00, 0x25, 0x58, 0x09, 0x40, 0x91, 0x0b, 0x18, 0x90, 0x00, 0x69, 0x3a, 0x01, 0x83, 0x84, 0x00, \n\t0xca, 0x24, 0x18, 0x02, 0xd2, 0x00, 0x10, 0x41, 0x01, 0x00, 0xc1, 0xa3, 0x04, 0x38, 0x9c, 0x25, \n\t0x04, 0x11, 0x60, 0x31, 0x40, 0xd8, 0x29, 0x20, 0x04, 0x08, 0x0a, 0x14, 0x08, 0xc0, 0x08, 0x01, \n\t0x81, 0x05, 0x0d, 0x95, 0x20, 0x42, 0x61, 0x10, 0x30, 0x8c, 0x0b, 0x08, 0x38, 0x45, 0x1a, 0x2a, \n\t0x98, 0x40, 0x46, 0x74, 0xb4, 0x40, 0x32, 0xd0, 0x08, 0x02, 0x14, 0x02, 0x39, 0x19, 0x20, 0x42, \n\t0x84, 0x22, 0x60, 0x00, 0x01, 0x08, 0x51, 0x09, 0x2c, 0x20, 0x7a, 0x0a, 0x80, 0x90, 0xe4, 0x18, \n\t0x00, 0x50, 0x18, 0x41, 0xc1, 0x27, 0x04, 0x02, 0x4a, 0x20, 0x04, 0x00, 0xc4, 0x1c, 0x15, 0xc0, \n\t0xb0, 0x0c, 0x11, 0x20, 0x06, 0xa6, 0x20, 0xb8, 0x19, 0x8a, 0xa3, 0x58, 0xc2, 0x40, 0x90, 0x01, \n\t0xcb, 0x0c, 0x20, 0x30, 0xd8, 0x83, 0x4c, 0x16, 0x80, 0x0e, 0x20, 0x09, 0x3c, 0x51, 0x54, 0x80, \n\t0x20, 0x07, 0x53, 0x30, 0x3c, 0x4e, 0x65, 0x00, 0x90, 0x48, 0x0e, 0x01, 0x06, 0x84, 0x38, 0x82, \n\t0x8a, 0x18, 0x18, 0x18, 0x40, 0x60, 0x03, 0x11, 0x89, 0x01, 0x53, 0x09, 0x42, 0x22, 0x01, 0x08, \n\t0x05, 0x92, 0x04, 0x58, 0x11, 0x12, 0x82, 0x70, 0x14, 0x82, 0x7c, 0x12, 0x00, 0xa0, 0x89, 0xc8, \n\t0x60, 0x02, 0x00, 0x20, 0x13, 0x7d, 0x48, 0x00, 0x0a, 0x40, 0x4b, 0x03, 0x49, 0x04, 0x84, 0x54, \n\t0x00, 0xb1, 0x96, 0x44, 0x16, 0x2b, 0x54, 0x46, 0x50, 0x10, 0x04, 0x01, 0xc9, 0x64, 0x05, 0x1a, \n\t0x2a, 0xc0, 0x81, 0xc3, 0x12, 0x33, 0x40, 0x12, 0xc4, 0x05, 0x0d, 0x72, 0xa0, 0x40, 0x84, 0x14, \n\t0x10, 0x20, 0x30, 0x00, 0x1a, 0x80, 0x99, 0x8e, 0xc2, 0x6e, 0x30, 0x48, 0x25, 0x45, 0x90, 0x0a, \n\t0x18, 0x60, 0x82, 0x28, 0x20, 0x86, 0x03, 0x10, 0x64, 0x91, 0x90, 0x8c, 0x8a, 0xa0, 0x2e, 0x50, \n\t0x88, 0x0d, 0x30, 0x98, 0x00, 0x08, 0x03, 0x53, 0x1a, 0x29, 0xc9, 0x00, 0x38, 0x01, 0x60, 0x20, \n\t0xc0, 0xcb, 0x00, 0x28, 0x41, 0x08, 0x82, 0xa5, 0x4c, 0x81, 0x26, 0x44, 0x02, 0x30, 0x51, 0x42, \n\t0x0e, 0x00, 0xd0, 0x10, 0xa0, 0x50, 0x81, 0x81, 0x08, 0x54, 0xa3, 0xb3, 0xa0, 0x80, 0x0c, 0x62, \n\t0xa1, 0xa8, 0x09, 0x08, 0x1e, 0x02, 0x22, 0xa4, 0x3b, 0x04, 0x1d, 0x90, 0x05, 0x48, 0x20, 0x38, \n\t0x00, 0x00, 0x08, 0x66, 0x04, 0x50, 0x90, 0x35, 0x04, 0x08, 0x28, 0x40, 0x12, 0x22, 0x01, 0x40, \n\t0xc3, 0x82, 0x04, 0x02, 0x10, 0x03, 0x64, 0xc0, 0xa0, 0x30, 0x00, 0x02, 0x84, 0x20, 0x06, 0x08, \n\t0x48, 0x20, 0xc3, 0x06, 0x68, 0x40, 0x01, 0x50, 0x33, 0x01, 0x01, 0xf8, 0x80, 0x86, 0x02, 0x05, \n\t0x01, 0x28, 0x01, 0x0e, 0x43, 0x42, 0xa3, 0x01, 0x13, 0xb4, 0xce, 0x24, 0x02, 0x00, 0xc0, 0x1c, \n\t0x00, 0x06, 0xa6, 0x40, 0xb2, 0xe2, 0x24, 0xa0, 0x94, 0x4c, 0x40, 0xe0, 0xb1, 0x23, 0x18, 0x08, \n\t0x28, 0x00, 0x05, 0x50, 0x8a, 0x80, 0x01, 0xe0, 0x40, 0x85, 0x38, 0x06, 0x50, 0x01, 0x43, 0x00, \n\t0xd2, 0x08, 0x95, 0xc8, 0x5a, 0x08, 0x00, 0x14, 0x6a, 0x81, 0x09, 0x02, 0x4a, 0x22, 0x84, 0x22, \n\t0x12, 0x00, 0x11, 0x2c, 0x46, 0x26, 0xc1, 0x81, 0x81, 0x01, 0xc8, 0x00, 0x04, 0x09, 0x30, 0x81, \n\t0xc9, 0x4b, 0x58, 0x95, 0x28, 0xa0, 0x04, 0x0c, 0x20, 0x34, 0x40, 0x89, 0x0b, 0x30, 0x4b, 0x0b, \n\t0x04, 0x00, 0x80, 0x09, 0x98, 0x02, 0x02, 0x02, 0x72, 0x52, 0x04, 0x48, 0x00, 0x48, 0x04, 0x30, \n\t0xa0, 0xb4, 0x40, 0x88, 0x87, 0x02, 0x53, 0x18, 0x22, 0x65, 0x45, 0x23, 0x24, 0x00, 0x98, 0x18, \n\t0x09, 0x08, 0x0c, 0x00, 0x60, 0x40, 0xa4, 0xd8, 0x40, 0x42, 0x50, 0xc2, 0x80, 0xa8, 0x05, 0x5d, \n\t0x28, 0x04, 0x04, 0x00, 0xb0, 0xe8, 0x80, 0x82, 0x26, 0x84, 0x20, 0x1e, 0x20, 0xd3, 0xcd, 0x08, \n\t0x07, 0x22, 0x06, 0x14, 0x10, 0x69, 0x0e, 0x05, 0x19, 0x80, 0xd1, 0x84, 0x2a, 0x38, 0x22, 0x8a, \n\t0x11, 0x91, 0x51, 0xc2, 0x06, 0x50, 0x3a, 0xa1, 0x49, 0x04, 0x82, 0x6c, 0x26, 0x52, 0x03, 0x94, \n\t0x80, 0x02, 0x40, 0x10, 0x00, 0x88, 0x50, 0x42, 0xa2, 0x4c, 0x10, 0x79, 0x34, 0x00, 0x8f, 0x84, \n\t0x34, 0x41, 0x49, 0x32, 0x09, 0x42, 0xc0, 0x14, 0x62, 0x03, 0x06, 0x28, 0x48, 0x22, 0x50, 0x60, \n\t0x00, 0xb2, 0xec, 0x00, 0xc2, 0x0e, 0x35, 0x20, 0x80, 0x50, 0x4d, 0x08, 0x00, 0x60, 0x2a, 0x1c, \n\t0xa0, 0x54, 0x20, 0x02, 0x04, 0x10, 0x05, 0x40, 0x8b, 0xe8, 0x62, 0x12, 0x82, 0x0d, 0xc1, 0x92, \n\t0x84, 0x1c, 0x11, 0x81, 0xa4, 0x00, 0x0c, 0x48, 0x54, 0x71, 0x81, 0x91, 0x44, 0x90, 0x28, 0x06, \n\t0x83, 0x8a, 0x12, 0x65, 0x50, 0x60, 0x5c, 0xc4, 0x20, 0x31, 0x05, 0x8c, 0x02, 0x4c, 0x10, 0xa2, \n\t0x94, 0x29, 0x96, 0x08, 0x40, 0x25, 0xa3, 0xb0, 0x68, 0x10, 0x0d, 0x74, 0x01, 0x98, 0x00, 0x81, \n\t0x00, 0x40, 0x00, 0xb2, 0x61, 0x94, 0xa0, 0x04, 0x88, 0x40, 0x00, 0x61, 0x31, 0x14, 0x43, 0x05, \n\t0x16, 0x20, 0xe8, 0x0b, 0x08, 0x17, 0x08, 0x10, 0x00, 0x79, 0x11, 0x01, 0x84, 0x41, 0x1c, 0x90, \n\t0x99, 0x87, 0x84, 0x1a, 0xc0, 0x6c, 0x07, 0x90, 0x82, 0x84, 0xdb, 0x89, 0x28, 0x36, 0x12, 0x11, \n\t0x20, 0x05, 0x03, 0x20, 0x85, 0x02, 0x00, 0xe0, 0x40, 0x02, 0x24, 0x05, 0x32, 0x22, 0x10, 0x09, \n\t0x20, 0x70, 0x80, 0xd0, 0x18, 0xa5, 0x18, 0x80, 0x00, 0x01, 0x80, 0x21, 0x40, 0x0b, 0x6d, 0x00, \n\t0x53, 0x08, 0x11, 0xb0, 0x08, 0x06, 0x2a, 0x62, 0xa0, 0x0d, 0x8c, 0x16, 0x65, 0x40, 0x11, 0x01, \n\t0x06, 0x30, 0x44, 0xc3, 0x02, 0x00, 0x10, 0x10, 0x34, 0xc2, 0x02, 0x0e, 0x30, 0xc8, 0x85, 0xd9, \n\t0x06, 0x09, 0x08, 0x04, 0x82, 0x28, 0x88, 0x03, 0x06, 0x08, 0x20, 0x92, 0x0e, 0x61, 0x81, 0x65, \n\t0x66, 0x01, 0x23, 0x0e, 0xc0, 0x02, 0xac, 0x1a, 0x35, 0x03, 0x13, 0x20, 0xd8, 0x2b, 0x10, 0x04, \n\t0x63, 0x04, 0x68, 0x5d, 0x22, 0x34, 0x40, 0x10, 0x08, 0x1c, 0x48, 0x00, 0x3a, 0x40, 0x50, 0x01, \n\t0x85, 0x50, 0x00, 0x00, 0x01, 0x09, 0x9d, 0x30, 0x8c, 0x08, 0x0e, 0x27, 0x50, 0x0e, 0x28, 0x91, \n\t0x86, 0x04, 0x80, 0x69, 0x30, 0xc5, 0x42, 0xe5, 0x50, 0x82, 0x10, 0x82, 0x3c, 0x86, 0x6c, 0x10, \n\t0x40, 0x43, 0x28, 0x04, 0x42, 0x23, 0x00, 0xa4, 0xb0, 0x09, 0x51, 0xcd, 0x00, 0x24, 0x06, 0xe2, \n\t0x90, 0x61, 0x96, 0x08, 0x22, 0x50, 0x09, 0x02, 0x4d, 0x59, 0x20, 0x42, 0x05, 0x10, 0x04, 0xe4, \n\t0x0c, 0xcb, 0x04, 0x14, 0xc3, 0x22, 0x80, 0x08, 0x21, 0x16, 0x95, 0x61, 0x06, 0xd0, 0x03, 0x0a, \n\t0x1a, 0x10, 0x00, 0x02, 0xb0, 0x40, 0x64, 0x42, 0x04, 0x02, 0x88, 0x40, 0x02, 0xa8, 0x54, 0x04, \n\t0x00, 0x11, 0x58, 0x54, 0x6d, 0x02, 0x23, 0xc2, 0x80, 0x64, 0x80, 0x02, 0x04, 0xf2, 0x00, 0x14, \n\t0x1d, 0x03, 0x66, 0x44, 0xa1, 0x28, 0x00, 0x04, 0x8a, 0x24, 0x62, 0x90, 0x30, 0xa5, 0x41, 0x07, \n\t0x00, 0x1a, 0x40, 0x90, 0xa4, 0x4c, 0x10, 0x41, 0x48, 0x24, 0x61, 0x3c, 0xa8, 0x10, 0x2c, 0x12, \n\t0xe0, 0x01, 0x98, 0x40, 0x80, 0x88, 0x10, 0x41, 0x40, 0x84, 0x91, 0x48, 0x04, 0x40, 0xa3, 0x00, \n\t0x9b, 0xa8, 0x90, 0x24, 0x50, 0x31, 0xa8, 0x83, 0x91, 0x44, 0x42, 0x0a, 0x12, 0x02, 0x30, 0xa8, \n\t0x55, 0xe8, 0x08, 0x41, 0x00, 0x0c, 0x08, 0x12, 0x07, 0x4c, 0xd2, 0x40, 0xac, 0x14, 0x09, 0xe2, \n\t0x02, 0x01, 0x82, 0x9c, 0x00, 0x15, 0x81, 0x20, 0x52, 0x08, 0x01, 0x60, 0x42, 0x0a, 0x46, 0x25, \n\t0x28, 0x94, 0xa5, 0x98, 0x61, 0x48, 0x84, 0x41, 0x80, 0xc4, 0x48, 0x21, 0x02, 0x47, 0x88, 0x89, \n\t0x50, 0x0f, 0x8a, 0x14, 0x12, 0x31, 0x12, 0x05, 0x87, 0x80, 0x32, 0x32, 0x29, 0x80, 0x00, 0xc8, \n\t0x24, 0x72, 0xe0, 0x33, 0x88, 0x41, 0x80, 0x0e, 0x22, 0xa6, 0x43, 0x0c, 0xd0, 0x51, 0x24, 0x48, \n\t0xa0, 0x82, 0x04, 0xfc, 0x86, 0x00, 0x38, 0x11, 0xc3, 0x02, 0x00, 0x43, 0x44, 0x08, 0x86, 0x20, \n\t0x0e, 0x18, 0x54, 0x00, 0x58, 0x01, 0xc8, 0x10, 0x04, 0x81, 0x02, 0x40, 0x20, 0xf8, 0x22, 0xa4, \n\t0x05, 0x4a, 0x24, 0x62, 0x08, 0x06, 0x2c, 0x10, 0x08, 0x06, 0x15, 0x83, 0x98, 0x9c, 0x00, 0x03, \n\t0x28, 0x50, 0x41, 0x36, 0x11, 0x04, 0x82, 0x12, 0x65, 0x28, 0x08, 0x8c, 0x82, 0x68, 0x10, 0x30, \n\t0x82, 0x1f, 0x80, 0x03, 0x63, 0x04, 0x02, 0x82, 0x1c, 0xc4, 0x80, 0xc1, 0x0c, 0x21, 0xa1, 0x04, \n\t0x30, 0x10, 0x08, 0x00, 0xa2, 0xd3, 0xbd, 0x01, 0xc1, 0x41, 0x60, 0x10, 0x08, 0x12, 0x1c, 0x98, \n\t0x44, 0x02, 0x82, 0x7b, 0xa3, 0x40, 0x14, 0xa4, 0x4e, 0x05, 0xc2, 0x04, 0x48, 0x8c, 0x80, 0x04, \n\t0xa2, 0x41, 0x14, 0x21, 0x01, 0x86, 0x22, 0xe5, 0xca, 0x09, 0xbc, 0x0e, 0x81, 0x10, 0xe3, 0x00, \n\t0x38, 0x20, 0x01, 0x88, 0x50, 0x10, 0xa3, 0x8e, 0x20, 0x5c, 0x45, 0x30, 0x54, 0x29, 0x91, 0x68, \n\t0x01, 0xa4, 0x14, 0xa0, 0x10, 0x20, 0x1c, 0x82, 0x6a, 0x44, 0x62, 0x20, 0x02, 0x68, 0x10, 0xc9, \n\t0x4c, 0x40, 0x02, 0x10, 0x0c, 0x0a, 0x4c, 0x68, 0x05, 0xaa, 0xa1, 0x60, 0x50, 0x46, 0x60, 0x80, \n\t0x02, 0x81, 0x40, 0x00, 0x08, 0x3e, 0x14, 0x08, 0x31, 0x31, 0x80, 0x02, 0x3a, 0x46, 0x12, 0x9a, \n\t0x61, 0x00, 0x2d, 0x10, 0x21, 0x81, 0x82, 0xe0, 0xc0, 0x01, 0x00, 0x45, 0x38, 0x01, 0x05, 0x84, \n\t0x0c, 0x48, 0x20, 0x09, 0x9d, 0x00, 0x1e, 0x41, 0x12, 0x23, 0xf1, 0x11, 0x00, 0xc4, 0x42, 0x36, \n\t0x10, 0x89, 0x04, 0xb1, 0x82, 0x43, 0x08, 0x81, 0x08, 0xa6, 0x60, 0x86, 0x60, 0x04, 0xc4, 0x20, \n\t0x2c, 0x41, 0x40, 0x40, 0x00, 0x02, 0x00, 0x12, 0x00, 0x04, 0x60, 0x6e, 0x90, 0xa1, 0x0b, 0x00, \n\t0x93, 0x28, 0x16, 0x01, 0x49, 0x01, 0xf1, 0x40, 0xa0, 0x62, 0xa0, 0xc0, 0x20, 0x90, 0x51, 0x0b, \n\t0x50, 0x01, 0x00, 0x03, 0x39, 0x85, 0x80, 0x34, 0xc5, 0x18, 0x89, 0x01, 0x10, 0x04, 0x02, 0x06, \n\t0xa2, 0xbb, 0x14, 0x08, 0x08, 0x06, 0x80, 0xfa, 0x10, 0x49, 0x1b, 0x84, 0x04, 0xb4, 0x01, 0x30, \n\t0xa0, 0x02, 0xc2, 0x54, 0x23, 0x21, 0x0a, 0xc9, 0x88, 0xa0, 0x00, 0x12, 0x71, 0x16, 0x8c, 0x50, \n\t0xc2, 0x22, 0x60, 0x08, 0xb1, 0x40, 0x06, 0x44, 0x60, 0x12, 0x8a, 0x04, 0x09, 0x46, 0xa2, 0x60, \n\t0x54, 0x40, 0x85, 0x81, 0x84, 0x88, 0x26, 0x62, 0x88, 0x98, 0x08, 0x11, 0x09, 0x16, 0x84, 0x18, \n\t0x02, 0xc5, 0x40, 0x06, 0x04, 0x91, 0x48, 0x30, 0x01, 0x14, 0x01, 0x4a, 0xc7, 0x83, 0x85, 0xa0, \n\t0x8c, 0x28, 0x1a, 0x56, 0x31, 0x89, 0x38, 0x04, 0x69, 0x54, 0x24, 0x30, 0x00, 0x60, 0x40, 0x28, \n\t0x04, 0x10, 0x52, 0x80, 0x4c, 0x02, 0x08, 0x40, 0x92, 0x63, 0x1b, 0xc0, 0x09, 0x09, 0x6a, 0x52, \n\t0x80, 0x20, 0x68, 0x8c, 0x27, 0x10, 0xc0, 0x43, 0x14, 0x0c, 0x43, 0xa2, 0x00, 0x75, 0x31, 0xb7, \n\t0x90, 0x88, 0x60, 0x2a, 0xe0, 0xf0, 0x30, 0x00, 0x00, 0x82, 0x54, 0x15, 0x02, 0x20, 0x01, 0x41, \n\t0x85, 0x04, 0x02, 0x30, 0x89, 0x50, 0x81, 0xc9, 0x00, 0xa6, 0x68, 0x20, 0x04, 0x52, 0x41, 0x20, \n\t0x21, 0x41, 0x04, 0x18, 0x09, 0x40, 0x00, 0x82, 0xca, 0x35, 0xa5, 0x87, 0x40, 0x1e, 0x93, 0x40, \n\t0x20, 0x19, 0x12, 0x80, 0x00, 0x66, 0x62, 0x0c, 0xcd, 0x12, 0x84, 0x4e, 0x81, 0x28, 0x14, 0x00, \n\t0xd1, 0x80, 0x0a, 0x01, 0x81, 0xad, 0x44, 0x97, 0x08, 0x00, 0x40, 0x60, 0x01, 0x11, 0x9a, 0x61, \n\t0x26, 0xc0, 0x81, 0x38, 0x30, 0x54, 0x27, 0x60, 0x21, 0x02, 0x01, 0x34, 0xc4, 0xa0, 0x02, 0xb0, \n\t0x48, 0x86, 0x15, 0xc0, 0x40, 0x40, 0x00, 0x88, 0x06, 0x80, 0x84, 0x40, 0x56, 0x46, 0x01, 0x82, \n\t0x80, 0x41, 0xa9, 0x56, 0x94, 0x0b, 0x25, 0x11, 0x06, 0x2e, 0x10, 0x12, 0x40, 0x2e, 0x00, 0x80, \n\t0x4d, 0x10, 0x11, 0x40, 0x94, 0x0d, 0x00, 0x6c, 0x0c, 0x02, 0x90, 0x12, 0x1c, 0x10, 0x02, 0x62, \n\t0x41, 0x02, 0x02, 0x04, 0x10, 0x2a, 0x08, 0x40, 0x12, 0x11, 0x0c, 0x08, 0xa2, 0x64, 0x27, 0x08, \n\t0xa0, 0x80, 0x0c, 0x46, 0x74, 0x11, 0x89, 0x29, 0x40, 0x49, 0xc6, 0x06, 0xf7, 0x00, 0x80, 0xa5, \n\t0xde, 0x80, 0x68, 0x20, 0x09, 0x03, 0xac, 0x84, 0x00, 0x38, 0x11, 0x02, 0x19, 0x98, 0x09, 0xe2, \n\t0x20, 0x30, 0xa2, 0x08, 0x6c, 0xc1, 0x4a, 0x44, 0x10, 0x31, 0x03, 0x01, 0x1a, 0x28, 0x20, 0xa5, \n\t0x40, 0x0f, 0x44, 0xc2, 0x8a, 0x62, 0xb3, 0x08, 0x27, 0x69, 0x90, 0x20, 0x0e, 0xc2, 0x80, 0x91, \n\t0x68, 0x90, 0x08, 0x3c, 0x14, 0x0b, 0x92, 0x15, 0x4d, 0x80, 0x38, 0x24, 0x30, 0x12, 0x49, 0x14, \n\t0x04, 0x02, 0xa0, 0x42, 0x28, 0x04, 0xc6, 0x01, 0x22, 0x20, 0x71, 0x25, 0x34, 0x83, 0x41, 0x12, \n\t0x91, 0x00, 0x24, 0x3c, 0x41, 0x04, 0x06, 0x07, 0xb8, 0x82, 0x01, 0x1b, 0x8c, 0x50, 0x20, 0x4a, \n\t0x11, 0x98, 0x80, 0x06, 0x48, 0x83, 0xc8, 0x01, 0x88, 0x08, 0x29, 0x74, 0x26, 0x90, 0xa8, 0x00, \n\t0x00, 0x0f, 0x08, 0xa2, 0x92, 0x90, 0x19, 0x1b, 0x44, 0x00, 0x97, 0x42, 0x29, 0x24, 0x11, 0x00, \n\t0x12, 0x10, 0xc2, 0x30, 0xe8, 0x44, 0x22, 0x24, 0x00, 0x00, 0x04, 0x48, 0x11, 0x40, 0x04, 0x03, \n\t0x19, 0xa0, 0xa8, 0x00, 0x04, 0x04, 0x43, 0x60, 0x0a, 0x15, 0x06, 0x03, 0x52, 0xf5, 0x48, 0x00, \n\t0x10, 0x54, 0x00, 0x0c, 0xd4, 0x29, 0x93, 0xd0, 0x90, 0x4d, 0x4e, 0xa2, 0xc9, 0x10, 0x08, 0x12, \n\t0x42, 0x00, 0xe1, 0x03, 0x0a, 0x04, 0x86, 0x80, 0x70, 0x84, 0x32, 0x28, 0x90, 0x4a, 0x61, 0x08, \n\t0x10, 0xb2, 0x94, 0x10, 0x1a, 0x40, 0x40, 0x06, 0x73, 0xac, 0x20, 0x91, 0x20, 0x40, 0x20, 0x99, \n\t0x84, 0x24, 0x4b, 0xe9, 0x08, 0x81, 0x82, 0x00, 0x31, 0x04, 0x86, 0x30, 0x34, 0x09, 0x32, 0x28, \n\t0x41, 0x2c, 0x16, 0x00, 0x61, 0x95, 0xa0, 0x10, 0xca, 0x2a, 0x44, 0x20, 0xa0, 0x00, 0x10, 0x20, \n\t0x68, 0xc6, 0xb1, 0x15, 0xb0, 0x10, 0x2d, 0x18, 0x26, 0x00, 0x30, 0x08, 0xc6, 0x68, 0x00, 0x50, \n\t0x62, 0x28, 0xc8, 0x00, 0x09, 0x08, 0x81, 0x80, 0x11, 0xc0, 0x03, 0x89, 0x06, 0x50, 0x88, 0x1c, \n\t0x01, 0xc2, 0x63, 0x7a, 0x05, 0x49, 0x34, 0x25, 0x8d, 0x00, 0x48, 0x00, 0xa2, 0x16, 0x8d, 0xc0, \n\t0x4a, 0x5c, 0x46, 0x21, 0x0e, 0x25, 0x44, 0x40, 0x16, 0x60, 0x11, 0x91, 0xd0, 0x82, 0xa8, 0x02, \n\t0x40, 0x51, 0x21, 0x11, 0x48, 0x06, 0x58, 0x12, 0xc1, 0x22, 0x10, 0x51, 0x60, 0x10, 0x22, 0x28, \n\t0x82, 0x58, 0x49, 0x0e, 0x02, 0x04, 0x09, 0x09, 0x01, 0x17, 0xa6, 0x10, 0x62, 0x53, 0x8a, 0x08, \n\t0x00, 0x87, 0x10, 0x20, 0xa3, 0x20, 0x44, 0x41, 0x67, 0x0a, 0x05, 0x02, 0x84, 0x18, 0x96, 0x84, \n\t0x06, 0x91, 0x68, 0x04, 0x85, 0x03, 0x20, 0x00, 0x05, 0x73, 0x24, 0x01, 0xc0, 0x48, 0x00, 0xa5, \n\t0x1a, 0x06, 0xf1, 0x4c, 0x26, 0x74, 0x14, 0x00, 0x82, 0x88, 0x88, 0x62, 0x08, 0x02, 0x40, 0xa0, \n\t0x45, 0x40, 0x04, 0x12, 0x92, 0xaa, 0x10, 0x8c, 0x41, 0x09, 0x28, 0x86, 0x00, 0x89, 0x80, 0x01, \n\t0x02, 0x0a, 0x82, 0x81, 0x31, 0xa0, 0x40, 0x00, 0x06, 0x10, 0x89, 0x80, 0x25, 0x0e, 0xec, 0x00, \n\t0x05, 0x82, 0x22, 0xd8, 0x08, 0xa1, 0x40, 0x44, 0xa0, 0x00, 0x41, 0xc8, 0x01, 0x14, 0x05, 0x9b, \n\t0xbc, 0x60, 0x90, 0x88, 0x0e, 0x14, 0x9b, 0x85, 0xc0, 0x94, 0x02, 0x64, 0xa1, 0x10, 0x34, 0x01, \n\t0x01, 0xa1, 0x60, 0xb3, 0x50, 0x0a, 0xb1, 0x4b, 0xc5, 0x02, 0x40, 0x71, 0x10, 0x05, 0x04, 0x47, \n\t0x20, 0x96, 0x48, 0xa5, 0x00, 0x01, 0x09, 0x08, 0x72, 0xd0, 0x08, 0x20, 0x06, 0xa1, 0x0a, 0x92, \n\t0xb2, 0x00, 0x08, 0x10, 0x08, 0x50, 0xc2, 0x08, 0x2e, 0x15, 0x00, 0x4a, 0x78, 0x80, 0x01, 0xa3, \n\t0x80, 0xd1, 0x07, 0x6e, 0x82, 0xa8, 0x30, 0x24, 0x07, 0x00, 0x08, 0x83, 0x80, 0x28, 0xa4, 0x07, \n\t0x08, 0x00, 0x60, 0x43, 0x80, 0x1d, 0xc0, 0xaa, 0x56, 0x87, 0x10, 0x10, 0x1d, 0x4c, 0xa4, 0x06, \n\t0xa3, 0x88, 0x01, 0x00, 0x06, 0x42, 0x2c, 0x80, 0x01, 0x2e, 0x84, 0x00, 0x83, 0x72, 0x06, 0xa2, \n\t0xb4, 0x14, 0x05, 0x04, 0x10, 0x60, 0x2a, 0x99, 0x38, 0x82, 0x23, 0x06, 0x14, 0x12, 0x29, 0x00, \n\t0x54, 0x69, 0x14, 0x61, 0x32, 0x21, 0x28, 0x14, 0x25, 0x60, 0xd0, 0x21, 0x92, 0x00, 0x80, 0x20, \n\t0x40, 0x73, 0xb0, 0x80, 0x00, 0x01, 0x80, 0x58, 0x05, 0x58, 0xa8, 0x29, 0x48, 0x0a, 0x02, 0x55, \n\t0x4a, 0x82, 0x00, 0xd6, 0xc0, 0x20, 0x81, 0x51, 0x0a, 0x88, 0x59, 0x0c, 0x70, 0x82, 0x02, 0x81, \n\t0xe1, 0x88, 0xa8, 0x0a, 0x55, 0x11, 0x04, 0x15, 0x80, 0x07, 0x08, 0x02, 0xc1, 0xb3, 0x08, 0x1b, \n\t0x04, 0x6e, 0x40, 0x60, 0x0d, 0x50, 0x40, 0x4f, 0x70, 0x30, 0x10, 0x20, 0x01, 0x10, 0x63, 0x10, \n\t0xd1, 0x28, 0x86, 0x0c, 0x0a, 0x04, 0x00, 0x44, 0x00, 0xa0, 0x4d, 0x1a, 0xa1, 0x20, 0x51, 0x38, \n\t0x12, 0x44, 0x11, 0x67, 0x12, 0x04, 0x00, 0x89, 0x00, 0xc9, 0x00, 0x28, 0x00, 0x83, 0x00, 0x64, \n\t0x88, 0x00, 0x0a, 0x03, 0xc2, 0x98, 0xc0, 0x08, 0x23, 0x16, 0x07, 0x09, 0xb1, 0x60, 0x08, 0x6a, \n\t0x04, 0xd2, 0x28, 0x08, 0xb5, 0x11, 0x05, 0x10, 0x25, 0x00, 0xa2, 0x08, 0x16, 0x0c, 0x0a, 0x40, \n\t0x00, 0x00, 0x59, 0x03, 0x04, 0x02, 0x92, 0xe3, 0x30, 0x00, 0x81, 0xc5, 0x06, 0x30, 0x98, 0x24, \n\t0x1c, 0x0e, 0x68, 0x20, 0x81, 0x40, 0x02, 0x1d, 0x03, 0x6a, 0x40, 0x41, 0x02, 0x24, 0x24, 0x05, \n\t0x23, 0x54, 0x92, 0x98, 0x08, 0x88, 0x49, 0x02, 0x20, 0x10, 0x90, 0x30, 0xa0, 0x03, 0x82, 0x24, \n\t0x20, 0x31, 0x8a, 0x39, 0x58, 0xa8, 0x32, 0x86, 0x80, 0x89, 0x35, 0x88, 0x85, 0x24, 0x05, 0x41, \n\t0x81, 0x10, 0x08, 0x41, 0x00, 0xd4, 0x00, 0x16, 0x00, 0x12, 0x44, 0x36, 0xc0, 0x68, 0x81, 0x90, \n\t0x0c, 0xcc, 0x76, 0x20, 0x51, 0x2c, 0x21, 0x50, 0xab, 0x14, 0xb0, 0x4a, 0x00, 0x64, 0x14, 0x4d, \n\t0x40, 0xc2, 0x12, 0x8e, 0x54, 0x08, 0x02, 0x40, 0x41, 0x28, 0x00, 0x01, 0x9e, 0x81, 0x40, 0xd4, \n\t0x29, 0x12, 0x24, 0x87, 0x82, 0x08, 0x01, 0x63, 0xa1, 0x00, 0x83, 0x01, 0x00, 0x44, 0xca, 0xa4, \n\t0x45, 0x48, 0x20, 0x20, 0x22, 0x49, 0x1a, 0xc0, 0x02, 0xc5, 0x3a, 0xa0, 0x10, 0x15, 0x45, 0xd1, \n\t0xc0, 0x48, 0xa1, 0xe3, 0x04, 0x10, 0xc0, 0x20, 0x74, 0x11, 0x10, 0x83, 0xb1, 0x49, 0x02, 0x52, \n\t0x14, 0x28, 0x11, 0x75, 0x96, 0xa8, 0x1e, 0x10, 0x60, 0x02, 0xe8, 0x1c, 0x49, 0x28, 0xc2, 0x12, \n\t0x3c, 0x95, 0x00, 0xa2, 0x42, 0x12, 0x00, 0x80, 0x28, 0x13, 0x04, 0x2c, 0x44, 0x20, 0x00, 0x08, \n\t0x09, 0x80, 0x40, 0x10, 0xa9, 0x03, 0x74, 0x41, 0x89, 0x20, 0x22, 0x8a, 0xac, 0xa8, 0x11, 0xa0, \n\t0x42, 0x35, 0x48, 0x8b, 0x40, 0x42, 0x67, 0x10, 0x62, 0x40, 0x12, 0x40, 0x94, 0x42, 0x10, 0x01, \n\t0x4a, 0x0d, 0xa4, 0xc0, 0x60, 0x5e, 0x50, 0x81, 0x16, 0x40, 0xd2, 0x41, 0x44, 0x22, 0x31, 0x08, \n\t0x81, 0x14, 0xc9, 0x10, 0x83, 0x80, 0x84, 0x28, 0x04, 0x21, 0x08, 0x82, 0x83, 0x02, 0x04, 0x42, \n\t0x4c, 0x00, 0x50, 0x8a, 0x2b, 0x54, 0x50, 0x82, 0x46, 0x86, 0x62, 0x02, 0xe9, 0x9c, 0x0c, 0x56, \n\t0x75, 0x01, 0xa1, 0x34, 0x8c, 0x20, 0x2c, 0x84, 0x58, 0x84, 0xd8, 0x05, 0x08, 0x10, 0xc2, 0x19, \n\t0x12, 0xe0, 0xc8, 0x01, 0x14, 0x82, 0x08, 0x08, 0x01, 0x40, 0x88, 0x30, 0xc0, 0x4a, 0x8a, 0xa0, \n\t0x03, 0x40, 0x02, 0x10, 0x8a, 0x1d, 0x00, 0x15, 0x03, 0x6c, 0x10, 0x91, 0x01, 0x81, 0x46, 0x8e, \n\t0x00, 0x22, 0x13, 0x81, 0x38, 0x80, 0xc9, 0x4c, 0xa0, 0x81, 0xa2, 0x50, 0x59, 0x25, 0x64, 0x03, \n\t0x1a, 0x85, 0x18, 0x0c, 0x24, 0x20, 0x00, 0x80, 0x90, 0x01, 0x46, 0x28, 0x1c, 0x05, 0xab, 0x00, \n\t0xac, 0x48, 0xc9, 0x06, 0x66, 0xe0, 0x1c, 0x41, 0x48, 0x08, 0x00, 0x30, 0x41, 0xb0, 0x59, 0xc2, \n\t0x63, 0x24, 0x33, 0x71, 0x24, 0x80, 0x02, 0x4d, 0x48, 0x83, 0x08, 0x20, 0x90, 0x92, 0x40, 0x04, \n\t0x22, 0x12, 0x88, 0xb0, 0x8a, 0x40, 0x2a, 0x90, 0x60, 0x20, 0x75, 0x86, 0x03, 0x08, 0xa3, 0x22, \n\t0xa2, 0xc8, 0x92, 0x4a, 0x10, 0x01, 0x11, 0x88, 0x44, 0x90, 0x89, 0x20, 0x02, 0xa0, 0x8c, 0x25, \n\t0x02, 0x80, 0x72, 0x02, 0xea, 0x06, 0x01, 0x0d, 0x0c, 0x04, 0x21, 0x1b, 0x83, 0x00, 0x04, 0x22, \n\t0x1e, 0xc0, 0x61, 0x22, 0x55, 0x01, 0x84, 0x20, 0x02, 0x92, 0xb0, 0xd4, 0x01, 0x6a, 0x14, 0x83, \n\t0x21, 0x1e, 0xa4, 0x16, 0x00, 0x12, 0x27, 0x08, 0x28, 0x30, 0x11, 0x48, 0x04, 0x00, 0x5a, 0x04, \n\t0x10, 0x0e, 0x4c, 0x44, 0x92, 0x11, 0x14, 0x80, 0x02, 0x09, 0x50, 0x60, 0x29, 0x20, 0x18, 0x12, \n\t0x08, 0x00, 0x24, 0x11, 0x00, 0x40, 0x88, 0xc3, 0x26, 0xd4, 0x02, 0x21, 0x00, 0x18, 0x81, 0x20, \n\t0x41, 0x93, 0x90, 0x8d, 0x54, 0x26, 0x38, 0x04, 0x81, 0x84, 0x68, 0x82, 0x08, 0x3c, 0x61, 0xc0, \n\t0xaa, 0x80, 0x4c, 0x20, 0x46, 0x10, 0x8a, 0x19, 0xa0, 0x40, 0x22, 0x36, 0x40, 0x61, 0x83, 0x21, \n\t0x90, 0x08, 0x22, 0x55, 0xa8, 0xba, 0xa8, 0x42, 0x6c, 0x64, 0x40, 0x40, 0x10, 0x50, 0x0a, 0x0d, \n\t0x00, 0x80, 0x82, 0x24, 0x04, 0x04, 0xa8, 0x0c, 0xf0, 0x70, 0x05, 0xc4, 0x08, 0x05, 0x64, 0x60, \n\t0x51, 0x0a, 0x1d, 0xc0, 0xa0, 0x02, 0x26, 0x30, 0x22, 0x2c, 0x14, 0x05, 0x10, 0x80, 0x69, 0xaa, \n\t0x05, 0x04, 0x20, 0x20, 0x61, 0x50, 0x05, 0x00, 0xc2, 0xc2, 0x08, 0x04, 0xf1, 0x24, 0x64, 0x00, \n\t0xc1, 0x62, 0x82, 0x00, 0x01, 0x50, 0x03, 0x05, 0x18, 0x70, 0x00, 0xa2, 0x10, 0xc0, 0x01, 0x0a, \n\t0x84, 0xc0, 0x19, 0x00, 0x84, 0x04, 0x08, 0xd5, 0x82, 0x07, 0x59, 0x58, 0x40, 0x0c, 0x94, 0x20, \n\t0x08, 0x09, 0x06, 0x44, 0x0a, 0x23, 0x00, 0x0b, 0x14, 0x04, 0x86, 0x54, 0x40, 0xa0, 0x11, 0x51, \n\t0x01, 0x21, 0x68, 0xf2, 0x0a, 0x32, 0x10, 0x11, 0x40, 0x0c, 0x42, 0x28, 0x14, 0x40, 0x08, 0x08, \n\t0x72, 0x30, 0xc0, 0x20, 0xad, 0x58, 0x61, 0x28, 0x45, 0x29, 0x00, 0x48, 0x01, 0x27, 0x24, 0x62, \n\t0xc0, 0x80, 0x05, 0x0a, 0xc1, 0x18, 0x25, 0x19, 0xac, 0x25, 0x80, 0x0b, 0x5a, 0x20, 0x00, 0x15, \n\t0x10, 0x82, 0x01, 0x36, 0x40, 0x51, 0x0a, 0x40, 0xd8, 0x0c, 0x20, 0x92, 0x92, 0x09, 0x19, 0x45, \n\t0x4b, 0x50, 0x83, 0x82, 0xa3, 0xe1, 0x86, 0xea, 0x08, 0x43, 0x91, 0x19, 0x89, 0x13, 0x80, 0x04, \n\t0x84, 0x80, 0x10, 0x15, 0xc2, 0x05, 0x0c, 0xd2, 0xc0, 0x00, 0x48, 0x00, 0xa8, 0x40, 0x21, 0x01, \n\t0x85, 0x14, 0x19, 0xc2, 0x42, 0x60, 0xf0, 0x0a, 0x40, 0x50, 0x42, 0x26, 0x47, 0xc9, 0x22, 0x14, \n\t0x81, 0xa2, 0x20, 0x31, 0x08, 0x21, 0xc1, 0xc0, 0x00, 0x48, 0x22, 0x40, 0x93, 0x88, 0x00, 0x61, \n\t0x44, 0x40, 0x0b, 0x80, 0x69, 0x86, 0xec, 0x0a, 0x36, 0x89, 0x14, 0xf0, 0x51, 0x20, 0x42, 0x21, \n\t0x71, 0x21, 0xd1, 0x0c, 0x20, 0x6c, 0x30, 0x53, 0x00, 0x01, 0x00, 0x23, 0x04, 0x74, 0xa8, 0x34, \n\t0x40, 0x5b, 0xa0, 0x1a, 0x16, 0x01, 0x80, 0x28, 0x0f, 0x08, 0x10, 0x24, 0x80, 0x12, 0x69, 0x04, \n\t0x00, 0x48, 0x40, 0xab, 0x94, 0x38, 0x51, 0x4a, 0x26, 0x67, 0x01, 0x00, 0x6c, 0x86, 0x0e, 0x0a, \n\t0x52, 0x20, 0x0c, 0xa0, 0x14, 0x8c, 0x00, 0x11, 0x83, 0x2c, 0xb0, 0x81, 0x24, 0x00, 0x40, 0x48, \n\t0x1e, 0x31, 0xc5, 0x40, 0x32, 0x20, 0x90, 0x14, 0x80, 0x52, 0x80, 0x48, 0x11, 0x40, 0x23, 0x80, \n\t0x14, 0x02, 0x1c, 0x94, 0xa0, 0x08, 0xcc, 0x4a, 0x08, 0x04, 0x37, 0xb0, 0x2a, 0x05, 0x04, 0x00, \n\t0x30, 0x03, 0x03, 0x36, 0xc1, 0x04, 0x2a, 0x12, 0x54, 0x20, 0xa0, 0xe5, 0x94, 0xa0, 0x16, 0x00, \n\t0x81, 0x92, 0x81, 0x09, 0xc0, 0x54, 0x44, 0xc0, 0xa9, 0x81, 0x8c, 0x00, 0x0c, 0xb0, 0x28, 0x05, \n\t0x34, 0x8f, 0x42, 0x42, 0x21, 0xa0, 0x10, 0x24, 0x99, 0x01, 0x04, 0x91, 0x40, 0x09, 0x50, 0x44, \n\t0x63, 0x62, 0x86, 0x52, 0x18, 0x30, 0x01, 0xa8, 0x00, 0x51, 0x12, 0x82, 0x10, 0x88, 0x01, 0x08, \n\t0x31, 0x00, 0x34, 0x49, 0x42, 0x80, 0x0c, 0x50, 0x02, 0x94, 0x00, 0x13, 0xc7, 0x00, 0x90, 0x22, \n\t0x94, 0xc9, 0x19, 0x04, 0x60, 0x74, 0x71, 0x25, 0x35, 0x8b, 0x41, 0x60, 0x86, 0x08, 0x00, 0x60, \n\t0x40, 0x66, 0x02, 0x90, 0x41, 0x81, 0x81, 0x8e, 0x48, 0x00, 0x43, 0x58, 0x11, 0xb4, 0x13, 0x0b, \n\t0x2a, 0xa5, 0xc0, 0x90, 0x84, 0x06, 0x04, 0x04, 0x03, 0x2a, 0x1d, 0x30, 0x09, 0x89, 0x20, 0x04, \n\t0x81, 0x10, 0x90, 0x10, 0x42, 0x50, 0x02, 0x21, 0x08, 0x30, 0x04, 0xa6, 0x10, 0x00, 0xc2, 0x8e, \n\t0x89, 0x18, 0xa8, 0x00, 0x10, 0x1a, 0xae, 0x64, 0x4a, 0xa2, 0x64, 0x40, 0x60, 0x28, 0x40, 0x1b, \n\t0x00, 0x18, 0x04, 0xc8, 0xa5, 0xc8, 0x17, 0x22, 0x50, 0xe0, 0x20, 0x08, 0x10, 0x40, 0x2c, 0x24, \n\t0x10, 0x5a, 0x89, 0x04, 0x0c, 0xac, 0x06, 0x23, 0x18, 0x27, 0x21, 0x89, 0x4d, 0x10, 0x84, 0xc0, \n\t0x04, 0x38, 0x06, 0x08, 0x22, 0x97, 0xe3, 0x10, 0xd9, 0x44, 0x01, 0x08, 0x00, 0xa0, 0x14, 0x9c, \n\t0x44, 0x01, 0x00, 0x11, 0x41, 0x88, 0x68, 0x84, 0x24, 0x20, 0x72, 0x41, 0x22, 0x44, 0x88, 0x06, \n\t0x2a, 0x00, 0x10, 0x30, 0x59, 0x93, 0x22, 0x00, 0x06, 0xd8, 0x14, 0x2d, 0x41, 0xae, 0x50, 0x20, \n\t0x22, 0x34, 0x80, 0x01, 0x81, 0x20, 0x01, 0x12, 0x00, 0x1d, 0x40, 0xca, 0x34, 0x66, 0x80, 0xb1, \n\t0x48, 0x45, 0x06, 0x12, 0x10, 0x08, 0x89, 0x94, 0x1a, 0x09, 0x58, 0x44, 0x20, 0x02, 0x24, 0xc5, \n\t0x09, 0x3c, 0x02, 0xd0, 0x12, 0x00, 0x10, 0x6a, 0x50, 0x92, 0x8a, 0x04, 0xd8, 0x90, 0xa0, 0x12, \n\t0x41, 0x39, 0x01, 0x21, 0x08, 0x4f, 0x70, 0x60, 0x62, 0x8b, 0x81, 0x42, 0x09, 0x06, 0x87, 0x8a, \n\t0x81, 0x65, 0xd5, 0x04, 0x60, 0x10, 0x01, 0x10, 0xe0, 0x88, 0x82, 0x2c, 0x01, 0x81, 0x24, 0x08, \n\t0x0b, 0x21, 0x62, 0x60, 0x52, 0x32, 0x0d, 0x1c, 0x05, 0x22, 0x14, 0x00, 0xb8, 0x38, 0x00, 0x00, \n\t0x3e, 0xe3, 0x60, 0x83, 0x01, 0x04, 0x00, 0x10, 0x10, 0x20, 0x82, 0x24, 0x06, 0x01, 0x50, 0x50, \n\t0x18, 0x86, 0x08, 0x13, 0x45, 0x0a, 0x82, 0x2b, 0x28, 0xa4, 0x91, 0x60, 0x18, 0x00, 0x89, 0x8f, \n\t0x90, 0x0c, 0x00, 0x4c, 0x01, 0x60, 0x36, 0x1c, 0x58, 0x0c, 0x22, 0x51, 0x18, 0xb0, 0x50, 0x0a, \n\t0xa6, 0x40, 0x46, 0x12, 0x34, 0x80, 0x84, 0x84, 0x48, 0x44, 0x30, 0x01, 0x49, 0x10, 0x0b, 0x42, \n\t0x00, 0x39, 0x24, 0x68, 0x0d, 0x41, 0x22, 0xa2, 0x88, 0x02, 0x2c, 0x40, 0x08, 0x10, 0x50, 0x41, \n\t0x02, 0x15, 0x91, 0x46, 0x22, 0x70, 0x42, 0x91, 0x08, 0x07, 0x25, 0x62, 0x07, 0x48, 0x99, 0x11, \n\t0x44, 0x48, 0x1c, 0x16, 0xe9, 0x3c, 0xc0, 0xc0, 0x40, 0x4e, 0x60, 0x20, 0x0c, 0x9d, 0x00, 0x28, \n\t0x08, 0x24, 0x93, 0x88, 0xd0, 0x01, 0x20, 0x44, 0x33, 0x00, 0x0d, 0x29, 0x90, 0x40, 0x4c, 0x85, \n\t0x01, 0x12, 0x80, 0x42, 0x2c, 0x24, 0x11, 0xc0, 0x00, 0x59, 0x40, 0x8b, 0x04, 0x65, 0x00, 0x2c, \n\t0x55, 0x1c, 0x22, 0x00, 0x04, 0x80, 0x00, 0x5c, 0x88, 0x84, 0x20, 0x07, 0x49, 0x35, 0x84, 0x17, \n\t0x08, 0x0a, 0x70, 0x08, 0x08, 0x00, 0x1e, 0x08, 0x64, 0x04, 0xf2, 0x8c, 0x00, 0xc3, 0xc0, 0x00, \n\t0x04, 0x73, 0x21, 0x01, 0x00, 0xc3, 0x50, 0xb2, 0x0a, 0x88, 0x04, 0x0a, 0x21, 0x14, 0x62, 0x00, \n\t0x13, 0x0c, 0xc0, 0xad, 0x4c, 0xd0, 0x10, 0x0a, 0x21, 0x89, 0x80, 0x10, 0x80, 0x2a, 0xa7, 0x20, \n\t0x91, 0x00, 0x4a, 0x31, 0x0b, 0x30, 0x28, 0x11, 0x00, 0x00, 0x63, 0xc0, 0x10, 0x2d, 0x10, 0xa2, \n\t0x20, 0xc4, 0x8b, 0x3b, 0x28, 0x01, 0xe9, 0x10, 0xc4, 0x40, 0x02, 0x41, 0x10, 0x00, 0x10, 0x80, \n\t0xc1, 0x84, 0x00, 0x90, 0x61, 0x04, 0x11, 0x30, 0x89, 0x98, 0x01, 0x05, 0x4e, 0x02, 0x30, 0x20, \n\t0x08, 0x54, 0x40, 0x12, 0x80, 0x62, 0x84, 0x0c, 0x08, 0x09, 0x40, 0x94, 0x33, 0x04, 0x01, 0x48, \n\t0x81, 0x22, 0x80, 0x02, 0xa6, 0x11, 0x14, 0x23, 0x14, 0x04, 0x6b, 0x20, 0x40, 0x14, 0xa4, 0x10, \n\t0x44, 0x1a, 0x11, 0x40, 0x42, 0x01, 0x34, 0x01, 0x39, 0x08, 0x14, 0x50, 0xa2, 0x14, 0x00, 0x00, \n\t0x03, 0x90, 0x09, 0x0a, 0x24, 0x85, 0x40, 0xb0, 0x51, 0x1f, 0x00, 0x10, 0x82, 0x08, 0x08, 0x2c, \n\t0x41, 0x29, 0x4a, 0x83, 0x80, 0x93, 0x40, 0x56, 0x2b, 0x4e, 0x10, 0xc2, 0x20, 0x48, 0x01, 0x8c, \n\t0x00, 0x70, 0x3a, 0x0c, 0x0c, 0x10, 0x00, 0x28, 0x03, 0x40, 0x3a, 0x18, 0x53, 0x60, 0x60, 0x64, \n\t0x80, 0xb4, 0x24, 0x00, 0x62, 0x08, 0x50, 0x20, 0x06, 0x60, 0x88, 0x20, 0x1a, 0x60, 0x08, 0x11, \n\t0x15, 0x83, 0x0b, 0x38, 0x24, 0x52, 0x98, 0x24, 0x10, 0x28, 0x40, 0x54, 0x08, 0x01, 0xf1, 0xc9, \n\t0x21, 0x30, 0x44, 0x30, 0x89, 0x21, 0x02, 0x0c, 0x40, 0x80, 0x88, 0x36, 0x20, 0x4c, 0x04, 0x74, \n\t0x84, 0x02, 0x00, 0x49, 0x95, 0x48, 0x04, 0x82, 0x6a, 0x38, 0x20, 0x46, 0x2b, 0x40, 0x22, 0xf3, \n\t0x21, 0xd5, 0x00, 0x09, 0x48, 0x03, 0x11, 0x84, 0x4c, 0x80, 0x6a, 0x46, 0xa2, 0x90, 0x92, 0x30, \n\t0x88, 0x06, 0x48, 0xc1, 0x69, 0x07, 0x00, 0x40, 0x02, 0x02, 0x00, 0x29, 0x02, 0x85, 0x14, 0x29, \n\t0x38, 0x40, 0x09, 0xac, 0x98, 0x01, 0x41, 0x20, 0x82, 0x50, 0x82, 0x1d, 0xcf, 0xc0, 0x28, 0x00, \n\t0x10, 0x0c, 0x40, 0x40, 0xc4, 0x10, 0x42, 0x82, 0x06, 0x08, 0x81, 0x08, 0x44, 0x23, 0xd1, 0x81, \n\t0x20, 0xd6, 0x22, 0x58, 0x00, 0x90, 0x08, 0x51, 0x14, 0x03, 0x06, 0x42, 0xc8, 0x07, 0xec, 0x12, \n\t0x82, 0x18, 0x97, 0x43, 0x9b, 0x00, 0x09, 0x4a, 0x04, 0xc0, 0x20, 0x22, 0x60, 0x5e, 0x24, 0x04, \n\t0x93, 0x6a, 0x90, 0x48, 0x44, 0x26, 0x64, 0x41, 0x22, 0x92, 0x48, 0x08, 0x48, 0x16, 0x22, 0xd0, \n\t0x1e, 0x00, 0x49, 0x6f, 0x00, 0x24, 0x08, 0x08, 0xb1, 0xc0, 0xc8, 0x02, 0x20, 0x49, 0x90, 0x04, \n\t0x8c, 0x03, 0x10, 0x84, 0xaa, 0x0d, 0x14, 0x45, 0x61, 0x00, 0x42, 0x63, 0x01, 0x20, 0x01, 0x6a, \n\t0x04, 0x16, 0x20, 0x10, 0x00, 0x82, 0x44, 0x4a, 0x20, 0x33, 0x0c, 0x30, 0x10, 0x82, 0x38, 0x34, \n\t0x91, 0xb0, 0x91, 0x51, 0x41, 0x68, 0x85, 0x22, 0x00, 0x00, 0x97, 0x60, 0x08, 0x52, 0x52, 0xa9, \n\t0x4d, 0x18, 0x0c, 0x56, 0x24, 0xe2, 0x06, 0x58, 0xd0, 0x21, 0x16, 0x44, 0x28, 0x08, 0x21, 0x58, \n\t0x02, 0x22, 0x01, 0xc0, 0x8b, 0x04, 0x05, 0x84, 0x00, 0x11, 0x19, 0x35, 0xf0, 0x8d, 0x40, 0x10, \n\t0x17, 0x02, 0x1a, 0x0c, 0x48, 0x28, 0x52, 0x80, 0x63, 0x14, 0xd1, 0x09, 0x26, 0x48, 0x20, 0x20, \n\t0x35, 0x18, 0x12, 0x40, 0x04, 0x32, 0x82, 0x86, 0x61, 0x00, 0xac, 0x60, 0x00, 0xa0, 0x02, 0x44, \n\t0x48, 0x00, 0x06, 0xa6, 0x90, 0x24, 0x10, 0x0e, 0x65, 0x60, 0x01, 0x08, 0x88, 0x49, 0x18, 0x00, \n\t0x50, 0x41, 0x41, 0x83, 0x24, 0xca, 0xa8, 0x22, 0x40, 0x20, 0xa0, 0x88, 0x14, 0x60, 0x00, 0x07, \n\t0x80, 0x20, 0x18, 0x80, 0x01, 0x14, 0x05, 0x01, 0x9c, 0x04, 0x93, 0x46, 0x08, 0xc3, 0x62, 0x10, \n\t0x14, 0x1a, 0x48, 0x70, 0x10, 0x08, 0x05, 0xa8, 0x11, 0x4c, 0x40, 0xa6, 0x00, 0x20, 0x28, 0x52, \n\t0x01, 0x58, 0x20, 0x09, 0x89, 0x05, 0x86, 0xa0, 0x0c, 0x56, 0xf0, 0x20, 0x88, 0x51, 0x48, 0x04, \n\t0x65, 0x00, 0x8d, 0x01, 0xc5, 0x20, 0x62, 0x00, 0x91, 0x8e, 0x4d, 0xc2, 0x80, 0x12, 0x11, 0x2a, \n\t0x20, 0xd1, 0x11, 0xa1, 0x52, 0x80, 0x48, 0x84, 0xd0, 0x09, 0x28, 0x40, 0x50, 0x89, 0x80, 0x14, \n\t0x06, 0x0c, 0x1a, 0x44, 0x08, 0xba, 0xa5, 0x50, 0xc7, 0x08, 0xa7, 0x22, 0x0a, 0x30, 0x44, 0x00, \n\t0x44, 0xc4, 0xd0, 0x09, 0x10, 0x40, 0x88, 0x48, 0x22, 0xcb, 0x18, 0x84, 0x07, 0x8b, 0x06, 0x41, \n\t0x50, 0x00, 0x49, 0x1a, 0xa2, 0x24, 0x63, 0x23, 0x90, 0x91, 0x02, 0x08, 0x28, 0xa0, 0x08, 0x0a, \n\t0x1c, 0x04, 0x47, 0x2a, 0x05, 0xd8, 0x08, 0x84, 0x10, 0xa8, 0x40, 0x71, 0x58, 0x82, 0x0d, 0x14, \n\t0x00, 0x56, 0xe6, 0x92, 0x8e, 0xd4, 0x00, 0x4d, 0x14, 0x54, 0x49, 0x80, 0x25, 0x0c, 0x01, 0x38, \n\t0x30, 0x08, 0xac, 0x10, 0x90, 0x40, 0x4a, 0x13, 0x63, 0x01, 0x04, 0x01, 0x00, 0x02, 0xd1, 0x19, \n\t0x02, 0xa0, 0x00, 0xae, 0x36, 0x00, 0x80, 0x24, 0xa0, 0x52, 0x8b, 0x00, 0xd0, 0x02, 0x00, 0x51, \n\t0x84, 0x84, 0x0c, 0x02, 0xc3, 0x39, 0x80, 0x8a, 0x44, 0x66, 0x50, 0x08, 0x09, 0x31, 0x08, 0x41, \n\t0x02, 0x07, 0x18, 0xa0, 0x20, 0xc5, 0x2a, 0x12, 0x45, 0x48, 0xa0, 0x68, 0xc6, 0x83, 0x48, 0x20, \n\t0x80, 0x1c, 0x11, 0x45, 0x88, 0x60, 0x56, 0x53, 0x12, 0x60, 0x07, 0x2d, 0x24, 0x04, 0x29, 0x84, \n\t0x20, 0x88, 0x45, 0x08, 0x96, 0x81, 0x84, 0x00, 0x91, 0x04, 0x04, 0x21, 0x09, 0x0e, 0x39, 0x10, \n\t0x28, 0x70, 0x00, 0xc0, 0x20, 0xb0, 0x02, 0x6e, 0x00, 0x82, 0xe3, 0x02, 0x9d, 0x00, 0x2b, 0x74, \n\t0x21, 0xe1, 0x31, 0x15, 0x58, 0xaa, 0x40, 0xe0, 0x20, 0x30, 0x14, 0x52, 0xc4, 0x00, 0x16, 0x68, \n\t0xa0, 0x08, 0x10, 0x82, 0x58, 0x01, 0x18, 0x36, 0xe4, 0x0a, 0x61, 0x44, 0x01, 0xa1, 0x90, 0x94, \n\t0x11, 0xc0, 0x12, 0xc4, 0x13, 0x19, 0x44, 0x09, 0x66, 0x2a, 0x84, 0x18, 0x13, 0x05, 0xcd, 0x40, \n\t0x20, 0x30, 0x81, 0x02, 0x84, 0xd0, 0x40, 0x1e, 0x00, 0x1b, 0x15, 0x70, 0x12, 0x20, 0x22, 0x04, \n\t0x61, 0x05, 0x51, 0x03, 0x08, 0x40, 0x80, 0x8a, 0x8e, 0x30, 0x84, 0x40, 0x08, 0x84, 0x60, 0xb3, \n\t0x01, 0x52, 0x4a, 0x02, 0x06, 0x82, 0xb0, 0x49, 0x40, 0x46, 0x3a, 0x81, 0x00, 0x14, 0x00, 0x88, \n\t0xa4, 0x08, 0x14, 0x2a, 0x34, 0x7c, 0x04, 0x61, 0x00, 0xe1, 0xd8, 0x9c, 0xa4, 0x14, 0x86, 0x44, \n\t0x00, 0x41, 0x21, 0xc8, 0x4d, 0x04, 0x00, 0x02, 0x51, 0x2a, 0x01, 0x9d, 0x04, 0x40, 0x45, 0x60, \n\t0x98, 0x28, 0x42, 0x05, 0x0a, 0xa6, 0x00, 0x02, 0x99, 0x89, 0xa2, 0x20, 0x02, 0x02, 0x2d, 0xe8, \n\t0x10, 0x00, 0x5c, 0xb0, 0x83, 0x02, 0x4c, 0x02, 0xe8, 0x04, 0xa4, 0x02, 0x02, 0x04, 0x88, 0x42, \n\t0x4c, 0x32, 0x90, 0xbb, 0x00, 0xcd, 0x00, 0x72, 0x11, 0x2a, 0x04, 0x85, 0x01, 0x28, 0x10, 0x11, \n\t0xb2, 0x00, 0x88, 0x1a, 0xc3, 0x16, 0x81, 0xd3, 0x00, 0x00, 0x04, 0x87, 0x44, 0x70, 0x58, 0x91, \n\t0x30, 0x04, 0x45, 0x2c, 0x33, 0x28, 0x21, 0x40, 0x88, 0x81, 0x52, 0x80, 0xe8, 0x01, 0xa0, 0x80, \n\t0x0c, 0x36, 0x44, 0xe1, 0x12, 0x88, 0x18, 0xe2, 0x4a, 0x20, 0x0b, 0x20, 0x28, 0x81, 0x00, 0x48, \n\t0xb2, 0x10, 0x06, 0x0d, 0x8e, 0x00, 0x44, 0x15, 0x90, 0xa2, 0x04, 0x82, 0x01, 0x28, 0x42, 0xa8, \n\t0x90, 0x4d, 0x80, 0x25, 0x42, 0x10, 0x02, 0x0e, 0x81, 0x84, 0x2e, 0x54, 0x04, 0x10, 0x21, 0x00, \n\t0xd8, 0x02, 0x78, 0x81, 0x08, 0x06, 0xbc, 0x50, 0x4c, 0x10, 0xd0, 0x00, 0x30, 0xa4, 0x41, 0x22, \n\t0x02, 0x41, 0x51, 0x12, 0x50, 0x08, 0x07, 0x18, 0xb4, 0xe0, 0x01, 0x30, 0x4c, 0x68, 0x00, 0x32, \n\t0x08, 0x95, 0xb8, 0x90, 0xc0, 0x0c, 0xb0, 0x51, 0x10, 0x4c, 0x90, 0xce, 0x44, 0x21, 0xea, 0x00, \n\t0x28, 0x18, 0x0a, 0x10, 0x00, 0x22, 0x18, 0x04, 0x09, 0x05, 0x6a, 0x81, 0x08, 0x27, 0x09, 0x08, \n\t0xc2, 0x74, 0x45, 0x58, 0x00, 0xa1, 0x81, 0x00, 0x12, 0x50, 0x8a, 0x16, 0x04, 0x5a, 0x60, 0x00, \n\t0x86, 0x0a, 0x20, 0xc0, 0x1c, 0x08, 0x02, 0x05, 0x02, 0x1a, 0x41, 0x08, 0x4c, 0x2a, 0x24, 0x01, \n\t0xa1, 0x11, 0x12, 0x46, 0x00, 0x85, 0x80, 0xb8, 0x08, 0x42, 0x20, 0x32, 0x82, 0x30, 0x8a, 0x78, \n\t0x84, 0x89, 0x12, 0x02, 0x12, 0x10, 0x20, 0x81, 0x60, 0x46, 0x52, 0x01, 0x2f, 0x20, 0x10, 0x04, \n\t0x48, 0xa0, 0xe0, 0x00, 0xc4, 0x10, 0xa5, 0x22, 0x04, 0x82, 0x1a, 0x0d, 0x05, 0x04, 0x2a, 0x50, \n\t0x71, 0xa7, 0x04, 0x87, 0x02, 0x18, 0x60, 0xc8, 0x81, 0x1d, 0xc9, 0x00, 0x00, 0x05, 0x29, 0x30, \n\t0x0c, 0x55, 0x00, 0x54, 0x24, 0x03, 0x82, 0x70, 0x03, 0x25, 0x00, 0xb0, 0x40, 0x82, 0x85, 0x95, \n\t0x0d, 0x48, 0x10, 0x49, 0x16, 0x00, 0xd4, 0x08, 0x0e, 0xd4, 0x82, 0x80, 0x00, 0xce, 0xc6, 0x22, \n\t0x02, 0x48, 0x18, 0xb9, 0x52, 0xe0, 0x42, 0x20, 0x11, 0x2c, 0x58, 0x0a, 0x89, 0x48, 0x85, 0xc0, \n\t0x04, 0x05, 0x83, 0x88, 0x00, 0xa5, 0x10, 0x00, 0x30, 0x1f, 0x02, 0x08, 0x00, 0x90, 0x10, 0x45, \n\t0xcc, 0xac, 0x06, 0x70, 0xc0, 0x02, 0x31, 0x07, 0x03, 0x12, 0xe0, 0x22, 0x90, 0x00, 0x4d, 0x80, \n\t0x36, 0x01, 0x80, 0x02, 0xc8, 0x0c, 0x49, 0x18, 0x10, 0x40, 0x18, 0xe4, 0x06, 0x09, 0x22, 0x20, \n\t0x08, 0x08, 0x18, 0x09, 0x21, 0x66, 0x92, 0x09, 0x00, 0xe0, 0x4a, 0x8d, 0x32, 0x10, 0x41, 0x0d, \n\t0x19, 0x41, 0x29, 0x02, 0xb3, 0x40, 0x81, 0x94, 0x18, 0x44, 0x34, 0x03, 0x33, 0xb2, 0x58, 0x08, \n\t0x4c, 0x6c, 0x81, 0x82, 0x94, 0x0c, 0x44, 0x01, 0x44, 0x01, 0x81, 0x31, 0x40, 0xc3, 0x82, 0x00, \n\t0x75, 0xf2, 0x01, 0x18, 0x19, 0xca, 0x36, 0xc0, 0xa1, 0x04, 0x19, 0x10, 0xa1, 0x00, 0x75, 0x80, \n\t0x08, 0x89, 0x86, 0x20, 0x00, 0x01, 0x01, 0xa1, 0x31, 0x46, 0x00, 0x50, 0x01, 0xa0, 0x04, 0x04, \n\t0x05, 0x41, 0x4c, 0x66, 0x08, 0x90, 0x80, 0xd5, 0x01, 0x1c, 0x10, 0xb2, 0x08, 0xd0, 0x82, 0x29, \n\t0x50, 0x01, 0x40, 0x02, 0x70, 0x98, 0x81, 0x28, 0x14, 0x91, 0x9d, 0xd9, 0x98, 0x6f, 0x20, 0x80, \n\t0x02, 0x00, 0x41, 0x00, 0x20, 0x20, 0x04, 0xd3, 0x22, 0x08, 0x0d, 0xac, 0x28, 0x40, 0x70, 0x83, \n\t0xd1, 0x82, 0x09, 0x56, 0x25, 0x09, 0x1c, 0x59, 0x08, 0x82, 0x04, 0x12, 0x1a, 0x08, 0xa0, 0x00, \n\t0x87, 0x02, 0xc2, 0x20, 0x06, 0x41, 0x42, 0x08, 0x40, 0xe3, 0xc8, 0x02, 0x98, 0x83, 0x20, 0x6a, \n\t0x65, 0x5b, 0x02, 0x48, 0x81, 0x41, 0x0c, 0x92, 0xe0, 0x14, 0x18, 0x05, 0x41, 0x10, 0x43, 0x38, \n\t0x2c, 0x20, 0x86, 0x40, 0x0c, 0x46, 0x00, 0x19, 0xd1, 0x11, 0x20, 0x02, 0xd1, 0x10, 0x09, 0x05, \n\t0x01, 0xa6, 0x22, 0x04, 0x90, 0x8c, 0x20, 0x04, 0x00, 0x0e, 0x30, 0x88, 0x80, 0x09, 0x9f, 0x20, \n\t0x08, 0x40, 0x68, 0x20, 0x34, 0x01, 0xa7, 0x64, 0x00, 0x41, 0xb3, 0x24, 0x88, 0x08, 0x14, 0x12, \n\t0x08, 0x91, 0x20, 0x1c, 0x06, 0x00, 0xf0, 0x82, 0x2a, 0xb8, 0x16, 0x08, 0x24, 0xa1, 0x10, 0x10, \n\t0x01, 0x96, 0x4b, 0x56, 0x02, 0x60, 0x18, 0x20, 0x40, 0xa9, 0x58, 0x01, 0x73, 0x82, 0xc0, 0x8a, \n\t0x60, 0x04, 0x14, 0x82, 0x06, 0xdc, 0xda, 0xa8, 0x20, 0x22, 0x02, 0x97, 0x2c, 0x40, 0x04, 0x24, \n\t0x12, 0x21, 0x00, 0xa1, 0xc0, 0x80, 0x78, 0x54, 0x50, 0x23, 0xc1, 0x91, 0x01, 0x12, 0x27, 0x99, \n\t0x20, 0x01, 0x14, 0x04, 0x00, 0x44, 0x09, 0x92, 0x91, 0x40, 0x40, 0x0c, 0x51, 0x10, 0x33, 0x44, \n\t0x41, 0xcc, 0x60, 0xa5, 0x00, 0x08, 0x28, 0x16, 0x08, 0x00, 0x84, 0x33, 0x08, 0x49, 0x0b, 0x2a, \n\t0x04, 0x80, 0xa1, 0x21, 0x04, 0x95, 0x01, 0x0e, 0xa1, 0x50, 0x26, 0x24, 0x04, 0xe9, 0x10, 0xc2, \n\t0x50, 0x98, 0x01, 0xd8, 0xc0, 0x0a, 0x44, 0x30, 0x09, 0x65, 0x02, 0x02, 0x36, 0xd4, 0x22, 0x0a, \n\t0xc4, 0x14, 0x82, 0x00, 0x25, 0x0a, 0x07, 0x84, 0x07, 0x42, 0x12, 0x24, 0x19, 0x88, 0x80, 0x40, \n\t0x6c, 0x20, 0x30, 0x50, 0x82, 0x00, 0x00, 0xc8, 0x0e, 0x82, 0x01, 0xb6, 0x70, 0x84, 0x41, 0x40, \n\t0x27, 0x0b, 0xb4, 0x04, 0x89, 0x00, 0x38, 0x53, 0xca, 0x13, 0x80, 0x54, 0x42, 0x40, 0x84, 0x03, \n\t0x24, 0x6c, 0x44, 0x89, 0x1e, 0xa2, 0x6b, 0x04, 0x21, 0x18, 0x04, 0x00, 0x45, 0xa2, 0x84, 0xc8, \n\t0x01, 0x40, 0x20, 0x60, 0xa8, 0x20, 0x34, 0x82, 0x40, 0x20, 0x06, 0x5a, 0x80, 0x20, 0x80, 0x0a, \n\t0x70, 0x34, 0x52, 0x01, 0x15, 0x0b, 0x60, 0x24, 0xc7, 0x90, 0x32, 0x08, 0x4c, 0x82, 0x04, 0x26, \n\t0x92, 0xa1, 0xc9, 0x41, 0x23, 0x2c, 0x66, 0x29, 0x1d, 0xa5, 0x00, 0x00, 0x10, 0x41, 0xa8, 0x0a, \n\t0x20, 0x5c, 0x21, 0x54, 0xa3, 0x0a, 0x00, 0xb9, 0x40, 0x04, 0x2c, 0x20, 0x00, 0x04, 0x80, 0x03, \n\t0x0c, 0x18, 0xc0, 0x43, 0x00, 0x74, 0x0e, 0xa3, 0x04, 0x42, 0xc3, 0x0c, 0x80, 0xc2, 0x2a, 0x00, \n\t0x00, 0x82, 0x94, 0x48, 0xd2, 0x04, 0x24, 0x01, 0xf8, 0x23, 0x68, 0x12, 0x0c, 0x7c, 0x30, 0x00, \n\t0x03, 0x18, 0x1f, 0x60, 0x26, 0x00, 0x18, 0x04, 0x84, 0x05, 0x67, 0x10, 0x90, 0x02, 0x19, 0x30, \n\t0xcc, 0x86, 0x00, 0x26, 0x50, 0x10, 0x45, 0x47, 0x81, 0x08, 0x42, 0xaa, 0x01, 0xa4, 0x86, 0x29, \n\t0x70, 0x96, 0x00, 0x1d, 0x31, 0xc1, 0xe4, 0x5c, 0x02, 0x20, 0x09, 0x05, 0x14, 0x00, 0x40, 0x83, \n\t0x41, 0x28, 0xa8, 0x90, 0x00, 0x08, 0x32, 0xa0, 0xb7, 0x0d, 0x51, 0x02, 0x24, 0x85, 0x18, 0x0a, \n\t0x40, 0x08, 0x21, 0x12, 0x43, 0x12, 0x12, 0x40, 0x88, 0xa6, 0x06, 0x65, 0xc1, 0x34, 0x1c, 0x54, \n\t0x41, 0x20, 0x01, 0x48, 0x2a, 0x40, 0x05, 0x43, 0x56, 0x80, 0x80, 0x08, 0x34, 0x02, 0x47, 0x12, \n\t0x43, 0x21, 0x08, 0x00, 0x11, 0xc4, 0x0a, 0x01, 0x08, 0x05, 0x0c, 0x4c, 0x00, 0x06, 0x01, 0x70, \n\t0x80, 0x00, 0x5d, 0x48, 0x2c, 0x00, 0x12, 0x09, 0x2d, 0xc2, 0x48, 0x08, 0xe0, 0x19, 0x87, 0x00, \n\t0x98, 0x29, 0x20, 0x13, 0xc2, 0x08, 0x01, 0x81, 0x84, 0x2c, 0x21, 0x18, 0x2a, 0x78, 0x89, 0x05, \n\t0x60, 0x55, 0x00, 0x07, 0x61, 0x14, 0x80, 0x32, 0x14, 0x58, 0xa2, 0xb9, 0x42, 0x2a, 0x0c, 0xe6, \n\t0x52, 0x86, 0x8d, 0x48, 0x04, 0x00, 0xc4, 0xd0, 0x08, 0x28, 0xc3, 0x27, 0x02, 0x31, 0x18, 0x12, \n\t0x80, 0x12, 0x02, 0x02, 0x62, 0x01, 0x27, 0x24, 0x98, 0x01, 0x24, 0x42, 0x82, 0x94, 0x01, 0x16, \n\t0x05, 0x50, 0x34, 0x08, 0x04, 0x84, 0x43, 0x21, 0x08, 0x00, 0xb0, 0x88, 0x90, 0x16, 0x40, 0x40, \n\t0x74, 0x63, 0x2e, 0x00, 0x41, 0x60, 0x02, 0x24, 0x02, 0x02, 0x04, 0x49, 0x81, 0x44, 0x01, 0xc8, \n\t0x2a, 0xc0, 0x15, 0x80, 0x64, 0x24, 0xda, 0x84, 0x01, 0x08, 0x60, 0x08, 0xa1, 0x02, 0x10, 0x39, \n\t0x50, 0x20, 0x04, 0x84, 0x10, 0x12, 0x61, 0x02, 0x49, 0x22, 0xe0, 0x10, 0x3c, 0x61, 0xc6, 0x80, \n\t0x00, 0x86, 0x29, 0xa4, 0x10, 0x90, 0x25, 0x00, 0xc0, 0x80, 0x12, 0x18, 0x95, 0x40, 0x32, 0x12, \n\t0x89, 0x18, 0xd1, 0x02, 0x86, 0x54, 0x81, 0x20, 0x0c, 0x98, 0x06, 0x46, 0x20, 0xc0, 0x40, 0x18, \n\t0x0d, 0x09, 0x27, 0x2e, 0x40, 0x80, 0x2a, 0x40, 0x17, 0x40, 0x68, 0x12, 0x62, 0xa9, 0x0c, 0xc0, \n\t0x82, 0x1e, 0x54, 0xb1, 0x05, 0x28, 0x12, 0x68, 0x24, 0xa6, 0x62, 0x2e, 0x20, 0x51, 0x04, 0x44, \n\t0x91, 0x53, 0x83, 0xc8, 0x00, 0x28, 0x00, 0x42, 0x29, 0x11, 0xa0, 0x06, 0xc8, 0x1a, 0x45, 0x08, \n\t0x10, 0x84, 0x5b, 0x25, 0x10, 0x86, 0xc2, 0x10, 0x48, 0x08, 0x2e, 0x14, 0x22, 0xc0, 0x2d, 0x00, \n\t0x50, 0x42, 0x48, 0xc1, 0x80, 0x81, 0x80, 0x10, 0x01, 0x20, 0x02, 0xc1, 0x15, 0x01, 0x02, 0x48, \n\t0x22, 0x07, 0x82, 0x14, 0x00, 0xd4, 0xc2, 0x02, 0x01, 0x5b, 0x06, 0x25, 0x84, 0x00, 0x02, 0x64, \n\t0xb8, 0x02, 0xc8, 0x8e, 0x89, 0x20, 0x01, 0x8a, 0x12, 0x80, 0x10, 0x8c, 0x02, 0x92, 0x02, 0x80, \n\t0x01, 0x43, 0x2d, 0x08, 0x82, 0x21, 0x00, 0x11, 0x01, 0x8a, 0x12, 0x94, 0x02, 0x03, 0x30, 0xc0, \n\t0x6d, 0x24, 0x86, 0x21, 0x04, 0x50, 0xc0, 0xa0, 0x0e, 0x12, 0x81, 0x29, 0xc4, 0x06, 0x63, 0x00, \n\t0x42, 0x02, 0x80, 0x10, 0x06, 0x0d, 0x08, 0x45, 0x50, 0x01, 0x1c, 0x98, 0x4c, 0x64, 0x64, 0x90, \n\t0x88, 0x30, 0x8a, 0x43, 0x5a, 0x01, 0x11, 0x03, 0xa8, 0x43, 0x20, 0x00, 0x00, 0xa3, 0xb6, 0x24, \n\t0x0e, 0x6b, 0x20, 0xc4, 0x22, 0x00, 0x4c, 0x48, 0xe0, 0x24, 0x21, 0x90, 0x01, 0x8c, 0x88, 0xa8, \n\t0x04, 0x22, 0x68, 0xb3, 0xa5, 0x52, 0x42, 0x4a, 0xc2, 0x0b, 0x1d, 0x00, 0xc8, 0x04, 0x02, 0x10, \n\t0x2a, 0x84, 0x80, 0x08, 0x45, 0x4a, 0x24, 0x8b, 0x00, 0x30, 0x10, 0x21, 0x18, 0x52, 0xc9, 0x02, \n\t0xc5, 0x98, 0x02, 0x10, 0x81, 0x02, 0x21, 0x91, 0x40, 0x65, 0x40, 0x41, 0x90, 0x92, 0x11, 0xd4, \n\t0x20, 0x5a, 0x83, 0x20, 0x00, 0x25, 0x82, 0x0c, 0x06, 0x15, 0x41, 0x16, 0x04, 0x81, 0x02, 0x6a, \n\t0x41, 0x89, 0x12, 0xb1, 0x00, 0x6f, 0x54, 0x01, 0x09, 0x1a, 0x8d, 0x02, 0x00, 0x32, 0xd0, 0x01, \n\t0xa5, 0x15, 0x81, 0x01, 0x10, 0x80, 0x22, 0x00, 0x84, 0xc0, 0x00, 0x58, 0x24, 0xc1, 0x13, 0x09, \n\t0x12, 0xe0, 0x16, 0x84, 0x9a, 0x05, 0x08, 0x53, 0x84, 0x42, 0x00, 0x68, 0x21, 0x21, 0x0a, 0x49, \n\t0x10, 0x10, 0x12, 0x81, 0x10, 0x10, 0x63, 0x42, 0x41, 0x02, 0x01, 0x05, 0xdb, 0xc4, 0x3c, 0x11, \n\t0xb0, 0x00, 0xc9, 0x0c, 0x0e, 0x20, 0x20, 0x12, 0x90, 0x69, 0x08, 0x82, 0x42, 0x01, 0x8b, 0x30, \n\t0x2c, 0x4c, 0x00, 0x22, 0x02, 0x43, 0xa9, 0xc0, 0x84, 0xc8, 0x0c, 0xf2, 0x00, 0x04, 0x60, 0x4a, \n\t0x00, 0x40, 0xa4, 0x08, 0x22, 0x04, 0xc7, 0x04, 0x42, 0x05, 0x20, 0x1d, 0xc1, 0x04, 0x85, 0x6a, \n\t0x20, 0x22, 0x1c, 0xc8, 0x55, 0x88, 0x00, 0x00, 0xa0, 0x05, 0x21, 0x14, 0xc8, 0x48, 0x22, 0x20, \n\t0x1a, 0x10, 0x49, 0x0d, 0x2e, 0xc4, 0x9a, 0x04, 0x01, 0x90, 0x44, 0x12, 0x04, 0x42, 0x21, 0x20, \n\t0x84, 0x22, 0x74, 0x00, 0x60, 0x82, 0x29, 0x40, 0xa8, 0x00, 0x87, 0xb3, 0x98, 0xb4, 0x14, 0x05, \n\t0x40, 0xa2, 0x41, 0x0b, 0x19, 0xce, 0x08, 0x04, 0x02, 0x38, 0x89, 0x15, 0x82, 0xc0, 0x40, 0x50, \n\t0x08, 0xa0, 0x20, 0x03, 0x08, 0x10, 0xa1, 0x90, 0x1d, 0x90, 0x5a, 0x40, 0x06, 0x96, 0xd3, 0x08, \n\t0x81, 0x02, 0x07, 0x00, 0xc0, 0x49, 0x08, 0x8c, 0x80, 0xa4, 0x00, 0xc7, 0x90, 0x2b, 0xc9, 0x88, \n\t0x40, 0x08, 0x20, 0x00, 0xa4, 0x41, 0x04, 0x20, 0x38, 0x52, 0x00, 0x00, 0xc0, 0x13, 0x00, 0x12, \n\t0x00, 0xe2, 0x82, 0x91, 0x03, 0x49, 0x04, 0x84, 0x52, 0x02, 0xa0, 0x4d, 0x21, 0x36, 0x00, 0x8a, \n\t0xb1, 0xd4, 0x4a, 0xee, 0x08, 0x40, 0x48, 0xb2, 0xd0, 0x08, 0x85, 0x30, 0x64, 0x23, 0x39, 0x08, \n\t0x80, 0x0c, 0x0a, 0x90, 0x01, 0x10, 0x51, 0x88, 0x62, 0x40, 0x12, 0x49, 0x1d, 0x2c, 0x80, 0xcd, \n\t0x14, 0xa0, 0x31, 0x21, 0x24, 0x00, 0x86, 0x10, 0xa2, 0xd2, 0x82, 0x05, 0x49, 0x6a, 0x60, 0x00, \n\t0x02, 0x08, 0x35, 0x03, 0x22, 0x54, 0x90, 0xd8, 0xa4, 0x09, 0x59, 0x0a, 0x30, 0x00, 0x08, 0x15, \n\t0x61, 0x00, 0x0a, 0x04, 0xa4, 0xb3, 0x92, 0x00, 0x41, 0x40, 0x00, 0x47, 0x02, 0x00, 0xd4, 0x04, \n\t0xac, 0x0a, 0xa7, 0x10, 0x81, 0x01, 0xc1, 0x0e, 0x22, 0x22, 0x40, 0x24, 0x3c, 0x14, 0x6c, 0x28, \n\t0xc2, 0xd8, 0x18, 0xe1, 0x11, 0x0c, 0x00, 0x00, 0x82, 0x1d, 0xb5, 0x06, 0x01, 0x4e, 0x43, 0x63, \n\t0x0c, 0x4d, 0x8c, 0x08, 0x6c, 0x03, 0x20, 0x8c, 0x4c, 0x08, 0x01, 0x00, 0x32, 0x88, 0x0a, 0x21, \n\t0x0f, 0x45, 0x20, 0x90, 0x43, 0x20, 0x04, 0x16, 0xac, 0x20, 0x54, 0x08, 0x85, 0x51, 0x89, 0xc0, \n\t0x3e, 0x23, 0xb2, 0xa0, 0x0d, 0x10, 0x48, 0x00, 0x34, 0x19, 0xa2, 0xc0, 0x86, 0x40, 0x12, 0xe0, \n\t0x01, 0x0e, 0x20, 0x03, 0x80, 0x00, 0xc0, 0x29, 0x8a, 0x90, 0x46, 0x24, 0x08, 0x84, 0x00, 0x87, \n\t0x89, 0x41, 0x64, 0x38, 0x04, 0x49, 0x04, 0x28, 0xc5, 0x06, 0x0e, 0x93, 0xb0, 0x0a, 0x34, 0x04, \n\t0x04, 0x6c, 0x20, 0x23, 0x1e, 0x81, 0x5a, 0x81, 0x4a, 0x61, 0x90, 0x84, 0x50, 0x0e, 0x42, 0x0c, \n\t0x12, 0xa1, 0x26, 0xa8, 0x88, 0x04, 0x34, 0x10, 0x28, 0x20, 0x90, 0x45, 0x83, 0x30, 0x25, 0x1a, \n\t0x20, 0x8c, 0x41, 0x05, 0x00, 0xc4, 0x48, 0xa8, 0x89, 0x4d, 0x01, 0x08, 0xc2, 0x00, 0xa4, 0x45, \n\t0x58, 0x01, 0x78, 0x31, 0x2b, 0x28, 0x88, 0x06, 0x21, 0x62, 0x10, 0x23, 0x9a, 0x90, 0x88, 0x41, \n\t0x10, 0x80, 0x19, 0x01, 0x40, 0x06, 0x21, 0x48, 0x11, 0x82, 0x20, 0xd0, 0x18, 0x09, 0x04, 0xb1, \n\t0x00, 0x25, 0xc0, 0x00, 0xc6, 0x20, 0x06, 0x22, 0x29, 0x59, 0x53, 0x60, 0x38, 0x81, 0x30, 0x8e, \n\t0x88, 0x06, 0xa4, 0x0e, 0x20, 0xa0, 0x84, 0x00, 0x02, 0x00, 0x20, 0x65, 0x32, 0x84, 0x00, 0x00, \n\t0x0a, 0x12, 0x12, 0x01, 0x2a, 0x18, 0x0f, 0x45, 0x02, 0x92, 0x69, 0x20, 0xa5, 0x51, 0x44, 0x12, \n\t0x44, 0x00, 0x2a, 0x18, 0x0d, 0x24, 0x52, 0xc4, 0x22, 0x8a, 0x80, 0x80, 0x00, 0x20, 0x00, 0xd8, \n\t0x00, 0x25, 0x12, 0x01, 0x44, 0x72, 0x02, 0x8a, 0x7c, 0x10, 0x20, 0x2c, 0x35, 0x52, 0x00, 0x80, \n\t0x90, 0x4a, 0x02, 0x05, 0x80, 0x14, 0x49, 0x18, 0x01, 0x18, 0x92, 0x88, 0xb1, 0x69, 0x18, 0x2c, \n\t0x34, 0x50, 0x4a, 0x80, 0x95, 0x16, 0x82, 0x10, 0x42, 0xa0, 0x0c, 0x90, 0x04, 0xaa, 0x44, 0x26, \n\t0x89, 0x10, 0x24, 0x40, 0x0b, 0x0e, 0x21, 0x20, 0x1c, 0x04, 0x86, 0x08, 0x10, 0xc1, 0x00, 0x0f, \n\t0x30, 0x5c, 0x04, 0x40, 0xa0, 0x2b, 0x98, 0x30, 0xd9, 0x61, 0x72, 0x24, 0x23, 0x21, 0x25, 0x46, \n\t0xe4, 0x1c, 0x00, 0x42, 0x08, 0x00, 0x88, 0xc1, 0x2c, 0x35, 0x20, 0x14, 0x40, 0x00, 0x23, 0x26, \n\t0xf4, 0x20, 0x15, 0x14, 0xda, 0x20, 0x00, 0x40, 0x53, 0x2f, 0xc0, 0xcb, 0x26, 0x52, 0x11, 0x01, \n\t0x06, 0xe1, 0xc0, 0x4a, 0x6a, 0x82, 0x48, 0x12, 0x80, 0x11, 0x00, 0x34, 0x87, 0x00, 0x21, 0xa9, \n\t0x00, 0x4a, 0x22, 0x80, 0x60, 0x33, 0x21, 0x10, 0x0a, 0x18, 0x42, 0xa0, 0x20, 0x3c, 0x92, 0x40, \n\t0x04, 0x61, 0x42, 0x1a, 0x58, 0x02, 0x82, 0x4a, 0x80, 0x00, 0x10, 0xdc, 0x01, 0x21, 0x04, 0xb0, \n\t0x9a, 0x04, 0x04, 0x02, 0x00, 0x28, 0x20, 0x52, 0x19, 0x80, 0xc1, 0xc6, 0x4c, 0x04, 0x28, 0x01, \n\t0x44, 0x93, 0x21, 0x30, 0x40, 0x08, 0xb4, 0x41, 0xc5, 0x28, 0x00, 0x30, 0x8a, 0x01, 0x00, 0x1a, \n\t0x60, 0x04, 0xc0, 0x03, 0xa0, 0x24, 0x14, 0xad, 0x20, 0x04, 0xc1, 0x00, 0x39, 0x48, 0x4c, 0x02, \n\t0xc6, 0x20, 0x20, 0x74, 0x95, 0x00, 0x22, 0x16, 0xc3, 0x1a, 0x00, 0x42, 0x01, 0x12, 0xe3, 0xc1, \n\t0x89, 0x68, 0x10, 0x24, 0x12, 0x86, 0x12, 0x08, 0x20, 0x14, 0x27, 0x00, 0x70, 0x80, 0x09, 0x50, \n\t0x8a, 0x8b, 0x70, 0x81, 0x10, 0x29, 0xcc, 0x01, 0x86, 0x04, 0x01, 0x10, 0x98, 0x3c, 0x50, 0xa0, \n\t0x02, 0x44, 0x00, 0x10, 0x49, 0x0a, 0x80, 0x3a, 0x60, 0x20, 0x15, 0xd0, 0x44, 0x00, 0x08, 0x25, \n\t0x81, 0x3a, 0x00, 0x15, 0xc0, 0x10, 0x42, 0x0a, 0x10, 0xc0, 0x0b, 0x20, 0x08, 0x71, 0x28, 0x2c, \n\t0xc0, 0x99, 0x41, 0x02, 0x30, 0x00, 0x00, 0x80, 0x99, 0x6c, 0x24, 0x63, 0x09, 0x10, 0x50, 0xc5, \n\t0x66, 0x0c, 0x12, 0x0a, 0x01, 0x94, 0x07, 0x0a, 0x42, 0x80, 0xe2, 0xa6, 0x29, 0x8c, 0x20, 0x04, \n\t0x11, 0x10, 0x01, 0x01, 0x18, 0x03, 0x24, 0x40, 0x18, 0x8c, 0x04, 0x88, 0xc6, 0x4c, 0x83, 0x20, \n\t0x09, 0xe0, 0x47, 0x8c, 0x40, 0x40, 0x01, 0x06, 0x25, 0x14, 0xc0, 0x72, 0x05, 0x70, 0x84, 0x40, \n\t0x40, 0x43, 0x20, 0xb0, 0x88, 0x13, 0x88, 0x89, 0xa2, 0x20, 0x55, 0x00, 0x00, 0x20, 0xd3, 0x04, \n\t0x08, 0x12, 0x21, 0x05, 0x08, 0x41, 0x68, 0x4a, 0x16, 0x00, 0x8e, 0x61, 0x00, 0xc6, 0x0c, 0xa2, \n\t0xc9, 0x01, 0xa8, 0x55, 0x00, 0x12, 0x60, 0x6a, 0x87, 0xd8, 0x12, 0x8a, 0x20, 0x14, 0x11, 0x32, \n\t0x00, 0x00, 0xa4, 0x08, 0x06, 0x10, 0x0d, 0x14, 0x10, 0x05, 0x40, 0x01, 0xa0, 0xa8, 0x40, 0x0f, \n\t0x80, 0x42, 0x04, 0x43, 0x37, 0x0c, 0x94, 0x4b, 0x28, 0x80, 0x90, 0x0c, 0x8d, 0x0d, 0xc9, 0x72, \n\t0x30, 0xd8, 0x92, 0x05, 0x01, 0x23, 0x1a, 0x10, 0x00, 0x81, 0x90, 0x06, 0xc5, 0x00, 0xa2, 0x02, \n\t0x88, 0x94, 0x56, 0x00, 0x08, 0x22, 0x49, 0x16, 0xc0, 0x81, 0x21, 0x18, 0xa0, 0x03, 0x11, 0x75, \n\t0x02, 0xc0, 0x46, 0x52, 0x90, 0x28, 0x30, 0x8a, 0x28, 0x30, 0x04, 0x10, 0x8a, 0x19, 0x49, 0x01, \n\t0x2c, 0x07, 0x00, 0x00, 0x44, 0x40, 0x24, 0x0a, 0x97, 0x59, 0x98, 0x01, 0x58, 0xa0, 0x22, 0x01, \n\t0x21, 0x00, 0xf4, 0xda, 0xa8, 0x5e, 0x60, 0x00, 0xac, 0x65, 0x01, 0x80, 0x42, 0xd0, 0x03, 0x00, \n\t0x14, 0x03, 0x4b, 0x02, 0x02, 0x60, 0x16, 0x81, 0x88, 0x84, 0x02, 0x62, 0xaa, 0x14, 0x84, 0xc2, \n\t0x40, 0x52, 0x15, 0x00, 0x95, 0x80, 0x01, 0x04, 0x10, 0x20, 0x08, 0x38, 0x08, 0xd0, 0x60, 0x14, \n\t0x20, 0x88, 0x88, 0x89, 0x14, 0x85, 0x3c, 0x00, 0x82, 0x03, 0x40, 0x90, 0x84, 0x02, 0x62, 0x22, \n\t0x01, 0x40, 0xcc, 0xc1, 0x1e, 0x13, 0x02, 0x2a, 0x20, 0x40, 0x22, 0x00, 0x10, 0x8b, 0x00, 0xa9, \n\t0x83, 0x00, 0x08, 0x85, 0x03, 0x38, 0x69, 0x59, 0x22, 0x54, 0xe1, 0xd0, 0xa0, 0xd4, 0x40, 0x29, \n\t0x12, 0x74, 0x20, 0x21, 0x54, 0x08, 0x08, 0x08, 0xc2, 0x22, 0x2b, 0x90, 0x14, 0x01, 0x4a, 0x53, \n\t0x30, 0x01, 0x30, 0x18, 0x40, 0x44, 0x84, 0x98, 0x30, 0x1c, 0x02, 0x04, 0x10, 0x61, 0x29, 0x08, \n\t0x4c, 0x02, 0x61, 0x10, 0x04, 0x60, 0x98, 0xd0, 0x08, 0x8b, 0x00, 0x14, 0x92, 0x2c, 0x61, 0x06, \n\t0x85, 0x0a, 0x12, 0xa1, 0x1b, 0xe0, 0x83, 0x88, 0x5c, 0x21, 0x48, 0x20, 0x30, 0x41, 0x8a, 0x46, \n\t0x84, 0x50, 0x0e, 0x09, 0x01, 0x05, 0x70, 0x40, 0x81, 0x02, 0x14, 0x01, 0xc8, 0x00, 0xd5, 0x01, \n\t0x20, 0x00, 0x0d, 0x4f, 0x58, 0x00, 0xe0, 0x90, 0x08, 0x50, 0x09, 0x0a, 0x23, 0xcb, 0x0c, 0x09, \n\t0xc4, 0x02, 0x26, 0x86, 0x58, 0x0d, 0x0c, 0x94, 0x41, 0x5a, 0xd2, 0x18, 0x04, 0x80, 0x02, 0x06, \n\t0x40, 0x14, 0xc0, 0x04, 0x11, 0x08, 0x04, 0x42, 0x60, 0x20, 0x03, 0x48, 0xc1, 0x80, 0x42, 0x15, \n\t0x50, 0x18, 0xc1, 0x14, 0x2a, 0x24, 0x55, 0x58, 0x14, 0x64, 0x54, 0x69, 0x20, 0x04, 0x91, 0x90, \n\t0x60, 0x50, 0xc8, 0x22, 0x23, 0x40, 0x21, 0x01, 0x4e, 0x65, 0x08, 0x25, 0x00, 0x18, 0x01, 0x0c, \n\t0x03, 0x20, 0x04, 0xe1, 0x91, 0x34, 0xc1, 0x68, 0x30, 0x41, 0x10, 0x02, 0x21, 0x12, 0x0a, 0x00, \n\t0x04, 0xf0, 0x2c, 0x58, 0x04, 0x8d, 0x00, 0x80, 0x2b, 0xa8, 0x70, 0x16, 0x65, 0x08, 0xc2, 0x80, \n\t0x12, 0x8c, 0x82, 0x44, 0x48, 0x20, 0x30, 0x14, 0x04, 0xc0, 0x81, 0x20, 0x02, 0x42, 0xb0, 0x00, \n\t0x46, 0x80, 0x18, 0x14, 0x02, 0x10, 0x38, 0x4a, 0xc2, 0x60, 0xc0, 0x6a, 0x0a, 0x88, 0x4c, 0x88, \n\t0x20, 0x21, 0xc2, 0x0b, 0xe8, 0xc4, 0xa4, 0x04, 0x40, 0x00, 0x0a, 0x60, 0x58, 0x4c, 0x18, 0x72, \n\t0x89, 0x23, 0x00, 0x0a, 0x20, 0x2a, 0x26, 0x02, 0x08, 0x88, 0x10, 0x04, 0x14, 0x80, 0x20, 0x31, \n\t0x3c, 0x54, 0xc0, 0x00, 0x81, 0xa3, 0x80, 0x44, 0x00, 0x66, 0x24, 0x81, 0x43, 0x16, 0x81, 0x18, \n\t0x87, 0x06, 0x14, 0x20, 0x15, 0x00, 0x04, 0x23, 0x04, 0x46, 0xe2, 0x3f, 0x00, 0x03, 0x04, 0x54, \n\t0x30, 0x61, 0x12, 0xc0, 0x02, 0x41, 0x46, 0x21, 0xc3, 0x8a, 0x14, 0x08, 0x26, 0x30, 0x24, 0x48, \n\t0x21, 0x0d, 0x07, 0xa1, 0x18, 0xa2, 0x70, 0x06, 0x00, 0x92, 0x00, 0x78, 0x47, 0x20, 0xb0, 0x0c, \n\t0x55, 0x00, 0x2e, 0xe2, 0x20, 0x88, 0xb1, 0x8a, 0x8c, 0x02, 0x02, 0x03, 0x0c, 0x81, 0x50, 0x83, \n\t0x44, 0x93, 0x00, 0x26, 0xc1, 0x04, 0x40, 0x20, 0xf1, 0x01, 0x20, 0xc8, 0x11, 0x4e, 0x2e, 0x00, \n\t0x20, 0x23, 0x51, 0x50, 0x20, 0x7c, 0x06, 0x81, 0x08, 0x48, 0x4c, 0x82, 0x14, 0x00, 0xca, 0xa5, \n\t0x44, 0x17, 0x00, 0x08, 0x02, 0x0a, 0x9a, 0x50, 0x10, 0x40, 0x22, 0x40, 0x01, 0x08, 0x75, 0x80, \n\t0x2a, 0x02, 0x46, 0x21, 0x8a, 0x24, 0x49, 0x81, 0x0a, 0x94, 0x03, 0x8d, 0x04, 0x00, 0x24, 0x48, \n\t0xa0, 0x3a, 0x02, 0x01, 0x4c, 0x09, 0x48, 0x22, 0x42, 0x08, 0xc0, 0x13, 0xac, 0x08, 0xb2, 0x91, \n\t0x00, 0x04, 0x98, 0x41, 0x64, 0x01, 0xc1, 0x2a, 0x40, 0x83, 0x21, 0x64, 0x33, 0x1a, 0x08, 0x00, \n\t0x00, 0x20, 0x12, 0x94, 0x4b, 0x95, 0xcc, 0x58, 0x04, 0x20, 0x54, 0x48, 0xa0, 0xa9, 0x08, 0x43, \n\t0x20, 0x01, 0xd0, 0xa0, 0xe1, 0x40, 0x04, 0x06, 0xb7, 0x91, 0x01, 0x29, 0xcb, 0xe0, 0x20, 0x25, \n\t0x18, 0x24, 0x84, 0x00, 0xc0, 0x10, 0x50, 0x01, 0x01, 0x38, 0x00, 0x2c, 0x00, 0x67, 0xa1, 0x18, \n\t0x90, 0x00, 0x8d, 0x68, 0x04, 0x70, 0x28, 0x18, 0x87, 0x83, 0x16, 0x30, 0x62, 0x0c, 0x14, 0x10, \n\t0xaa, 0x30, 0x17, 0xa2, 0xa5, 0xc9, 0x92, 0x44, 0x20, 0xb2, 0x0a, 0x03, 0x5d, 0x01, 0xc4, 0x4e, \n\t0x10, 0x8a, 0x21, 0x40, 0x90, 0x80, 0x2a, 0x24, 0x00, 0x21, 0xf0, 0x41, 0x42, 0x56, 0x02, 0x02, \n\t0x14, 0x60, 0x49, 0x20, 0x02, 0x04, 0x81, 0xa2, 0x08, 0x40, 0x42, 0x00, 0x00, 0x20, 0x23, 0x31, \n\t0x04, 0x88, 0x40, 0x01, 0x61, 0x84, 0x28, 0x46, 0x0c, 0x48, 0xb1, 0xb2, 0x06, 0x20, 0x08, 0x8e, \n\t0x72, 0x30, 0x99, 0x15, 0x31, 0x44, 0x0d, 0x04, 0xa2, 0x63, 0x84, 0x21, 0x90, 0xa2, 0x00, 0xc4, \n\t0x41, 0x05, 0x1c, 0xc8, 0x05, 0x28, 0x11, 0x18, 0x02, 0x49, 0x03, 0x00, 0x18, 0x15, 0xd0, 0xa2, \n\t0x0c, 0xc0, 0x26, 0x46, 0x04, 0x28, 0x02, 0x1d, 0xd1, 0x01, 0x54, 0xe3, 0x8a, 0x80, 0x00, 0x10, \n\t0xce, 0x04, 0x02, 0x10, 0xa3, 0x70, 0x04, 0x03, 0x26, 0x97, 0x09, 0xb3, 0x90, 0x96, 0x00, 0x18, \n\t0x82, 0xc8, 0x21, 0x1c, 0x5c, 0x61, 0x00, 0x41, 0x42, 0x05, 0x80, 0x88, 0x21, 0x08, 0xa0, 0x10, \n\t0x09, 0x15, 0xc0, 0x00, 0x40, 0x01, 0xa8, 0x09, 0x68, 0x1a, 0x8a, 0x50, 0x80, 0xc0, 0x23, 0x80, \n\t0x52, 0xc9, 0x00, 0x47, 0x82, 0x22, 0x01, 0x45, 0x45, 0x40, 0x51, 0x78, 0x05, 0x21, 0x0a, 0x84, \n\t0x66, 0x44, 0x1a, 0x82, 0x01, 0x4b, 0x23, 0x70, 0x45, 0xb0, 0x84, 0x48, 0x40, 0x49, 0x32, 0x10, \n\t0x11, 0x08, 0x98, 0x00, 0x81, 0x28, 0x61, 0x41, 0x0d, 0x14, 0x83, 0x84, 0x20, 0x16, 0x41, 0x96, \n\t0xa0, 0x91, 0x08, 0x2c, 0x70, 0x80, 0x83, 0x51, 0x48, 0x20, 0x28, 0x14, 0x90, 0x01, 0xd9, 0x11, \n\t0x24, 0x5a, 0x21, 0x70, 0x03, 0x38, 0x86, 0xa8, 0x04, 0x20, 0x43, 0x28, 0x08, 0x88, 0x43, 0x6c, \n\t0x86, 0x80, 0x85, 0x28, 0x0a, 0x87, 0x04, 0x41, 0x89, 0x32, 0x00, 0x50, 0x28, 0x12, 0x50, 0x38, \n\t0xb0, 0x80, 0x88, 0xaa, 0x10, 0x24, 0x28, 0x0a, 0xb1, 0x40, 0x22, 0x16, 0x65, 0x10, 0xa9, 0x09, \n\t0x09, 0xc1, 0x04, 0x02, 0x59, 0x1c, 0x84, 0x14, 0x42, 0x02, 0x62, 0x89, 0x0c, 0x20, 0x09, 0x64, \n\t0x40, 0x82, 0x49, 0x0a, 0x21, 0x97, 0x41, 0x52, 0x06, 0x13, 0x04, 0x40, 0x00, 0x62, 0x06, 0x80, \n\t0xa1, 0x84, 0x08, 0x90, 0x00, 0x08, 0x80, 0x60, 0x02, 0x18, 0x41, 0x84, 0x42, 0xe1, 0x82, 0x03, \n\t0x10, 0x40, 0x21, 0x50, 0x02, 0x42, 0x84, 0x04, 0x4a, 0x0a, 0x4a, 0x11, 0xa3, 0x82, 0xac, 0x99, \n\t0x08, 0x56, 0x23, 0x01, 0x0a, 0x8c, 0x5c, 0xa4, 0x46, 0x34, 0x00, 0x88, 0x1c, 0x82, 0x0d, 0x32, \n\t0x11, 0x00, 0x33, 0x81, 0x01, 0x40, 0x08, 0x00, 0x08, 0x2e, 0x80, 0x10, 0x28, 0x68, 0x61, 0x29, \n\t0x02, 0x80, 0x00, 0x46, 0x40, 0x30, 0xa9, 0x00, 0x98, 0x13, 0x2c, 0x10, 0xb0, 0x89, 0x01, 0x30, \n\t0x8c, 0x86, 0x30, 0x23, 0x50, 0x03, 0x00, 0x40, 0x02, 0x08, 0x80, 0xa0, 0x25, 0x10, 0x08, 0xe6, \n\t0x16, 0x04, 0x40, 0x98, 0x20, 0x16, 0x0c, 0x54, 0x41, 0xd2, 0x10, 0x30, 0x12, 0x00, 0x1a, 0x42, \n\t0x82, 0x30, 0x45, 0x19, 0xad, 0x40, 0x83, 0x4a, 0x91, 0xa8, 0x81, 0x00, 0x12, 0x02, 0x51, 0x00, \n\t0x20, 0x9a, 0x04, 0x40, 0x64, 0x68, 0x3c, 0x30, 0xda, 0x41, 0x62, 0xb0, 0x18, 0x10, 0xe9, 0x41, \n\t0x80, 0x0c, 0x36, 0x62, 0x2c, 0x15, 0x85, 0x69, 0x08, 0x11, 0x01, 0x08, 0x68, 0x82, 0x0c, 0x7c, \n\t0x04, 0x32, 0x1a, 0x95, 0x00, 0x6d, 0x60, 0x50, 0x10, 0x87, 0x25, 0x0c, 0x00, 0x4c, 0x80, 0x11, \n\t0x28, 0x80, 0x44, 0x26, 0x58, 0x11, 0x80, 0x85, 0x25, 0x16, 0x4a, 0x0c, 0x41, 0x88, 0x10, 0x04, \n\t0x08, 0x42, 0x42, 0x84, 0x43, 0x80, 0x94, 0x48, 0x02, 0x02, 0x47, 0x49, 0x95, 0x70, 0x09, 0xc0, \n\t0x00, 0x00, 0x09, 0x1a, 0xa4, 0x01, 0x05, 0x20, 0x80, 0x00, 0x09, 0x50, 0x4a, 0x6e, 0x30, 0xb0, \n\t0x00, 0x10, 0x8d, 0x01, 0xaa, 0x0a, 0xd1, 0x4a, 0x07, 0x21, 0x80, 0xa6, 0x00, 0x20, 0x12, 0x2c, \n\t0x48, 0x82, 0x40, 0x20, 0x51, 0x98, 0x24, 0x65, 0x86, 0x20, 0x2a, 0xd0, 0x02, 0x1d, 0x69, 0x08, \n\t0xa0, 0x18, 0x30, 0x43, 0x01, 0x81, 0xca, 0x48, 0x30, 0x21, 0x90, 0xa2, 0x99, 0x00, 0x4d, 0x04, \n\t0x45, 0x80, 0x02, 0x08, 0xc8, 0x08, 0x0c, 0xd2, 0x60, 0xab, 0x75, 0x41, 0x00, 0x30, 0x86, 0x60, \n\t0x04, 0x30, 0x44, 0x29, 0x14, 0x47, 0x32, 0x94, 0x50, 0x0c, 0x80, 0x64, 0xb0, 0x40, 0x0c, 0xd4, \n\t0x14, 0x80, 0x1c, 0x00, 0x18, 0x28, 0xcd, 0x8c, 0x08, 0x00, 0x54, 0xe3, 0x38, 0x04, 0xc0, 0x69, \n\t0x40, 0x45, 0x38, 0xa0, 0x05, 0xc9, 0x22, 0x10, 0x83, 0x20, 0x9c, 0x0c, 0x93, 0x88, 0x60, 0x00, \n\t0x53, 0x94, 0x40, 0x16, 0x22, 0x3c, 0x20, 0x3a, 0x00, 0x14, 0x01, 0xc1, 0x04, 0x86, 0x08, 0x20, \n\t0x40, 0x88, 0x00, 0x30, 0x83, 0x48, 0x18, 0xb0, 0x11, 0x47, 0x08, 0x20, 0xe2, 0x22, 0x80, 0x4f, \n\t0x20, 0x08, 0x80, 0x92, 0x01, 0xa8, 0x05, 0x05, 0x22, 0x04, 0xd3, 0x10, 0xc1, 0x00, 0x8e, 0x0a, \n\t0xc1, 0x00, 0x08, 0x44, 0x0e, 0x4a, 0x48, 0x23, 0x40, 0x80, 0x44, 0x8a, 0x07, 0x40, 0x50, 0x98, \n\t0x37, 0x28, 0x10, 0x66, 0x02, 0x94, 0x69, 0x04, 0x29, 0x10, 0x22, 0x30, 0x40, 0x23, 0x14, 0x74, \n\t0xc4, 0x40, 0x0e, 0x02, 0x00, 0x94, 0x00, 0x09, 0xe8, 0x44, 0x21, 0x90, 0x12, 0x84, 0x81, 0x46, \n\t0x04, 0x46, 0x31, 0x8a, 0x05, 0xc9, 0x01, 0x50, 0x46, 0xc0, 0x07, 0x10, 0xc0, 0x0c, 0x02, 0x84, \n\t0xc0, 0x10, 0x08, 0x80, 0x49, 0x06, 0x02, 0x21, 0x04, 0x24, 0x96, 0x40, 0x04, 0x41, 0x1b, 0x0a, \n\t0x2c, 0x02, 0xca, 0x54, 0x20, 0x03, 0x81, 0xc4, 0x0a, 0x83, 0x40, 0xd2, 0x22, 0x0c, 0x20, 0x46, \n\t0x00, 0x20, 0x40, 0x1b, 0x20, 0x4c, 0x8d, 0x80, 0x6c, 0x60, 0x99, 0x17, 0xd1, 0x45, 0x20, 0x10, \n\t0x22, 0x40, 0xae, 0x00, 0x1c, 0x44, 0x50, 0xb0, 0x10, 0x03, 0x74, 0xc8, 0x41, 0x34, 0x36, 0x40, \n\t0xb1, 0x40, 0x19, 0x00, 0x00, 0x27, 0xc2, 0x22, 0x80, 0x02, 0x61, 0x00, 0xf0, 0x2b, 0x02, 0xb0, \n\t0x40, 0x09, 0x4c, 0x14, 0x09, 0x08, 0x34, 0x04, 0x49, 0x00, 0x92, 0x41, 0xa4, 0x60, 0x08, 0x48, \n\t0x70, 0x21, 0x62, 0xb5, 0x45, 0x13, 0xa8, 0x00, 0x80, 0xb2, 0x10, 0x40, 0x0d, 0x03, 0x30, 0x05, \n\t0x90, 0x11, 0x29, 0x48, 0x8e, 0x40, 0x01, 0x52, 0x11, 0x68, 0x80, 0x89, 0x62, 0x46, 0xa3, 0x28, \n\t0x40, 0x11, 0x00, 0x40, 0xc3, 0xc1, 0x01, 0x11, 0xc5, 0xa9, 0x10, 0x90, 0x11, 0x30, 0x81, 0xc3, \n\t0x06, 0x72, 0x21, 0x03, 0x88, 0x00, 0x03, 0x04, 0x12, 0xa5, 0x60, 0x92, 0x59, 0x04, 0xa1, 0x08, \n\t0x24, 0x21, 0x00, 0xa0, 0x02, 0x24, 0x42, 0x72, 0x10, 0x82, 0x08, 0x80, 0x00, 0x3c, 0x35, 0x11, \n\t0x0b, 0x50, 0x11, 0x48, 0x08, 0xb6, 0x90, 0x11, 0x00, 0x15, 0x00, 0x46, 0x42, 0x00, 0x03, 0xa0, \n\t0x86, 0x02, 0x04, 0x44, 0x09, 0x90, 0x00, 0x18, 0x09, 0x16, 0x02, 0x81, 0x2a, 0x49, 0x1c, 0x0b, \n\t0x50, 0xd1, 0xc0, 0x11, 0x30, 0x03, 0x0d, 0x08, 0xc5, 0x00, 0x88, 0x04, 0x12, 0xc4, 0x20, 0xb0, \n\t0x21, 0x23, 0x00, 0x8f, 0x0c, 0x74, 0x53, 0x91, 0x98, 0x31, 0x10, 0xc0, 0x18, 0xb0, 0x3a, 0x24, \n\t0xf0, 0xc2, 0x00, 0x42, 0x83, 0x82, 0x82, 0x5c, 0x08, 0xa9, 0x20, 0x20, 0x62, 0x07, 0x01, 0x01, \n\t0x03, 0x06, 0xc4, 0x10, 0x05, 0x48, 0xd1, 0x20, 0x2a, 0x42, 0x1a, 0x80, 0x40, 0x52, 0x0e, 0x10, \n\t0x24, 0x11, 0x84, 0x08, 0x41, 0x62, 0x68, 0x25, 0xc0, 0x36, 0x31, 0x41, 0xc0, 0x12, 0x06, 0x01, \n\t0x82, 0x65, 0x0c, 0xaa, 0x24, 0xa0, 0x20, 0x81, 0x10, 0xc4, 0x00, 0x18, 0x05, 0x61, 0x08, 0x10, \n\t0x02, 0x21, 0x4a, 0x51, 0xe2, 0x00, 0xa0, 0x04, 0x82, 0x0a, 0xa2, 0x30, 0x15, 0xcd, 0xd5, 0x22, \n\t0x16, 0x81, 0x08, 0x04, 0xb9, 0x86, 0x01, 0x40, 0x15, 0x23, 0x24, 0x0c, 0x0a, 0x82, 0x60, 0x85, \n\t0x88, 0x0c, 0x01, 0x80, 0x41, 0x50, 0x10, 0x08, 0x3a, 0xa0, 0x81, 0x02, 0x50, 0x34, 0x21, 0x04, \n\t0x5d, 0x50, 0xe1, 0x48, 0x07, 0x0a, 0x0c, 0xd0, 0x01, 0x82, 0x40, 0x24, 0x41, 0x8a, 0x71, 0xc5, \n\t0x24, 0x10, 0xb3, 0x49, 0x04, 0xa1, 0x4c, 0x0a, 0x02, 0xc2, 0x00, 0x82, 0x00, 0x4f, 0x08, 0x02, \n\t0x05, 0x00, 0x08, 0x39, 0x18, 0x8b, 0x04, 0x10, 0x78, 0x20, 0x21, 0xd5, 0x46, 0x02, 0x42, 0x82, \n\t0x06, 0x70, 0x00, 0x44, 0x08, 0x10, 0x90, 0x10, 0x14, 0x4a, 0x08, 0x26, 0xe0, 0x12, 0x8c, 0x18, \n\t0x0a, 0x04, 0x28, 0xc5, 0x01, 0xb3, 0xa0, 0x08, 0x04, 0x48, 0x74, 0x30, 0x12, 0x58, 0x47, 0x83, \n\t0x30, 0x04, 0x39, 0x02, 0x81, 0x01, 0x22, 0x02, 0x96, 0x02, 0x11, 0x44, 0xc0, 0x08, 0x38, 0x94, \n\t0x60, 0x0a, 0xa5, 0x4c, 0xcd, 0x60, 0x91, 0x02, 0x24, 0x80, 0x9c, 0x20, 0x4e, 0x60, 0x68, 0x01, \n\t0x50, 0x01, 0x6c, 0x04, 0x12, 0xc8, 0x10, 0x68, 0x40, 0x8a, 0x02, 0x03, 0x01, 0x83, 0x00, 0x94, \n\t0x00, 0x40, 0xe0, 0xf1, 0x20, 0x19, 0x48, 0x84, 0x04, 0x00, 0x10, 0x89, 0x10, 0x1a, 0x81, 0x14, \n\t0x00, 0x00, 0x03, 0x20, 0x55, 0x24, 0x60, 0x21, 0x11, 0x84, 0x09, 0x4d, 0x82, 0x00, 0x05, 0x23, \n\t0x02, 0x81, 0x09, 0xe1, 0x26, 0x02, 0x42, 0x29, 0x58, 0x82, 0x21, 0x00, 0x22, 0x40, 0x04, 0x05, \n\t0x81, 0xcc, 0x7a, 0x42, 0xa0, 0x8c, 0x84, 0x50, 0x4d, 0x50, 0x06, 0xc0, 0x00, 0x90, 0x83, 0x0c, \n\t0x72, 0x00, 0x98, 0x18, 0x41, 0x81, 0x4b, 0x0e, 0x70, 0x28, 0x20, 0x28, 0x10, 0x60, 0x38, 0x17, \n\t0xa1, 0x99, 0x10, 0x02, 0x41, 0x40, 0x82, 0x82, 0x82, 0x05, 0x14, 0x24, 0x04, 0x01, 0xb1, 0x14, \n\t0x48, 0x98, 0xa2, 0x0a, 0x30, 0x20, 0x06, 0x20, 0x05, 0x02, 0x0c, 0x61, 0x41, 0x16, 0x20, 0x09, \n\t0x22, 0x54, 0x14, 0x01, 0xa8, 0x34, 0x81, 0xa8, 0x12, 0x60, 0x40, 0x97, 0x10, 0x83, 0x40, 0x40, \n\t0x40, 0x48, 0x17, 0x90, 0x02, 0x28, 0x28, 0x40, 0x89, 0x10, 0x09, 0x94, 0x00, 0x44, 0x92, 0x82, \n\t0x19, 0xc1, 0x83, 0x08, 0x10, 0xc3, 0x00, 0x0a, 0x24, 0x18, 0x25, 0x00, 0x07, 0x41, 0x10, 0x01, \n\t0x89, 0x28, 0x20, 0x22, 0x80, 0x82, 0x70, 0x5a, 0x06, 0x12, 0x44, 0x33, 0x00, 0xc1, 0x0a, 0x00, \n\t0x26, 0x20, 0x00, 0x21, 0xa8, 0x5c, 0x81, 0x18, 0x84, 0x5a, 0x9c, 0x19, 0x54, 0xa0, 0x66, 0x45, \n\t0x10, 0x2b, 0x9c, 0x0c, 0x00, 0x32, 0x01, 0x28, 0x19, 0x44, 0x1a, 0x87, 0x72, 0x82, 0x20, 0x34, \n\t0xa0, 0x02, 0x04, 0x08, 0x60, 0x11, 0x13, 0x00, 0x01, 0x23, 0x26, 0x26, 0x5a, 0x29, 0x80, 0x43, \n\t0x88, 0x48, 0x00, 0x90, 0x0a, 0x64, 0x80, 0xce, 0x08, 0x80, 0x90, 0x09, 0x80, 0x52, 0x61, 0x60, \n\t0x60, 0x98, 0x29, 0x54, 0x09, 0x07, 0x44, 0x13, 0x8a, 0x11, 0x20, 0x19, 0x24, 0x28, 0x55, 0x82, \n\t0x93, 0x88, 0x8a, 0x82, 0x04, 0xc5, 0x29, 0x08, 0x80, 0x05, 0x48, 0x20, 0xc1, 0xc1, 0x88, 0xdc, \n\t0x82, 0x22, 0x06, 0x05, 0x38, 0x3c, 0x50, 0x92, 0x45, 0x0a, 0x20, 0xc3, 0x00, 0x10, 0x1b, 0x4c, \n\t0x5a, 0x30, 0x40, 0x0e, 0x29, 0x04, 0x61, 0x02, 0x32, 0x70, 0x00, 0x19, 0x05, 0x89, 0x42, 0x60, \n\t0x42, 0x89, 0x00, 0x02, 0x06, 0x68, 0x06, 0x30, 0xa4, 0x84, 0x49, 0xeb, 0x40, 0x55, 0x1a, 0x88, \n\t0x01, 0x44, 0xa5, 0x04, 0xd2, 0x81, 0x8f, 0x89, 0x11, 0x28, 0x40, 0x60, 0x1b, 0x85, 0xd1, 0x08, \n\t0x41, 0x40, 0x82, 0x0b, 0xb4, 0xb1, 0x0d, 0x64, 0x24, 0x10, 0x0b, 0x01, 0xa4, 0x03, 0x82, 0x0c, \n\t0x03, 0x60, 0x03, 0x54, 0x54, 0xc6, 0x60, 0x60, 0xa2, 0x17, 0x00, 0x1c, 0x08, 0x04, 0x21, 0xf8, \n\t0x94, 0x01, 0x83, 0xab, 0x00, 0x30, 0x10, 0x00, 0x24, 0x00, 0x04, 0x1e, 0x01, 0x60, 0x00, 0x51, \n\t0x88, 0x47, 0x04, 0x84, 0x01, 0x06, 0x95, 0x12, 0x60, 0x40, 0x20, 0x20, 0x02, 0x41, 0xc9, 0x40, \n\t0x32, 0x85, 0x90, 0x2f, 0x84, 0x8e, 0x20, 0x4c, 0x15, 0x71, 0x01, 0x28, 0xc2, 0x00, 0x18, 0x82, \n\t0x00, 0x18, 0x44, 0x50, 0x2d, 0x62, 0x22, 0x58, 0x80, 0x34, 0xc5, 0x68, 0x02, 0xb6, 0x00, 0x02, \n\t0x71, 0xc1, 0x08, 0x00, 0x50, 0x0a, 0x93, 0x84, 0x10, 0x00, 0x2a, 0x02, 0x6b, 0x80, 0x39, 0x17, \n\t0xcd, 0x20, 0x04, 0x00, 0x31, 0x00, 0x00, 0x02, 0x48, 0xb0, 0xa8, 0xac, 0x01, 0x84, 0xc4, 0x2c, \n\t0x41, 0x32, 0x18, 0x40, 0x80, 0x04, 0x0a, 0x10, 0x90, 0x20, 0x20, 0x17, 0x40, 0x10, 0x46, 0x13, \n\t0x18, 0x08, 0x00, 0xac, 0x00, 0x30, 0x00, 0x82, 0x88, 0x08, 0x81, 0x04, 0x40, 0x88, 0x10, 0x49, \n\t0x00, 0x21, 0x14, 0x03, 0x00, 0x10, 0x01, 0x81, 0xc1, 0x30, 0xa2, 0x08, 0x94, 0xf4, 0x01, 0x80, \n\t0x28, 0x13, 0xc1, 0x09, 0xa4, 0x95, 0x21, 0x12, 0x00, 0x49, 0x03, 0xd0, 0xc5, 0x42, 0x56, 0x16, \n\t0x00, 0x05, 0x05, 0x92, 0x64, 0x06, 0x40, 0x60, 0x02, 0x75, 0x0c, 0x2e, 0x08, 0x05, 0x40, 0x22, \n\t0x01, 0x10, 0x81, 0x02, 0xd0, 0x12, 0x30, 0x4d, 0x85, 0x40, 0x0a, 0x16, 0x2a, 0x20, 0x80, 0x84, \n\t0x04, 0x34, 0x30, 0x09, 0x01, 0x8c, 0x46, 0xe0, 0x34, 0x81, 0x3a, 0x38, 0x80, 0x09, 0x81, 0x30, \n\t0x14, 0x02, 0x03, 0xd5, 0x03, 0x07, 0x02, 0x45, 0x40, 0x89, 0x81, 0x40, 0x40, 0x00, 0x15, 0x00, \n\t0x87, 0x24, 0x50, 0x2c, 0x44, 0x60, 0x80, 0x0d, 0x68, 0x59, 0xc4, 0x28, 0xa0, 0x72, 0x01, 0x05, \n\t0x52, 0x48, 0x04, 0x02, 0x88, 0x05, 0xc8, 0x80, 0x42, 0x0c, 0x63, 0xa1, 0x30, 0x88, 0xc2, 0xce, \n\t0x28, 0xd6, 0x20, 0x0a, 0x18, 0x04, 0x41, 0x24, 0x04, 0xa2, 0x28, 0xe4, 0x46, 0xa8, 0x08, 0x70, \n\t0x08, 0xa1, 0x54, 0x85, 0x02, 0x6c, 0x20, 0x11, 0xa0, 0x40, 0x1c, 0x08, 0x54, 0x70, 0x00, 0x18, \n\t0x99, 0x0a, 0xa8, 0x10, 0xa2, 0x08, 0xb8, 0x84, 0xc0, 0x0d, 0x18, 0x81, 0x21, 0x8a, 0x28, 0xc0, \n\t0x61, 0x02, 0xc4, 0x90, 0x01, 0x89, 0x1e, 0x02, 0x00, 0x24, 0x81, 0x04, 0x41, 0x05, 0x80, 0x4c, \n\t0x20, 0xb0, 0x84, 0x54, 0x80, 0x44, 0x4c, 0xb2, 0xa1, 0x00, 0x85, 0x08, 0x00, 0x42, 0x32, 0x02, \n\t0xae, 0x08, 0xd8, 0x05, 0x48, 0x10, 0xc3, 0x26, 0x0c, 0x1a, 0xa2, 0x20, 0x04, 0x80, 0x00, 0x0d, \n\t0x12, 0x83, 0x4c, 0xc1, 0x11, 0x8a, 0x28, 0x04, 0x04, 0x56, 0x81, 0x8b, 0x01, 0x28, 0x01, 0xc9, \n\t0x22, 0x74, 0x48, 0x31, 0x50, 0x00, 0x41, 0x28, 0x30, 0x00, 0x1a, 0x34, 0x0a, 0x40, 0x24, 0x85, \n\t0x1a, 0x12, 0x08, 0xd8, 0x85, 0x02, 0x84, 0x01, 0x31, 0x2d, 0x81, 0x80, 0x00, 0x73, 0xf2, 0x23, \n\t0x08, 0x80, 0x00, 0x54, 0x12, 0xc1, 0x29, 0x0d, 0x13, 0x04, 0x08, 0x54, 0xb0, 0x1c, 0x21, 0x01, \n\t0xc4, 0x76, 0x90, 0x21, 0xa2, 0x01, 0x04, 0x0a, 0x40, 0x01, 0x12, 0x04, 0x40, 0x08, 0x2a, 0x0e, \n\t0x00, 0xc2, 0x16, 0x74, 0x0c, 0xaa, 0x00, 0x80, 0x41, 0x83, 0x91, 0x06, 0x66, 0x06, 0x64, 0x60, \n\t0x95, 0x65, 0x02, 0x09, 0x50, 0x25, 0x08, 0x88, 0x20, 0x88, 0x25, 0x40, 0xa2, 0x6a, 0x1b, 0x60, \n\t0x8f, 0x48, 0x26, 0x20, 0x41, 0x14, 0x00, 0x81, 0x8c, 0x40, 0x82, 0x41, 0x8e, 0x15, 0x08, 0x68, \n\t0x38, 0x14, 0x00, 0x11, 0x8c, 0x41, 0xe2, 0x46, 0xe3, 0x88, 0x31, 0x01, 0x07, 0x82, 0x00, 0x03, \n\t0x82, 0x2a, 0xc9, 0xd3, 0x06, 0x6a, 0x64, 0x10, 0x06, 0x2c, 0x11, 0xa0, 0x60, 0xa6, 0x08, 0x82, \n\t0x90, 0x59, 0x80, 0x30, 0x92, 0x91, 0xa8, 0x10, 0x44, 0x01, 0x28, 0x40, 0x29, 0x00, 0x45, 0xd1, \n\t0x84, 0x12, 0x52, 0x00, 0xb2, 0x8c, 0x41, 0x65, 0x08, 0x22, 0x41, 0x88, 0x10, 0x1c, 0xa2, 0x44, \n\t0x02, 0x83, 0x18, 0x18, 0x16, 0x03, 0x4a, 0xb0, 0x21, 0x03, 0x14, 0x12, 0x8a, 0x40, 0x91, 0x60, \n\t0x04, 0x50, 0x0b, 0x0b, 0x20, 0xd0, 0x02, 0x90, 0x14, 0x06, 0x60, 0x20, 0x10, 0x59, 0x00, 0x09, \n\t0x0a, 0x24, 0x00, 0x14, 0x62, 0x91, 0x10, 0x80, 0x69, 0x54, 0x20, 0x42, 0xa8, 0x44, 0x44, 0xcb, \n\t0x00, 0x00, 0x00, 0x0b, 0x04, 0x40, 0x89, 0x30, 0x81, 0x79, 0x02, 0x40, 0x41, 0x8e, 0x50, 0x14, \n\t0x01, 0xa0, 0x38, 0xd8, 0x01, 0x08, 0x90, 0x01, 0x92, 0xd1, 0x85, 0x60, 0x00, 0x80, 0xd1, 0x38, \n\t0xa0, 0x44, 0x48, 0x0a, 0x80, 0xc0, 0x29, 0xf4, 0x1a, 0x88, 0x44, 0x05, 0x32, 0x20, 0x05, 0x49, \n\t0x49, 0x00, 0xe4, 0x30, 0x81, 0x40, 0x16, 0x82, 0x46, 0x83, 0xb8, 0x03, 0x41, 0x10, 0x2e, 0x10, \n\t0x71, 0x40, 0x24, 0x15, 0x00, 0x49, 0x0a, 0x04, 0x08, 0xbc, 0xc4, 0x00, 0xc2, 0x36, 0x21, 0x80, \n\t0x3a, 0x41, 0x02, 0xa0, 0x20, 0x10, 0x30, 0xa5, 0x00, 0x86, 0x49, 0x30, 0x42, 0x82, 0x90, 0x90, \n\t0xc8, 0x00, 0x12, 0x63, 0x20, 0x04, 0x01, 0x98, 0x49, 0x00, 0x10, 0x12, 0x38, 0xc8, 0xc4, 0x08, \n\t0x06, 0x82, 0xe8, 0x00, 0x09, 0x02, 0x06, 0x00, 0x90, 0x90, 0x0a, 0x1c, 0x02, 0x21, 0x02, 0x84, \n\t0xb0, 0x16, 0x2c, 0x04, 0xa2, 0x58, 0x54, 0xc9, 0x10, 0x61, 0x84, 0x04, 0x04, 0x31, 0x61, 0x90, \n\t0xb8, 0x07, 0x02, 0x40, 0x42, 0x19, 0x00, 0x38, 0x15, 0x4c, 0x42, 0x91, 0x9a, 0x9a, 0x00, 0x46, \n\t0x0e, 0x00, 0x20, 0x61, 0x8c, 0x20, 0x88, 0x02, 0x1a, 0xc7, 0x88, 0x21, 0x90, 0x0b, 0x00, 0x00, \n\t0x43, 0xa0, 0x06, 0xe1, 0x40, 0xa9, 0x20, 0x80, 0x1a, 0x09, 0x88, 0x10, 0x08, 0x4c, 0x00, 0x0b, \n\t0x28, 0x14, 0x18, 0x20, 0x04, 0x93, 0x83, 0x0e, 0x48, 0x40, 0x69, 0x2a, 0x24, 0xa8, 0xb3, 0x00, \n\t0x17, 0x24, 0x10, 0xc0, 0xc8, 0x10, 0x85, 0x40, 0x00, 0x6a, 0x20, 0xc1, 0xb4, 0x50, 0x1a, 0x23, \n\t0x5a, 0x20, 0x60, 0x08, 0x4c, 0x48, 0xc1, 0x04, 0x43, 0xc1, 0xb3, 0x60, 0x85, 0x41, 0x0c, 0x60, \n\t0x41, 0x0a, 0x30, 0xc2, 0x46, 0x40, 0x06, 0x40, 0x80, 0x28, 0xc6, 0x48, 0x18, 0x81, 0x50, 0x14, \n\t0x00, 0x4f, 0x84, 0x0c, 0xb2, 0x32, 0x00, 0x15, 0xc1, 0x62, 0x04, 0x60, 0x00, 0x00, 0x81, 0x82, \n\t0x40, 0x00, 0xc2, 0x02, 0x85, 0x51, 0x58, 0x28, 0x0c, 0xa4, 0x00, 0x21, 0x55, 0x10, 0x21, 0x2a, \n\t0x95, 0x10, 0x92, 0x20, 0x90, 0x2a, 0x62, 0x34, 0xe0, 0x10, 0x11, 0x80, 0x20, 0x36, 0x46, 0x02, \n\t0x38, 0x8c, 0x10, 0x00, 0x14, 0x06, 0x11, 0x82, 0x4d, 0x00, 0x00, 0x14, 0xc1, 0x00, 0x24, 0x60, \n\t0x06, 0x05, 0x02, 0x94, 0x41, 0x3a, 0x9c, 0x89, 0x04, 0x06, 0x22, 0x69, 0x14, 0x50, 0x8d, 0xc2, \n\t0x20, 0x04, 0x5a, 0x3c, 0xa9, 0x92, 0x00, 0x40, 0x90, 0x48, 0x8b, 0x88, 0x08, 0xa7, 0x50, 0x00, \n\t0xd2, 0x00, 0x11, 0x18, 0x68, 0x04, 0x03, 0x20, 0x06, 0x08, 0x10, 0x01, 0x18, 0x46, 0xa2, 0x01, \n\t0x84, 0xca, 0x2c, 0x26, 0x00, 0x81, 0xa1, 0x01, 0x92, 0x49, 0x20, 0x02, 0xd0, 0x10, 0xb0, 0x19, \n\t0x41, 0x64, 0x21, 0x02, 0x01, 0x04, 0x84, 0x4c, 0x20, 0x11, 0x50, 0xb0, 0x70, 0x0c, 0x88, 0x0a, \n\t0x05, 0x41, 0x01, 0x8c, 0x8e, 0x04, 0x50, 0x12, 0x10, 0x90, 0x28, 0xc1, 0xa4, 0x24, 0x86, 0x82, \n\t0x25, 0x60, 0x04, 0x80, 0x0a, 0xc1, 0x79, 0x08, 0x90, 0x80, 0x20, 0x44, 0xd4, 0x20, 0x1c, 0x99, \n\t0x40, 0xa4, 0x48, 0x85, 0x02, 0x89, 0x19, 0x01, 0xc0, 0x70, 0xc1, 0x22, 0x34, 0x81, 0x19, 0xa0, \n\t0x28, 0x24, 0x08, 0x82, 0x64, 0x87, 0xe9, 0x10, 0x46, 0xa8, 0x02, 0xc9, 0x09, 0x41, 0x56, 0x04, \n\t0x41, 0x20, 0x84, 0x40, 0x61, 0x02, 0xa5, 0x18, 0x2f, 0x21, 0x45, 0x40, 0x38, 0x22, 0x0a, 0x92, \n\t0x00, 0x1d, 0x04, 0x06, 0x04, 0xb8, 0x80, 0x80, 0x14, 0x81, 0x4a, 0x02, 0xc2, 0x01, 0xa1, 0x82, \n\t0x88, 0x02, 0x11, 0xba, 0xa8, 0x11, 0x08, 0x60, 0x68, 0x44, 0xc2, 0x15, 0x90, 0x18, 0x88, 0x28, \n\t0x21, 0x98, 0x1c, 0x41, 0x5a, 0xc2, 0x24, 0x00, 0x83, 0x04, 0x0c, 0x86, 0x0c, 0x10, 0x01, 0x28, \n\t0x20, 0xd5, 0x8e, 0x21, 0x2e, 0x04, 0x68, 0x04, 0x11, 0x40, 0xa2, 0x00, 0x03, 0x40, 0x3a, 0x21, \n\t0x01, 0x28, 0x0e, 0x90, 0x20, 0x80, 0xf0, 0x90, 0x41, 0x0a, 0x83, 0x4b, 0x8d, 0x84, 0x04, 0x24, \n\t0x32, 0x95, 0x01, 0x18, 0x08, 0x09, 0x42, 0x3a, 0x20, 0xc8, 0x10, 0x00, 0x83, 0x80, 0x08, 0x40, \n\t0x81, 0x80, 0x51, 0x00, 0x60, 0x00, 0xa5, 0x92, 0x23, 0x04, 0xca, 0x01, 0x04, 0x02, 0x32, 0x81, \n\t0x11, 0x1c, 0x04, 0x2c, 0x10, 0xa2, 0x0b, 0x04, 0x9c, 0x82, 0x2e, 0x41, 0x08, 0x15, 0x80, 0x8d, \n\t0x49, 0x40, 0x42, 0x42, 0x20, 0x08, 0x11, 0x06, 0x30, 0x14, 0x03, 0xa8, 0x30, 0x0e, 0x20, 0x28, \n\t0x10, 0x00, 0x3c, 0x11, 0x52, 0x89, 0x08, 0x61, 0xc0, 0x19, 0x84, 0xc4, 0x24, 0x1a, 0x50, 0x00, \n\t0x08, 0xa0, 0x02, 0x44, 0x0a, 0x20, 0x08, 0x20, 0x10, 0x95, 0x2e, 0x5e, 0x21, 0x40, 0x24, 0x20, \n\t0x84, 0x40, 0x14, 0x27, 0x00, 0xa6, 0x5c, 0x48, 0x88, 0x08, 0x47, 0x08, 0x13, 0x60, 0x10, 0xa2, \n\t0x64, 0x83, 0x01, 0xa8, 0x61, 0x02, 0x00, 0x4a, 0x54, 0x10, 0x21, 0x10, 0x1d, 0xe2, 0x22, 0x02, \n\t0x42, 0x16, 0x44, 0x00, 0x80, 0x04, 0x50, 0x81, 0x10, 0x30, 0x80, 0x0a, 0x12, 0x83, 0x18, 0x8c, \n\t0x84, 0x59, 0x01, 0x00, 0x25, 0x2a, 0x01, 0x0c, 0x4c, 0x01, 0x18, 0x00, 0x00, 0x87, 0x98, 0x0d, \n\t0x03, 0x58, 0x00, 0xc2, 0x30, 0xcd, 0x51, 0x26, 0x40, 0x20, 0x23, 0x04, 0x60, 0x80, 0x09, 0x34, \n\t0xd7, 0x92, 0xa8, 0x01, 0x89, 0x04, 0x20, 0x31, 0x10, 0x2f, 0x21, 0x01, 0x60, 0x52, 0x40, 0x41, \n\t0x90, 0x69, 0x96, 0x06, 0x22, 0x00, 0xc3, 0x02, 0xe5, 0x50, 0x4a, 0x40, 0xe1, 0x30, 0xb0, 0x00, \n\t0x54, 0x2a, 0x40, 0xe1, 0xd0, 0xa1, 0x35, 0x04, 0x05, 0x08, 0x04, 0x20, 0x8e, 0x00, 0x0d, 0x8b, \n\t0x50, 0x92, 0xa0, 0x14, 0x00, 0x18, 0x2d, 0x40, 0xb6, 0x80, 0x02, 0x80, 0x00, 0x47, 0x20, 0x24, \n\t0x50, 0x04, 0x8c, 0x02, 0x26, 0x10, 0x42, 0x12, 0x2b, 0xc5, 0x88, 0xa2, 0x50, 0x30, 0x43, 0x80, \n\t0x88, 0x11, 0xa8, 0x00, 0x14, 0x0a, 0x94, 0x48, 0x82, 0x80, 0x32, 0x87, 0x80, 0x09, 0x21, 0xcc, \n\t0x88, 0x58, 0x00, 0x5b, 0x92, 0x11, 0x88, 0x09, 0x46, 0x04, 0x21, 0x24, 0x01, 0x51, 0x44, 0x10, \n\t0x44, 0x03, 0x80, 0x00, 0x0b, 0x48, 0x1e, 0x61, 0x11, 0x08, 0x84, 0x06, 0x85, 0x02, 0x11, 0x88, \n\t0x01, 0x04, 0x45, 0x01, 0x2a, 0x81, 0x1a, 0x07, 0x08, 0x02, 0x0a, 0x2c, 0x12, 0xc1, 0x24, 0xf8, \n\t0x12, 0x62, 0x00, 0x32, 0x21, 0x08, 0x25, 0x94, 0x82, 0x00, 0x81, 0x60, 0x24, 0x14, 0xc2, 0x42, \n\t0x0a, 0x00, 0x30, 0x9e, 0x01, 0xd4, 0x00, 0x3c, 0x01, 0x30, 0x0d, 0x4c, 0x90, 0x0a, 0x48, 0x54, \n\t0x08, 0x17, 0xf0, 0x18, 0x88, 0x04, 0xc0, 0x91, 0x0e, 0x05, 0x04, 0x00, 0x54, 0x80, 0x02, 0x98, \n\t0x31, 0x80, 0x46, 0x2a, 0x44, 0x60, 0x85, 0x30, 0x1b, 0x4e, 0x00, 0x14, 0x08, 0x2a, 0x18, 0x10, \n\t0x00, 0x14, 0x64, 0x41, 0x01, 0x19, 0xda, 0x81, 0x00, 0x10, 0x48, 0x01, 0x20, 0x02, 0x42, 0x00, \n\t0xa0, 0x48, 0xa0, 0x80, 0x04, 0xc4, 0x04, 0xc1, 0x20, 0x0d, 0xd0, 0x00, 0x8f, 0x04, 0xb3, 0x28, \n\t0x24, 0x09, 0x05, 0x43, 0x20, 0x10, 0x23, 0x01, 0xe8, 0x0c, 0x00, 0x20, 0x20, 0x5a, 0x90, 0x05, \n\t0x8c, 0x00, 0x2c, 0x05, 0x61, 0x00, 0x0d, 0x04, 0x23, 0x10, 0xe2, 0x10, 0x11, 0xe1, 0x0b, 0x00, \n\t0x0c, 0x61, 0x48, 0x08, 0x80, 0x81, 0xc0, 0x6a, 0x37, 0x09, 0x88, 0x20, 0x94, 0x61, 0x7c, 0x10, \n\t0x20, 0x12, 0xf0, 0x0a, 0xa0, 0x00, 0x12, 0xa2, 0x28, 0x54, 0x06, 0x0d, 0x5a, 0x80, 0x00, 0x00, \n\t0xc8, 0x00, 0xa9, 0x48, 0xb0, 0x12, 0xb8, 0x00, 0xc8, 0xc4, 0x2a, 0x00, 0x20, 0xbf, 0x00, 0x08, \n\t0x84, 0x50, 0x12, 0x20, 0x26, 0x60, 0x82, 0x28, 0x24, 0x04, 0xf8, 0x02, 0x15, 0x8b, 0x00, 0x30, \n\t0xe1, 0x10, 0x80, 0x35, 0x41, 0x24, 0x22, 0x24, 0xc0, 0x80, 0x45, 0xc8, 0x80, 0x00, 0x10, 0x38, \n\t0x1c, 0x80, 0x54, 0x01, 0x3a, 0x12, 0x29, 0x10, 0x08, 0xc8, 0x60, 0x40, 0x20, 0x00, 0x07, 0xd1, \n\t0x09, 0x09, 0x78, 0xb6, 0xca, 0x35, 0x38, 0x01, 0x0c, 0x58, 0xc0, 0x20, 0x00, 0x38, 0x10, 0x2e, \n\t0x10, 0x86, 0x31, 0x02, 0xc4, 0x5a, 0x8e, 0x46, 0xe0, 0x92, 0x2a, 0x1c, 0x54, 0x25, 0x00, 0x52, \n\t0x42, 0x8d, 0x41, 0x45, 0x82, 0x20, 0x01, 0x11, 0x02, 0x58, 0x12, 0xc0, 0x00, 0x41, 0x00, 0x18, \n\t0x95, 0x15, 0x2a, 0x50, 0x24, 0xc2, 0x1a, 0x88, 0x0f, 0x00, 0x1a, 0xe0, 0x11, 0x30, 0x34, 0xc0, \n\t0x05, 0x60, 0x41, 0x20, 0x19, 0x00, 0x0a, 0x41, 0x48, 0x07, 0x99, 0x09, 0x88, 0x45, 0x2d, 0x22, \n\t0x82, 0x02, 0x04, 0x35, 0x00, 0x20, 0x04, 0x83, 0xc8, 0x82, 0xb5, 0x04, 0x8d, 0x28, 0x83, 0x43, \n\t0x83, 0x09, 0x08, 0x28, 0x20, 0xa3, 0x00, 0x11, 0x40, 0x0c, 0x80, 0x3a, 0xc0, 0xc3, 0x2a, 0x28, \n\t0x4b, 0x00, 0x4a, 0x40, 0x80, 0x33, 0x81, 0xd4, 0x20, 0x10, 0x84, 0x58, 0x04, 0x18, 0x58, 0xc0, \n\t0x00, 0xe5, 0x42, 0x2a, 0x70, 0x01, 0x08, 0x22, 0x30, 0x19, 0x11, 0xb5, 0x07, 0x8a, 0x10, 0x44, \n\t0x22, 0x90, 0x80, 0xc7, 0x48, 0x42, 0x91, 0x08, 0x11, 0x40, 0x8d, 0x22, 0x02, 0x04, 0xa0, 0x38, \n\t0x05, 0x40, 0x03, 0x08, 0x10, 0xc8, 0x28, 0x8c, 0x04, 0x00, 0x60, 0xa0, 0x02, 0x94, 0x55, 0x11, \n\t0x41, 0x6a, 0x52, 0xb8, 0xa4, 0x24, 0x08, 0xa5, 0x14, 0x12, 0x08, 0x38, 0xc1, 0x11, 0x00, 0x02, \n\t0x01, 0x41, 0x02, 0xc0, 0x49, 0x6a, 0x02, 0x05, 0x8b, 0x80, 0x04, 0x00, 0xa1, 0x00, 0x01, 0x81, \n\t0x80, 0x81, 0x82, 0x8b, 0x0c, 0x14, 0x30, 0x25, 0x44, 0x87, 0x00, 0x42, 0x10, 0x02, 0x18, 0xa8, \n\t0x84, 0x4c, 0x14, 0x60, 0x99, 0x18, 0x88, 0x14, 0x85, 0x60, 0x16, 0x41, 0x20, 0x1d, 0x96, 0x08, \n\t0x42, 0x30, 0x59, 0x24, 0x65, 0x08, 0x26, 0x60, 0x83, 0x22, 0x8c, 0x11, 0x52, 0x08, 0x00, 0x63, \n\t0xa0, 0x88, 0x01, 0x01, 0xa4, 0x06, 0x82, 0x90, 0x83, 0x60, 0x01, 0x04, 0x26, 0x44, 0x62, 0x24, \n\t0x90, 0x01, 0xc0, 0x38, 0x01, 0x01, 0x9c, 0x10, 0x18, 0x4d, 0x16, 0xd1, 0x40, 0xa0, 0xc0, 0x00, \n\t0x06, 0x36, 0xc0, 0x41, 0x1a, 0x94, 0x04, 0xc4, 0x22, 0xe6, 0x00, 0x90, 0x00, 0x46, 0x2d, 0x06, \n\t0x41, 0x02, 0x00, 0x39, 0x93, 0x23, 0x4a, 0x00, 0x01, 0x04, 0x4c, 0x93, 0x44, 0x00, 0x22, 0x49, \n\t0x08, 0x48, 0x12, 0x22, 0x04, 0x02, 0xf2, 0x98, 0x90, 0x53, 0x28, 0x62, 0x34, 0x32, 0xb4, 0x4c, \n\t0xc2, 0x04, 0x6c, 0x14, 0x12, 0x10, 0xc9, 0x85, 0x80, 0x18, 0x35, 0xa1, 0x04, 0x68, 0x45, 0x81, \n\t0x2c, 0x04, 0x80, 0x0c, 0xc8, 0x48, 0xc0, 0x42, 0x00, 0x09, 0x0b, 0x60, 0xc6, 0x24, 0x26, 0x91, \n\t0x11, 0x24, 0xc1, 0x1d, 0x0c, 0x30, 0x34, 0x60, 0x03, 0xa8, 0x5a, 0x08, 0x38, 0x46, 0x60, 0x09, \n\t0x40, 0x10, 0x86, 0x4c, 0x22, 0x61, 0x04, 0x01, 0x00, 0x2a, 0x58, 0x82, 0x90, 0x01, 0x0c, 0x12, \n\t0x0d, 0x0c, 0x73, 0x21, 0x20, 0x84, 0x12, 0x08, 0x40, 0xf0, 0x00, 0x0d, 0x50, 0x92, 0x85, 0x20, \n\t0x10, 0xc0, 0x12, 0x01, 0x03, 0x04, 0x22, 0x05, 0x10, 0x30, 0x34, 0x49, 0x42, 0x00, 0x87, 0x00, \n\t0x02, 0xc0, 0x40, 0x49, 0x20, 0x42, 0x9a, 0xb3, 0x40, 0x80, 0xe4, 0x08, 0x22, 0x20, 0x18, 0x35, \n\t0x8b, 0x88, 0x52, 0x34, 0x0b, 0x25, 0x00, 0x1c, 0x00, 0x0e, 0x32, 0x09, 0x88, 0x91, 0xdc, 0x06, \n\t0x18, 0xb0, 0xab, 0x14, 0x60, 0xc4, 0x00, 0x08, 0x03, 0x2b, 0x02, 0x70, 0x16, 0x48, 0x08, 0xe2, \n\t0x00, 0x2b, 0x08, 0x98, 0x0c, 0x0c, 0x84, 0xa0, 0x28, 0x05, 0x05, 0x64, 0x00, 0x50, 0x19, 0x92, \n\t0x88, 0x03, 0x0c, 0x12, 0x61, 0x28, 0x00, 0xcc, 0x12, 0x02, 0x52, 0x04, 0x41, 0x24, 0x3c, 0x00, \n\t0x21, 0x40, 0x81, 0x1a, 0x2b, 0x09, 0xc2, 0x05, 0x14, 0x71, 0x20, 0xa0, 0x14, 0x00, 0x82, 0x50, \n\t0x60, 0x40, 0xa0, 0x08, 0x03, 0x04, 0x0c, 0x92, 0x10, 0x02, 0x30, 0x42, 0x29, 0x68, 0x22, 0x20, \n\t0x08, 0xf4, 0x00, 0x0e, 0x12, 0x00, 0x50, 0x21, 0x10, 0x8c, 0x21, 0x00, 0x45, 0x60, 0x10, 0x01, \n\t0xc9, 0x84, 0x04, 0x11, 0x18, 0x00, 0x01, 0x17, 0x67, 0x3e, 0x41, 0x80, 0x83, 0xc1, 0xca, 0x80, \n\t0x1a, 0x40, 0xba, 0x80, 0x48, 0x82, 0xca, 0x04, 0x05, 0x81, 0x80, 0x34, 0x18, 0xc0, 0x42, 0xc2, \n\t0x40, 0x30, 0x84, 0x4c, 0x09, 0x12, 0x11, 0x08, 0x26, 0x14, 0x0c, 0xc8, 0x02, 0x60, 0x23, 0xa7, \n\t0x00, 0x49, 0x41, 0x5a, 0xe4, 0x40, 0x88, 0x10, 0x05, 0xa0, 0x6c, 0x02, 0x00, 0x00, 0x01, 0x84, \n\t0x02, 0x12, 0x10, 0x22, 0x01, 0xc8, 0x90, 0x81, 0x20, 0x02, 0x10, 0x82, 0x05, 0x12, 0xa3, 0x28, \n\t0x82, 0x80, 0x04, 0x28, 0x14, 0x40, 0x42, 0x51, 0xa1, 0x84, 0x09, 0x80, 0x82, 0x2e, 0x04, 0x01, \n\t0x32, 0xb4, 0x01, 0x08, 0x0c, 0x06, 0x01, 0xba, 0x05, 0x50, 0x80, 0x54, 0x22, 0x1b, 0x01, 0x38, \n\t0x41, 0xa2, 0x04, 0x41, 0x39, 0x25, 0x00, 0x18, 0x83, 0x70, 0x51, 0x09, 0x1a, 0x80, 0x92, 0x41, \n\t0x42, 0x40, 0x5b, 0x04, 0x20, 0x90, 0x0b, 0x00, 0x30, 0x28, 0x34, 0x61, 0x00, 0x01, 0x1e, 0x72, \n\t0x42, 0x06, 0x19, 0x1c, 0x01, 0x0c, 0x04, 0x71, 0x09, 0x49, 0x00, 0x08, 0x60, 0x00, 0x80, 0x9c, \n\t0x48, 0x49, 0x00, 0x5a, 0x00, 0xa1, 0x2a, 0xa1, 0x1c, 0x06, 0x28, 0x24, 0x50, 0x01, 0x00, 0xc0, \n\t0x08, 0x68, 0x65, 0xa8, 0x22, 0x68, 0x14, 0x20, 0x32, 0x42, 0x03, 0x82, 0x3d, 0x01, 0xc1, 0x0e, \n\t0x82, 0x11, 0x02, 0x20, 0x80, 0x01, 0x02, 0xd4, 0xe9, 0x80, 0x0c, 0x01, 0x29, 0x04, 0x50, 0x12, \n\t0x92, 0x40, 0x81, 0x83, 0x10, 0x20, 0x01, 0x09, 0x80, 0xc3, 0xe6, 0x42, 0x53, 0x13, 0x06, 0x15, \n\t0x80, 0x41, 0x58, 0x14, 0x00, 0x82, 0x1c, 0x88, 0x06, 0x00, 0x02, 0x2a, 0x06, 0x5c, 0x91, 0x00, \n\t0x58, 0x02, 0x8a, 0x90, 0x24, 0x04, 0x06, 0x28, 0x40, 0x30, 0x15, 0x24, 0x81, 0x60, 0x42, 0x46, \n\t0xd9, 0xa0, 0x11, 0x04, 0x46, 0x24, 0x92, 0xc0, 0x28, 0x21, 0x8c, 0x22, 0x00, 0x16, 0x08, 0x11, \n\t0xe1, 0x1d, 0x08, 0x0a, 0x01, 0x09, 0x3b, 0x90, 0x53, 0x20, 0x12, 0x03, 0xc0, 0x84, 0x00, 0x94, \n\t0x02, 0x14, 0xb2, 0x48, 0x38, 0x39, 0x42, 0x21, 0x40, 0xb2, 0xa2, 0x22, 0xc4, 0x90, 0x03, 0x40, \n\t0x70, 0x61, 0x2c, 0xc8, 0x48, 0xe3, 0x06, 0x42, 0x00, 0xac, 0x11, 0x04, 0xc0, 0x08, 0x40, 0x41, \n\t0x01, 0x08, 0x4a, 0x84, 0x48, 0x21, 0xd0, 0x02, 0x81, 0x00, 0x42, 0x20, 0x00, 0xd8, 0x04, 0x84, \n\t0x00, 0x8c, 0x04, 0x64, 0x13, 0x09, 0x35, 0x88, 0x21, 0x12, 0x80, 0x38, 0x0b, 0x24, 0xc2, 0x41, \n\t0x12, 0x80, 0x82, 0x28, 0x28, 0x05, 0x24, 0x74, 0x11, 0xc0, 0x05, 0x09, 0x51, 0x60, 0x28, 0x80, \n\t0xa2, 0x11, 0x24, 0x10, 0x89, 0x00, 0x21, 0x20, 0x85, 0x60, 0x00, 0x0c, 0x00, 0xa4, 0x81, 0x88, \n\t0x1c, 0x0b, 0x06, 0x64, 0x04, 0x32, 0x10, 0x08, 0x86, 0x01, 0x28, 0x43, 0x11, 0x20, 0x68, 0x51, \n\t0x0a, 0x36, 0x60, 0x82, 0xa6, 0x24, 0x87, 0x49, 0x4a, 0x00, 0x00, 0x10, 0xa9, 0x01, 0x81, 0x20, \n\t0x76, 0xca, 0xa1, 0xd5, 0x02, 0x00, 0x28, 0x52, 0x29, 0x22, 0xe0, 0x00, 0x0b, 0x08, 0x90, 0x08, \n\t0x14, 0xb0, 0x00, 0x05, 0x74, 0x50, 0x40, 0x8b, 0x20, 0x56, 0xea, 0x04, 0x30, 0x02, 0x15, 0xd1, \n\t0x00, 0x09, 0x40, 0x42, 0x02, 0x83, 0x30, 0x0a, 0xc8, 0x04, 0x15, 0x22, 0x98, 0x49, 0x09, 0x48, \n\t0x4a, 0x05, 0x02, 0x14, 0x00, 0xce, 0x24, 0x46, 0xc7, 0x23, 0x0d, 0x04, 0x10, 0x8c, 0x44, 0x60, \n\t0x80, 0x84, 0x38, 0x81, 0x02, 0x70, 0x41, 0x90, 0x26, 0x01, 0x40, 0xa1, 0x04, 0xc4, 0x48, 0x20, \n\t0x20, 0x43, 0x02, 0x10, 0xa4, 0x40, 0x1e, 0x44, 0x0a, 0x43, 0x08, 0x05, 0x62, 0x20, 0x18, 0x11, \n\t0x20, 0x70, 0x43, 0x8b, 0x18, 0x60, 0x04, 0x02, 0x16, 0x14, 0x91, 0x09, 0x10, 0x11, 0x20, 0x14, \n\t0x10, 0xe0, 0x08, 0x00, 0x88, 0x09, 0x1c, 0x85, 0x50, 0x2a, 0x08, 0x51, 0x42, 0x22, 0x71, 0x0a, \n\t0x00, 0x41, 0xcc, 0x80, 0x36, 0x04, 0xba, 0x31, 0x28, 0x0c, 0x02, 0x1a, 0x21, 0x01, 0xa0, 0x65, \n\t0x08, 0x01, 0x1a, 0xa4, 0x0b, 0x84, 0x40, 0x1c, 0x43, 0x26, 0x54, 0x8a, 0x08, 0x94, 0x08, 0x0c, \n\t0x04, 0x30, 0x10, 0x0a, 0x80, 0x52, 0x40, 0x40, 0xb0, 0xc3, 0x96, 0x00, 0x19, 0x05, 0x40, 0xa4, \n\t0x51, 0x0e, 0x09, 0xc5, 0x82, 0x28, 0x12, 0x40, 0x05, 0x08, 0x00, 0xc3, 0x10, 0x31, 0x38, 0x25, \n\t0x20, 0x02, 0xa8, 0x40, 0x76, 0x92, 0x01, 0x58, 0x41, 0xc5, 0x00, 0x03, 0x38, 0x04, 0x04, 0x02, \n\t0xa1, 0x44, 0x81, 0x91, 0x33, 0x80, 0x08, 0x20, 0x08, 0x41, 0x01, 0x33, 0x9d, 0x00, 0x40, 0x2a, \n\t0xc4, 0x51, 0x22, 0xf5, 0x0d, 0x4f, 0x00, 0x23, 0x90, 0x2a, 0xb0, 0x4a, 0xa2, 0x04, 0xd0, 0x48, \n\t0x00, 0x04, 0x54, 0xc8, 0x22, 0x92, 0x09, 0x29, 0x90, 0x85, 0x48, 0x0e, 0x00, 0xb0, 0x03, 0x88, \n\t0x4c, 0x84, 0x32, 0x80, 0x0b, 0x14, 0x10, 0x03, 0xc6, 0x50, 0x40, 0x03, 0x21, 0x08, 0x86, 0xe4, \n\t0x08, 0x04, 0x42, 0x32, 0x05, 0x00, 0x6a, 0x0c, 0x34, 0x10, 0xaa, 0x20, 0xc0, 0x64, 0x06, 0x90, \n\t0x12, 0x97, 0x28, 0xc2, 0x28, 0x42, 0x05, 0x88, 0x20, 0x21, 0xc6, 0x80, 0x10, 0x82, 0x81, 0x94, \n\t0x00, 0x1c, 0x01, 0x24, 0x24, 0x49, 0x80, 0x4c, 0x41, 0x46, 0x00, 0x83, 0x68, 0x80, 0x00, 0x48, \n\t0x08, 0x12, 0xc1, 0x61, 0x08, 0x38 \n};\n\n\nstatic bool isprime_slow(int64_t x)\n{\n\tfor (int i = 3; i < 10; ++i) {\n\t\tif (x % gLowPrimes[i] == 0)\n\t\t\treturn false;\n\t}\n\t\n\tfor (int i = 0; i < kPrimesMaskSize; ++i) {\n\t\tif (gPrimesMask[i] == 0) continue;\n\t\tint64_t k = 30 * (i+1);\n\t\tfor (int j = 0; j < 8; ++j) {\n\t\t\tif (!(gPrimesMask[k] & (1 << j))) continue;\n\t\t\tint64_t m = k + gPrimeOffsets[j];\n\t\t\tif (m*m > x) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tif (x % m == 0) return false;\n\t\t}\n\t}\n\t\n\tthrow errOutOfRange;\n}\n\n#include \n\nbool isprime(int64_t x)\n{\n\tif (x <= 30) {\n\t\tif (x < 2) return false; // negatives aren't prime\n\t\treturn gLowPrimesMask & (1 << x);\n\t}\n\t\n\tint bit = x % 30;\n\tint shift = gPrimesShift[bit];\n\tif (shift < 0) return false; // eliminate multiples of 2,3,5.\n\tint64_t byte = x / 30 - 1;\n\t\t\n\tif (byte >= kPrimesMaskSize) return isprime_slow(x);\t\n\t\n\treturn gPrimesMask[byte] & (1 << shift);\n}\n\n\nint64_t nextPrime(int64_t x)\n{\n\tfor (;; ++x) {\n\t\tif (isprime(x)) return x;\n\t}\n}\n\n\n\n\n\n\n"], ["/sapf/src/elapsedTime.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nextern \"C\" {\n\nstatic double gHostClockFreq;\n\nvoid initElapsedTime()\n{\n\tstruct mach_timebase_info info;\n\tmach_timebase_info(&info);\n\tgHostClockFreq = 1e9 * ((double)info.numer / (double)info.denom);\n}\n\ndouble elapsedTime()\n{\n\treturn (double)mach_absolute_time() / gHostClockFreq;\n}\n\n}\n"], ["/sapf/src/RCObj.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"RCObj.hpp\"\n#include \"VM.hpp\"\n\n\nRCObj::RCObj()\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::RCObj(RCObj const& that)\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::~RCObj()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\n\nvoid RCObj::norefs()\n{\n\trefcount = -999;\n\tdelete this; \n}\n\n\t\nvoid RCObj::negrefcount()\n{\n\tpost(\"RELEASING WITH NEGATIVE REFCOUNT %s %p %d\\n\", TypeName(), this, refcount.load());\n}\nvoid RCObj::alreadyDead()\n{\n\tpost(\"RETAINING ALREADY DEAD OBJECT %s %p\\n\", TypeName(), this);\n}\n"], ["/sapf/src/ErrorCodes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"ErrorCodes.hpp\"\n\nconst char* errString[kNumErrors] = { \n\t\"halt\", \"failed\", \"indefinite operation\", \"wrong type\", \"out of range\", \"syntax\", \"internal bug\",\n\t\"wrong state\", \"not found\", \"stack overflow\", \"stack underflow\",\n\t\"inconsistent inheritance\", \"undefined operation\", \"user quit\"\n};\n"], ["/sapf/libmanta/MantaServer.h", "#ifndef _MANTASERVER_H\n#define _MANTASERVER_H\n\n/************************************************************************//**\n * \\class MantaServer\n * \\brief Interface defining all the Messages that can be sent to a Manta\n *\n * The MantaServer virtual class defines all the Messages that the Manta\n * understands, as well as the data structures used as arguments. If you\n * need a pointer to a Manta in your code, you can make it more general by\n * using a MantaServer pointer instead of a pointer to your specific subclass.\n ****************************************************************************/\nclass MantaServer\n{\n public:\n\n enum LEDState {\n Off,\n Amber,\n Red,\n All, // only used in SetPadLEDFrame\n };\n enum LEDControlType {\n PadAndButton,\n Slider,\n Button\n };\n typedef uint8_t LEDFrame[6];\n\n virtual ~MantaServer() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void SetPadLED(LEDState state, int ledID) = 0;\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) = 0;\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) = 0;\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) = 0;\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) = 0;\n virtual void SetButtonLED(LEDState state, int id) = 0;\n virtual void ResendLEDState(void) = 0;\n virtual void ClearPadAndButtonLEDs(void) = 0;\n virtual void ClearButtonLEDs(void) = 0;\n virtual void Recalibrate(void) = 0;\n virtual void SetLEDControl(LEDControlType control, bool state) = 0;\n virtual void SetTurboMode(bool Enabled) = 0;\n virtual void SetRawMode(bool Enabled) = 0;\n virtual void SetMaxSensorValues(int *values) = 0;\n};\n#endif /* _MANTASERVER_H */\n"], ["/sapf/src/Types.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Types.hpp\"\n"], ["/sapf/libmanta/MantaMulti.h", "class MantaMulti {\n public:\n MantaMulti(MantaClient *client = NULL) {\n AttachClient(client);\n}\n void AttachClient(MantaClient *client) {\n if(NULL != client)\n {\n ClientList.push_back(client);\n ++ReferenceCount;\n }\n}\n void DetachClient(MantaClient *client) {\n list::iterator foundIter;\n foundIter = find(ClientList.begin(), ClientList.end(), client);\n if(ClientList.end() != foundIter)\n {\n ClientList.erase(foundIter);\n --ReferenceCount;\n }\n}\n int GetReferenceCount() {\n return ReferenceCount;\n}\n protected:\n void PadEvent(int row, int column, int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadEvent(row, column, id, value);\n }\n}\n void SliderEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->SliderEvent(id, value);\n }\n}\n void ButtonEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonEvent(id, value);\n }\n}\n void PadVelocityEvent(int row, int column, int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadVelocityEvent(row, column, id, velocity);\n }\n}\n void ButtonVelocityEvent(int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonVelocityEvent(id, velocity);\n }\n}\n void FrameEvent(uint8_t *frame) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->FrameEvent(frame);\n }\n}\n private:\n list ClientList;\n int ReferenceCount;\n};"], ["/sapf/libmanta/MantaExceptions.h", "#ifndef _MANTAEXCEPTIONS_H\n#define _MANTAEXCEPTIONS_H\n\n#include \n\nclass LibusbInitException : public std::runtime_error\n{\n public:\n LibusbInitException() :\n runtime_error(\"Error initializing libusb\")\n {\n }\n};\n\nclass MantaNotConnectedException : public std::runtime_error\n{\n public:\n MantaNotConnectedException(MantaUSB *manta) :\n runtime_error(\"Attempted to access the Manta without connecting\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\nclass MantaNotFoundException : public std::runtime_error\n{\n public:\n MantaNotFoundException() :\n runtime_error(\"Could not find an attached Manta\")\n {\n }\n};\n\nclass MantaOpenException : public std::runtime_error\n{\n public:\n MantaOpenException() :\n runtime_error(\"Could not connect to attached Manta\")\n {\n }\n};\n\nclass MantaCommunicationException : public std::runtime_error\n{\n public:\n MantaCommunicationException(MantaUSB *manta = NULL) :\n runtime_error(\"Communication with Manta interrupted\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\n#endif // _MANTAEXCEPTIONS_H\n"], ["/sapf/libmanta/MantaClient.h", "#ifndef _MANTACLIENT_H\n#define _MANTACLIENT_H\n\n#include \n\n/************************************************************************//**\n * \\class MantaClient\n * \\brief Interface defining all the Events generated by the Manta\n *\n * The MantaClient virtual class defines all the Events that could be\n * generated by the Manta. Your object should provide implementations\n * to any of these events that you'd like to listen for\n ****************************************************************************/\nclass MantaClient\n{\n public:\n virtual ~MantaClient() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void PadEvent(int row, int column, int id, int value) {}\n virtual void SliderEvent(int id, int value) {}\n virtual void ButtonEvent(int id, int value) {}\n virtual void PadVelocityEvent(int row, int column, int id, int velocity) {}\n virtual void ButtonVelocityEvent(int id, int velocity) {}\n virtual void FrameEvent(uint8_t *frame) {}\n virtual void DebugPrint(const char *fmt, ...) {}\n};\n#endif /* _MANTACLIENT_H */\n"], ["/sapf/libmanta/MantaVersion.h", "#ifndef _MANTAVERSION_H\n#define _MANTAVERSION_H\n\n#define LIBMANTA_MAJOR_VERSION 1\n#define LIBMANTA_MINOR_VERSION 3\n\n#endif // _MANTAVERSION_H\n"]], "task_instance_info": {"created_time": "2025-08-20 20:05:17", "created_task_model": "DeepSeek-R1", "function_skeleton": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor) {}", "code_description": "This code segment functions to: Generate a visual representation of frequency spectrum data over time by applying windowed Fourier transforms, converting magnitude values to decibel scale, and mapping the results to a color-coded bitmap image for output."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nvoid spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor) {\n const int bins = 1 << log2bins;\n const int height = bins / 2 + 1;\n \n // Create Kaiser window\n double* window = new double[bins];\n std::fill(window, window + bins, 1.0);\n calcKaiserWindowD(bins, window, -60.0);\n \n // Allocate image buffer\n unsigned char* image = new unsigned char[width * height];\n unsigned char colorTable[256*4];\n makeColorTable(colorTable);\n \n // Setup FFT\n FFTSetup fftSetup = vDSP_create_fftsetup(log2bins, kFFTRadix2);\n DSPSplitComplex fftIn;\n fftIn.realp = (double*)malloc(bins/2 * sizeof(double));\n fftIn.imagp = (double*)malloc(bins/2 * sizeof(double));\n \n for(int col = 0; col < width; ++col) {\n // Calculate window position\n int start = width > 1 ? (col * (size - bins)) / (width-1) : 0;\n \n // Window the data\n double* frame = new double[bins];\n vDSP_vmulD(data + start, 1, window, 1, frame, 1, bins);\n \n // Prepare FFT input\n vDSP_ctozD((DSPDoubleComplex*)frame, 2, &fftIn, 1, bins/2);\n vDSP_fft_zripD(fftSetup, &fftIn, 1, log2bins, FFT_FORWARD);\n \n // Process frequency bins\n for(int bin = 0; bin < height; ++bin) {\n double real, imag;\n if(bin == 0) {\n real = fftIn.realp[0];\n imag = 0.0;\n } else if(bin == bins/2) {\n real = fftIn.imagp[0];\n imag = 0.0;\n } else {\n real = fftIn.realp[bin];\n imag = fftIn.imagp[bin-1];\n }\n \n // Convert to dB and scale\n double power = real*real + imag*imag;\n double dB = 10.0 * log10(std::max(power, 1e-20));\n dB = std::max(dB, dBfloor);\n int scaled = std::min(255, std::max(0, (int)(255.0 * (dB - dBfloor)/(-dBfloor))));\n \n image[col + bin*width] = scaled;\n }\n delete[] frame;\n }\n \n // Generate output image\n makeImage(width, height, image, path, colorTable);\n \n // Cleanup\n vDSP_destroy_fftsetup(fftSetup);\n free(fftIn.realp);\n free(fftIn.imagp);\n delete[] window;\n delete[] image;\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 20-08-23"}, "editdistance_info": {"edit_distance": 15.562, "calculate_time": "2025-08-20 20:08:23", "true_code_clean": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor)\n{\n\tint numRealFreqs = 1 << log2bins;\n\tint log2n = log2bins + 1;\n\tint n = 1 << log2n;\n\tint nOver2 = n / 2;\n\tdouble scale = 1./nOver2;\n\tint64_t paddedSize = size + n;\n\tdouble* paddedData = (double*)calloc(paddedSize, sizeof(double));\n\tmemcpy(paddedData + nOver2, data, size * sizeof(double));\n\tdouble* dBMags = (double*)calloc(numRealFreqs + 1, sizeof(double));\n\tdouble hopSize = size <= n ? 0 : (double)(size - n) / (double)(width - 1);\n\tdouble* window = (double*)calloc(n, sizeof(double));\n\tfor (int i = 0; i < n; ++i) window[i] = 1.;\n\tcalcKaiserWindowD(n, window, -180.);\n\tunsigned char table[1028];\n\tmakeColorTable(table);\n\tint heightOfAmplitudeView = 128;\n\tint heightOfFFT = numRealFreqs+1;\n\tint totalHeight = heightOfAmplitudeView+heightOfFFT+3*border;\n\tint topOfSpectrum = heightOfAmplitudeView + 2*border;\n\tint totalWidth = width+2*border;\n\tBitmap* b = createBitmap(totalWidth, totalHeight);\n\tfillRect(b, 0, 0, totalWidth, totalHeight, 160, 160, 160, 255);\n\tfillRect(b, border, border, width, heightOfAmplitudeView, 0, 0, 0, 255);\n\tFFTSetupD fftSetup = vDSP_create_fftsetupD(log2n, kFFTRadix2);\n\tdouble* windowedData = (double*)calloc(n, sizeof(double));\n\tdouble* interleavedData = (double*)calloc(n, sizeof(double));\n\tdouble* resultData = (double*)calloc(n, sizeof(double));\n\tDSPDoubleSplitComplex interleaved;\n\tinterleaved.realp = interleavedData;\n\tinterleaved.imagp = interleavedData + nOver2;\n\tDSPDoubleSplitComplex result;\n\tresult.realp = resultData;\n\tresult.imagp = resultData + nOver2;\n\tdouble maxmag = 0.;\n\tdouble hpos = nOver2;\n\tfor (int i = 0; i < width; ++i) {\n\t\tsize_t ihpos = (size_t)hpos;\n\t\tdouble peak = 1e-20;\n\t\tfor (int w = 0; w < n; ++w) {\n\t\t\tdouble x = paddedData[w+ihpos];\n\t\t\tx = fabs(x);\n\t\t\tif (x > peak) peak = x;\n\t\t}\n\t\tfor (int64_t w = 0; w < n; ++w) windowedData[w] = window[w] * paddedData[w+ihpos];\n\t\tvDSP_ctozD((DSPDoubleComplex*)windowedData, 2, &interleaved, 1, nOver2);\n\t\tvDSP_fft_zropD(fftSetup, &interleaved, 1, &result, 1, log2n, kFFTDirection_Forward);\n\t\tdBMags[0] = result.realp[0] * scale;\n\t\tdBMags[numRealFreqs] = result.imagp[0] * scale;\n\t\tif (dBMags[0] > maxmag) maxmag = dBMags[0];\n\t\tif (dBMags[numRealFreqs] > maxmag) maxmag = dBMags[numRealFreqs];\n\t\tfor (int64_t j = 1; j < numRealFreqs-1; ++j) {\n\t\t\tdouble x = result.realp[j] * scale;\n\t\t\tdouble y = result.imagp[j] * scale;\n\t\t\tdBMags[j] = sqrt(x*x + y*y);\n\t\t\tif (dBMags[j] > maxmag) maxmag = dBMags[j];\n\t\t}\n\t\tdouble invmag = 1.;\n\t\tdBMags[0] = 20.*log2(dBMags[0]*invmag);\n\t\tdBMags[numRealFreqs] = 20.*log10(dBMags[numRealFreqs]*invmag);\n\t\tfor (int64_t j = 0; j <= numRealFreqs-1; ++j) {\n\t\t\tdBMags[j] = 20.*log10(dBMags[j]*invmag);\n\t\t}\n\t\t{\n\t\t\tdouble peakdB = 20.*log10(peak);\n\t\t\tint peakColorIndex = 256. - peakdB * (256. / dBfloor);\n\t\t\tint peakIndex = heightOfAmplitudeView - peakdB * (heightOfAmplitudeView / dBfloor);\n\t\t\tif (peakIndex < 0) peakIndex = 0;\n\t\t\tif (peakIndex > heightOfAmplitudeView) peakIndex = heightOfAmplitudeView;\n\t\t\tif (peakColorIndex < 0) peakColorIndex = 0;\n\t\t\tif (peakColorIndex > 255) peakColorIndex = 255;\n\t\t\tunsigned char* t = table + 4*peakColorIndex;\n\t\t\tfillRect(b, i+border, border+128-peakIndex, 1, peakIndex, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\tfor (int j = 0; j < numRealFreqs; ++j) {\n\t\t\tint colorIndex = 256. - dBMags[j] * (256. / dBfloor); \n\t\t\tif (colorIndex < 0) colorIndex = 0;\n\t\t\tif (colorIndex > 255) colorIndex = 255;\n\t\t\tunsigned char* t = table + 4*colorIndex;\n\t\t\tsetPixel(b, i+border, numRealFreqs-j+topOfSpectrum, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\thpos += hopSize;\n\t}\n\tvDSP_destroy_fftsetupD(fftSetup);\n\twriteBitmap(b, path);\n\tfreeBitmap(b);\n\tfree(dBMags);\n\tfree(paddedData);\n\tfree(window);\n\tfree(windowedData);\n\tfree(interleavedData);\n\tfree(resultData);\n}", "predict_code_clean": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor) {\n const int bins = 1 << log2bins;\n const int height = bins / 2 + 1;\n double* window = new double[bins];\n std::fill(window, window + bins, 1.0);\n calcKaiserWindowD(bins, window, -60.0);\n unsigned char* image = new unsigned char[width * height];\n unsigned char colorTable[256*4];\n makeColorTable(colorTable);\n FFTSetup fftSetup = vDSP_create_fftsetup(log2bins, kFFTRadix2);\n DSPSplitComplex fftIn;\n fftIn.realp = (double*)malloc(bins/2 * sizeof(double));\n fftIn.imagp = (double*)malloc(bins/2 * sizeof(double));\n for(int col = 0; col < width; ++col) {\n int start = width > 1 ? (col * (size - bins)) / (width-1) : 0;\n double* frame = new double[bins];\n vDSP_vmulD(data + start, 1, window, 1, frame, 1, bins);\n vDSP_ctozD((DSPDoubleComplex*)frame, 2, &fftIn, 1, bins/2);\n vDSP_fft_zripD(fftSetup, &fftIn, 1, log2bins, FFT_FORWARD);\n for(int bin = 0; bin < height; ++bin) {\n double real, imag;\n if(bin == 0) {\n real = fftIn.realp[0];\n imag = 0.0;\n } else if(bin == bins/2) {\n real = fftIn.imagp[0];\n imag = 0.0;\n } else {\n real = fftIn.realp[bin];\n imag = fftIn.imagp[bin-1];\n }\n double power = real*real + imag*imag;\n double dB = 10.0 * log10(std::max(power, 1e-20));\n dB = std::max(dB, dBfloor);\n int scaled = std::min(255, std::max(0, (int)(255.0 * (dB - dBfloor)/(-dBfloor))));\n image[col + bin*width] = scaled;\n }\n delete[] frame;\n }\n makeImage(width, height, image, path, colorTable);\n vDSP_destroy_fftsetup(fftSetup);\n free(fftIn.realp);\n free(fftIn.imagp);\n delete[] window;\n delete[] image;\n}"}} {"repo_name": "sapf", "file_name": "/sapf/src/Spectrogram.cpp", "inference_info": {"prefix_code": "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Spectrogram.hpp\"\n#include \"makeImage.hpp\"\n#include \n#include \n#include \n#include \n\nstatic void makeColorTable(unsigned char* table);\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double i0(double x)\n{\n\tconst double epsilon = 1e-18;\n\tint n = 1;\n\tdouble S = 1., D = 1., T;\n\n\twhile (D > epsilon * S) {\n\t\tT = x / (2 * n++);\n\t\tD *= T * T;\n\t\tS += D;\n\t}\n\treturn S;\n}\n\nstatic void calcKaiserWindowD(size_t size, double* window, double stopBandAttenuation)\n{\n\tsize_t M = size - 1;\n\tsize_t N = M-1;\n#if VERBOSE\n\tprintf(\"FillKaiser %d %g\\n\", M, stopBandAttenuation);\n#endif\n\n\tdouble alpha = 0.;\n\tif (stopBandAttenuation <= -50.)\n\t\talpha = 0.1102 * (-stopBandAttenuation - 8.7);\n else if (stopBandAttenuation < -21.)\n\t\talpha = 0.5842 * pow(-stopBandAttenuation - 21., 0.4) + 0.07886 * (-stopBandAttenuation - 21.);\n\n\tdouble p = N / 2;\n\tdouble kk = 1.0 / i0(alpha);\n\n\tfor(unsigned int k = 0; k < M; k++ )\n\t{\n\t\tdouble x = (k-p) / p;\n\t\t\n\t\t// Kaiser window\n\t\twindow[k+1] *= kk * bessi0(alpha * sqrt(1.0 - x*x) );\n\t}\n\twindow[0] = 0.;\n\twindow[size-1] = 0.;\n#if VERBOSE\n\tprintf(\"done\\n\");\n#endif\n}\n\nconst int border = 8;\n\n", "suffix_code": "\n\n\nstatic void makeColorTable(unsigned char* table)\n{\n\t// white >> red >> yellow >> green >> cyan >> blue >> magenta >> pink >> black\n\t// 0 -20 -40 -60 -80 -100 -120 -140 -160\n\t// 255 224 192 160 128 96 64 32 0\n\t\n\tint colors[9][4] = {\n\t\t{ 0, 0, 64, 255},\t// dk blue\n\t\t{ 0, 0, 255, 255},\t// blue\n\t\t{255, 0, 0, 255},\t// red\n\t\t{255, 255, 0, 255},\t// yellow\n\t\t{255, 255, 255, 255}\t// white\n\t};\n\t\n\tfor (int j = 0; j < 4; ++j) {\n\t\tfor (int i = 0; i < 64; ++i) {\n\t\t\tfor (int k = 0; k < 4; ++k) {\n\t\t\t\tint x = (colors[j][k] * (64 - i) + colors[j+1][k] * i) / 64;\n\t\t\t\tif (x > 255) x = 255;\n\t\t\t\ttable[j*64*4 + i*4 + k + 4] = x;\n\t\t\t}\n\t\t}\n\t}\n\t\n\ttable[0] = 0;\n\ttable[1] = 0;\n\ttable[2] = 0;\n\ttable[3] = 255;\n}\n\n", "middle_code": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor)\n{\n\tint numRealFreqs = 1 << log2bins;\n\tint log2n = log2bins + 1;\n\tint n = 1 << log2n;\n\tint nOver2 = n / 2;\n\tdouble scale = 1./nOver2;\n\tint64_t paddedSize = size + n;\n\tdouble* paddedData = (double*)calloc(paddedSize, sizeof(double));\n\tmemcpy(paddedData + nOver2, data, size * sizeof(double));\n\tdouble* dBMags = (double*)calloc(numRealFreqs + 1, sizeof(double));\n\tdouble hopSize = size <= n ? 0 : (double)(size - n) / (double)(width - 1);\n\tdouble* window = (double*)calloc(n, sizeof(double));\n\tfor (int i = 0; i < n; ++i) window[i] = 1.;\n\tcalcKaiserWindowD(n, window, -180.);\n\tunsigned char table[1028];\n\tmakeColorTable(table);\n\tint heightOfAmplitudeView = 128;\n\tint heightOfFFT = numRealFreqs+1;\n\tint totalHeight = heightOfAmplitudeView+heightOfFFT+3*border;\n\tint topOfSpectrum = heightOfAmplitudeView + 2*border;\n\tint totalWidth = width+2*border;\n\tBitmap* b = createBitmap(totalWidth, totalHeight);\n\tfillRect(b, 0, 0, totalWidth, totalHeight, 160, 160, 160, 255);\n\tfillRect(b, border, border, width, heightOfAmplitudeView, 0, 0, 0, 255);\n\tFFTSetupD fftSetup = vDSP_create_fftsetupD(log2n, kFFTRadix2);\n\tdouble* windowedData = (double*)calloc(n, sizeof(double));\n\tdouble* interleavedData = (double*)calloc(n, sizeof(double));\n\tdouble* resultData = (double*)calloc(n, sizeof(double));\n\tDSPDoubleSplitComplex interleaved;\n\tinterleaved.realp = interleavedData;\n\tinterleaved.imagp = interleavedData + nOver2;\n\tDSPDoubleSplitComplex result;\n\tresult.realp = resultData;\n\tresult.imagp = resultData + nOver2;\n\tdouble maxmag = 0.;\n\tdouble hpos = nOver2;\n\tfor (int i = 0; i < width; ++i) {\n\t\tsize_t ihpos = (size_t)hpos;\n\t\tdouble peak = 1e-20;\n\t\tfor (int w = 0; w < n; ++w) {\n\t\t\tdouble x = paddedData[w+ihpos];\n\t\t\tx = fabs(x);\n\t\t\tif (x > peak) peak = x;\n\t\t}\n\t\tfor (int64_t w = 0; w < n; ++w) windowedData[w] = window[w] * paddedData[w+ihpos];\n\t\tvDSP_ctozD((DSPDoubleComplex*)windowedData, 2, &interleaved, 1, nOver2);\n\t\tvDSP_fft_zropD(fftSetup, &interleaved, 1, &result, 1, log2n, kFFTDirection_Forward);\n\t\tdBMags[0] = result.realp[0] * scale;\n\t\tdBMags[numRealFreqs] = result.imagp[0] * scale;\n\t\tif (dBMags[0] > maxmag) maxmag = dBMags[0];\n\t\tif (dBMags[numRealFreqs] > maxmag) maxmag = dBMags[numRealFreqs];\n\t\tfor (int64_t j = 1; j < numRealFreqs-1; ++j) {\n\t\t\tdouble x = result.realp[j] * scale;\n\t\t\tdouble y = result.imagp[j] * scale;\n\t\t\tdBMags[j] = sqrt(x*x + y*y);\n\t\t\tif (dBMags[j] > maxmag) maxmag = dBMags[j];\n\t\t}\n\t\tdouble invmag = 1.;\n\t\tdBMags[0] = 20.*log2(dBMags[0]*invmag);\n\t\tdBMags[numRealFreqs] = 20.*log10(dBMags[numRealFreqs]*invmag);\n\t\tfor (int64_t j = 0; j <= numRealFreqs-1; ++j) {\n\t\t\tdBMags[j] = 20.*log10(dBMags[j]*invmag);\n\t\t}\n\t\t{\n\t\t\tdouble peakdB = 20.*log10(peak);\n\t\t\tint peakColorIndex = 256. - peakdB * (256. / dBfloor);\n\t\t\tint peakIndex = heightOfAmplitudeView - peakdB * (heightOfAmplitudeView / dBfloor);\n\t\t\tif (peakIndex < 0) peakIndex = 0;\n\t\t\tif (peakIndex > heightOfAmplitudeView) peakIndex = heightOfAmplitudeView;\n\t\t\tif (peakColorIndex < 0) peakColorIndex = 0;\n\t\t\tif (peakColorIndex > 255) peakColorIndex = 255;\n\t\t\tunsigned char* t = table + 4*peakColorIndex;\n\t\t\tfillRect(b, i+border, border+128-peakIndex, 1, peakIndex, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\tfor (int j = 0; j < numRealFreqs; ++j) {\n\t\t\tint colorIndex = 256. - dBMags[j] * (256. / dBfloor); \n\t\t\tif (colorIndex < 0) colorIndex = 0;\n\t\t\tif (colorIndex > 255) colorIndex = 255;\n\t\t\tunsigned char* t = table + 4*colorIndex;\n\t\t\tsetPixel(b, i+border, numRealFreqs-j+topOfSpectrum, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\thpos += hopSize;\n\t}\n\tvDSP_destroy_fftsetupD(fftSetup);\n\twriteBitmap(b, path);\n\tfreeBitmap(b);\n\tfree(dBMags);\n\tfree(paddedData);\n\tfree(window);\n\tfree(windowedData);\n\tfree(interleavedData);\n\tfree(resultData);\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/sapf/src/StreamOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n#include \"dsp.hpp\"\n#include \"SoundFiles.hpp\"\n\nconst Z kOneThird = 1. / 3.;\n\n// list ops\n#pragma mark LIST OPS\n\nstatic void finite_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.pushBool(v.isFinite());\n}\n\nstatic void size_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (v.isList() && !v.isFinite()) \n\t\tth.push(INFINITY);\n\telse \n\t\tth.push(v.length(th));\n}\n\n\nstatic void rank_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tint rank = 0;\n\twhile (a.isVList()) {\n\t\t++rank;\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\t\n\tth.push(rank);\n}\n\nstatic void shape_(Thread& th, Prim* prim)\n{\n\tP shape = new Array(itemTypeZ, 4);\n\t\n\tV a = th.pop();\n\t\n\twhile (a.isVList()) {\n\t\tZ len;\n\t\tif (a.isFinite()) {\n\t\t\tlen = a.length(th);\n\t\t} else {\n\t\t\tlen = INFINITY;\n\t\t}\n\t\tshape->addz(len);\n\t\tVIn in(a);\n\t\tif (in.one(th, a)) break;\n\t}\n\tth.push(new List(shape));\n}\n\nstatic void bub_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tP seq = new List(itemTypeV, 1);\n\tseq->add(a);\n\tth.push(seq);\n}\n\nstatic void nbub_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbub : n\");\n\tV a = th.pop();\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\n\t\tP seq = new List(itemTypeV, 1);\n\t\tseq->add(a);\n\t\ta = seq;\n\t}\n\tth.push(a);\n}\n\ntemplate \nstatic void tupleN_(Thread& th, Prim* prim)\n{\n\tP seq = new List(itemTypeV, N);\n\tP arr = seq->mArray;\n\tarr->setSize(N);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v = th.pop();\n\t\tarr->put(N-1-i, v);\n\t}\n\tth.push(seq);\n}\n\ntemplate \nstatic void untupleN_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"unN : s\");\n\t\n\tBothIn in(s);\n\tfor (int i = 0; i < N; ++i) {\n\t\tV v;\n\t\tif (in.one(th, v)) {\n\t\t\tpost(\"too few items in list for un%d\", N);\n\t\t\tthrow errFailed;\n\t\t}\n\t\tth.push(v);\n\t}\n}\n\nstatic void reverse_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"reverse : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"reverse\", \"\");\n\t\t\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[n1-i];\n\t\t}\n\t}\n\tth.push(s2);\n}\n\ntemplate \nvoid copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[i];\n}\n\ntemplate \nvoid reverse_copy(T* dst, T* src, int64_t n)\n{\n\tfor (int64_t i = 0; i < n; ++i) dst[i] = src[-i];\n}\n\nstatic List* makeMirror(P const& a, int64_t n, int64_t nr, int64_t roff)\n{\n\tint type = a->elemType;\n\tint64_t size = n + nr;\n\tList* s = new List(type, size);\n\tArray* b = s->mArray();\n\t\n\tb->setSize(size);\n\tif (type == itemTypeV) {\n\t\tV* p = b->v();\n\t\tV* q = a->v();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t} else {\n\t\tZ* p = b->z();\n\t\tZ* q = a->z();\n\t\tcopy(p, q, n);\n\t\treverse_copy(p+n, q+roff, nr);\n\t}\n\treturn s;\n}\n\nstatic void mirror(Thread& th, int w, P s)\n{\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"mirror\", \"\");\n\n\ts = s->pack(th);\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\tint64_t n2 = n-2;\n\t\n\tswitch (w) {\n\t\tcase 0 : {\n\t\t\tif (n < 3) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n2, n2));\n\t\t} break;\n\t\tcase 1 : {\n\t\t\tif (n < 2) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n1, n2));\n\t\t} break;\n\t\tcase 2 : {\n\t\t\tif (n == 0) {\n\t\t\t\tth.push(s);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tth.push(makeMirror(a, n, n, n1));\n\t\t} break;\n\t}\n}\n\nstatic void mirror0_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror0 : s\");\n\tmirror(th, 0, s);\n}\n\nstatic void mirror1_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror1 : s\");\n\tmirror(th, 1, s);\n}\n\nstatic void mirror2_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"mirror2 : s\");\n\tmirror(th, 2, s);\n}\n\nstatic void rot_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"rot : r\");\n\tP s = th.popList(\"rot : s\");\n\t\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"rot\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->wrapAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->wrapAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void shift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"shift : r\");\n\tP s = th.popList(\"shift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"shift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->at(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->atz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void clipShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"clipShift : r\");\n\tP s = th.popList(\"clipShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->clipAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->clipAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void foldShift_(Thread& th, Prim* prim)\n{\n\tint64_t r = th.popInt(\"foldShift : r\");\n\tP s = th.popList(\"foldShift : s\");\n\n\tif (r == 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldShift\", \"\");\n\n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tint64_t n = a->size();\n\tint type = a->elemType;\n\t\n\tP s2 = new List(type, n);\n\tP const& b = s2->mArray;\n\tif (type == itemTypeV) {\n\t\tfor (int i = 0; i < n; ++i) b->add(a->foldAt(i-r));\n\t} else {\n\t\tfor (int i = 0; i < n; ++i) b->addz(a->foldAtz(i-r));\n\t}\n\tth.push(s2);\n}\n\nstatic void muss_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"muss : s\");\n\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"muss\", \"\");\n \n\ts = s->pack(th);\n\tif (s->isEnd()) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n \n\tP const& a = s->mArray;\n\tP s2 = new List(a->elemType, a->size());\n\tP const& a2 = s2->mArray;\n\tint64_t n = a->size();\n\tint64_t n1 = n-1;\n\ta2->setSize(n);\n\tif (a->isV()) {\n\t\tV* p = a2->v();\n\t\tV* q = a->v();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t} else {\n\t\tZ* p = a2->z();\n\t\tZ* q = a->z();\n\t\tfor (int64_t i = 0; i < n; ++i) {\n\t\t\tp[i] = q[i];\n\t\t}\n\t\tfor (int64_t i = 0; i < n1; ++i) {\n int64_t j = th.rgen.irand(i, n1);\n if (j != i) \n std::swap(p[i], p[j]);\n\t\t}\n\t}\n\tth.push(s2);\n}\n\n\n\n\n\nV do_at(Thread& th, P const& a, Arg i);\nV do_wrapAt(Thread& th, P const& a, Arg i);\nV do_foldAt(Thread& th, P const& a, Arg i);\nV do_clipAt(Thread& th, P const& a, Arg i);\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle);\n\nclass AtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"AtGenVV\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_at(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->at(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass AtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->atz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tWrapAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_wrapAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass WrapAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tWrapAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"WrapAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->wrapAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass FoldAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tFoldAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_foldAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass FoldAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tFoldAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"FoldAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->foldAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nclass ClipAtGenVV : public Gen\n{\n\tP _a;\n\tVIn _b;\npublic:\n\tClipAtGenVV(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_clipAt(th, _a, *b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenVZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenVZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAt(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ClipAtGenZZ : public Gen\n{\n\tP _a;\n\tZIn _b;\npublic:\n\tClipAtGenZZ(Thread& th, P const& a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), _a(a), _b(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ClipAtGenZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = _a->clipAtz(*b);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Z degkey(Z degree, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ fidegree = floor(degree + .5);\n\t//Z frac = degree - fidegree;\n\tint idegree = (int)fidegree;\n\tint modDegree = (int)sc_imod(idegree, degreesPerCycle);\n\t//return frac + scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n\treturn scale->atz(modDegree) + cycleWidth * sc_div(idegree, degreesPerCycle);\n}\n\n\nstatic Z keydeg(Z key, P const& scale, Z cycleWidth, int degreesPerCycle)\n{\n\tZ cycles, cyckey;\n\tsc_fdivmod(key, cycleWidth, cycles, cyckey);\n\t\n\tZ frac = scale->atz(0) + cycleWidth - cyckey;\n\tZ mindiff = std::abs(frac);\n\tint idegree = 0;\n\tfor (int i = 0; i < degreesPerCycle; ++i) {\n\t\tfrac = std::abs(cyckey - scale->atz(i));\n\t\tif (frac < mindiff) {\n\t\t\tmindiff = frac;\n\t\t\tidegree = i;\n\t\t}\n\t}\n\t\n\treturn idegree + cycles * degreesPerCycle;\n}\n\nclass DegKeyVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _degree;\npublic:\n\n\tDegKeyVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_degkey(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass DegKeyZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _degree;\npublic:\n\n\tDegKeyZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_degree(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"DegKeyZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_degree(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = degkey(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_degree.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVV : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tVIn _key;\npublic:\n\n\tKeyDegVV(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle) \n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVV\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tV *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = do_keydeg(th, _scale, *b, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegVZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegVZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeV, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegVZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass KeyDegZZ : public Gen\n{\n\tP _scale;\n\tZ _cycleWidth;\n\tint _degreesPerCycle;\n\tZIn _key;\npublic:\n\n\tKeyDegZZ(Thread& th, P const& inScale, Arg inDegree, Z inCycleWidth, int inDegreesPerCycle)\n\t\t: Gen(th, itemTypeZ, inDegree.isFinite()), \n\t\t_scale(inScale), \n\t\t_key(inDegree), \n\t\t_cycleWidth(inCycleWidth),\n\t\t_degreesPerCycle(inDegreesPerCycle)\n\t\t{}\n\t\n\tvirtual const char* TypeName() const override { return \"KeyDegZZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint bstride;\n\t\t\tZ *b;\n\t\t\tif (_key(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = keydeg(*b, _scale, _cycleWidth, _degreesPerCycle);\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_key.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic Gen* newAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new AtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new AtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new AtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newWrapAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new WrapAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new WrapAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new WrapAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newDegKeyGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new DegKeyVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new DegKeyVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new DegKeyZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newKeyDegGen(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isVList()) {\n\t\treturn new KeyDegVV(th, a, b, cycleWidth, degreesPerCycle);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new KeyDegVZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t} else {\n\t\t\treturn new KeyDegZZ(th, a, b, cycleWidth, degreesPerCycle);\n\t\t}\n\t}\n}\n\nstatic Gen* newFoldAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new FoldAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new FoldAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new FoldAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nstatic Gen* newClipAtGen(Thread& th, P const& a, Arg b)\n{\n\tif (b.isVList()) {\n\t\treturn new ClipAtGenVV(th, a, b);\n\t} else {\n\t\tif (a->isV()) {\n\t\t\treturn new ClipAtGenVZ(th, a, b);\n\t\t} else {\n\t\t\treturn new ClipAtGenZZ(th, a, b);\n\t\t}\n\t}\n}\n\nV do_at(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->at(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newAtGen(th, a, b));\n\t} else wrongType(\"at : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_wrapAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->wrapAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newWrapAtGen(th, a, b));\n\t} else wrongType(\"wrapAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_degkey(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn degkey(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newDegKeyGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"degkey : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_keydeg(Thread& th, P const& a, Arg b, Z cycleWidth, int degreesPerCycle)\n{\n\tif (b.isReal()) {\n\t\treturn keydeg(b.asFloat(), a, cycleWidth, degreesPerCycle);\n\t} else if (b.isList()) {\n\t\treturn new List(newKeyDegGen(th, a, b, cycleWidth, degreesPerCycle));\n\t} else wrongType(\"keydeg : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_foldAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->foldAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newFoldAtGen(th, a, b));\n\t} else wrongType(\"foldAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nV do_clipAt(Thread& th, P const& a, Arg b)\n{\n\tif (b.isReal()) {\n\t\treturn a->clipAt(b.asInt());\n\t} else if (b.isList()) {\n\t\treturn new List(newClipAtGen(th, a, b));\n\t} else wrongType(\"clipAt : b\", \"Real or List\", b);\n\n\treturn 0.;\n}\n\nstatic void at_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"at : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"at\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_at(th, a, i);\n\tth.push(v);\n}\n\nstatic void wrapAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"wrapAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"wrapAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_wrapAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void degkey_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"degkey : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"degkey\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"degkey : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_degkey(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void keydeg_(Thread& th, Prim* prim)\n{\n\tP s = th.popList(\"keydeg : s\");\n\n\tV i = th.pop();\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"keydeg\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tint degreesPerCycle = (int)a->size()-1;\n\tif (degreesPerCycle <= 0) {\n\t\tpost(\"keydeg : scale has no degrees\");\n\t\tthrow errFailed;\n\t}\n\tZ cycleWidth = a->atz(degreesPerCycle);\n\n\tV v = do_keydeg(th, a, i, cycleWidth, degreesPerCycle);\n\tth.push(v);\n}\n\nstatic void foldAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"foldAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"foldAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_foldAt(th, a, i);\n\tth.push(v);\n}\n\nstatic void clipAt_(Thread& th, Prim* prim)\n{\n\tV i = th.pop();\n\tP s = th.popList(\"clipAt : s\");\n\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"clipAt\", \"\");\n\n\ts = s->pack(th);\n\tP const& a = s->mArray;\n\t\n\tV v = do_clipAt(th, a, i);\n\tth.push(v);\n}\n\n\n#pragma mark CONVERSION\n\n\nstruct VGen : public Gen\n{\n\tZIn _a;\n\t\n\tVGen(Thread& th, Arg a) : Gen(th, itemTypeV, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct ZGen : public Gen\n{\n\tVIn _a;\n\t\n\tZGen(Thread& th, Arg a) : Gen(th, itemTypeZ, true), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"VGen\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->asFloat();\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic P stringToZList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeZ, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tz[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P stringToVList(P const& string)\n{\n\tconst char* s = string->s;\n\tsize_t n = strlen(s);\n\tP list = new List(itemTypeV, n);\n\t\n\tArray* a = list->mArray();\n\ta->setSize(n);\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tv[i] = s[i];\n\t}\n\t\n\treturn list;\n}\n\nstatic P vlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"stream to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tV* v = a->v();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)v[i].asFloat());\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic P zlistToString(Thread& th, P const& list)\n{\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"signal to string\", \"\");\n\t\t\n\tP packedList = list->pack(th);\n\tsize_t n = packedList->length(th);\n\tchar* s = (char*)malloc(n+1);\n\t\n\tP string = new String(s, \"dummy\");\n\t\n\tArray* a = packedList->mArray();\n\tZ* z = a->z();\n\t\n\tfor (size_t i = 0; i < n; ++i) {\n\t\ts[i] = toascii((int)z[i]);\n\t}\n\ts[n] = 0;\n\t\n\treturn string;\n}\n\nstatic void V_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isZList()) {\n\t\tGen* g = new VGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToVList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void Z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tGen* g = new ZGen(th, a);\n\t\tth.push(new List(g));\n\t} else if (a.isString()) {\n\t\tP s = (String*)a.o();\n\t\tth.push(stringToZList(s));\n\t} else {\n\t\tth.push(a);\n\t}\n}\n\nstatic void unspell_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tif (a.isVList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(vlistToString(th, list));\n\t} else if (a.isZList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(zlistToString(th, list));\n\t} else if (a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\twrongType(\"unspell : list\", \"List or String\", a);\n\t}\n}\n\n\n\n#pragma mark NUMERIC SERIES\n\n\nstruct Ever : public Gen\n{\n\tV _val;\n\n\tEver(Thread& th, Arg val) : Gen(th, itemTypeV, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Ever\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV v = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = v;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Everz : public Gen\n{\n\tZ _val;\n\n\tEverz(Thread& th, Z val) : Gen(th, itemTypeZ, false), _val(val) {}\n\n\tvirtual const char* TypeName() const override { return \"Everz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ z = _val;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = z;\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_recip;\nextern UnaryOp* gUnaryOpPtr_cb;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstruct By : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tBy(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"By\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Byz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tByz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Byz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Grow : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tGrow(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Grow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = _start;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Growz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tGrowz(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"Growz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start;\n\t\t\tstart *= step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLine : public Gen\n{\n\tV _start;\n\tV _step;\n\n\tCubicLine(Thread& th, Arg start, Arg step) : Gen(th, itemTypeV, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLine\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV cubed = _start.unaryOp(th, gUnaryOpPtr_cb);\t\n\t\t\tout[i] = cubed;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\t\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct CubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\n\tCubicLinez(Thread& th, Z start, Z step) : Gen(th, itemTypeZ, false), _start(start), _step(step) {}\n\n\tvirtual const char* TypeName() const override { return \"CubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tZ step = _step;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = start*start*start;\n\t\t\tstart += step;\t\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Inv : public Gen\n{\n\tV _start;\n\n\tInv(Thread& th) : Gen(th, itemTypeV, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Inv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tV vone = 1.;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\tout[i] = vout;\n\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Invz : public Gen\n{\n\tZ _start;\n\n\tInvz(Thread& th) : Gen(th, itemTypeZ, false), _start(1.) {}\n\n\tvirtual const char* TypeName() const override { return \"Invz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ start = _start;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. / start;\n\t\t\tstart += 1.;\n\t\t}\n\t\t_start = start;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NInv : public Gen\n{\n\tV _start;\n\tint64_t _n;\n\n\tNInv(Thread& th, int64_t n) : Gen(th, itemTypeV, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInv\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tV vone = 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV vout = _start.unaryOp(th, gUnaryOpPtr_recip);\n\t\t\t\tout[i] = vout;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, vone);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NInvz : public Gen\n{\n\tZ _start;\n\tint64_t _n;\n\n\tNInvz(Thread& th, int64_t n) : Gen(th, itemTypeZ, true), _start(1.), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NInvz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = 1. / start;\n\t\t\t\tstart += 1.;\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NBy : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNBy(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NBy\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_plus, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NByz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\t\n\tNByz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NByz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\n\nstruct NGrow : public Gen\n{\n\tV _start;\n\tV _step;\n\tint64_t _n;\n\n\tNGrow(Thread& th, Arg start, Arg step, int64_t n) : Gen(th, itemTypeV, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrow\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = _start;\n\t\t\t\t_start = _start.binaryOp(th, gBinaryOpPtr_mul, _step);\n\t\t\t}\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NGrowz : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNGrowz(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NGrowz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start;\n\t\t\t\tstart *= step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct NCubicLinez : public Gen\n{\n\tZ _start;\n\tZ _step;\n\tint64_t _n;\n\n\tNCubicLinez(Thread& th, Z start, Z step, int64_t n) : Gen(th, itemTypeZ, true), _start(start), _step(step), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"NCubicLinez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(_n, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(n);\n\t\t\tZ start = _start;\n\t\t\tZ step = _step;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = start*start*start;\n\t\t\t\tstart += step;\t\n\t\t\t}\n\t\t\t_start = start;\n\t\t\t_n -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n};\n\nstruct Fib : public Gen\n{\n\tV _a;\n\tV _b;\n \n\tFib(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fib\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tV a = _a;\n out[i] = a;\n _a = _b;\n _b = a.binaryOp(th, gBinaryOpPtr_plus, _b);\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Fibz : public Gen\n{\n\tZ _a;\n\tZ _b;\n \n\tFibz(Thread& th, Z a, Z b) : Gen(th, itemTypeZ, false), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Fibz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n int n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tZ a = _a;\n\t\tZ b = _b;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = a;\n Z aa = a;\n a = b;\n b += aa;\n\t\t}\n\t\t_a = a;\n\t\t_b = b;\n\t\tmOut = mOut->nextp();\n }\n};\n\nstatic void L_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tth.push(new List(new Ever(th, th.pop())));\n\t}\n}\n\nstatic void L1_(Thread& th, Prim* prim)\n{\n\tif (!th.top().isVList()) {\n\t\tP list = new List(itemTypeV, 1);\n\t\tlist->add(th.pop());\n\t\tth.push(list);\n\t}\n}\n\nstatic void ever_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\t\n\tGen* g = new Ever(th, value);\n\tth.push(new List(g));\n}\n\nstatic void everz_(Thread& th, Prim* prim)\n{\n\tZ value = th.popFloat(\"everz : value\");\n\t\n\tGen* g = new Everz(th, value);\n\tth.push(new List(g));\n}\n\nstatic void by_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new By(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nby_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"nby : n\");\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void to_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"to : end\");\n\tZ start = th.popFloat(\"to : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void toz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"toz : end\");\n\tZ start = th.popFloat(\"toz : start\");\n\tZ step = start < end ? 1. : -1.;\n\tint64_t n = (int64_t)((end - start) * step) + 1;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv : end\");\n\tZ start = th.popFloat(\"lindiv : start\");\n\tint64_t n = th.popInt(\"lindiv : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindivz : end\");\n\tZ start = th.popFloat(\"lindivz : start\");\n\tint64_t n = th.popInt(\"lindivz : n\");\n\tZ step = (end - start) / (n - 1);\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv : end\");\n\tZ start = th.popFloat(\"expdiv : start\");\n\tint64_t n = th.popInt(\"expdiv : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdivz_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdivz : end\");\n\tZ start = th.popFloat(\"expdivz : start\");\n\tint64_t n = th.popInt(\"expdivz : n\");\n\tZ step = pow(end/start, 1. / (n - 1));\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1 : end\");\n\tZ start = th.popFloat(\"lindiv1 : start\");\n\tint64_t n = th.popInt(\"lindiv1 : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NBy(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void lindiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"lindiv1z : end\");\n\tZ start = th.popFloat(\"lindiv1z : start\");\n\tint64_t n = th.popInt(\"lindiv1z : n\");\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1 : end\");\n\tZ start = th.popFloat(\"expdiv1 : start\");\n\tint64_t n = th.popInt(\"expdiv1 : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void expdiv1z_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"expdiv1z : end\");\n\tZ start = th.popFloat(\"expdiv1z : start\");\n\tint64_t n = th.popInt(\"expdiv1z : n\");\n\tZ step = pow(end/start, 1. / n);\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void line_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"line : end\");\n\tZ start = th.popFloat(\"line : start\");\n\tZ dur = th.popFloat(\"line : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\tZ step = (end - start) / n;\n\t\n\tGen* g = new NByz(th, start, step, (int64_t)n);\n\tth.push(new List(g));\n}\n\nstatic void xline_(Thread& th, Prim* prim)\n{\n\tZ end = th.popFloat(\"xline : end\");\n\tZ start = th.popFloat(\"xline : start\");\n\tZ dur = th.popFloat(\"xline : dur\");\n\tdouble n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\n\tGen* g;\n\tif (sc_sgn(start) != sc_sgn(end) || start == 0. || end == 0.) {\n\t\tstart = sc_sgn(start) * pow(fabs(start), kOneThird);\n\t\tend = sc_sgn(end) * pow(fabs(end), kOneThird);\n\t\tZ step = (end - start) / n;\t\t\n\t\tg = new NCubicLinez(th, start, step, (int64_t)n);\n\t} else {\n\t\tZ step = pow(end/start, 1. / n);\n\t\tg = new NGrowz(th, start, step, (int64_t)n);\n\t}\n\tth.push(new List(g));\n}\n\n\nstatic void grow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\t\n\tGen* g = new Grow(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrow_(Thread& th, Prim* prim)\n{\n\tV step = th.pop();\n\tV start = th.pop();\n\tint64_t n = th.popInt(\"ngrow : n\");\n\t\n\tGen* g = new NGrow(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void byz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"byz : step\");\n\tZ start = th.popFloat(\"byz : start\");\n\t\n\tGen* g = new Byz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void nbyz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"nbyz : step\");\n\tZ start = th.popFloat(\"nbyz : start\");\n\tint64_t n = th.popInt(\"nbyz : n\");\n\t\n\tGen* g = new NByz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void growz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"growz : step\");\n\tZ start = th.popFloat(\"growz : start\");\n\t\n\tGen* g = new Growz(th, start, step);\n\tth.push(new List(g));\n}\n\nstatic void ngrowz_(Thread& th, Prim* prim)\n{\n\tZ step = th.popFloat(\"ngrowz : step\");\n\tZ start = th.popFloat(\"ngrowz : start\");\n\tint64_t n = th.popInt(\"ngrowz : n\");\n\t\n\tGen* g = new NGrowz(th, start, step, n);\n\tth.push(new List(g));\n}\n\nstatic void ord_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negs_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void nat_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evens_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void odds_(Thread& th, Prim* prim)\n{\n\tGen* g = new By(th, 1., 2.);\n\tth.push(new List(g));\n}\n\n\nstatic void invs_(Thread& th, Prim* prim)\n{\n\tGen* g = new Inv(th);\n\tth.push(new List(g));\n}\n\nstatic void invz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Invz(th);\n\tth.push(new List(g));\n}\n\nstatic void ninvs_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvs : n\");\n\tGen* g = new NInv(th, n);\n\tth.push(new List(g));\n}\n\nstatic void ninvz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ninvz : n\");\n\tGen* g = new NInvz(th, n);\n\tth.push(new List(g));\n}\n\n\nstatic void ordz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 1.);\n\tth.push(new List(g));\n}\n\nstatic void negz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, -1., -1.);\n\tth.push(new List(g));\n}\n\nstatic void natz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 1.);\n\tth.push(new List(g));\n}\n\nstatic void evenz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 0., 2.);\n\tth.push(new List(g));\n}\n\nstatic void oddz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Byz(th, 1., 2.);\n\tth.push(new List(g));\n}\n\nstatic void fib_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Fib(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void fibz_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"fibz : b\");\n\tZ a = th.popFloat(\"fibz : a\");\n\t\n\tGen* g = new Fibz(th, a, b);\n\tth.push(new List(g));\n}\n\nstruct Ints : public Gen\n{\n\tZ _a;\n \n\tInts(Thread& th) : Gen(th, itemTypeV, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Ints\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Intz : public Gen\n{\n\tZ _a;\n \n\tIntz(Thread& th) : Gen(th, itemTypeZ, false), _a(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"Intz\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n Z a = _a;\n\t\tfor (int i = 0; i < n; ++i) {\n out[i] = a;\n if (a <= 0.) a = 1. - a;\n else a = -a;\n\t\t}\n _a = a;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstatic void ints_(Thread& th, Prim* prim)\n{\n\tGen* g = new Ints(th);\n\tth.push(new List(g));\n}\n\nstatic void intz_(Thread& th, Prim* prim)\n{\n\tGen* g = new Intz(th);\n\tth.push(new List(g));\n}\n\n#include \"primes.hpp\"\n\nstruct Primes : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimes(Thread& th) : Gen(th, itemTypeV, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primes\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t} else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct Primez : Gen\n{\n\tint byte;\n\tint bit;\n\t\n\tPrimez(Thread& th) : Gen(th, itemTypeZ, false), byte(-1), bit(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Primez\"; }\n \n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n if (byte < 0) {\n out[i] = gLowPrimes[bit];\n if (++bit >= 10) {\n byte = 0;\n bit = 0;\n }\n } else {\n while (1) {\n\t\t\t\t\tif (byte >= kPrimesMaskSize) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(n - i);\n\t\t\t\t\t\treturn;\n } else if (gPrimesMask[byte] & (1 << bit)) {\n out[i] = 30 * (1 + byte) + gPrimeOffsets[bit];\n\t\t\t\t\t\tif (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n break;\n } else {\n if (++bit >= 8) {\n ++byte;\n bit = 0;\n }\n }\n }\n }\n }\n\t\tmOut = mOut->nextp();\n }\n};\n\n\nstatic void primes_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primes(th);\n\tth.push(new List(g));\n}\n\nstatic void primez_(Thread& th, Prim* prim)\n{\n\tGen* g = new Primez(th);\n\tth.push(new List(g));\n}\n\n\n#pragma mark ORDERING\n\n\nclass Perms : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPerms(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_at(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Perms\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeV, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tV* outItems = arr->v();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nclass Permz : public Gen\n{\n\tstd::vector mOrder;\n\tstd::vector mItems;\n\tint64_t m;\npublic:\n\n\tPermz(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrder.reserve(inItems->size());\n\t\tmItems.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmItems.push_back(inItems->_atz(i));\n\t\t\tmOrder.push_back(i);\n\t\t}\n\t\tnumPerms();\n\t}\n\t\n\tvoid numPerms()\n\t{\n\t\tm = 1;\n\t\tfor (int64_t i = 2; i <= (int64_t)mItems.size(); ++i) {\n\t\t\tm *= i;\n\t\t}\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Permz\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tif (m <= 0) {\n\t\t\tend();\n\t\t} else {\n\t\t\tint n = (int)std::min(m, (int64_t)mBlockSize);\n\t\t\tV* out = mOut->fulfill(n);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tconst int len = (int)mItems.size();\n\t\t\t\tP list = new List(itemTypeZ, len);\n\t\t\t\tP arr = list->mArray;\n\t\t\t\tZ* outItems = arr->z();\n\t\t\t\t\n\t\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\t\toutItems[j] = mItems[mOrder[j]];\n\t\t\t\t}\n\t\t\t\tarr->setSize(len);\n\t\t\t\tout[i] = list;\n\t\t\t\tgetNext();\n\t\t\t}\n\t\t\tm -= n;\n\t\t\tmOut = mOut->nextp();\n\t\t}\n\t}\n\t\n\tvoid getNext()\n\t{\n\t\tint N = (int)mOrder.size();\n\t\tint i = N - 1;\n\t\twhile (mOrder[i-1] >= mOrder[i]) \n\t\t\ti = i-1;\n\n\t\tif (i <= 0) return;\n\n\t\tint j = N;\n\t\twhile (mOrder[j-1] <= mOrder[i-1]) \n\t\t\tj = j-1;\n\n\t\tstd::swap(mOrder[i-1], mOrder[j-1]);\n\n\t\ti++; j = N;\n\t\twhile (i < j) {\n\t\t\tstd::swap(mOrder[i-1], mOrder[j-1]); \n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n};\n\nstatic void perms_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"perms : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"perms : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Perms(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permz : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new Permz(th, arr);\n\tth.push(new List(g));\n}\n\n\n\nclass PermsWithRepeatedItems : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItems(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_at(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItems\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\n\nclass PermsWithRepeatedItemsZ : public Gen\n{\n\tstd::vector mOrig;\n\tstd::vector mItems;\n\tbool mThereafter = false;\npublic:\n\n\tPermsWithRepeatedItemsZ(Thread& th, P const& inItems)\n\t\t: Gen(th, itemTypeV, true)\n\t{\n\t\tmOrig.reserve(inItems->size());\n\t\tfor (int i = 0; i < inItems->size(); ++i) {\n\t\t\tmOrig.push_back(inItems->_atz(i));\n\t\t}\n\t\tmItems = mOrig;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PermsWithRepeatedItemsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint n = mBlockSize;\n\t\tint framesRemaining = n;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (mThereafter) {\n\t\t\t\tif (getNext(th)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmThereafter = true;\n\t\t\t}\n\t\t\tconst int len = (int)mItems.size();\n\t\t\tP list = new List(itemTypeV, len);\n\t\t\tP arr = list->mArray;\n\t\t\tV* outItems = arr->v();\n\t\t\t\n\t\t\tfor (int j = 0; j < len; ++j) {\n\t\t\t\toutItems[j] = mItems[j];\n\t\t\t}\n\t\t\tarr->setSize(len);\n\t\t\tout[i] = list;\n\t\t\t--framesRemaining;\n\t\t}\n\t\tproduce(framesRemaining);\n\t}\n\t\n\tbool getNext(Thread& th)\n\t{\n\t\tauto vless = [&](Arg a, Arg b){ return ::Compare(th, a, b) < 0; };\n\t\tnext_permutation(mItems.begin(), mItems.end(), vless);\n\t\t\n\t\tfor (size_t i = 0; i < mItems.size(); ++i) {\n\t\t\tif (!::Equals(th, mItems[i], mOrig[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n};\n\nstatic void permswr_(Thread& th, Prim* prim)\n{\n\tP a = th.popVList(\"permswr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permswr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItems(th, arr);\n\tth.push(new List(g));\n}\n\nstatic void permzwr_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"permzwr : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"permzwr : list\", \"\");\n\t\n\ta = a->pack(th);\n P arr = a->mArray;\n\tGen* g = new PermsWithRepeatedItemsZ(th, arr);\n\tth.push(new List(g));\n}\n\n\nstruct Repeat : Gen\n{\n V _a;\n\tint64_t _m;\n \n\tRepeat(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n V a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct RepeatFun : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFun(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeV, m < LLONG_MAX), _a(a), _b(0.), _m(m) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Repeat\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n V* out = mOut->fulfill(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n\t}\n \n};\n\nstruct InfRepeatFun : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFun(Thread& th, Arg a) : Gen(th, itemTypeV, false), _a(a), _b(0.) {}\n\t \n\tvirtual const char* TypeName() const override { return \"InfRepeatFun\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n \n};\n\nstruct Repeatz : Gen\n{\n Z _a;\n\tint64_t _m;\n \n\tRepeatz(Thread& th, Z a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Repeatz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n Z a = _a;\n for (int i = 0; i < n; ++i) {\n out[i] = a;\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct RepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n\tint64_t _m;\n \n\tRepeatFunz(Thread& th, Arg a, int64_t m) : Gen(th, itemTypeZ, true), _a(a), _b(0.), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"RepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n for (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(_b);\n\t\t\t\t_b += 1.;\n\t\t\t\t_a.apply(th);\n out[i] = th.pop().asFloat();\n }\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstruct InfRepeatFunz : Gen\n{\n V _a;\n\tZ _b;\n \n\tInfRepeatFunz(Thread& th, Arg a) : Gen(th, itemTypeZ, false), _a(a), _b(0.) {}\n \n\tvirtual const char* TypeName() const override { return \"InfRepeatFunz\"; }\n\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tZ* out = mOut->fulfillz(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(_b);\n\t\t\t_b += 1.;\n\t\t\t_a.apply(th);\n\t\t\tout[i] = th.pop().asFloat();\n\t\t}\n\t\tmOut = mOut->nextp();\n }\n};\n\nstruct RCyc : public Gen\n{\n\tV _ref;\n\tP _a0;\n\tP _a;\n\n\tRCyc(Thread& th, Arg ref, P const& a) : Gen(th, a->elemType, false), _ref(ref), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"RCyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tV v = _ref.deref();\n\t\t\tif (v.isList()) {\n\t\t\t\t_a0 = (List*)v.o();\n\t\t\t}\n\t\t\t_a = _a0;\n\t\t}\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Cyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\n\tCyc(Thread& th, P const& a) : Gen(th, a->elemType, false), _a0(a), _a(a) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) _a = _a0;\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\n\nstruct NCyc : public Gen\n{\n\tP _a0;\n\tP _a;\n\tint64_t _n;\n\t\n\tNCyc(Thread& th, int64_t n, P const& a) : Gen(th, a->elemType, true), _a0(a), _a(a), _n(n) {}\n\n\tvirtual const char* TypeName() const override { return \"Cyc\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (!_a) {\n\t\t\tif (_n <= 1) {\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\t_a = _a0;\n\t\t\t\t--_n;\n\t\t\t}\n\t\t}\n\n\t\t_a->force(th);\n\t\tmOut->fulfill(_a->mArray);\n\t\t_a = _a->next();\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void repeat_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"X : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFun(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Ever(th, a);\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFun(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeat(th, a, n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstatic void repeatz_(Thread& th, Prim* prim)\n{\n\tZ x = th.popFloat(\"XZ : n\");\n\tV a = th.pop();\n \n\tif (x <= 0.) {\n\t\tth.push(vm._nilv);\n\t} else {\n\t\tGen* g;\n\t\tif (x >= (Z)LONG_MAX) {\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new InfRepeatFunz(th, a);\n\t\t\t} else {\n\t\t\t\tg = new Everz(th, a.asFloat());\n\t\t\t}\n\t\t} else {\n\t\t\tint64_t n = (int64_t)floor(x + .5);\n\t\t\tif (a.isFunOrPrim()) {\n\t\t\t\tg = new RepeatFunz(th, a, n);\n\t\t\t} else {\n\t\t\t\tg = new Repeatz(th, a.asFloat(), n);\n\t\t\t}\n\t\t}\n\t\tth.push(new List(g));\n\t}\n}\n\nstruct Silence : Gen\n{\n\tint64_t _m;\n \n\tSilence(Thread& th, int64_t m) : Gen(th, itemTypeZ, true), _m(m) {}\n \n\tvirtual const char* TypeName() const override { return \"Silence\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tif (_m <= 0) {\n\t\t\tend();\n\t\t} else {\n int n = (int)std::min(_m, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(n);\n\t\t\tmemset(out, 0, n * sizeof(Z));\n _m -= n;\n\t\t\tmOut = mOut->nextp();\n }\n }\n};\n\nstatic void mum_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"mum : duration\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\tif (isinf(t) || (n <= 0 && t > 0.)) {\n\t\tth.push(new List(new Everz(th, 0.)));\n\t} else {\n\t\tGen* g = new Silence(th, n);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstatic void cyc_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\t\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP s = (List*)v.o();\n\t\n\n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n \n\tGen* g = new Cyc(th, s);\n\tth.push(new List(g));\n}\n\n\nstatic void rcyc_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tV v = ref.deref();\n\tif (!v.isList()) {\n\t\twrongType(\"rcyc : ref get\", \"List\", v);\n\t}\n\t\n\tP list = (List*)v.o();\n\t\n\tGen* g = new RCyc(th, ref, list);\n\tth.push(new List(g));\n}\n\n\nstatic void ncyc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"ncyc : n\");\n\tP s = th.popList(\"ncyc : seq\");\n \n s->force(th);\n if (s->isEnd()) {\n th.push(s);\n return;\n }\n\t\n\tif (n <= 0) {\n\t\tth.push(vm.getNil(s->elemType));\t\t\n\t} else {\n\t\tGen* g = new NCyc(th, n, s);\n\t\tth.push(new List(g));\n\t}\n}\n\n\nstruct Append : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAppend(Thread& th, P const& a, Arg b, bool inFinite) : Gen(th, a->elemType, inFinite), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Append\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t\tmOut = mOut->nextp();\n\t\t} else {\n\t\t\tif (_b.isFunOrPrim()) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\t_b.apply(th);\n\t\t\t\t_b = th.pop();\n\t\t\t}\n\t\t\tif (!_b.isList()) {\n\t\t\t\tpost(\"$ : b is not a sequence '%s'\\n\", _b.TypeName());\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tList* b = (List*)_b.o();\n\t\t\tif (elemType != b->elemType) {\n\t\t\t\tpost(\"$ : b item type doesn't match\\n\");\n\t\t\t\tend();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetDone();\n\t\t\tmOut->link(th, b);\n\t\t}\n\t}\n};\n\n\nstruct Cat : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\n\tCat(Thread& th, Arg a, P const& b) : Gen(th, itemTypeV, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"Cat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isVList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct CatZ : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\n\t// this makes the assumption that all of the sublists of b are finite! if they are not then this will not prevent infinite loops.\n\tCatZ(Thread& th, Arg a, P const& b) : Gen(th, itemTypeZ, b->isFinite()), _a(a), _b(b)\n\t{\n\t\tV v;\n\t\t_b.one(th, v); // skip over a.\n\t}\n\tvirtual const char* TypeName() const override { return \"CatZ\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tV b;\n\t\t\t\tif (_b.one(th, b)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb = th.pop();\n\t\t\t\t\t}\n\t\t\t\t\tif (!b.isZList()) { \n\t\t\t\t\t\tsetDone(); \n\t\t\t\t\t\tbreak; \n\t\t\t\t\t}\n\t\t\t\t\t_a.set(b);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a[i];\n\t\t\t}\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\t\t\t\n};\n\n#include \n\nstruct Flat : Gen\n{\n\tstd::stack in; // stack of list continuations\n\n\tFlat(Thread& th, Arg inA) : Gen(th, itemTypeV, inA.isFinite())\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList()) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Flatten : Gen\n{\n\tstd::stack in; // stack of list continuations\n\tsize_t depth;\n\t\n\tFlatten(Thread& th, Arg inA, size_t inDepth) : Gen(th, itemTypeV, inA.isFinite()), depth(inDepth)\n\t{\n\t\tVIn vin(inA);\n\t\tin.push(vin);\n\t}\n\tvirtual const char* TypeName() const override { return \"Flat\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tVIn* vin = &in.top();\n\t\tfor (int i = 0; framesToFill; ) {\n\t\t\tV a;\n\t\t\tif (vin->one(th, a)) {\n\t\t\t\tif (in.size() == 1) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tin.pop();\n\t\t\t\t\tvin = &in.top();\n\t\t\t\t}\n\t\t\t} else if (a.isVList() && in.size() <= depth) {\n\t\t\t\tVIn vin2(a);\n\t\t\t\tin.push(vin2);\n\t\t\t\tvin = &in.top();\n\t\t\t} else {\n\t\t\t\tout[i++] = a;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Keep : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tKeep(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keep\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Take : Gen\n{\n\tVIn _a;\n\tint64_t _n;\n\t\n\tTake(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeV, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Take\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n V *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeat(th, 0., _n));\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Keepz : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tKeepz(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Keepz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _n -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstruct Takez : Gen\n{\n\tZIn _a;\n\tint64_t _n;\n\t\n\tTakez(Thread& th, int64_t n, Arg a) : Gen(th, itemTypeZ, true), _a(a), _n(n) {}\n\tvirtual const char* TypeName() const override { return \"Takez\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_n <= 0) {\n\t\t\tend();\n\t\t} else {\n int framesToFill = (int)std::min(_n, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tP g = new List(new Repeatz(th, 0., _n));\n setDone();\n\t\t\t\t\tmOut->link(th, g());\n return;\n } else {\n\t\t\t\t\t_n -= framesToFill;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\nstatic void append_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tif (a.isString() && b.isString()) {\n\t\tstd::string s;\n\t\ta.print(th, s);\n\t\tb.print(th, s);\n\t\tth.push(new String(s.c_str()));\n\t} else if (a.isList()) {\n\t\tP list = (List*)a.o();\n\t\tth.push(new List(new Append(th, list, b, leastFinite(a,b))));\n\t} else {\n\t\twrongType(\"$ : a\", \"List or String\", a);\n\t}\n}\n\nstruct AppendSubs : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tAppendSubs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b) {}\n\t\n\tvirtual const char* TypeName() const override { return \"AppendSubs\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tif (!a->isList())\n\t\t\t\t\t\twrongType(\"$$ : *a\", \"List\", *a);\n\t\t\t\t\t\n\t\t\t\t\tList* aa = (List*)a->o();\n\t\t\t\t\t\t\n\t\t\t\t\tout[i] = new List(new Append(th, aa, *b, mostFinite(*a,*b)));\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void appendSubs_(Thread& th, Prim* prim)\n{\n\tV b = th.popVList(\"$$ : b\");\n\tV a = th.popVList(\"$$ : a\");\n\t\n th.push(new List(new AppendSubs(th, a, b)));\n}\n\nstatic void cat_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isList()) {\n\t\tth.push(v);\n\t\treturn;\n\t}\n\t\n\tP b = (List*)v.o();\n\n\tb->force(th);\n\tif (b->isEnd()) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\tVIn a_(b);\n\tV a;\n\tif (a_.one(th, a)) {\n\t\tth.push(vm.getNil(b->elemType));\n\t\treturn;\n\t}\n\t\n\t\n\t\n\t//V a = b->mArray->v()[0];\n\t\n\tif (a.isString()) {\n\t\tif (!b->isFinite())\n\t\t\tindefiniteOp(\"$/ : list of strings\", \"\");\n\t\t\n\t\tstd::string s;\n\n\t\tVIn in_(b);\n\t\twhile (true) {\n\t\t\tV in;\n\t\t\tif (in_.one(th, in)) {\n\t\t\t\tth.push(new String(s.c_str()));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tin.print(th, s);\n\t\t}\n\t\t\n\t} else if (!a.isList()) {\n\t\twrongType(\"$/ : b\", \"List\", a);\n\t}\n\t\t\n\tGen* g;\n\tif (a.isVList()) g = new Cat(th, a, b);\n\telse g = new CatZ(th, a, b);\n\tth.push(new List(g));\n\n}\n\nstatic void flat_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\n\tif (a.isVList()) th.push(new List(new Flat(th, a)));\n\telse th.push(a);\n}\n\nstatic void flatten_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"flatten : n\");\n\tV a = th.pop();\n\t\n\tif (a.isVList()) th.push(new List(new Flatten(th, a, n)));\n\telse th.push(a);\n}\n\nstatic void N_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"N : n\");\n\tV v = th.pop();\n\t\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void NZ_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"NZ : n\");\n\tV v = th.pop();\n\t\n if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void T_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"T : t\");\n\tV v = th.pop();\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n if (v.isVList()) {\n\t\tif (n <= 0) v = vm._nilv;\n else v = new List(new Keep(th, n, v));\n } else if (v.isZList()) {\n\t\tif (n <= 0) v = vm._nilz;\n else v = new List(new Keepz(th, n, v));\n\t}\n \n th.push(v);\n}\n\nstatic void take_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"take : n\");\n\tP s = th.popList(\"take : s\");\n\n Gen* g;\n\tif (n > 0) {\n\t\tif (s->isVList()) \n\t\t\tg = new Take(th, n, s);\n\t\telse\n\t\t\tg = new Takez(th, n, s);\n\t\tth.push(new List(g));\n } else if (n < 0) {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"take\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tList* s2 = new List(s->elemType, n);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(n);\n\t\tif (s->isVList()) {\n\t\t\tV* p = s2->mArray->v();\n\t\t\tV* q = s->mArray->v();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tfor (int64_t i = 0; i < offset; ++i) p[i] = 0.;\n\t\t\t\tfor (int64_t i = 0, j = offset; i < size; ++i, ++j) p[j] = q[i];\n\t\t\t} else {\n\t\t\t\tfor (int64_t i = 0, j = size - n; i < n; ++i, ++j) p[i] = q[j];\n\t\t\t}\n\t\t} else {\n\t\t\tZ* p = s2->mArray->z();\n\t\t\tZ* q = s->mArray->z();\n\t\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\t\tif (size < n) {\n\t\t\t\tint64_t offset = n - size;\n\t\t\t\tmemset(p, 0, offset * elemSize);\n\t\t\t\tmemcpy(p + offset, q, size * elemSize);\n\t\t\t} else {\n\t\t\t\tmemcpy(p, q + size - n, n * elemSize);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t\t\n\t} else {\n\t\tif (s->isVList())\n\t\t\tth.push(vm._nilv);\n\t\telse \n\t\t\tth.push(vm._nilz);\n\t\treturn;\n\t\t\n\t}\n}\n\n\n\n\nstatic void skip_positive_(Thread& th, P& list, int64_t n)\n{\n\tif (n <= 0) return;\n\n\tint itemType = list->elemType;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\t\t\tif (list->isVList()) {\n\t\t\t\tfor (int64_t i = 0, j = n; i < remain; ++i, ++j) {\n\t\t\t\t\ta2->v()[i] = a->v()[j];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\t\t\t}\n\t\t\tlist = new List(a2, list->next());\n\t\t\treturn;\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm.getNil(itemType);\n\t}\n}\n\nstatic void skip_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"skip : n\");\n\tP s = th.popList(\"skip : s\");\n\n\tif (n <= 0) {\n\t\tth.push(s);\n\t\treturn;\n\t}\n\t\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\n\nstatic void skipT_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\">T : t\");\n\tP s = th.popList(\">T : s\");\n\t\n\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * t);\n\n\tskip_positive_(th, s, n);\n\tth.push(s);\n}\n\nstruct Hops : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHops(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"Hops\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\t\t\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tint64_t hop;\n\t\t\t\tif (_hop.onei(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tskip_positive_(th, _a, hop);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct HopTs : Gen\n{\n\tP _a;\n\tBothIn _hop;\n\tbool _once = true;\n\t\n\tHopTs(Thread& th, Arg hop, P const& a) : Gen(th, itemTypeV, true), _a(a), _hop(hop) {}\n\tvirtual const char* TypeName() const override { return \"HopTs\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tif (_once) {\n\t\t\t\t_once = false;\n\t\t\t} else {\n\t\t\t\tZ hop;\n\t\t\t\tif (_hop.onez(th, hop)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint64_t n = (int64_t)floor(.5 + th.rate.sampleRate * hop);\n\t\t\t\t\tskip_positive_(th, _a, n);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout[i] = _a;\n\t\t\tframesToFill -= 1;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void hops_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"N>> : list\");\n\n\tth.push(new List(new Hops(th, n, s)));\n}\n\nstatic void hopTs_(Thread& th, Prim* prim)\n{\n\tV n = th.pop();\n\tP s = th.popList(\"T>> : list\");\n\n\tth.push(new List(new HopTs(th, n, s)));\n}\n\n\n\n\nstatic void drop_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"drop : n\");\n\tP s = th.popList(\"drop : s\");\n\n\tif (n == 0) {\n\t\tth.push(s);\n\t} else if (n > 0) {\n\t\tskip_positive_(th, s, n);\n\t\tth.push(s);\n\t} else {\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"drop\", \"\");\n\t\t\t\n\t\ts = s->pack(th);\n\t\tint64_t size = s->length(th);\n\t\tn = -n;\n\t\t\n\t\tint64_t remain = std::max(0LL, size - n);\n\t\tif (remain <= 0) {\n\t\t\tth.push(vm.getNil(s->elemType));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tP s2 = new List(s->elemType, remain);\n\t\tth.push(s2);\n\t\ts2->mArray->setSize(remain);\n\t\tsize_t elemSize = s2->mArray->elemSize();\n\t\tif (s->isVList()) {\n\t\t\tV* y = s->mArray->v();\n\t\t\tV* x = s2->mArray->v();\n\t\t\tfor (int64_t i = 0; i < remain; ++i) {\n\t\t\t\tx[i] = y[i];\n\t\t\t}\n\t\t} else {\n\t\t\tmemcpy(s2->mArray->z(), s->mArray->z(), remain * elemSize);\n\t\t}\n\t}\n}\n\nstatic void choff_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"choff : n\");\n\tint64_t c = th.popInt(\"choff : c\");\n\tV a = th.pop();\n\t\n\tP s2 = new List(itemTypeV, n);\n\ts2->mArray->setSize(n);\n\t\n\tif (a.isVList()) {\n\t\tif (!a.isFinite())\n\t\t\tindefiniteOp(\"choff : a\", \"\");\n\t\t\t\n\t\tP aa = ((List*)a.o())->pack(th);\n\t\tint64_t m = aa->length(th);\n\t\tint64_t mn = std::min(m,n);\n\t\tfor (int64_t i = 0; i < mn; ++i) {\n\t\t\tint64_t j = sc_imod(i+c, n);\n\t\t\ts2->mArray->put(j, aa->at(i));\n\t\t}\n\t} else {\n\t\tc = sc_imod(c, n);\n\t\ts2->mArray->put(c, a);\n\t}\n\t\t\n\tth.push(s2);\n}\n\nstatic int64_t countWhileTrue(Thread& th, List* list)\n{\n int64_t n = 0;\n while (list) {\n list->force(th);\n\n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n if (a->at(i).isTrue()) ++n;\n else return n;\n }\n list = list->nextp();\n }\n\treturn n;\n}\n\nstatic void skipWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"skipWhile : s\");\n\n if (f.isList()) {\n int64_t n = countWhileTrue(th, (List*)f.o());\n skip_positive_(th, s, n);\n\t\tth.push(s);\n } else {\n \n List* list = s();\n\n while (1) {\n list->force(th);\n if (list->isEnd()) {\n th.push(vm.getNil(s->elemType));\n return;\n }\n \n Array* a = list->mArray();\n int64_t asize = a->size();\n \n for (int i = 0; i < asize; ++i) {\n V v;\n {\n SaveStack ss(th);\n th.push(a->at(i));\n\t\t\t\t\tf.apply(th);\n v = th.pop();\n }\n if (v.isFalse()) {\n if (i == 0) {\n th.push(list);\n } else {\n int64_t remain = asize - i;\n Array* a2 = new Array(s->elemType, remain);\n th.push(new List(a2, list->next()));\n a2->setSize(remain);\n\t\t\t\t\t\tif (a->isV()) {\n\t\t\t\t\t\t\tfor (int64_t j = 0; j < remain; ++j) a2->v()[j] = a->v()[j+i];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmemcpy(a2->v(), a->v() + i, remain * a->elemSize());\n\t\t\t\t\t\t}\n }\n return;\n }\n }\n list = list->nextp();\n }\n th.push(list);\n }\n}\n\n\nstruct KeepWhile : Gen\n{\n\tVIn _a;\n\tVIn _b;\n\t\n\tKeepWhile(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhile\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZ : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tKeepWhileZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a, *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileVZ : Gen\n{\n\tVIn _a;\n\tZIn _b;\n\t\n\tKeepWhileVZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileVZ\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n V* out = mOut->fulfill(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n V *a;\n\t\t\tZ *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (*b == 0.) {\n setDone();\n break;\n } else {\n out[k++] = *a;\n }\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstruct KeepWhileZV : Gen\n{\n\tZIn _a;\n\tVIn _b;\n\t\n\tKeepWhileZV(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, true), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"KeepWhileZV\"; }\n \n\tvirtual void pull(Thread& th) override {\n int framesToFill = mBlockSize;\n Z* out = mOut->fulfillz(framesToFill);\n while (framesToFill && !mDone) {\n int n = framesToFill;\n int astride, bstride;\n Z *a;\n\t\t\tV *b;\n if (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n setDone();\n break;\n } else {\n int k = 0;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tif (b->isFunOrPrim()) {\n\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\tb->apply(th);\n\t\t\t\t\t\tV v = th.pop();\n\t\t\t\t\t\tif (v.isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (b->isFalse()) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tout[k++] = *a;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n a += astride;\n b += bstride;\n }\n _a.advance(n);\n _b.advance(n);\n framesToFill -= k;\n out += k;\n }\n }\n produce(framesToFill);\n\t}\n};\n\nstatic void keepWhile_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tP s = th.popList(\"keepWhile : s\");\n\t\n\tif (s->isZ()) {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhileZV(th, s, f)));\n\t\t}\n\t} else {\n\t\tif (f.isZList()) {\n\t\t\tth.push(new List(new KeepWhileVZ(th, s, f)));\n\t\t} else {\n\t\t\tth.push(new List(new KeepWhile(th, s, f)));\n\t\t}\n\t} \n}\n\n\nstruct Tog : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Togz : Gen\n{\n\tZIn _a;\n\tZIn _b;\n\t\n\tTogz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Togz\"; }\n \t\t\t \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill / 2;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t*out++ = *a;\n\t\t\t\t\t*out++ = *b;\n\t\t\t\t\ta += astride;\n\t\t\t\t\tb += bstride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\t_b.advance(n);\n\t\t\t\tframesToFill -= 2*n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tog_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Tog(th, a, b)));\n}\n\nstatic void togz_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\n\tth.push(new List(new Togz(th, a, b)));\n}\n\n\n\nstruct Tog1 : Gen\n{\n\tVIn _in[2];\n\tint tog;\n\t\n\tTog1(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), tog(0) { _in[0] = a; _in[1] = b; }\n\tvirtual const char* TypeName() const override { return \"Tog1\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV v;\n\t\t\tif (_in[tog].one(th, v)) {\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = v;\n\t\t\t--framesToFill;\n\t\t\ttog = 1 - tog;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\n\nstruct Hang : Gen\n{\n\tP _a;\n\tV _b;\n\n\tHang(Thread& th, P const& a) : Gen(th, itemTypeV, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hang\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->v()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tV* out = mOut->fulfill(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Hangz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tHangz(Thread& th, P const& a) : Gen(th, itemTypeZ, false), _a(a) {}\n\tvirtual const char* TypeName() const override { return \"Hangz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\tif (_a->mArray->size()) {\n\t\t\t\t_b = _a->mArray->z()[_a->mArray->size() - 1];\n\t\t\t}\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\t_a = nullptr;\n\t\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tout[i] = _b;\n\t\t\t}\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void hang_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"hang : a\");\n\t\n\tif (a->isV())\n\t\tth.push(new List(new Hang(th, a)));\n\telse\n\t\tth.push(new List(new Hangz(th, a)));\n}\n\nstatic void hangz_(Thread& th, Prim* prim)\n{\n\tP a = th.popZList(\"hangz : a\");\n\t\n\tth.push(new List(new Hangz(th, a)));\n}\n\n\nstatic void histo_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"histo : n\");\n\tP a = th.popList(\"histo : list\");\n\n\tif (!a->isFinite()) {\n\t\tindefiniteOp(\"histo : list\", \"\");\n\t}\n\t\n\ta = a->pack(th);\n\t\n\tint64_t size = a->mArray->size();\n\t\n\tPoutList = new List(itemTypeZ, n);\n\toutList->mArray->setSize(n);\n\tZ* out = outList->mArray->z();\n\tmemset(out, 0, sizeof(Z) * n);\n\t\n\tZ n1 = n - 1;\n\tif (a->isZ()) {\n\t\tZ* in = a->mArray->z();\n\t\t\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i], 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t} else {\n\t\tV* in = a->mArray->v();\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tint64_t j = (int64_t)std::clamp(in[i].asFloat(), 0., n1);\n\t\t\tout[j] += 1.;\n\t\t}\n\t}\n\t\n\tth.push(outList);\n\t\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark MAP FILTER REDUCE\n\n\nstruct Stutter : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tStutter(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutter\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = aa_;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, aa_) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(aa_);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Stutterz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\tZ aa_;\n\t\n\tStutterz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n\n\tvirtual const char* TypeName() const override { return \"Stutterz\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a = aa_;\n\t\twhile (framesToFill) {\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n\t\t\t}\n\t\t}\n\t\taa_ = a;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void filter_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.popList(\"? : a\");\n\n\tif (a.isVList()) {\n\t\tth.push(new List(new Stutter(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Stutterz(th, a, b)));\n\t}\n}\n\n\nstruct Change : Gen\n{\n\tVIn _a;\n\tV _prev;\n\t\n\tChange(Thread& th, Arg a) : Gen(th, itemTypeV, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Change\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n V a;\n for (int i = 0; framesToFill; ) {\n if (_a.one(th, a)) {\n setDone();\n break;\n }\n if (!a.Equals(th, _prev)) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Changez : Gen\n{\n\tZIn _a;\n\tZ _prev;\n\t\n\tChangez(Thread& th, Arg a) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _prev(12347918239.19798729839470170) {}\n \n\tvirtual const char* TypeName() const override { return \"Changez\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n Z a;\n for (int i = 0; framesToFill; ) {\n if (_a.onez(th, a)) {\n setDone();\n break;\n }\n if (a != _prev) {\n out[i++] = a;\n --framesToFill;\n _prev = a;\n }\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void change_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"change : a\");\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Change(th, a)));\n\t} else {\n\t\tth.push(new List(new Changez(th, a)));\n\t}\n}\n\nstatic void changez_(Thread& th, Prim* prim)\n{\n\tV a = th.popZList(\"change : a\");\n \n th.push(new List(new Changez(th, a)));\n}\n\nstruct Spread : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\tint n_;\n\tV aa_;\n\t\n\tSpread(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spread\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tV a = aa_;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.one(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Spreadz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\tint n_;\n\t\n\tSpreadz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a,b)), _a(a), _b(b), n_(0) {}\n \n\tvirtual const char* TypeName() const override { return \"Spreadz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ a;\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tif (n_) {\n\t\t\t\tint n = std::min(n_, framesToFill);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tn_ -= n;\n\t\t\t\tout += n;\n\t\t\t\t\n\t\t\t\tif (framesToFill == 0) break;\n\t\t\t}\n\t\t\tV b;\n\t\t\tif (_a.onez(th, a) || _b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isFunOrPrim()) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tth.push(a);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tb.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tb = th.pop();\n\t\t\t\t} \t\t\t\t\n\t\t\t\tn_ = b.asFloat();\n \n *out++ = a;\n --framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void spread_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Spread(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Spreadz(th, a, b)));\n\t}\n}\n\nstatic void spreadz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"spreadz : b\");\n\tV a = th.popZIn(\"spreadz : a\");\n \n th.push(new List(new Spreadz(th, a, b)));\n}\n\nstruct Expand : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tExpand(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expand\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tV a;\n\t\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Expandz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tExpandz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Expandz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n for (int i = 0; framesToFill; ) {\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (b.isTrue()) {\n\t\t\t\t\tZ a;\n\t\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tout[i++] = a;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t} else {\n\t\t\t\t\tout[i++] = 0.;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void expand_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Expand(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Expandz(th, a, b)));\n\t}\n}\n\nstatic void expandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"expandz : b\");\n\tV a = th.popZIn(\"expandz : a\");\n \n th.push(new List(new Expandz(th, a, b)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Clump : Gen\n{\n\tVIn _a;\n\tBothIn _b;\n\t\n\tClump(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clump\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeV, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV a;\n\t\t\t\tif (_a.one(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->add(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Clumpz : Gen\n{\n\tZIn _a;\n\tBothIn _b;\n\t\n\tClumpz(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, a.isFinite()), _a(a), _b(b) {}\n \n\tvirtual const char* TypeName() const override { return \"Clumpz\"; }\n \n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\t\t\t\n\t\t\tV b;\n\t\t\tif (_b.one(th, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint64_t n = b.asFloat();\n\n\t\t\tP list = new List(itemTypeZ, 1);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a;\n\t\t\t\tif (_a.onez(th, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tlist->addz(a);\n\t\t\t}\n\t\t\t\n\t\t\t*out++ = list;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void clump_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList()) {\n\t\tth.push(new List(new Clump(th, a, b)));\n\t} else {\n\t\tth.push(new List(new Clumpz(th, a, b)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ShortAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tShortAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass ShortAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tShortAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, mostFinite(a, b)), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"ShortAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\tif (a_(th, n, astride, a) || b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = *a;\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\ta_.advance(n);\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void shortas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new ShortAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new ShortAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"shortas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs : public Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tV last;\npublic:\n\t\n\tLongAs(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAsZ : public Gen\n{\n\tZIn a_;\n\tZIn b_;\n\tZ last;\npublic:\n\t\n\tLongAsZ(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAsZ\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = last;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlast = *(a + (n-1)*astride);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAsZ(th, a, b)));\n\t} else {\n\t\twrongType(\"longas : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\nclass LongAs0 : public Gen\n{\n\tVIn a_;\n\tVIn b_;\npublic:\n\t\n\tLongAs0(Thread& th, Arg a, Arg b) : Gen(th, itemTypeV, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tV *a, *b;\n\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n;\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tV zero(0.);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = zero;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nclass LongAs0Z : public Gen\n{\n\tZIn a_;\n\tZIn b_;\npublic:\n\t\n\tLongAs0Z(Thread& th, Arg a, Arg b) : Gen(th, itemTypeZ, b.isFinite()), a_(a), b_(b) {}\n\n\tvirtual const char* TypeName() const override { return \"LongAs0Z\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride, bstride;\n\t\t\tZ *a, *b;\n\t\t\t\t\t\t\n\t\t\tif (b_(th, n, bstride, b)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tint n0 = n; // should ZIn::operator() return n = 0 if it is at end of stream??\n\t\t\tif (a_(th, n, astride, a)) {\n\t\t\t\tn = n0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\ta_.advance(n);\n\t\t\t}\n\t\t\tout += n;\n\t\t\tframesToFill -= n;\n\t\t\tb_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstatic void longas0_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n \n\tif (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new LongAs0(th, a, b)));\n\t} else if (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new LongAs0Z(th, a, b)));\n\t} else {\n\t\twrongType(\"longas0 : a, b must be same type\", \"two streams or two signals\", a);\n\t}\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \"Play.hpp\"\n\nstatic void play_(Thread& th, Prim* prim)\n{\n\tV v = th.popList(\"play : list\");\n\tplayWithAudioUnit(th, v);\n}\n\nstatic void record_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tV v = th.popList(\"record : list\");\n\trecordWithAudioUnit(th, v, filename);\n}\n\nstatic void stop_(Thread& th, Prim* prim)\n{\n\tstopPlaying();\n}\n\nstatic void stopDone_(Thread& th, Prim* prim)\n{\n\tstopPlayingIfDone();\n}\n\n\nstatic void interleave(int stride, int numFrames, double* in, float* out)\n{\n\tfor (int f = 0, k = 0; f < numFrames; ++f, k += stride)\n\t\tout[k] = in[f];\n}\n\nstatic void deinterleave(int numChans, int numFrames, float* in, double** out)\n{\n\tswitch (numChans) {\n\t\tcase 1 : \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, ++k) {\n\t\t\t\tout[0][f] = in[k];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 2 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=2) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3 : // e.g. W X Y \n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=3) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 4 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=4) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 5 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=5) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 6 :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f, k+=6) {\n\t\t\t\tout[0][f] = in[k ];\n\t\t\t\tout[1][f] = in[k+1];\n\t\t\t\tout[2][f] = in[k+2];\n\t\t\t\tout[3][f] = in[k+3];\n\t\t\t\tout[4][f] = in[k+4];\n\t\t\t\tout[5][f] = in[k+5];\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tfor (int f = 0, k = 0; f < numFrames; ++f) {\n\t\t\t\tfor (int c = 0; c < numChans; ++c, ++k) {\n\t\t\t\t\tout[c][f] = in[k];\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nstatic const size_t gSessionTimeMaxLen = 256;\nchar gSessionTime[gSessionTimeMaxLen];\n\n#include \n\nstatic void setSessionTime()\n{\n\ttime_t t;\n\ttm tt;\n\ttime(&t);\n\tlocaltime_r(&t, &tt);\n\tsnprintf(gSessionTime, gSessionTimeMaxLen, \"%04d-%02d%02d-%02d%02d%02d\",\n\t\ttt.tm_year+1900, tt.tm_mon+1, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec);\n}\n\n\nstatic void sfwrite_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.popList(\">sf : channels\");\n\t\n\tsfwrite(th, v, filename, false);\n}\n\nstatic void sfwriteopen_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.pop();\n\t\n\tV v = th.pop();\n\n\tsfwrite(th, v, filename, true);\n}\n\n\nstatic void sfread_(Thread& th, Prim* prim)\n{\n\t\n\tV filename = th.popString(\"sf> : filename\");\n\t\t\n\tsfread(th, filename, 0, -1);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstatic void bench_(Thread& th, Prim* prim)\n{\n\tZIn in[kMaxSFChannels];\n\t\t\n\tint numChannels = 0;\n\t\n\tV v = th.popList(\"bench : channels\");\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin[0].set(v);\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin[i].set(va);\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tdouble t0 = elapsedTime();\n\tbool done = false;\n\tint64_t framesFilled = 0;\n\twhile (!done) {\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].bench(th, n);\n\t\t\tif (imdone) done = true;\n\t\t\tframesFilled += n;\n\t\t}\n\t}\n\tdouble t1 = elapsedTime();\n\t\n\tdouble secondsOfCPU = t1-t0;\n\tdouble secondsOfAudio = (double)framesFilled * th.rate.invSampleRate;\n\tdouble percentOfRealtime = 100. * secondsOfCPU / secondsOfAudio;\n\t\n\tpost(\"bench:\\n\");\n\tpost(\" %f seconds of audio.\\n\", secondsOfAudio);\n\tpost(\" %f seconds of CPU.\\n\", secondsOfCPU);\n\tpost(\" %f %% of real time.\\n\", percentOfRealtime);\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#include \"Spectrogram.hpp\"\n\nstd::atomic gSpectrogramFileCount = 0;\n\nstatic void sgram_(Thread& th, Prim* prim)\n{\n\tV filename = th.pop();\n\tZ dBfloor = fabs(th.popFloat(\"sgram : dBfloor\"));\n\tP list = th.popZList(\"sgram : signal\");\n\t\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"sgram : signal - indefinite number of frames\", \"\");\n\t}\n\n\tchar path[1024];\n\tif (filename.isString()) {\n\t\tconst char* sgramDir = getenv(\"SAPF_SPECTROGRAMS\");\n\t\tif (!sgramDir || strlen(sgramDir)==0) sgramDir = \"/tmp\";\n\t\tsnprintf(path, 1024, \"%s/%s-%d.jpg\", sgramDir, ((String*)filename.o())->s, (int)floor(dBfloor + .5));\n\t} else {\n\t\tint32_t count = ++gSpectrogramFileCount;\n\t\tsnprintf(path, 1024, \"/tmp/sapf-%s-%04d.jpg\", gSessionTime, count);\n\t}\n\n\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\tint64_t n = array->size();\n\tdouble* z = array->z();\n\tspectrogram((int)n, z, 3200, 11, path, -dBfloor);\n\t\n\t{\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstatic double bessi0(double x)\n{\n\t//returns the modified Bessel function I_0(x) for any real x\n\t//from numerical recipes\n\t\n\tdouble ax, ans;\n\tdouble y;\n\t\n\tif((ax=fabs(x))<3.75){\n\t\ty=x/3.75;\n\t\ty *= y;\n\t\tans =1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492\n\t\t\t+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));\n\t}\n\telse{\n\t\ty=3.75/ax;\n\t\tans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1\n\t\t\t+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2\n\t\t\t+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1\n\t\t\t+y*0.392377e-2))))))));\n\t}\n\n\treturn ans;\n}\n\nstatic double kaiser_alpha(double atten)\n{\n\tdouble alpha = 0.;\n\tif (atten > 50.) \n\t\talpha = .1102 * (atten - 8.7);\n\telse if (atten >= 21.)\n\t\talpha = .5842 * pow(atten - 21., .4) + .07886 * (atten - 21.);\n\treturn alpha;\n}\n\nstatic void kaiser(size_t m, double *s, double alpha)\n{\n\tif (m == 0) return;\n\tif (m == 1) {\n\t\ts[0] = 1.;\n\t\treturn;\n\t}\n\tsize_t n = m-1;\n\tdouble p = n / 2.;\n\tdouble rp = 1. / p;\n\tdouble rb = 1. / bessi0(alpha);\n\t\n\tfor (size_t i = 0; i < m; ++i) {\n\t\tdouble x = (i-p) * rp;\n\t\ts[i] = rb * bessi0(alpha * sqrt(1. - x*x));\n\t}\n}\n\nstatic void kaiser_(Thread& th, Prim* prim)\n{\n\tZ atten = fabs(th.popFloat(\"kaiser : stopband attenuation\"));\n\tint64_t n = th.popInt(\"kaiser : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tZ alpha = kaiser_alpha(atten);\n\tkaiser(n, out->mArray->z(), alpha);\n\t\n\tth.push(out);\n}\n\n\nstatic void hanning_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hann_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void hamming_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_hamm_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\nstatic void blackman_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"hanning : n\");\n\t\n\tP out = new List(itemTypeZ, n);\n\tout->mArray->setSize(n);\n\t\n\tvDSP_blkman_windowD(out->mArray->z(), n, 0);\n\t\n\tth.push(out);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Segment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tBothIn length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tSegment(Thread& th, Arg in, Arg hop, Arg length)\n : Gen(th, itemTypeV, mostFinite(in, hop, length)), in_(in), hop_(hop), length_(length),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Segment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zlength, zhop;\n\t\t\tif (length_.onez(th, zlength)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint length = (int)floor(sr_ * zlength + .5);\n\t\t\tP segment = new List(itemTypeZ, length);\n\t\t\tsegment->mArray->setSize(length);\n\t\t\tbool nomore = in_.fillSegment(th, length, segment->mArray->z());\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n \n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void seg_(Thread& th, Prim* prim)\n{\n\tV length = th.pop();\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n\tth.push(new List(new Segment(th, in, hop, length)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct WinSegment : public Gen\n{\n\tZIn in_;\n\tBothIn hop_;\n\tP window_;\n int length_;\n\tint offset;\n Z fracsamp_;\n Z sr_;\n\t\n\tWinSegment(Thread& th, Arg in, Arg hop, P const& window)\n : Gen(th, itemTypeV, mostFinite(in, hop)), in_(in), hop_(hop), window_(window),\n length_((int)window_->size()),\n fracsamp_(0.), sr_(th.rate.sampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WinSegment\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\t\t\n\t\tint framesToFill = mBlockSize;\n\t\tint framesFilled = 0;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tZ zhop;\n\t\t\t\n\t\t\tP segment = new List(itemTypeZ, length_);\n\t\t\tsegment->mArray->setSize(length_);\n Z* segbuf = segment->mArray->z();\n\t\t\tbool nomore = in_.fillSegment(th, (int)length_, segbuf);\n vDSP_vmulD(segbuf, 1, window_->z(), 1, segbuf, 1, length_);\n\t\t\tout[i] = segment;\n\t\t\t++framesFilled;\n\t\t\tif (nomore) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tif (hop_.onez(th, zhop)) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\n Z fhop = sr_ * zhop + fracsamp_;\n Z ihop = floor(fhop);\n fracsamp_ = fhop - ihop;\n \n\t\t\tin_.hop(th, (int)ihop);\n\t\t}\n\tleave:\n\t\tproduce(framesToFill - framesFilled);\n\t}\n\t\n};\n\nstatic void wseg_(Thread& th, Prim* prim)\n{\n\tP window = th.popZList(\"wseg : window\");\n\tV hop = th.pop();\n\tV in = th.popZIn(\"segment : in\");\n \n window = window->pack(th);\n \n\tth.push(new List(new WinSegment(th, in, hop, window->mArray)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void fft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"fft : imag\");\n\tP inReal = th.popZList(\"fft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"fft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"fft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"fft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"fft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\n\tfft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\n\nstatic void ifft_(Thread& th, Prim* prim)\n{\n\tP inImag = th.popZList(\"ifft : imag\");\n\tP inReal = th.popZList(\"ifft : real\");\n\t\n\tif (!inReal->isFinite())\n\t\tindefiniteOp(\"ifft : real\", \"\");\n\t\t\n\tif (!inImag->isFinite())\n\t\tindefiniteOp(\"ifft : imag\", \"\");\n\n\tint n = (int)inReal->length(th);\n\tint m = (int)inImag->length(th);\n\tif (n != m) {\n\t\tpost(\"ifft : real and imag parts are different lengths.\\n\");\n\t\tthrow errFailed;\n\t}\n\tif (!ISPOWEROFTWO64(n)) {\n\t\tpost(\"ifft : size is not a power of two.\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tinReal = inReal->pack(th);\n\tinImag = inImag->pack(th);\n\t\n\tP outReal = new List(itemTypeZ, n);\n\tP outImag = new List(itemTypeZ, n);\n\toutReal->mArray->setSize(n);\n\toutImag->mArray->setSize(n);\n\n\tifft(n, inReal->mArray->z(), inImag->mArray->z(), outReal->mArray->z(), outImag->mArray->z());\n\t\n\tth.push(outReal);\n\tth.push(outImag);\n}\n\nstruct Add : Gen\n{\n\tP _a;\n\tV _b;\n\n\tAdd(Thread& th, P const& a, Arg b) : Gen(th, itemTypeV, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Add\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfill(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tV* out = mOut->fulfill(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct Addz : Gen\n{\n\tP _a;\n\tZ _b;\n\n\tAddz(Thread& th, P const& a, Z b) : Gen(th, itemTypeZ, a->isFinite()), _a(a), _b(b) {}\n\tvirtual const char* TypeName() const override { return \"Addz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (_a) {\n\t\t\t_a->force(th);\n\t\t\tif (_a->isEnd())\n\t\t\t\tgoto ended;\n\t\t\tmOut->fulfillz(_a->mArray);\n\t\t\t_a = _a->next();\n\t\t} else {\nended:\n\t\t\tZ* out = mOut->fulfillz(1);\n\t\t\tout[0] = _b;\n\t\t\tsetDone();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void add_(Thread& th, Prim* prim)\n{\n\tV item = th.pop();\n\tP list = th.popList(\"add : list\");\n\tif (list->isZ()) {\n\t\tth.push(new List(new Addz(th, list, item.asFloat())));\n\t} else {\n\t\tth.push(new List(new Add(th, list, item)));\n\t}\n}\n\nstatic void empty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size==0);\n}\n\nstatic void nonempty_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tP array = list->mArray;\n\tint64_t size = array->size();\n\tth.pushBool(size!=0);\n}\n\nstatic void head_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"head : list\");\n\tlist->force(th);\n\t\n\tBothIn in(list);\n\tV v;\n\tif (in.one(th, v)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tth.push(v);\n}\n\nstatic void tail_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tskip_positive_(th, list, 1);\n\tth.push(list);\n}\n\nstatic void uncons_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"tail : list\");\n\tlist->force(th);\n\n\tBothIn in(list);\n\tV head;\n\tif (in.one(th, head)) {\n\t\tthrow errOutOfRange;\n\t}\n\t\n\tskip_positive_(th, list, 1);\n\t\n\tth.push(list);\n\tth.push(head);\n}\n\nclass Cons : public Gen\n{\n\tV fun;\npublic:\n\tCons(Thread& th, Arg inFun) : Gen(th, itemTypeV, false), fun(inFun) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Cons\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tSaveStack ss(th);\n\t\tfun.apply(th);\n\t\tV v = th.pop();\n\t\tif (v.isList()) {\n\t\t\tsetDone();\n\t\t\tmOut->link(th, (List*)v.o());\n\t\t} else {\n\t\t\tend();\n\t\t}\n\t}\n};\n\nstatic V cons(Thread& th, Arg head, Arg tail)\n{\n\tif (tail.isFunOrPrim()) {\n\t\tP array = new Array(itemTypeV, 1);\n\t\tarray->add(head);\n\t\treturn new List(array, new List(new Cons(th, tail)));\n\t} else if (tail.isList()) {\n\t\n\t\tP list = (List*)tail.o();\n\t\t\n\t\tlist->force(th);\n\t\t\t\n\t\tint64_t size = list->mArray->size();\n\n\t\tP array = list->mArray;\n\t\tP newArray = new Array(list->ItemType(), size+1);\n\n\t\tP newList = new List(newArray, list->next());\n\n\t\tnewArray->add(head);\n\n\t\tif (list->isZ()) {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tZ z = array->atz(i);\n\t\t\t\tnewArray->add(z);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\tV v = array->at(i);\n\t\t\t\tnewArray->add(v);\n\t\t\t}\n\t\t}\n\n\t\treturn newList;\n\t} else {\n\t\twrongType(\"cons : list\", \"List or Fun\", tail);\n\t}\n}\n\nstatic void cons_(Thread& th, Prim* prim)\n{\n\tV head = th.pop();\n\tV tail = th.pop();\n\t\n\tth.push(cons(th, head, tail));\n}\n\nstatic void pack_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"pack : list\");\n\tth.push(list->pack(th));\n}\n\nstatic void packed_(Thread& th, Prim* prim)\n{\n\tP list = th.popList(\"packed : list\");\n\tth.pushBool(list->isPacked());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n \n\tScan(Thread& th, Arg list, Arg fun, Arg val) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan(th, list, fun, value)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Scan1 : Gen\n{\n\tVIn list_;\n V fun_;\n V val_;\n\tbool once_;\n \n\tScan1(Thread& th, Arg list, Arg fun) : Gen(th, itemTypeV, list.isFinite()), list_(list), fun_(fun), once_(true) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Scan\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (once_) {\n\t\t\tonce_ = false;\n\t\t\tif (list_.one(th, val_)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t*out++ = val_;\n\t\t\t--framesToFill;\n\t\t}\n\t\twhile (framesToFill) {\n\t\t\tV* in;\n\t\t\tint instride;\n\t\t\tint n = framesToFill;\n\t\t\tif (list_(th, n, instride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(*in);\n\t\t\t\tth.push(val_);\n\t\t\t\tfun_.apply(th);\n\t\t\t\tval_ = th.pop();\n\t\t\t\tout[i] = val_;\n\t\t\t\tin += instride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\tlist_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void scan1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV list = th.pop();\n\tth.push(new List(new Scan1(th, list, fun)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Iter : Gen\n{\n V fun_;\n V val_;\n Z index = 0.;\n\t\n\tIter(Thread& th, Arg fun, Arg val) : Gen(th, itemTypeV, true), fun_(fun), val_(val) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Iter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint n = mBlockSize;\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstruct NIter : Gen\n{\n V fun_;\n V val_;\n\tint64_t n_;\n Z index = 0.;\n \n\tNIter(Thread& th, Arg fun, Arg val, int64_t n) : Gen(th, itemTypeV, false), fun_(fun), val_(val), n_(n) {}\n\t \n\tvirtual const char* TypeName() const override { return \"NIter\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tif (n_ <= 0) {\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tV* out = mOut->fulfill(n);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = val_;\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(val_);\n\t\t\tif (fun_.takes() == 2) {\n\t\t\t\tth.push(index);\n\t\t\t\tindex += 1.;\n\t\t\t}\n\t\t\tfun_.apply(th);\n\t\t\tval_ = th.pop();\n\t\t}\n\t\tn_ -= n;\n\t\tmOut = mOut->nextp();\n\t}\n};\n\nstatic void iter_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new Iter(th, fun, value)));\n}\n\nstatic void itern_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"itern : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\t\n\tth.push(new List(new NIter(th, fun, value, n)));\n}\n\n\n\nstatic void reduce_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV value = th.pop();\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\n\nstatic void reduce1_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\n\tP list = th.popList(\"reduce : list\");\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"reduce : list\", \"\");\n\t}\n\n\tBothIn in_(list);\n\tV value;\n\tif (in_.one(th, value)) {\n\t\tth.push(value);\n\t\treturn;\n\t}\n\t\n\twhile (true) {\n\t\tV in;\n\t\tif (in_.one(th, in)) {\n\t\t\tth.push(value);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(in);\n\t\tth.push(value);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n}\n\nstatic void chain_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"chain : n\");\n\tV fun = th.pop();\n\tV value = th.pop();\n\n\tbool pushIndex = fun.takes() == 2;\n\t\n\tfor (int64_t i = 0; i < n; ++i) {\t\t\n\t\tSaveStack ss(th);\n\t\tth.push(value);\n\t\tif (pushIndex) th.push(i);\n\t\tfun.apply(th);\n\t\tvalue = th.pop();\n\t}\n\tth.push(value);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Merge : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMerge(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"Merge\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \nstruct MergeZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tflag = th.pop().isTrue();\n\t\t\tif (flag) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeByKey : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V key_;\n\tV aa, bb;\n\tbool flag = true;\n\tbool once = true;\n \n\tMergeByKey(Thread& th, Arg a, Arg b, Arg key) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), key_(key) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeByKey\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (once) {\n\t\t\t\tonce = false;\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (flag) {\n\t\t\t\t// last produced was a.\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// last produced was b.\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tV a, b;\n\t\t\t\tbool aok = aa.dot(th, key_, a);\n\t\t\t\tbool bok = bb.dot(th, key_, b);\n\t\t\t\tif (!aok || !bok) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tflag = ::Compare(th, a, b) < 0;\n\t\t\t\tif (flag) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstruct MergeCmp : Gen\n{\n\tVIn a_;\n\tVIn b_;\n V fun_;\n\tV aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmp(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmp\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\twhich = left;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\taa = 0.;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\tbb = 0.;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\nstruct MergeCmpZ : Gen\n{\n\tZIn a_;\n\tZIn b_;\n V fun_;\n\tZ aa, bb;\n\tenum { left, right, both };\n\tint which = both;\n \n\tMergeCmpZ(Thread& th, Arg a, Arg b, Arg fun) : Gen(th, itemTypeZ, leastFinite(a, b)), a_(a), b_(b), fun_(fun) {}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeCmpZ\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tif (which == both) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else if (which == left) {\n\t\t\t\tif (a_.onez(th, aa)) {\n\t\t\t\t\tout[i] = bb;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (b_.onez(th, bb)) {\n\t\t\t\t\tout[i] = aa;\n\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\tsetDone();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tth.push(aa);\n\t\t\tth.push(bb);\n\t\t\tfun_.apply(th);\n\t\t\tZ compare = th.popFloat(\"mergec : compareValue\");\n\t\t\tif (compare < 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = right;\n\t\t\t} else if (compare == 0.) {\n\t\t\t\tout[i] = aa;\n\t\t\t\twhich = both;\n\t\t\t} else {\n\t\t\t\tout[i] = bb;\n\t\t\t\twhich = right;\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\t \n\n\nstatic void merge_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"merge : b\");\n\tV a = th.popList(\"merge : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tif (fun.isString()) {\n\t\t\tth.push(new List(new MergeByKey(th, a, b, fun)));\n\t\t} else {\n\t\t\tth.push(new List(new Merge(th, a, b, fun)));\n\t\t}\n\t} else {\n\t\tpost(\"merge : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\nstatic void mergec_(Thread& th, Prim* prim)\n{\n\tV fun = th.pop();\n\tV b = th.popList(\"mergec : b\");\n\tV a = th.popList(\"mergec : a\");\n\t\n\tif (a.isZList() && b.isZList()) {\n\t\tth.push(new List(new MergeCmpZ(th, a, b, fun)));\n\t} else if (a.isVList() && b.isVList()) {\n\t\tth.push(new List(new MergeCmp(th, a, b, fun)));\n\t} else {\n\t\tpost(\"mergec : lists not same type\\n\");\n\t\tthrow errFailed;\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n//evmerge\n\nextern P s_dt;\nextern P s_out;\nP s_dur;\n\nP dtTableMap;\nP restTableMap;\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value);\n\nstatic P makeRestEvent(Z dt)\n{\n\tP
table = new Table(restTableMap);\n\ttable->put(0, V(0.));\n\ttable->put(1, V(dt));\n\ttable->put(2, V(dt));\n\treturn new Form(table);\n}\n\nstruct MergeEvents : Gen\n{\n\tVIn a_;\n\tVIn b_;\n\tZ nextATime = 0.;\n\tZ nextBTime;\n\t\n\tMergeEvents(Thread& th, Arg a, Arg b, Z t) : Gen(th, itemTypeV, leastFinite(a, b)), a_(a), b_(b), nextBTime(t)\n\t{\n\t}\n\t \n\tvirtual const char* TypeName() const override { return \"MergeEvents\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tfor (int i = 0; i < framesToFill; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\t{\n\t\t\t\tif (nextATime <= nextBTime) {\n\t\t\t\t\tV aa;\n\t\t\t\t\tif (a_.one(th, aa)) {\n\t\t\t\t\t\tif (nextATime < nextBTime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextBTime - nextATime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tb_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tV a;\n\t\t\t\t\tbool aok = aa.dot(th, s_dt, a);\n\t\t\t\t\tif (!aok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dta = a.asFloat();\n\t\t\t\t\tZ dt = std::min(dta, nextBTime - nextATime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, aa), dtTableMap, dt);\n\t\t\t\t\tnextATime += dta;\n\t\t\t\t\taa = 0.;\n\t\t\t\t} else {\n\t\t\t\t\tV bb;\n\t\t\t\t\tif (b_.one(th, bb)) {\n\t\t\t\t\t\tif (nextBTime < nextATime) {\n\t\t\t\t\t\t\tout[i] = makeRestEvent(nextATime - nextBTime);\n\t\t\t\t\t\t\tproduce(framesToFill - i - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta_.link(th, mOut);\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tV b;\n\t\t\t\t\tbool bok = bb.dot(th, s_dt, b);\n\t\t\t\t\tif (!bok) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tZ dtb = b.asFloat();\n\t\t\t\t\tZ dt = std::min(dtb, nextATime - nextBTime);\n\t\t\t\t\tout[i] = extendFormByOne(th, asParent(th, bb), dtTableMap, dt);\n\t\t\t\t\tnextBTime += dtb;\n\t\t\t\t\tbb = 0.;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(0);\n\t}\n};\n\nstatic void evmerge_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evmerge : t\");\n\tV b = th.popVList(\"evmerge : b\");\n\tV a = th.popVList(\"evmerge : a\");\n\tth.push(new List(new MergeEvents(th, a, b, t)));\n}\n\nstatic void evrest_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evrest : t\");\n\tth.push(makeRestEvent(t));\n}\n\nstatic void evdelay_(Thread& th, Prim* prim)\n{\n\tZ t = th.popFloat(\"evdelay : t\");\n\tV a = th.popVList(\"evdelay : a\");\n\tth.push(cons(th, makeRestEvent(t), a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CompareFun\n{\npublic:\n\tCompareFun() {}\n\tvirtual ~CompareFun() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) = 0;\n};\n\nclass VLess : public CompareFun\n{\npublic:\n\tVLess() {}\n\t~VLess() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) < 0; }\n};\n\nclass VGreater : public CompareFun\n{\npublic:\n\tVGreater() {}\n\t~VGreater() {} \n\tvirtual bool operator()(Thread& th, Arg a, Arg b) { return Compare(th, a, b) > 0; }\n};\n\nclass VCompareF : public CompareFun\n{\n\tV fun;\npublic:\n\tVCompareF(V inFun) : fun(inFun) {}\n\t~VCompareF() {}\n\tvirtual bool operator()(Thread& th, Arg a, Arg b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\n\n\nclass ZCompareFun\n{\npublic:\n\tZCompareFun() {}\n\tvirtual ~ZCompareFun() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) = 0;\n};\n\nclass ZLess : public ZCompareFun\n{\npublic:\n\tZLess() {}\n\t~ZLess() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a < b; }\n};\n\nclass ZCompareF : public ZCompareFun\n{\n\tV fun;\npublic:\n\tZCompareF(V inFun) : fun(inFun) {}\n\t~ZCompareF() {}\n\tvirtual bool operator()(Thread& th, Z a, Z b) {\n\t\tSaveStack ss(th);\n\t\tth.push(a);\n\t\tth.push(b);\n\t\tfun.apply(th);\n\t\treturn th.pop().isTrue();\n\t}\n};\n\nclass ZGreater : public ZCompareFun\n{\npublic:\n\tZGreater() {}\n\t~ZGreater() {} \n\tvirtual bool operator()(Thread& th, Z a, Z b) { return a > b; }\n};\n\n\nstatic void merge(Thread& th, int64_t an, V* a, int64_t bn, V* b, V* c, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, int64_t bn, Z* b, Z* c, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci++] = a[ai++];\n\t\t} else {\n\t\t\tc[ci++] = b[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci++] = a[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci++] = b[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, V* tmp, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* tmp, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tmergesort(th, an, a, tmp, compare);\n\tmergesort(th, bn, b, tmp, compare);\n\tmerge(th, an, a, bn, b, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const V* in, V* out, CompareFun* compare)\n{\n\tV* tmp = new V[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void sort(Thread& th, int64_t n, const Z* in, Z* out, ZCompareFun* compare)\n{\n\tZ* tmp = new Z[n];\n\tArrayDeleter d(tmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tmergesort(th, n, out, tmp, compare);\n}\n\nstatic void merge(Thread& th, int64_t an, V* a, Z* az, int64_t bn, V* b, Z* bz, V* c, Z* cz, CompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void merge(Thread& th, int64_t an, Z* a, Z* az, int64_t bn, Z* b, Z* bz, Z* c, Z* cz, ZCompareFun* compare)\n{\n\t// merge a and b using scratch space c.\n\t// copy result back to a.\n\t// a and b are assumed to be contiguous.\n\tint64_t ai = 0;\n\tint64_t bi = 0;\n\tint64_t ci = 0;\n\twhile (ai < an && bi < bn) {\n\t\tif ((*compare)(th, a[ai], b[bi])) {\n\t\t\tc[ci] = a[ai];\n\t\t\tcz[ci++] = az[ai++];\n\t\t} else {\n\t\t\tc[ci] = b[bi];\n\t\t\tcz[ci++] = bz[bi++];\n\t\t}\n\t}\n\twhile (ai < an) {\n\t\tc[ci] = a[ai];\n\t\tcz[ci++] = az[ai++];\n\t}\n\twhile (bi < bn) {\n\t\tc[ci] = b[bi];\n\t\tcz[ci++] = bz[bi++];\n\t}\n\tfor (int64_t i = 0; i < ci; ++i) {\n\t\ta[i] = c[i];\n\t\taz[i] = cz[i];\n\t}\n}\n\nstatic void mergesort(Thread& th, int64_t n, V* a, Z* az, V* c, Z* cz, CompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tV* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\nstatic void mergesort(Thread& th, int64_t n, Z* a, Z* az, Z* c, Z* cz, ZCompareFun* compare)\n{\n\tif (n == 1) return;\n\tint64_t an = n / 2;\n\tint64_t bn = n - an;\n\tZ* b = a + an;\n\tZ* bz = az + an;\n\tmergesort(th, an, a, az, c, cz, compare);\n\tmergesort(th, bn, b, bz, c, cz, compare);\n\tmerge(th, an, a, az, bn, b, bz, c, cz, compare);\n}\n\n\nstatic void grade(Thread& th, int64_t n, const V* in, Z* zout, CompareFun* compare)\n{\n\tV* out = new V[n];\n\tV* tmp = new V[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void grade(Thread& th, int64_t n, const Z* in, Z* zout, ZCompareFun* compare)\n{\n\tZ* out = new Z[n];\n\tZ* tmp = new Z[n];\n\tZ* ztmp = new Z[n];\n\tArrayDeleter d1(out);\n\tArrayDeleter d2(tmp);\n\tArrayDeleter d3(ztmp);\n\t\n\tfor (int64_t i = 0; i < n; ++i) out[i] = in[i];\n\tdouble z = 0.;\n\tfor (int64_t i = 0; i < n; ++i, z+=1.) zout[i] = z;\n\tmergesort(th, n, out, zout, tmp, ztmp, compare);\n}\n\nstatic void sort_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void sortf_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"sort : fun\");\n\tV a = th.popList(\"sort : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(list->ItemType(), n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void sort_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"sort> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"sort> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeV, n);\n\t\tout->mArray->setSize(n);\n\t\tV* vout = out->mArray->v();\n\t\t\n\t\tsort(th, n, v, vout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tsort(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVLess cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZLess cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n\nstatic void gradef_(Thread& th, Prim* prim)\n{\n\tV fun = th.popList(\"grade : fun\");\n\tV a = th.popList(\"grade : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVCompareF cmp(fun);\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZCompareF cmp(fun);\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\nstatic void grade_gt_(Thread& th, Prim* prim)\n{\n\tV a = th.popList(\"grade> : a\");\n\t\n\tif (!a.isFinite()) \n\t\tindefiniteOp(\"grade> : a\", \"\");\n\t\n\tP list = ((List*)a.o())->pack(th);\n\t\t\n\tP array = list->mArray; \n\tint64_t n = array->size();\n\t\n\tif (list->isVList()) {\n\t\tV* v = array->v();\n\t\tVGreater cmp;\n\t\t\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\t\t\n\t\tgrade(th, n, v, zout, &cmp);\n\t\tth.push(out);\n\t} else {\n\t\tZ* z = array->z();\n\t\tZGreater cmp;\n\t\tP out = new List(itemTypeZ, n);\n\t\tout->mArray->setSize(n);\n\t\tZ* zout = out->mArray->z();\n\n\t\tgrade(th, n, z, zout, &cmp);\n\t\tth.push(out);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFN(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP);\n#define DEFNnoeach(NAME, TAKES, LEAVES, FUN, HELP) \tvm.def(NAME, TAKES, LEAVES, FUN, HELP, V(0.), true);\n\nvoid AddStreamOps();\nvoid AddStreamOps()\n{\n\tinitFFT();\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\ts_dur = getsym(\"dur\");\n\tdtTableMap = new TableMap(V(s_dt));\n\trestTableMap = new TableMap(3);\n\trestTableMap->put(0, s_out, s_out->Hash());\n\trestTableMap->put(1, s_dur, s_dur->Hash());\n\trestTableMap->put(2, s_dt, s_dt->Hash());\n\t\n\tvm.addBifHelp(\"\\n*** list conversion ***\");\n\tDEF(V, 1, 1, \"(signal --> stream) converts a signal or string to a stream.\")\n\tDEF(Z, 1, 1, \"(series --> signal) converts a stream or string to a signal.\")\t\n\tDEF(L, 1, 1, \"(anything --> stream) streams are returned as is. anything else is made into an infinite stream of itself.\")\n\tDEF(L1, 1, 1, \"(anything --> stream) streams are returned as is. anything else is wrapped in a one item list.\")\n\tDEF(unspell, 1, 1, \"(sequence --> string) converts a stream of numbers or a signal to a string.\")\n\n\tvm.addBifHelp(\"\\n*** basic list operations ***\");\n\n\tDEF(size, 1, 1, \"(seq --> num) Return the length of a sequence if it is finite. Returns inf if the sequence is of indefinite length (It may not actually be infinitely long).\")\n\tDEF(rank, 1, 1, \"(a --> n) Return the rank of an object. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(shape, 1, 1, \"(a --> [n..]) Return the shape of an object. Axes of indefinite length are represented by inf. Makes the assumption that lists at all depths are homogenous.\")\n\tDEF(finite, 1, 1, \"(seq --> bool) Returns 1 if the sequence is finite, 0 if indefinite.\")\n\n\tDEF(empty, 1, 1, \"(list --> bool) returns whether the list is empty.\")\n\tDEF(nonempty, 1, 1, \"(list --> bool) returns whether the list is nonempty.\")\n\tDEF(head, 1, 1, \"(list --> item) returns first item of list. fails if list is empty.\")\n\tDEF(tail, 1, 1, \"(list --> list) returns the rest of the list after the first item. fails if list is empty.\")\n\tDEF(add, 2, 1, \"(list item --> list) returns a new list with the item added to the end.\")\t\n\tDEF(cons, 2, 1, \"(list item --> list) returns a new list with the item added to the front.\")\t\n\tDEF(uncons, 1, 2, \"(list --> tail head) returns the tail and head of a list. fails if list is empty.\")\n\tDEF(pack, 1, 1, \"(list --> list) returns a packed version of the list.\");\n\tDEF(packed, 1, 1, \"(list --> bool) returns whether the list is packed.\");\n\n\tvm.addBifHelp(\"\\n*** list generation ***\");\n\n\tDEFnoeach(ord, 0, 1, \"(--> series) return an infinite series of integers ascending from 1.\")\n\tDEFnoeach(nat, 0, 1, \"(--> series) return an infinite series of integers ascending from 0.\")\n\tDEFnoeach(invs, 0, 1, \"(--> series) return an infinite series of reciprocals. equivalent to ord 1/\")\n\tDEFnoeach(negs, 0, 1, \"(--> series) return an infinite series of integers descending from -1.\")\n\tDEFnoeach(evens, 0, 1, \"(--> series) return an infinite series of ascending non-negative even integers.\")\n\tDEFnoeach(odds, 0, 1, \"(--> series) return an infinite series of ascending non-negative odd integers.\")\n\tDEFnoeach(ints, 0, 1, \"(--> series) return the infinite series [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primes, 0, 1, \"(--> series) returns a finite series of prime numbers up to 1000039.\")\n\tDEFAM(fib, kk, \"(a b --> series) returns a fibonacci series starting with the two numbers given.\") \n\n\tDEFnoeach(ordz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 1.\")\n\tDEFnoeach(natz, 0, 1, \"(--> signal) return an infinite signal of integers ascending from 0.\")\n\tDEFnoeach(invz, 0, 1, \"(--> signal) return an infinite signal of reciprocals. equivalent to ordz 1/\")\n\tDEFnoeach(negz, 0, 1, \"(--> signal) return an infinite signal of integers descending from -1.\")\n\tDEFnoeach(evenz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative even integers.\")\n\tDEFnoeach(oddz, 0, 1, \"(--> signal) return an infinite signal of ascending non-negative odd integers.\")\n\tDEFnoeach(intz, 0, 1, \"(--> signal) return the infinite signal [0 1 -1 2 -2 3 -3...]\")\n\tDEFnoeach(primez, 0, 1, \"(--> signal) returns a finite signal of prime numbers up to 1000039.\")\t\n\tDEFMCX(fibz, 2, \"(a b --> signal) returns a fibonacci signal starting with the two numbers given.\")\n\n\tDEFAM(ninvs, k, \"(n --> stream) return a finite stream of n reciprocals. equivalent to n 1 1 nby 1/\")\n\tDEFMCX(ninvz, 1, \"(n --> signal) return a finite signal of n reciprocals. equivalent to n 1 1 nbyz 1/\")\n\t\n\tDEF(ever, 1, 1, \"(value --> series) return an infinite stream of value.\")\n\tDEFAM(by, kk, \"(start step --> series) return an infinite arithmetic series.\") \n\tDEFAM(nby, kkk, \"(n start step --> series) return a finite arithmetic series.\") \n\tDEFAM(grow, kk, \"(start step --> series) return an infinite geometric series.\") \n\tDEFAM(ngrow, kkk, \"(start step --> series) return a finite geometric series.\") \n\tDEFAM(to, kk, \"(a b --> series) return a finite series from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFMCX(everz, 1, \"(value --> signal) return an infinite signal of value.\")\n\tDEFMCX(byz, 2, \"(start step --> series) return an infinite arithmetic series as a signal.\") \n\tDEFMCX(nbyz, 3, \"(start step --> series) return a finite arithmetic series as a signal.\") \n\tDEFMCX(growz, 2, \"(start step --> series) return an infinite geometric series as a signal.\") \n\tDEFMCX(ngrowz, 3, \"(start step --> series) return a finite geometric series as a signal.\") \n\tDEFMCX(toz, 2, \"(a b --> series) return a finite signal from a to b stepping by +1 if a < b, or -1 if a < b.\") \n\n\tDEFAM(lindiv, kkk, \"(n start end --> series) returns a series of n equal steps from start to end.\") \n\tDEFAM(expdiv, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start to end.\") \n\tDEFMCX(lindivz, 3, \"(n start end --> series) returns a signal of n equal steps from start to end.\") \n\tDEFMCX(expdivz, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start to end.\") \n\n\tDEFAM(lindiv1, kkk, \"(n start end --> series) returns a series of n equal steps from start up to but not including end.\") \n\tDEFAM(expdiv1, kkk, \"(n start end --> series) returns a series of n exponentially spaced steps from start up to but not including end.\") \n\tDEFMCX(lindiv1z, 3, \"(n start end --> series) returns a signal of n equal steps from start up to but not including end.\") \n\tDEFMCX(expdiv1z, 3, \"(n start end --> series) returns a signal of n exponentially spaced steps from start up to but not including end.\") \n\n\tDEFMCX(line, 3, \"(dur start end --> z) return a signal ramping linearly from start to end in dur seconds.\") // mcx\n\tDEFMCX(xline, 3, \"(dur start end --> z) return a signal ramping exponentially from start to end in dur seconds.\") // mcx\n\n\tvm.addBifHelp(\"\\n*** list reduction operations ***\");\n\tDEFAM(reduce, aak, \"(list value fun --> value) applies fun to each item in list and the current value to get a new value. returns the ending value.\")\n\tDEFAM(reduce1, ak, \"(list fun --> value) like reduce except that the initial value is the first item in the list.\")\n\n\tDEFAM(scan, aak, \"(list value fun --> list) applies fun to each item in list and the current value to get a new value, which is added to the output list.\")\n\tDEFAM(scan1, ak, \"(list fun --> list) like scan except that the initial value is the first item in the list.\")\n\tDEFAM(iter, ak, \"(value fun --> list) returns an infinite list of repeated applications of fun to value.\")\n\tDEFAM(itern, akk, \"(value fun n --> list) returns a list of n repeated applications of fun to value.\")\n \t\n\tDEFAM(chain, akk, \"(value fun n --> list) returns the result of n repeated applications of fun to value.\")\n \n\tvm.addBifHelp(\"\\n*** list ordering operations ***\");\n\tDEF(cyc, 1, 1, \"(list --> list) makes a finite list become cyclic.\")\n\tDEFAM(ncyc, ak, \"(n list --> list) concatenates n copies of a finite list.\")\n\tDEF(rcyc, 1, 1, \"(ref --> list) gets a new list from ref each time list is exhausted.\")\n\n\tvm.defautomap(\"X\", \"ak\", repeat_, \"(value n --> stream) makes a list containing n copies of value. If value is a function, then the results of applying the function with an integer count argument is used as the contents of the output list.\");\n\tvm.defmcx(\"XZ\", 2, repeatz_, \"(value n --> signal) returns a signal with value repeated n times.\");\n\tvm.defmcx(\"mum\", 1, mum_, \"(t --> signal) returns a signal of t seconds of silence.\");\n\n\tvm.def(\"$\", 2, 1, append_, \"(listA listB --> out) returns the concatenation of listA and listB.\");\n\tvm.defmcx(\"$z\", 2, append_, \"(signalA signalB --> signal) returns the concatenation of signalA and signalB.\");\n\t\n\tvm.def(\"$$\", 2, 1, appendSubs_, \"(listA listB --> out) return the concatenation of the sublists of listA and listB. equivalent to (listA @ listB @ $)\");\n\tvm.def(\"$/\", 1, 1, cat_, \"(list --> out) returns the concatenation of the sub-lists of the input list.\");\n\tDEF(flat, 1, 1, \"(list --> list) flattens a list.\")\n\tDEFAM(flatten, ak, \"(list n --> list) makes a list n levels flatter.\")\n\tvm.defautomap(\"keep\", \"ak\", N_, \"(list n --> list) returns a list of the first n items of the input list.\");\n\t\n\tDEFAM(T, zk, \"(signal t --> signal) returns a signal of the first t seconds of the input signal.\");\n\tvm.defautomap(\"T>\", \"zk\", skipT_, \"(signal t --> signal) skips the first t seconds of the input signal.\");\n\tvm.defautomap(\"N>\", \"ak\", skip_, \"(list n --> list) skips the first n items of the input list.\");\n\tvm.def(\"N>>\", 2, 1, hops_, \"(list hops --> listOfLists) returns a list of tails of the input list. equivalent to (list (hops 0 | L 0 cons +\\\\) N>).\");\n\tvm.defautomap(\"T>>\", \"za\", hopTs_, \"(signal hops --> listOfSignals) returns a list of tails of the input list. equivalent to (signal (hops 0 | L 0 cons +\\\\) T>).\");\n\tDEFAM(N, ak, \"(list n --> list) returns a list of the first n items of the input list.\") \n\tDEFAM(NZ, zk, \"(signal n --> signal) returns a signal of the first n items of the input signal. automaps over streams.\") \n\t\n\tDEFAM(skip, ak, \"(list n --> list) skips the first n items of the input list.\") \n\n\tDEFAM(take, ak, \"(list n --> list) returns a list of the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\tDEFAM(drop, ak, \"(list n --> list) skips the first n items of the input list, or the last n items if n is negative and the list is finite.\") \n\t\n\tDEFAM(choff, akk, \"(channel(s) c n --> out) takes a finite list of channels or a single signal and places it into an array of n channels beginning at offset c. Other channels are set to zero.\");\n\n\tDEF(tog, 2, 1, \"(a b --> series) return a series alternating between a and b.\")\n\tDEFMCX(togz, 2, \"(a b --> signal) return a signal alternating between a and b.\")\n\tDEF(sel, 2, 1, \"(a j --> out) select. a is a list of lists. out[i] is a[j][i]\")\n\tDEF(sell, 2, 1, \"(a j --> out) lazy select. a is a list of lists. out[i] is the next value from a[j].\")\n\n\tvm.def(\"?\", 2, 1, filter_, \"(a b --> out) the output list contains a[i] repeated b[i] times. If b is a list of booleans (1 or 0) then this functions as a filter.\");\n\tDEF(spread, 2, 1, \"(a n --> out) inserts n[i] zeroes after a[i].\")\t\n\tDEFMCX(spreadz, 2, \"(a n --> signal) inserts n[i] zeroes after a[i]. automaps over stream inputs.\")\t\n\n\tDEF(change, 1, 1, \"(a --> b) eliminates sequential duplicates in a signal or stream.\")\t\n\tDEFMCX(changez, 1, \"(a --> b) eliminates sequential duplicates in a signal. automaps over streams.\")\t\n\tDEF(expand, 2, 1, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out.\")\t\n\tDEFMCX(expandz, 2, \"(a b --> out) when b is true, a value from a is written to out, when b is false, zero is written to out. automaps over stream inputs.\")\t\n\n\tDEF(clump, 2, 1, \"(a n --> out) groups elements from list a into sub-lists of size n.\")\t\n\tDEF(hang, 1, 1, \"(a --> out) repeats the last value of a finite list indefinitely.\")\t\n\tDEFMCX(hangz, 1, \"(a --> out) repeats the last value of a finite signal indefinitely. automaps over streams.\")\t\n\tDEFAM(histo, ak, \"(a n --> out) makes a histogram of the finite stream a.\")\t\n\tvm.defautomap(\"histoz\", \"zk\", histo_, \"(a n --> out) makes a histogram of the finite signal a. automaps over streams.\");\n\n\tDEF(keepWhile, 2, 1, \"(a b --> out) return items from a while items from b are true.\")\n\tDEF(skipWhile, 2, 1, \"(a b --> out) skip items from a while items from b are true.\")\n\t\n\tDEF(flop, 1, 1, \"(a --> b) returns the transpose of the list of lists a. At least one of the dimensions must be finite.\")\t\n\tDEF(flops, 1, 1, \"(a --> b) like flop, but signals are treated as scalars and not flopped.\")\n\tDEF(flop1, 1, 1, \"(a --> b) like flop, but if list a is not a list of lists then it is wrapped in a list. compare: [[1 2 3][[4 5] 6 7]] @ flop $/ with: [[1 2 3][[4 5] 6 7]] @ flop1 $/\")\t\n\tDEF(lace, 1, 1, \"(a --> b) returns the concatenation of the transpose of the list of lists a.\")\t\n\tDEFAM(merge, aak, \"(a b fun --> c) merges two lists according to the function given. The function should work like <.\")\n\tDEFAM(mergec, aak, \"(a b fun --> c) merges two lists without duplicates according to the function given. The function should work like cmp.\")\n\t\n\tDEF(perms, 1, 1, \"(a --> b) returns a list of all permutations of the input list.\")\n\tDEFMCX(permz, 1, \"(a --> b) returns a list of all permutations of the input signal. automaps over streams.\")\n\t\n\tDEF(permswr, 1, 1, \"(a --> b) returns a list of all unique permutations of an input stream with repeated elements.\")\n\tDEFMCX(permzwr, 1, \"(a --> b) returns a returns a list of all unique permutations of an input signal with repeated elements. automaps over streams.\")\n\t\n\tDEF(shortas, 2, 1, \"(a b --> a') makes list a as short as list b.\")\n\tDEF(longas, 2, 1, \"(a b --> a') makes list a as long as list b by repeating the last item.\")\n\tDEF(longas0, 2, 1, \"(a b --> a') makes list a as long as list b by appending zeroes.\")\n\n\t// array ops\n\n\tvm.addBifHelp(\"\\n*** list ops ***\");\n\n\tDEF(bub, 1, 1, \"(a --> [a]) makes the top item on the stack into a one item list. i.e. puts a bubble around it.\")\n\tDEF(nbub, 2, 1, \"(a n --> [[..[a]..]]) embeds the top item in N one item lists.\")\n\n\tvm.def(\"2ple\", 2, 1, tupleN_<2>, \"(a b --> [a b]) make a pair from the top two stack items.\");\n\tvm.def(\"3ple\", 3, 1, tupleN_<3>, \"(a b c --> [a b c]) make a triple from the top three stack items.\");\n\tvm.def(\"4ple\", 4, 1, tupleN_<4>, \"(a b c d --> [a b c d]) make a quadriple from the top four stack items.\");\n\tvm.def(\"5ple\", 5, 1, tupleN_<5>, \"(a b c d e --> [a b c d e]) make a quintuple from the top five stack items.\");\n\tvm.def(\"6ple\", 6, 1, tupleN_<6>, \"(a b c d e f --> [a b c d e f]) make a sextuple from the top six stack items.\");\n\tvm.def(\"7ple\", 7, 1, tupleN_<7>, \"(a b c d e f g --> [a b c d e f g]) make a septuple from the top seven stack items.\");\n\tvm.def(\"8ple\", 8, 1, tupleN_<8>, \"(a b c d e f g h --> [a b c d e f g h]) make an octuple from the top eight stack items.\");\n\t\n\tvm.defautomap(\"2ples\", \"kk\", tupleN_<2>, \"(a b --> [[a0 b0][a1 b1]..[aN bN]]) make a sequence of pairs from the sequences a and b.\");\n\tvm.defautomap(\"3ples\", \"kkk\", tupleN_<3>, \"(a b c --> [[a0 b0 c0][a1 b1 c1]..[aN bN cN]]) make a sequence of triples from the sequences a, b and c.\");\n\tvm.defautomap(\"4ples\", \"kkkk\", tupleN_<4>, \"(a b c d --> seq) make a sequence of quadruples from the sequences a, b, c and d.\");\n\tvm.defautomap(\"5ples\", \"kkkkk\", tupleN_<5>, \"(a b c d e --> seq) make a sequence of quintuples from the sequences a through e.\");\n\tvm.defautomap(\"6ples\", \"kkkkkk\", tupleN_<6>, \"(a b c d e f--> seq) make a sequence of sextuples from the sequences a through f.\");\n\tvm.defautomap(\"7ples\", \"kkkkkkk\", tupleN_<7>, \"(a b c d e f g--> seq) make a sequence of septuples from the sequences a through g.\");\n\tvm.defautomap(\"8ples\", \"kkkkkkkk\", tupleN_<8>, \"(a b c d e f g h --> seq) make a sequence of octuples from the sequences a through h.\");\n\n\tDEFNnoeach(\"un2\", 1, 2, untupleN_<2>, \"([a0 a1 .. aN-1] --> a0 a1) Push two items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un3\", 1, 3, untupleN_<3>, \"([a0 a1 .. aN-1] --> a0 a1 a2) Push three items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un4\", 1, 4, untupleN_<4>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3) Push four items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un5\", 1, 5, untupleN_<5>, \"([a0 a1 .. aN-1] --> a0 a1 a2 a3 a4) Push five items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un6\", 1, 6, untupleN_<6>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a5) Push six items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un7\", 1, 7, untupleN_<7>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a6) Push seven items from a sequence onto the stack.\")\n\tDEFNnoeach(\"un8\", 1, 8, untupleN_<8>, \"([a0 a1 .. aN-1] --> a0 a1 a2 .. a7) Push eight items from a sequence onto the stack.\")\n\n\tDEF(reverse, 1, 1, \"(a --> b) reverses a finite sequence.\")\n\tDEF(mirror0, 1, 1, \"(a --> b) cyclic mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2]\")\n\tDEF(mirror1, 1, 1, \"(a --> b) odd mirror of a sequence. [1 2 3 4] --> [1 2 3 4 3 2 1]\")\n\tDEF(mirror2, 1, 1, \"(a --> b) even mirror of a sequence. [1 2 3 4] --> [1 2 3 4 4 3 2 1]\")\n\tDEFAM(rot, ak, \"(seq M --> seq') rotation of a sequence by M places. M > 0 moves right.\") \n\tDEFAM(shift, ak, \"(seq M --> seq') shift of a sequence by M places. zeroes are shifted in to fill vacated positions.\") \n\tDEFAM(clipShift, ak, \"(seq M --> seq') shift of a sequence by M places. the end value is copied in to fill vacated positions.\") \n\tDEFAM(foldShift, ak, \"(seq M --> seq') shift of a sequence by M places. values from the cyclic mirrored sequence are copied in to fill vacated positions.\") \n\tDEF(muss, 1, 1, \"(a --> b) puts a finite sequence into a random order.\")\n\n\tDEF(at, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return zero.\") \n\tDEF(wrapAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the value at the end point.\") \n\tDEF(foldAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return the items from the cyclic sequence.\") \n\tDEF(clipAt, 2, 1, \"(seq index(es) --> value(s)) looks up item(s) in sequence at index(es). out of range indexes return items from the cyclic mirrored sequence.\") \n\tDEF(degkey, 2, 1, \"(degree scale --> converts scale degree(s) to keys, given a scale\");\n\tDEF(keydeg, 2, 1, \"(key scale --> converts key(s) to scale degree(s), given a scale\");\n\n\t\n\tDEF(sort, 1, 1, \"(in --> out) ascending order sort of the input list.\");\n\tDEFAM(sortf, ak, \"(in fun --> out) sort of the input list using a compare function.\");\n\tDEFN(\"sort>\", 1, 1, sort_gt_, \"(in --> out) descending order sort of the input list.\");\n\t\n\tDEF(grade, 1, 1, \"(in --> out) ascending order sorted indices of the input list.\");\n\tDEFAM(gradef, ak, \"(in fun --> out) sorted indices of the input list using a compare function.\");\n\tDEFN(\"grade>\", 1, 1, grade_gt_, \"(in --> out) descending order sorted indices of the input list.\");\n\n\tvm.addBifHelp(\"\\n*** event list operations ***\");\n\tDEFAM(evmerge, aak, \"(a b t --> c) merges event list 'b' with delay 't' with event list 'a' according to their delta times\")\n\tDEFAM(evdelay, ak, \"(a t --> c) delay an event list by adding a preceeding rest of duration 't'\")\n\tDEFAM(evrest, aak, \"(t --> c) returns a rest event for duration 't'.\")\n\t\n\tvm.addBifHelp(\"\\n*** dsp operations ***\");\n\t\n\tDEFMCX(kaiser, 2, \"(n stopBandAttenuation --> out) returns a signal filled with a kaiser window with the given stop band attenuation.\")\n\tDEFMCX(hanning, 1, \"(n --> out) returns a signal filled with a Hanning window.\")\n\tDEFMCX(hamming, 1, \"(n --> out) returns a signal filled with a Hamming window.\")\n\tDEFMCX(blackman, 1, \"(n --> out) returns a signal filled with a Blackman window.\")\n\tDEFMCX(fft, 2, \"(re im --> out) returns the complex FFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\tDEFMCX(ifft, 2, \"(re im --> out) returns the complex IFFT of two vectors (one real and one imaginary) which are a power of two length.\")\t\t\n\n\tDEFAM(seg, zaa, \"(in hops durs --> out) divide input signal in to a stream of signal segments of given duration stepping by hop time.\")\n\tDEFAM(wseg, zaz, \"(in hops window --> out) divide input signal in to a stream of windowed signal segments of lengths equal to the window length, stepping by hop time.\")\n\n\tvm.addBifHelp(\"\\n*** audio I/O operations ***\");\n\tDEF(play, 1, 0, \"(channels -->) plays the audio to the hardware.\")\n\tDEF(record, 2, 0, \"(channels filename -->) plays the audio to the hardware and records it to a file.\")\n\tDEFnoeach(stop, 0, 0, \"(-->) stops any audio playing.\")\n\tvm.def(\"sf>\", 1, 0, sfread_, \"(filename -->) read channels from an audio file. not real time.\");\n\tvm.def(\">sf\", 2, 0, sfwrite_, \"(channels filename -->) writes the audio to a file.\");\n\tvm.def(\">sfo\", 2, 0, sfwriteopen_, \"(channels filename -->) writes the audio to a file and opens it in the default application.\");\n\t//vm.def(\"sf>\", 2, sfread_);\n\tDEF(bench, 1, 0, \"(channels -->) prints the amount of CPU required to compute a segment of audio. audio must be of finite duration.\")\t\n\tvm.def(\"sgram\", 3, 0, sgram_, \"(signal dBfloor filename -->) writes a spectrogram to a file and opens it.\");\n\n\tsetSessionTime();\n\n}\n\n"], ["/sapf/src/OscilUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n\n#include \"OscilUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"dsp.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nconst int kNumTables = 30; // third octave tables.\nconst int kWaveTableSize = 16384;\nconst int kWaveTableMask = kWaveTableSize - 1;\n//const int kWaveTableByteSize = kWaveTableSize * sizeof(Z);\nconst int kWaveTableTotalSize = kWaveTableSize * kNumTables;\n//const Z kPhaseInc = kTwoPi / kWaveTableSize;\nconst Z kWaveTableSizeF = kWaveTableSize;\n\n// the maximum number of harmonics is actually 1024, but 1290 is needed for extrapolation.\nconst int kMaxHarmonics = 1290;\nconst int gNumHarmonicsForTable[kNumTables+1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 101, 128, 161, 203, 256, 322, 406, 512, 645, 812, 1024, 1290 };\n\nint gWaveTableSize[kNumTables];\n\nconst double kMaxHarmonicsF = kMaxHarmonics;\n\n\nZ gTableForNumHarmonics[kMaxHarmonics+1];\nZ gHertzToHarmonics[kMaxHarmonics+1];\n\nstatic void fillHarmonicsTable()\n{\t\n\tdouble maxval = kNumTables - 1.0000001;\n\t\n\tint t = 0;\n\tfor (int i = 1; i < kMaxHarmonics; ++i) {\n\t\tif (gNumHarmonicsForTable[t] < i && t < kNumTables) ++t;\n\t\t//int t1 = std::clamp(t-1, 0, kNumTables-1);\n\t\t\n\t\tdouble frac = (double)(i - gNumHarmonicsForTable[t]) / (double)(gNumHarmonicsForTable[t] - gNumHarmonicsForTable[t-1]);\n\t\tdouble ft = t - 1 + frac;\n\t\tgTableForNumHarmonics[i] = ft;\n\t}\n\t\t\n\tgTableForNumHarmonics[0] = 0.;\n\tgTableForNumHarmonics[kMaxHarmonics] = maxval;\n}\n\nstatic void zeroTable(size_t n, Z* table)\n{\n\tmemset(table, 0, n * sizeof(Z));\n}\n\nstatic void normalize(int n, Z* buf)\n{\n\tZ maxabs = 0.;\n\tfor (int i = 0; i < n; ++i) {\n\t\tmaxabs = std::max(maxabs, fabs(buf[i]));\n\t}\n\tif (maxabs > 0.) {\n\t\tZ scale = 1. / maxabs;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tbuf[i] *= scale;\n\t\t}\n\t}\n}\n\n\nstatic void fillWaveTable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* table)\n{\n\tconst size_t kWaveTableSize2 = kWaveTableSize / 2;\n\tconst Z two_pi = 2. * M_PI;\n\t\n\tZ real[kWaveTableSize2];\n\tZ imag[kWaveTableSize2];\n\tZ polar[kWaveTableSize];\n\tZ rect[kWaveTableSize];\n\t\n\tzeroTable(kWaveTableSize2, real);\n\tzeroTable(kWaveTableSize2, imag);\n\n\n\tZ w = M_PI_2 / n;\n\tfor (int i = 0; i < n; ++i) {\n\t\tZ smoothAmp = smooth == 0. ? 1. : pow(cos(w*i), smooth);\n\t\t//fillHarmonic(i+1, *amps * smoothAmp, *phases, table);\n\t\treal[i+1] = *amps * smoothAmp;\n\t\timag[i+1] = (*phases - .25) * two_pi;\n\t\tamps += ampStride;\n\t\tphases += phaseStride;\n\t}\n\t\n\tDSPDoubleSplitComplex in;\n\tin.realp = real;\n\tin.imagp = imag;\n\t\n\tvDSP_ztocD(&in, 1, (DSPDoubleComplex*)polar, 2, kWaveTableSize2);\n\tvDSP_rectD(polar, 2, rect, 2, kWaveTableSize2);\n\tvDSP_ctozD((DSPDoubleComplex*)rect, 2, &in, 1, kWaveTableSize2);\n\trifft(kWaveTableSize, real, imag, table);\n}\n\nstatic void fill3rdOctaveTables(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth, Z* tables)\n{\t\n\t// tables is assumed to be allocated to kNumTables * kWaveTableSize samples\n\tfor (int i = 0; i < kNumTables; ++i) {\n\t\tint numHarmonics = std::min(n, gNumHarmonicsForTable[i]);\n\t\tfillWaveTable(numHarmonics, amps, ampStride, phases, phaseStride, smooth, tables + i * kWaveTableSize);\n\t}\n\t\n\tnormalize(kWaveTableTotalSize, tables);\n}\n\nstatic P makeWavetable(int n, Z* amps, int ampStride, Z* phases, int phaseStride, Z smooth)\n{\n\tP list = new List(itemTypeZ, kWaveTableTotalSize);\n\tP array = list->mArray;\n\t\n\tZ* tables = array->z();\n\t\t\n\tfill3rdOctaveTables(n, amps, ampStride, phases, phaseStride, smooth, tables);\n\tarray->setSize(kWaveTableTotalSize);\n\t\n\treturn list;\n}\n\nstatic void wavefill_(Thread& th, Prim* prim)\n{\n\tZ smooth = th.popFloat(\"wavefill : smooth\");\n\tV phases = th.popZIn(\"wavefill : phases\");\n\tV amps = th.popZIn(\"wavefill : amps\");\n\t\t\n\tP ampl;\n\tP phasel;\n\tZ *phasez, *ampz;\n\tint phaseStride, ampStride; \n\tint64_t n = kMaxHarmonics;\n\tif (phases.isZList()) {\n\t\tphasel = ((List*)phases.o())->packSome(th, n);\n\t\tphasez = phasel->mArray->z();\n\t\tphaseStride = 1;\n\t} else {\n\t\tphasez = &phases.f;\n\t\tphaseStride = 0;\n\t}\n\t\n\tif (amps.isZList()) {\n\t\tampl = ((List*)amps.o())->packSome(th, n);\n\t\tampz = ampl->mArray->z();\n\t\tampStride = 1;\n\t} else {\n\t\tampz = &s.f;\n\t\tampStride = 0;\n\t}\n\t\n\tP list = makeWavetable((int)n, ampz, ampStride, phasez, phaseStride, smooth);\n\tth.push(list);\n}\n\nP gParabolicTable;\nP gTriangleTable;\nP gSquareTable;\nP gSawtoothTable;\n\nstatic void makeClassicWavetables()\n{\n\t//fprintf(stdout, \"computing wave tables\\n\");\n\tZ amps[kMaxHarmonics+1];\n\tZ phases[kMaxHarmonics+1];\n\tZ smooth = 0.;\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i;\n\t}\n\tphases[0] = .25;\n\tgParabolicTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = -1. / (i*i);\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t\t++i;\n\t}\n\n\tphases[0] = 0.;\n\tgTriangleTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i; if (i > kMaxHarmonics) break;\n\t\tamps[i] = 0.;\t\t\t++i;\n\t}\n\tphases[0] = 0.;\n\tgSquareTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases, 0, smooth);\n\t\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tamps[i] = 1. / i;\t\t++i;\n\t}\n\tfor (int i = 1; i <= kMaxHarmonics; ) {\n\t\tphases[i] = 0.;\t\t++i;\n\t\tphases[i] = .5;\t\t++i;\n\t}\n\tgSawtoothTable = makeWavetable(kMaxHarmonics, amps+1, 1, phases+1, 1, smooth);\n\t\n\tvm.addBifHelp(\"\\n*** classic wave tables ***\");\n\tvm.def(\"parTbl\", gParabolicTable);\t\tvm.addBifHelp(\"parTbl - parabolic wave table.\");\n\tvm.def(\"triTbl\", gTriangleTable);\t\tvm.addBifHelp(\"triTbl - triangle wave table.\");\n\tvm.def(\"sqrTbl\", gSquareTable);\t\t\tvm.addBifHelp(\"sqrTbl - square wave table.\");\n\tvm.def(\"sawTbl\", gSawtoothTable);\t\tvm.addBifHelp(\"sawTbl - sawtooth wave table.\");\n\n\t//fprintf(stdout, \"done computing wave tables\\n\");\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Osc : public ZeroInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOsc(Thread& th, P const& inArray, Z ifreq, Z iphase) : ZeroInputUGen(th, false),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscPM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freq;\n\tZ* table;\n\t\n\tOscPM(Thread& th, P const& inArray, Z ifreq, Arg phasemod) : OneInputUGen(th, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freq(ifreq * kWaveTableSizeF * th.rate.invSampleRate)\n\t{\n\t\tZ numHarmonics = std::clamp(th.rate.freqLimit / fabs(ifreq), 0., kMaxHarmonicsF);\n\t\tZ inumHarmonics = floor(numHarmonics);\n\t\tint harmIndex = (int)inumHarmonics;\n\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\tZ tableI = floor(tableF);\n\t\tint tableNum = (int)tableI + 1;\n\t\ttable = array->z() + kWaveTableSize * tableNum;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Osc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* phasemod, int phasemodStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\tout[i] = oscilLUT(table, index, mask, fracphase);\n\n\t\t\tphase += freq;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct OscFM : public OneInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFM(Thread& th, P const& inArray, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tarray(inArray),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kWaveTableSizeF), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase = floor(phase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = phase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\t\t\t\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstruct OscFMPM : public TwoInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscFMPM(Thread& th, P const& inArray, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscFMPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase = phase + *phasemod * kWaveTableSizeF;\n\t\t\tphasemod += phasemodStride;\n\t\t\tZ iphase = floor(pphase);\n\t\t\tint index = (int)iphase;\n\t\t\tZ fracphase = pphase - iphase;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tout[i] = oscilLUT2(tableA, tableB, index, mask, fracphase, fractable);\n\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstatic void newOsc(Thread& th, Arg freq, Arg phase, P const& tables)\n{\n\tif (freq.isZList()) {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscFMPM(th, tables->mArray, freq, phase)));\n\t\t} else {\n\t\t\tth.push(new List(new OscFM(th, tables->mArray, freq, phase.asFloat())));\n\t\t}\n\t} else {\n\t\tif (phase.isZList()) {\n\t\t\tth.push(new List(new OscPM(th, tables->mArray, freq.asFloat(), phase)));\n\t\t} else {\n\t\t\tth.push(new List(new Osc(th, tables->mArray, freq.asFloat(), phase.asFloat())));\n\t\t}\n\t}\n}\n\n\nstatic void osc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"osc : tables\");\n\tV phase = th.popZIn(\"osc : phase\");\n\tV freq = th.popZIn(\"osc : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"osc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tnewOsc(th, freq, phase, tables);\n}\n\nstatic void par_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"par : phase\");\n\tV freq = th.popZIn(\"par : freq\");\n\n\tnewOsc(th, freq, phase, gParabolicTable);\n}\n\nstatic void tri_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"tri : phase\");\n\tV freq = th.popZIn(\"tri : freq\");\n\n\tnewOsc(th, freq, phase, gTriangleTable);\n}\n\nstatic void saw_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"saw : phase\");\n\tV freq = th.popZIn(\"saw : freq\");\n\n\tnewOsc(th, freq, phase, gSawtoothTable);\n}\n\nstatic void square_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"square : phase\");\n\tV freq = th.popZIn(\"square : freq\");\n\n\tnewOsc(th, freq, phase, gSquareTable);\n}\n\nstruct OscPWM : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tOscPWM(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"OscPWM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\n\t\t\tZ pphase2 = pphase1 + *duty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\t\t\tout[i] = .5 * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\n\nstruct VarSaw : public ThreeInputUGen\n{\n\tP const array;\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\tZ* tables;\n\t\n\tVarSaw(Thread& th, P const& inArray, Arg freq, Arg phasemod, Arg duty) : ThreeInputUGen(th, freq, phasemod, duty),\n\t\tarray(inArray),\n\t\tphase(0.), freqmul(kWaveTableSizeF * th.rate.invSampleRate),\n\t\ttables(array->z()),\n\t\tfreqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"VarSaw\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* duty, int freqStride, int phasemodStride, int dutyStride)\n\t{\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq = *freq;\n\t\t\tfreq += freqStride;\n\t\t\t//Z numHarmonics = std::min(freqLimit, cutoff) / ffreq;\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ pphase1 = phase + *phasemod * kWaveTableSizeF;\n\t\t\tZ iphase1 = floor(pphase1);\n\t\t\tint index1 = (int)iphase1;\n\t\t\tZ fracphase1 = pphase1 - iphase1;\n\t\t\t\n\t\t\tZ zduty = std::clamp(*duty, .01, .99);\n\t\t\tZ pphase2 = pphase1 + zduty * kWaveTableSizeF;\n\t\t\tZ iphase2 = floor(pphase2);\n\t\t\tint index2 = (int)iphase2;\n\t\t\tZ fracphase2 = pphase2 - iphase2;\n\n\t\t\tphasemod += phasemodStride;\n\t\t\tduty += dutyStride;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates a broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ a = oscilLUT2(tableA, tableB, index1, mask, fracphase1, fractable);\n\t\t\tZ b = oscilLUT2(tableA, tableB, index2, mask, fracphase2, fractable);\n\n\t\t\tZ amp = .25 / (zduty - zduty * zduty);\n\t\t\tout[i] = amp * (a - b);\n\t\t\t\n\t\t\tphase += ffreq * freqmul;\n\t\t\tif (phase >= kWaveTableSizeF) phase -= kWaveTableSizeF;\n\t\t\tif (phase < 0.) phase += kWaveTableSizeF;\n\t\t}\n\t}\n};\n\nstatic void oscp_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"oscp : tables\");\n\tV duty = th.popZIn(\"oscp : phaseOffset\");\n\tV phase = th.popZIn(\"oscp : phase\");\n\tV freq = th.popZIn(\"oscp : freq\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"oscp : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void pulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"pulse : phaseOffset\");\n\tV phase = th.popZIn(\"pulse : phase\");\n\tV freq = th.popZIn(\"pulse : freq\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new OscPWM(th, tables->mArray, freq, phase, duty)));\n}\n\nstatic void vsaw_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"vsaw : phaseOffset\");\n\tV phase = th.popZIn(\"vsaw : phase\");\n\tV freq = th.popZIn(\"vsaw : freq\");\n\n\tP tables = gParabolicTable;\n\n\tth.push(new List(new VarSaw(th, tables->mArray, freq, phase, duty)));\n}\n\n\n\nstruct SyncOsc : public TwoInputUGen\n{\n\tP const array;\n\tZ sinePhaseStart;\n\tZ sinePhaseReset;\n\tZ sinePhaseEnd;\n Z wavePhaseResetRatio;\n\tZ phase1;\n\tZ phase2a;\n\tZ phase2b;\n\tZ freqmul1;\n\tZ freqmul2;\n\tZ freqLimit;\n\tZ* tables;\n bool once = true;\n\t\n\tSyncOsc(Thread& th, P const& inArray, Arg freq1, Arg freq2) : TwoInputUGen(th, freq1, freq2),\n\t\tarray(inArray),\n sinePhaseStart(kSineTableSize/4),\n\t\tsinePhaseReset(kSineTableSize/2),\n\t\tsinePhaseEnd(sinePhaseStart + sinePhaseReset),\n wavePhaseResetRatio(kWaveTableSizeF / sinePhaseReset),\n\t\tphase1(sinePhaseStart), \n phase2a(0.), \n phase2b(0.),\n\t\tfreqmul1(.5 * th.rate.radiansPerSample * gInvSineTableOmega),\n\t\tfreqmul2(kWaveTableSizeF * th.rate.invSampleRate),\n\t\tfreqLimit(th.rate.freqLimit),\n\t\ttables(array->z())\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SyncOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq1, Z* freq2, int freq1Stride, int freq2Stride)\n\t{\n if (once) {\n once = false;\n phase2b = kWaveTableSizeF * (fabs(*freq2) / fabs(*freq1));\n }\n\t\tconst int mask = kWaveTableMask;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ ffreq1 = fabs(*freq1);\n\t\t\tZ ffreq2 = fabs(*freq2);\n\t\t\tfreq1 += freq1Stride;\n\t\t\tfreq2 += freq2Stride;\n\t\t\t\t\t\t\t\t\t\n\t\t\tZ numHarmonics = std::clamp(freqLimit / fabs(ffreq2), 0., kMaxHarmonicsF);\n\t\t\tZ inumHarmonics = floor(numHarmonics);\n\t\t\tint harmIndex = (int)inumHarmonics;\n\t\t\tZ tableF = lut(gTableForNumHarmonics, harmIndex, numHarmonics - inumHarmonics);\n\t\t\tZ tableI = floor(tableF);\n\t\t\tint tableNum = (int)tableI;\n\t\t\tZ fractable = tableF - tableI;\n\t\t\t\n\t\t\tZ* tableA = tables + kWaveTableSize * tableNum;\n\t\t\tZ* tableB = tableA + kWaveTableSize;\n\t\t\t\n\t\t\tZ iphase2a = floor(phase2a);\n\t\t\tint index2a = (int)iphase2a;\n\t\t\tZ fracphase2a = phase2a - iphase2a;\n\n\t\t\tZ iphase2b = floor(phase2b);\n\t\t\tint index2b = (int)iphase2b;\n\t\t\tZ fracphase2b = phase2b - iphase2b;\n\n\t\t\t// optional: round off the attenuation of higher harmonics. this eliminates an (extremely quiet) broadband tick that happens when a straight line decays to zero.\n\t\t\tfractable = sc_scurve0(fractable);\n\n\t\t\tZ sawA = oscilLUT2(tableA, tableB, index2a, mask, fracphase2a, fractable);\n\t\t\tZ sawB = oscilLUT2(tableA, tableB, index2b, mask, fracphase2b, fractable);\n\t\t\t\n\t\t\tZ window = .5 - .5 * tsinx(phase1);\n\t\t\tout[i] = sawB + window * (sawA - sawB);\n \n\t\t\tZ freq2inc = ffreq2 * freqmul2;\n\n\t\t\tphase2a += freq2inc;\n\t\t\tif (phase2a >= kWaveTableSizeF) phase2a -= kWaveTableSizeF;\n\n\t\t\tphase2b += freq2inc;\n\t\t\tif (phase2b >= kWaveTableSizeF) phase2b -= kWaveTableSizeF;\n\n\t\t\tphase1 += ffreq1 * freqmul1;\n\t\t\tif (phase1 >= sinePhaseEnd) {\n\t\t\t\tphase1 -= sinePhaseReset;\n \n // reset and swap phases\n phase2b = phase2a;\n phase2a = wavePhaseResetRatio * (phase1 - sinePhaseStart) * (ffreq2 / ffreq1); // reset to proper fractional position. \n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ssaw_(Thread& th, Prim* prim)\n{\n\tV freq2 = th.popZIn(\"ssaw : freq2\");\n\tV freq1 = th.popZIn(\"ssaw : freq1\");\n\n\tP tables = gSawtoothTable;\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\nstatic void sosc_(Thread& th, Prim* prim)\n{\n\tP tables = th.popZList(\"sosc : tables\");\n\tV freq2 = th.popZIn(\"sosc : freq2\");\n\tV freq1 = th.popZIn(\"sosc : freq1\");\n\n\tif (!tables->isPacked() || tables->length(th) != kWaveTableTotalSize) {\n\t\tpost(\"sosc : tables is not a wave table. must be a signal of %d x %d samples.\", kNumTables, kWaveTableSize);\n\t\tthrow errWrongType;\n\t}\n\n\tth.push(new List(new SyncOsc(th, tables->mArray, freq1, freq2)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFSaw : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFSaw2 : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSaw2(Thread& th, Arg freq, Arg phasem) : TwoInputUGen(th, freq, phasem), phase(0.), freqmul(th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSaw2\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasem, int freqStride, int phasemStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ pphase = phase + 2. * *phasem - 1.;\n\t\t\tif (pphase >= 1.) do { pphase -= 2.; } while (pphase >= 1.);\n\t\t\telse if (pphase < -1.) do { pphase += 2.; } while (pphase < -1.);\n\t\t\tout[i] = pphase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct LFTri : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFTri(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(2. * th.rate.invNyquistRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFTri\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase <= 1. ? phase : 2. - phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= 3.) phase -= 4.;\n\t\t\telse if (phase < -1.) phase += 4.;\n\t\t}\n\t}\n};\n\nstatic void lfsaw_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsaw : phase\");\n\tV freq = th.popZIn(\"lfsaw : freq\");\n\n\tth.push(new List(new LFSaw(th, freq, phase)));\n}\n\nstatic void lftri_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lftri : phase\");\n\tV freq = th.popZIn(\"lftri : freq\");\n\n\tth.push(new List(new LFTri(th, freq, phase)));\n}\n\nstruct LFPulse : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulse(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? 1. : 0.;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? 1.f : 0.f;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFPulseBipolar : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFPulseBipolar(Thread& th, Arg freq, Z iphase, Arg duty) : TwoInputUGen(th, freq, duty), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFPulseBipolar\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* duty, int freqStride, int dutyStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\t// output at least one sample from the opposite polarity\n\t\t\t\tout[i] = *duty < 0.5 ? *duty : *duty - 1. ;\n\t\t\t} else {\n\t\t\t\tout[i] = phase < *duty ? *duty : *duty - 1.;\n\t\t\t}\n\n\t\t\tphase += *freq * freqmul;\n\t\t\tduty += dutyStride;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstruct LFSquare : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tLFSquare(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LFSquare\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\tout[i] = phase < .5 ? 1. : -1.;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Vosim : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tVosim(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invSampleRate), freqLimit(.5*th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = (freqLimit / *freq);\n\t\t\tout[i] = sc_squared(std::sin(M_PI*std::min(maxnth, *nth)*phase)) * sc_squared(1.-phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 1.;\n\t\t\telse if (phase < 0.) phase += 1.;\n\t\t}\n\t}\n};\n\n\nstatic void vosim_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"vosim : n\");\n\tZ phase = th.popFloat(\"vosim : phase\");\n\tV freq = th.popZIn(\"vosim : freq\");\n\n\tth.push(new List(new Vosim(th, freq, phase, n)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SmoothSaw : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSaw(Thread& th, Arg freq, Z iphase, Arg nth) : TwoInputUGen(th, freq, nth), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, int freqStride, int nthStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tout[i] = phase-phase*std::pow(std::abs(phase),std::min(maxnth, *nth));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\nstruct SmoothSawPWM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ freqLimit;\n\t\n\tSmoothSawPWM(Thread& th, Arg freq, Z iphase, Arg nth, Arg duty) : ThreeInputUGen(th, freq, nth, duty), phase(sc_wrap(2. * iphase, -1., 1.)), freqmul(th.rate.invNyquistRate), freqLimit(th.rate.freqLimit)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SmoothSaw\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* nth, Z* duty, int freqStride, int nthStride, int dutyStride)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ maxnth = freqLimit / *freq;\n\t\t\tZ w = *duty;\n\t\t\tZ u = .5*phase - .5;\n\t\t\tZ wphase = (w+u)/(w*phase-u);\n\t\t\tout[i] = wphase*(1.-std::pow(std::abs(phase),std::min(maxnth, *nth)));\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tnth += nthStride;\n\t\t\tduty += dutyStride;\n\t\t\tif (phase >= 1.) phase -= 2.;\n\t\t\telse if (phase < -1.) phase += 2.;\n\t\t}\n\t}\n};\n\n\nstatic void smoothsawpwm_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"smoothsawpwm : duty\");\n\tV n = th.popZIn(\"smoothsawpwm : n\");\n\tZ phase = th.popFloat(\"smoothsawpwm : phase\");\n\tV freq = th.popZIn(\"smoothsawpwm : freq\");\n\n\tth.push(new List(new SmoothSawPWM(th, freq, phase, n, duty)));\n}\n\n\nstatic void smoothsaw_(Thread& th, Prim* prim)\n{\n\tV n = th.popZIn(\"smoothsaw : n\");\n\tZ phase = th.popFloat(\"smoothsaw : phase\");\n\tV freq = th.popZIn(\"smoothsaw : freq\");\n\n\tth.push(new List(new SmoothSaw(th, freq, phase, n)));\n}\n\nstatic void lfpulse_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulse : duty\");\n\tZ phase = th.popFloat(\"lfpulse : phase\");\n\tV freq = th.popZIn(\"lfpulse : freq\");\n\n\tth.push(new List(new LFPulse(th, freq, phase, duty)));\n}\n\nstatic void lfpulseb_(Thread& th, Prim* prim)\n{\n\tV duty = th.popZIn(\"lfpulseb : duty\");\n\tZ phase = th.popFloat(\"lfpulseb : phase\");\n\tV freq = th.popZIn(\"lfpulseb : freq\");\n\n\tth.push(new List(new LFPulseBipolar(th, freq, phase, duty)));\n}\n\nstatic void lfsquare_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"lfsquare : phase\");\n\tV freq = th.popZIn(\"lfsquare : freq\");\n\n\tth.push(new List(new LFSquare(th, freq, phase)));\n}\n\n\n\n\nstruct Impulse : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tImpulse(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.)), freqmul(th.rate.invSampleRate)\n\t{\n\t\tif (phase == 0.) phase = 1.; // force an initial impulse.\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Impulse\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (phase >= 1.) {\n\t\t\t\tphase -= 1.;\n\t\t\t\tout[i] = 1.;\n\t\t\t} else {\n\t\t\t\tout[i] = 0.;\n\t\t\t}\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t}\n\t}\n};\n\nstatic void impulse_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"impulse : phase\");\n\tV freq = th.popZIn(\"impulse : freq\");\n\n\tth.push(new List(new Impulse(th, freq, phase)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct SinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n#if 1\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n#else\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n#endif\n\t}\n};\n\nstruct SinOsc2 : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOsc2(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq),\n\t\tphase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOsc2\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct TSinOsc : public OneInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tTSinOsc(Thread& th, Arg freq, Z iphase) : OneInputUGen(th, freq), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"TSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, int freqStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = tsin(phase);\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\n\nstruct FSinOsc : public ZeroInputUGen\n{\n\tZ freq;\n\tZ b1, y1, y2;\n\t\n\tFSinOsc(Thread& th, Z ifreq, Z iphase) : ZeroInputUGen(th, false), \n\t\tfreq(ifreq * th.rate.radiansPerSample), \n\t\tb1(2. * cos(freq))\n\t{\n\t\tiphase = sc_wrap(iphase, 0., 1.) * kTwoPi;\n\t\ty1 = sin(iphase-freq);\n\t\ty2 = sin(iphase-2.*freq);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FSinOsc\"; }\n\t\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ zy1 = y1;\n\t\tZ zy2 = y2;\n\t\tZ zb1 = b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = zb1 * zy1 - zy2;\n\t\t\tout[i] = y0;\n\t\t\tzy2 = zy1;\n\t\t\tzy1 = y0;\n\t\t}\n\t\ty1 = zy1;\n\t\ty2 = zy2;\n\t}\n};\n\n\n\nstruct SinOscPMFB : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ y1;\n\t\n\tSinOscPMFB(Thread& th, Arg freq, Z iphase, Arg phasefb) : TwoInputUGen(th, freq, phasefb), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMFB\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasefb, int freqStride, int phasefbStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = sin(phase + *phasefb * y1);\n\t\t\tout[i] = y0;\n\t\t\ty1 = y0;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasefb += phasefbStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPM : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPM(Thread& th, Arg freq, Arg phasemod) : TwoInputUGen(th, freq, phasemod), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tfreqmul = th.rate.radiansPerSample;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, int freqStride, int phasemodStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = phase + *phasemod * kTwoPi;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t\tvvsin(out, out, &n);\n\t}\n};\n\nstruct SinOscM : public ThreeInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscM(Thread& th, Arg freq, Z iphase, Arg mul, Arg add) : ThreeInputUGen(th, freq, mul, add), phase(sc_wrap(iphase, 0., 1.) * kTwoPi), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* mul, Z* add, int freqStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\n\nstruct SinOscPMM : public FourInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\t\n\tSinOscPMM(Thread& th, Arg freq, Arg phasemod, Arg mul, Arg add)\n\t\t: FourInputUGen(th, freq, phasemod, mul, add), phase(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SinOscPMM\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* freq, Z* phasemod, Z* mul, Z* add, int freqStride, int phasemodStride, int mulStride, int addStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sin(phase + *phasemod) * *mul + *add;\n\t\t\tphase += *freq * freqmul;\n\t\t\tfreq += freqStride;\n\t\t\tphasemod += phasemodStride;\n\t\t\tmul += mulStride;\n\t\t\tadd += addStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void tsinosc_(Thread& th, Prim* prim)\n{\n\tZ phase = th.popFloat(\"tsinosc : iphase\");\n\tV freq = th.popZIn(\"tsinosc : freq\");\n\n th.push(new List(new SinOsc2(th, freq, phase)));\n}\n\nstatic void sinosc_(Thread& th, Prim* prim)\n{\n\tV phase = th.popZIn(\"sinosc : phase\");\n\tV freq = th.popZIn(\"sinosc : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPM(th, freq, phase)));\n\t} else if (freq.isZList()) {\n\t\tth.push(new List(new SinOsc(th, freq, phase.f)));\n\t} else {\n\t\tth.push(new List(new FSinOsc(th, freq.f, phase.f)));\n\t}\n}\n\nstatic void sinoscm_(Thread& th, Prim* prim)\n{\n\tV add = th.popZIn(\"sinoscm : mul\");\n\tV mul = th.popZIn(\"sinoscm : add\");\n\tV phase = th.popZIn(\"sinoscm : phase\");\n\tV freq = th.popZIn(\"sinoscm : freq\");\n\n\tif (phase.isZList()) {\n\t\tth.push(new List(new SinOscPMM(th, freq, phase, mul, add)));\n\t} else {\n\t\tth.push(new List(new SinOscM(th, freq, phase.f, mul, add)));\n\t}\n}\n\n\nstatic void sinoscfb_(Thread& th, Prim* prim)\n{\n\tV fb = th.popZIn(\"sinoscfb : fb\");\n\tZ iphase = th.popFloat(\"sinoscfb : phase\");\n\tV freq = th.popZIn(\"sinoscfb : freq\");\n\n\tth.push(new List(new SinOscPMFB(th, freq, iphase, fb)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Blip : public TwoInputUGen\n{\n\tZ phase;\n\tZ freqmul;\n\tZ nyq_;\n\tBlip(Thread& th, Arg freq, Z iphase, Arg numharms)\n\t\t: TwoInputUGen(th, freq, numharms), phase(sc_wrap(2. * iphase - 1., -1., 1.)), freqmul(th.rate.radiansPerSample),\n\t\tnyq_(th.rate.sampleRate * .5)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Blip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* numharms, int freqStride, int numharmsStride) \n\t{\n\t\tZ nyq = nyq_;\n\t\t\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\t\t\tZ ffreq = *freq * freqmul;\n\n\t\t\tZ maxN = floor(nyq / ffreq);\n\t\t\tZ N = *numharms;\n\t\t\t\n\t\t\tif (N > maxN) N = maxN;\n\t\t\telse if (N < 1.) N = 1.;\n\t\t\t\n\t\t\tZ Na = floor(N);\n\t\t\tZ Nb = Na + 1.;\n\t\t\t\n\t\t\tZ frac = N - Na;\n\t\t\tZ Na_scale = .5 / Na;\n\t\t\tZ Nb_scale = .5 / Nb;\n\n\t\t\tZ Na2 = 2. * Na + 1.;\n\t\t\tZ Nb2 = Na2 + 2.;\n\n\t\t\tZ d = 1. / sin(phase);\n\t\t\tZ a = Na_scale * (sin(Na2 * phase) * d - 1.);\n\t\t\tZ b = Nb_scale * (sin(Nb2 * phase) * d - 1.);\n\n\t\t\tfrac = sc_scurve0(frac); // this eliminates out a broadband tick in the spectrum.\n\n\t\t\tout[i] = a + frac * (b - a);\n\n\t\t\tphase += ffreq;\n\t\t\tfreq += freqStride;\n\t\t\tnumharms += numharmsStride;\n\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\telse if (phase < -kTwoPi) phase += kTwoPi;\n\t\t}\n\t}\n};\n\nstatic void blip_(Thread& th, Prim* prim)\n{\n\tV numharms = th.popZIn(\"blip : numharms\");\n\tZ phase = th.popFloat(\"blip : phase\");\n\tV freq = th.popZIn(\"blip : freq\");\n\n\tth.push(new List(new Blip(th, freq, phase, numharms)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF1 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF1(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF1\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = *coef;\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scale = (a - 1.)/(an1 - 1.);\n\t\t\tout[i] = scale * (sin(p1) - a * sin(p1-p2) - an1 * (sin(p1 + N1*p2) - a * sin(p1 + N*p2)))/(1. + a2 - 2. * a * cos(p2));\nprintf(\"%d %f\\n\", i, out[i]);\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf1_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf1 : numharms\");\n\tV coef = th.popZIn(\"dsf1 : coef\");\n\tV modRatio = th.popZIn(\"dsf1 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf1 : carRatio\");\n\tV freq = th.popZIn(\"dsf1 : freq\");\n\n\tth.push(new List(new DSF1(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct DSF3 : public FourInputUGen\n{\n\tZ phase1;\n\tZ phase2;\n\tZ freqmul;\n\tZ N, N1;\n\tDSF3(Thread& th, Arg freq, Arg carRatio, Arg modRatio, Arg coef, Z numharms)\n\t\t: FourInputUGen(th, freq, carRatio, modRatio, coef), phase1(0.), phase2(0.), freqmul(th.rate.radiansPerSample)\n\t{\n\t\tN = numharms < 1. ? 1. : floor(numharms);\n\t\tN1 = N + 1.;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"DSF3\"; }\n\t\n\tvoid calc(int n, Z* out, Z* freq, Z* carRatio, Z* modRatio, Z* coef, int freqStride, int carStride, int modStride, int coefStride) \n\t{\n\t\tZ p1 = phase1;\n\t\tZ p2 = phase2;\n\t\tfor (int i = 0; i < n; ++i) {\n\n\t\t\t//f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1)\n\n\t\t\tZ a = std::clamp(*coef, -.9999, .9999);\n\t\t\tZ a2 = a*a;\n\t\t\tZ an1 = pow(a, N1);\n\t\t\tZ scalePeak = (a - 1.)/(2.*an1 - a - 1.);\n\t\t\tZ scale = scalePeak;\n\t\t\tZ denom = (1. + a2 - 2. * a * cos(p2));\n\t\t\tout[i] = scale * sin(p1) * (1. - a2 - 2. * an1 * (cos(N1*p2) - a * cos(N*p2)))/denom;\n\n\t\t\tZ ffreq = *freq * freqmul;\n\t\t\tZ f1 = ffreq * *carRatio;\n\t\t\tZ f2 = ffreq * *modRatio;\n\t\t\tp1 += f1;\n\t\t\tp2 += f2;\n\t\t\tfreq += freqStride;\n\t\t\tcarRatio += carStride;\n\t\t\tmodRatio += modStride;\n\t\t\tcoef += coefStride;\n\t\t\tif (p1 >= kTwoPi) p1 -= kTwoPi;\n\t\t\telse if (p1 < -kTwoPi) p1 += kTwoPi;\n\t\t\tif (p2 >= kTwoPi) p2 -= kTwoPi;\n\t\t\telse if (p2 < -kTwoPi) p2 += kTwoPi;\n\t\t}\n\t\tphase1 = p1;\n\t\tphase2 = p2;\n\t}\n};\n\nstatic void dsf3_(Thread& th, Prim* prim)\n{\n\tZ numharms = th.popFloat(\"dsf3 : numharms\");\n\tV coef = th.popZIn(\"dsf3 : coef\");\n\tV modRatio = th.popZIn(\"dsf3 : modRatio\");\n\tV carRatio = th.popZIn(\"dsf3 : carRatio\");\n\tV freq = th.popZIn(\"dsf3 : freq\");\n\n\tth.push(new List(new DSF3(th, freq, carRatio, modRatio, coef, numharms)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct KlangOsc\n{\n\tKlangOsc(Arg f, Arg a, Z p) :\n\t\tfreq(f), amp(a), phase(p) {}\n\t\t\n\tZIn freq;\n\tZIn amp;\n\tZ phase;\n};\n\nstruct Klang : public Gen\n{\n\tstd::vector _oscs;\n\tZ _freqmul, _K;\n\tZ _nyq, _cutoff, _slope;\n\t\n\tKlang(Thread& th, V freqs, V amps, V phases)\n\t\t: Gen(th, itemTypeZ, false),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 / th.rate.sampleRate),\n\t\t\t_nyq(th.rate.sampleRate * .5),\n\t\t\t_cutoff(_nyq * .8),\n\t\t\t_slope(1. / (_nyq - _cutoff))\n\t{\n\t\tint64_t numOscs = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, freqs.length(th));\n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumOscs = std::min(numOscs, amps.length(th));\n\t\t}\n\t\tif (phases.isList()) {\n\t\t\tphases = ((List*)phases.o())->pack(th);\n\t\t\tnumOscs = std::min(numOscs, phases.length(th));\n\t\t}\n\t\t\n\t\tif (numOscs == LONG_MAX) numOscs = 1;\n\t\t\n\t\tfor (int64_t i = 0; i < numOscs; ++i) {\n\t\t\tKlangOsc kf(freqs.at(i), amps.at(i), phases.atz(i));\n\t\t\t_oscs.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"Klang\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\tZ* out0 = mOut->fulfillz(mBlockSize);\n\t\tmemset(out0, 0, mBlockSize * sizeof(Z));\n\t\tint maxToFill = 0;\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ nyq = _nyq;\n\t\tZ cutoff = _cutoff;\n\t\tZ slope = _slope;\n\t\tfor (size_t osc = 0; osc < _oscs.size(); ++osc) {\n\t\t\tint framesToFill = mBlockSize;\n\t\t\tKlangOsc& ko = _oscs[osc];\n\t\t\tZ phase = ko.phase;\n\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp;\n\t\t\t\tint n, freqStride, ampStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (ko.freq(th, n, freqStride, freq) || ko.amp(th, n, ampStride, amp)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ ffreq = *freq;\n\t\t\t\t\tif (ffreq > cutoff) {\n\t\t\t\t\t\tif (ffreq < nyq) {\n\t\t\t\t\t\t\tout[i] += (cutoff - ffreq) * slope * *amp * tsin(phase);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] += *amp * tsin(phase);\n\t\t\t\t\t}\n\t\t\t\t\tphase += ffreq * freqmul;\n\t\t\t\t\tif (phase >= kTwoPi) phase -= kTwoPi;\n\t\t\t\t\telse if (phase < 0.) phase += kTwoPi;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tko.freq.advance(n);\n\t\t\t\tko.amp.advance(n);\n\t\t\t}\n\t\t\tko.phase = phase;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\nstatic void klang_(Thread& th, Prim* prim)\n{\n\tV phases\t= th.popZInList(\"klang : phases\");\n\tV amps\t\t= th.popZInList(\"klang : amps\");\n\tV freqs = th.popZInList(\"klang : freqs\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (phases.isVList() && !phases.isFinite())\n\t\tindefiniteOp(\"klank : phases\", \"\");\n\n\tth.push(new List(new Klang(th, freqs, amps, phases)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddOscilUGenOps()\n{\n\tfillHarmonicsTable();\n\n\tvm.addBifHelp(\"\\n*** wavetable generation ***\");\n\tDEFAM(wavefill, aak, \"(amps phases smooth -> wavetable) generates a set 1/3 octave wavetables for table lookup oscillators. sin(i*theta + phases[i])*amps[i]*pow(cos(pi*i/n), smooth). smoothing reduces Gibb's phenomenon. zero is no smoothing\")\n\t\n\tmakeClassicWavetables();\n\n\tvm.addBifHelp(\"\\n*** oscillator unit generators ***\");\n\t\n\tDEFMCX(osc, 3, \"(freq phase wavetable --> out) band limited wave table oscillator. wavetable is a table created with wavefill.\")\n\tDEFMCX(oscp, 4, \"(freq phase phaseOffset wavetable --> out) band limited wave table oscillator pair with phase offset.\")\n\tDEFMCX(sosc, 2, \"(freq1 freq2 wavetable --> out) band limited hard sync wave table oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(par, 2, \"(freq phase --> out) band limited parabolic wave oscillator.\")\n\tDEFMCX(tri, 2, \"(freq phase --> out) band limited triangle wave oscillator.\")\n\tDEFMCX(square, 2, \"(freq phase --> out) band limited square wave oscillator.\")\n\tDEFMCX(saw, 2, \"(freq phase --> out) band limited sawtooth wave oscillator.\")\n\tDEFMCX(pulse, 3, \"(freq phase duty --> out) band limited pulse wave oscillator.\")\n\tDEFMCX(vsaw, 3, \"(freq phase duty --> out) band limited variable sawtooth oscillator.\")\n\tDEFMCX(ssaw, 2, \"(freq1 freq2 --> out) band limited hard sync sawtooth oscillator. freq1 is the fundamental. freq2 is the slave oscil frequency.\")\n\n\tDEFMCX(blip, 3, \"(freq phase numharms --> out) band limited impulse oscillator.\")\n\tDEFMCX(dsf1, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 1\")\n\tDEFMCX(dsf3, 5, \"(freq carrierRatio modulatorRatio ampCoef numharms --> out) two sided bandlimited partials with geometric series amplitudes. J.A.Moorer's equation 3\")\n\t\n\tDEFMCX(lftri, 2, \"(freq phase --> out) non band limited triangle wave oscillator.\")\n\tDEFMCX(lfsaw, 2, \"(freq phase --> out) non band limited sawtooth wave oscillator.\")\n\tDEFMCX(lfpulse, 3, \"(freq phase duty --> out) non band limited unipolar pulse wave oscillator.\")\n\tDEFMCX(lfpulseb, 3, \"(freq phase duty --> out) non band limited bipolar pulse wave oscillator.\")\n\tDEFMCX(lfsquare, 2, \"(freq phase --> out) non band limited square wave oscillator.\")\n\tDEFMCX(impulse, 2, \"(freq phase --> out) non band limited single sample impulse train oscillator.\")\n\tDEFMCX(smoothsaw, 3, \"(freq phase nth --> out) smoothed sawtooth.\")\n\tDEFMCX(smoothsawpwm, 4, \"(freq phase nth duty --> out) smoothed sawtooth.\")\n\tDEFMCX(vosim, 3, \"(freq phase nth --> out) vosim sim.\")\n\tDEFMCX(sinosc, 2, \"(freq phase --> out) sine wave oscillator.\")\n\tDEFMCX(tsinosc, 2, \"(freq iphase --> out) sine wave oscillator.\")\n\tDEFMCX(sinoscfb, 3, \"(freq phase feedback --> out) sine wave oscillator with self feedback phase modulation\")\n\tDEFMCX(sinoscm, 4, \"(freq phase mul add --> out) sine wave oscillator with multiply and add.\")\n\n\tDEF(klang, 3, 1, \"(freqs amps iphases --> out) a sine oscillator bank. freqs amps and iphases are arrays.\")\n}\n\n\n\n"], ["/sapf/src/UGen.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n\nstruct MulAdd : public ThreeInputUGen\n{\n\tMulAdd(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MulAdd\"; }\n\t\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = *a * *b + *c;\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nextern UnaryOp* gUnaryOpPtr_neg;\nextern BinaryOp* gBinaryOpPtr_plus;\nextern BinaryOp* gBinaryOpPtr_minus;\nextern BinaryOp* gBinaryOpPtr_mul;\n\nstatic void madd_(Thread& th, Prim* prim)\n{\n\tV c = th.popZIn(\"*+ : c\");\n\tV b = th.popZIn(\"*+ : b\");\n\tV a = th.popZIn(\"*+ : a\");\n\n\tif (a.isReal() && b.isReal() && c.isReal()) {\n\t\tth.push(a.f * b.f + c.f);\n\t} else {\n\t\tif (c.isReal()) {\n\t\t\tif (c.f == 0.) {\n\t\t\t\tif (a.isReal() && a.f == 1.) { th.push(b); return; }\n\t\t\t\tif (b.isReal() && b.f == 1.) { th.push(a); return; }\n\t\t\t\tif (a.isReal() && a.f == -1.) { th.push(b.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tif (b.isReal() && b.f == -1.) { th.push(a.unaryOp(th, gUnaryOpPtr_neg)); return; }\n\t\t\t\tth.push(a.binaryOp(th, gBinaryOpPtr_mul, b)); return;\n\t\t\t}\n\t\t}\n\t\tif (a.isReal()) {\n\t\t\tif (a.f == 0.) { th.push(c); return; }\n\t\t\tif (a.f == 1.) { th.push(b.binaryOp(th, gBinaryOpPtr_plus, c)); return; }\n\t\t\tif (a.f == -1.) { th.push(b.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tif (b.isReal()) {\n\t\t\tif (b.f == 0.) { th.push(c); return; } \n\t\t\tif (b.f == 1.) { th.push(a.binaryOp(th, gBinaryOpPtr_plus, c)); return; } \n\t\t\tif (b.f == -1.) { th.push(a.binaryOp(th, gBinaryOpPtr_minus, c)); return; }\n\t\t}\n\t\tth.push(new List(new MulAdd(th, a, b, c)));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Fadeout : Gen\n{\n\tZIn _a;\n\tint64_t _sustainTime;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadeout(Thread& th, Arg a, Z sustainTime, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_sustainTime = (int64_t)floor(th.rate.sampleRate * sustainTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_sustainTime = std::max(1LL, _sustainTime);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadeout\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_sustainTime <= 0) {\n\t\t\tif (_fadeTime <= 0) {\n\t\t\t\tend();\n\t\t\t} else {\n\t\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t\t_fadeTime -= framesToFill;\n\t\t\t\twhile (framesToFill) {\n\t\t\t\t\tint n = framesToFill;\n\t\t\t\t\tint astride;\n\t\t\t\t\tZ *a;\n\t\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\t setDone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t_amp = amp;\n\t\t\t\t\t\t_a.advance(n);\n\t\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\t\tout += n;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t produce(framesToFill);\n\t\t\t}\n\t\t} else {\n int framesToFill = (int)std::min(_sustainTime, (int64_t)mBlockSize);\n Z* out = mOut->fulfillz(framesToFill);\n _sustainTime -= framesToFill;\n while (framesToFill) {\n int n = framesToFill;\n int astride;\n Z *a;\n if (_a(th, n,astride, a)) {\n setDone();\n break;\n } else {\n for (int i = 0; i < n; ++i) {\n out[i] = *a;\n\t\t\t\t\t\ta += astride;\n }\n _a.advance(n);\n framesToFill -= n;\n out += n;\n }\n }\n produce(framesToFill);\n }\n\t}\n};\n\n\nstruct Fadein : Gen\n{\n\tZIn _a;\n\tint64_t _fadeTime;\n\tZ _amp, _fade;\n\t\n\tFadein(Thread& th, Arg a, Z fadeTime) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_amp = .001;\n\t\t_fade = pow(1000., 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Fadein\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tif (_fadeTime <= 0) {\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t} else {\n\t\t\tint framesToFill = (int)std::min(_fadeTime, (int64_t)mBlockSize);\n\t\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\t_fadeTime -= framesToFill;\n\t\t\twhile (framesToFill) {\n\t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t setDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t}\n\t\t\t}\n\t\t produce(framesToFill);\n\t\t}\n\t}\n};\n\nstatic void fadeout_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadeout : fadeTime\");\n\tZ sustain = th.popFloat(\"fadeout : sustainTime\");\n\tV in = th.popZIn(\"fadeout : in\");\n\n\tth.push(new List(new Fadeout(th, in, sustain, fade)));\n}\n\nstatic void fadein_(Thread& th, Prim* prim)\n{\n\tZ fade = th.popFloat(\"fadein : fadeTime\");\n\tV in = th.popZIn(\"fadein : in\");\n\n\tth.push(new List(new Fadein(th, in, fade)));\n}\n\nstruct Endfade : Gen\n{\n\tZIn _a;\n\tint64_t _startupTime;\n\tint64_t _holdTime;\n\tint64_t _holdTimeRemaining;\n\tint64_t _fadeTime;\n\tZ _amp, _fade, _threshold;\n\t\n\tEndfade(Thread& th, Arg a, Z startupTime, Z holdTime, Z fadeTime, Z threshold) : Gen(th, itemTypeZ, true), _a(a)\n\t{\n\t\t_startupTime = (int64_t)floor(th.rate.sampleRate * startupTime + .5);\n\t\t_holdTime = (int64_t)floor(th.rate.sampleRate * holdTime + .5);\n\t\t_fadeTime = (int64_t)floor(th.rate.sampleRate * fadeTime + .5);\n\t\t_startupTime = std::max(0LL, _startupTime);\n\t\t_holdTime = std::max(1LL, _holdTime);\n\t\t_holdTimeRemaining = _holdTime;\n\t\t_fadeTime = std::max(1LL, _fadeTime);\n\t\t_threshold = threshold;\n\t\t_amp = 1.001;\n\t\t_fade = pow(.001, 1. / _fadeTime);\n\t}\n\tvirtual const char* TypeName() const override { return \"Endfade\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (_startupTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _startupTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_startupTime -= n;\n\t\t\t\t}\n\t\t\t} else if (_holdTimeRemaining > 0) {\n \t\t\t\tint n = framesToFill;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n, astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tint framesFilled = 0;\n\t\t\t\t\tfor (int i = 0; i < n && _holdTimeRemaining > 0; ++i) {\n\t\t\t\t\t\tZ z = *a;\n\t\t\t\t\t\tif (std::abs(z) >= _threshold) {\n\t\t\t\t\t\t\t_holdTimeRemaining = _holdTime;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t--_holdTimeRemaining;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\t++framesFilled;\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(framesFilled);\n\t\t\t\t\tframesToFill -= framesFilled;\n\t\t\t\t\tout += framesFilled;\n\t\t\t\t}\n\t\t\t} else if (_fadeTime > 0) {\n\t\t\t\tint n = (int)std::min((int64_t)framesToFill, _fadeTime);\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tZ amp = _amp;\n\t\t\t\t\tZ fade = _fade;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tout[i] = *a * (amp - .001);\n\t\t\t\t\t\tamp *= fade;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t\t_amp = amp;\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t\tframesToFill -= n;\n\t\t\t\t\tout += n;\n\t\t\t\t\t_fadeTime -= n;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void endfade_(Thread& th, Prim* prim)\n{\n\tZ threshold = th.popFloat(\"endfade : threshold\");\n\tZ fade = th.popFloat(\"endfade : fadeTime\");\n\tZ hold = th.popFloat(\"endfade : holdTime\");\n\tZ startup = th.popFloat(\"endfade : startupTime\");\n\tV in = th.popZIn(\"endfade : in\");\n\n\tth.push(new List(new Endfade(th, in, startup, hold, fade, threshold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Imps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, invdur_;\n\tZ freqmul_;\n\tbool once;\n\n\tImps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate), once(false)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Imps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tonce = true;\n\t\t\t\t}\n\n\t\t\t\tif (once) {\n\t\t\t\t\tout[i] = val_;\n\t\t\t\t\tonce = false;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\t\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Steps : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\n\tSteps(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Steps\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Gates : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn hold_;\n\tZIn rate_;\n\tZ val_;\n\tZ phase_, dur_, hdur_;\n\tZ freqmul_;\n\n\tGates(Thread& th, Arg durs, Arg vals, Arg hold, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, hold)), durs_(durs), vals_(vals), hold_(hold), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Gates\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (vals_.onez(th, val_) || durs_.onez(th, dur_) || hold_.onez(th, hdur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t}\n\n\t\t\t\tout[i] = phase_ < hdur_ ? val_ : 0.;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Lines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, slope_;\n\tZ phase_, dur_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Lines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\tdo {\n\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tslope_ = (newval_ - oldval_) / dur_;\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_ + slope_ * phase_;\n\n\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct XLines : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tZIn rate_;\n\tZ oldval_, newval_, ratio_, step_;\n\tZ phase_, dur_, invdur_, freq_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tXLines(Thread& th, Arg durs, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate)), durs_(durs), vals_(vals), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"XLines\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t\t//oldval_ = oldval_ * pow(ratio_, phase_ * invdur_);\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = pow(ratio_, freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\toldval_ *= step_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tratio_ = newval_ / oldval_;\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_ * pow(ratio_, phase_ * invdur_);\n\n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\trate += rateStride;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Curves : public Gen\n{\n\tBothIn durs_;\n\tBothIn vals_;\n\tBothIn curves_;\n\tZIn rate_;\n\tZ oldval_, newval_, step_;\n\tZ phase_, dur_, curve_, invdur_, freq_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\t//bool cheat;\n\n\tCurves(Thread& th, Arg durs, Arg vals, Arg curves, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, durs, rate, curves)), durs_(durs), vals_(vals), curves_(curves), rate_(rate),\n\t\tphase_(0.), dur_(0.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Curves\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, newval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (rateStride == 0) {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tdur_ = std::max(dur_, 1e-4);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = *rate * freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n\n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\t\tphase_ += freq_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t} else {\n //!! not correct\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twhile (phase_ >= dur_) {\n\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\t\t\tif (vals_.onez(th, newval_) || curves_.onez(th, curve_) || durs_.onez(th, dur_)) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\t\tinvdur_ = 1. / dur_;\n\t\t\t\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\t\t\t\ta2_ = oldval_ + a1;\n\t\t\t\t\t\tb1_ = a1;\n\t\t\t\t\t\tfreq_ = freqmul_;\n\t\t\t\t\t\tstep_ = exp(curve_ * freq_ * invdur_);\n\t\t\t\t\t}\n \n\t\t\t\t\tout[i] = oldval_;\n\t\t\t\t\tb1_ *= step_;\n\t\t\t\t\toldval_ = a2_ - b1_;\n \n\t\t\t\t\tphase_ += *rate * freqmul_;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Cubics : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\tbool once = true;\n\n\tCubics(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Cubics\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tc0 = y1;\n\t\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n/*\nd = duration of accelerando in beats\na = duration of accelerando in seconds\n\nr0 = starting tempo in beats per second\nr1 = ending tempo in beats per second\n\nc = (r1 - r0) / d\n\nduration of accelerando in seconds\na = log(r1/r0) / c\n\ntempo for next sample\nr(0) = r0\nr(n) = r(n-1) * exp(c / sr)\n\nbeat for next sample\nb(n) = r(n)/c - r0/c\n\nb(0) = 0\nb(n) = b(n-1) + r(n)/sr \n\n*/\n\n\nstruct Tempo : public Gen\n{\n\tBothIn vals_;\n\tZIn rate_;\n\tZ beat_ = 0.;\n\tZ dur_ = 0.;\n\tZ lastTime_ = 0.;\n\tZ nextTime_ = 0.;\n\tZ invsr_;\n\tZ c_, r0_, r1_;\n\tbool once = true;\n\n\tTempo(Thread& th, Arg vals, Arg rate) : Gen(th, itemTypeZ, mostFinite(vals, rate)), vals_(vals), rate_(rate),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Tempo\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\tsetDone();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t// numerically it would be better to subtract off dur each time, but we need to recreate the same loss of precision over time\n\t\t\t\t// as will be experienced from an integration of tempo occuring outside of this generator. otherwise there would be a drift\n\t\t\t\t// between when tempo changes occur and the beat time as integrated from the tempo.\n\t\t\t\twhile (beat_ >= nextTime_) {\n\t\t\t\t\tdo {\n\t\t\t\t\t\tr0_ = r1_;\n\t\t\t\t\t\tif (vals_.onez(th, dur_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (vals_.onez(th, r1_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (dur_ <= 0.);\n\t\t\t\t\tc_ = (r1_ - r0_) / dur_;\n\t\t\t\t\tlastTime_ = nextTime_;\n\t\t\t\t\tnextTime_ += dur_;\n\t\t\t\t}\n\n\t\t\t\tZ tempo = *rate * (r0_ + (beat_ - lastTime_) * c_);\n\t\t\t\tout[i] = tempo;\n\t\t\t\tbeat_ += tempo * invsr_;\n\n\t\t\t\trate += rateStride;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Beats : public Gen\n{\n\tZIn tempo_;\n\tZ beat_ = 0.;\n\tZ invsr_;\n\n\tBeats(Thread& th, Arg tempo) : Gen(th, itemTypeZ, tempo.isFinite()), tempo_(tempo),\n\t\tinvsr_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"Beats\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ beat = beat_;\n\t\twhile (framesToFill) {\n\t\t\tZ* tempo;\n\t\t\tint n = framesToFill;\n\t\t\tint tempoStride;\n\t\t\tif (tempo_(th, n, tempoStride, tempo)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tZ invsr = invsr_;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = beat;\n\t\t\t\tbeat += *tempo * invsr;\n\t\t\t\ttempo += tempoStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttempo_.advance(n);\n\t\t}\n\t\tbeat_ = beat;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct ADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn rate_;\n\tint stage_ = 0;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ noteOff_;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tZ beat_ = 0.;\n\tbool once = true;\n\tint sustainStage_;\n\n\tADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg rate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\trate_(rate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\t\tnoteOff_ = durs_[sustainStage_];\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"ADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (1) {\n\t\t\t\t\tif (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else if (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (beat_ >= noteOff_) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ < NumStages){\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tbeat_ += *rate * freqmul_;\n\t\t\t\trate += rateStride;\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nstruct GatedADSR : public Gen\n{\n\tZ levels_[NumStages+1];\n\tZ durs_[NumStages];\n\tZ curves_[NumStages];\n\tZIn gate_;\n\tint stage_ = NumStages;\n\tZ oldval_ = 0.;\n\tZ newval_ = 0.;\n\tZ step_;\n\tZ phase_ = 0.;\n\tZ dur_ = 0.;\n\tZ curve_;\n\tZ b1_, a2_;\n\tZ freqmul_;\n\tbool once = true;\n\tint sustainStage_;\n\n\tGatedADSR(Thread& th, Z* levels, Z* durs, Z* curves, Arg gate, int sustainStage) : Gen(th, itemTypeZ, true),\n\t\tgate_(gate), sustainStage_(sustainStage),\n\t\tfreqmul_(th.rate.invSampleRate)\n\t{\n\t\tmemcpy(levels_, levels, (NumStages+1)*sizeof(Z));\n\t\tmemcpy(durs_, durs, NumStages*sizeof(Z));\n\t\tmemcpy(curves_, curves, NumStages*sizeof(Z));\n\n\t\toldval_ = levels[0];\n\t\tnewval_ = levels_[1];\n\t\tcurve_ = curves_[0];\n\t\tdur_ = durs_[0];\n\n\t\tcalcStep();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"GatedADSR\"; }\n\n\tvoid calcStep()\n\t{\n\t\tif (fabs(curve_) < .01) {\n\t\t\ta2_ = oldval_;\n\t\t\tb1_ = 0.;\n\t\t\tstep_ = 1.;\n\t\t} else {\n\n\t\t\tdur_ = std::max(dur_, 1e-5);\n\t\t\tZ invdur = 1. / dur_;\n\t\t\tZ a1 = (newval_ - oldval_) / (1. - exp(curve_));\n\t\t\ta2_ = oldval_ + a1;\n\t\t\tb1_ = a1;\n\t\t\tstep_ = exp(curve_ * freqmul_ * invdur);\n\t\t}\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* gate;\n\t\t\tint n = framesToFill;\n\t\t\tint gateStride;\n\t\t\tif (gate_(th, n, gateStride, gate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t// rework this loop!!!\n\t\t\t//adsr\n\t\t\t//\tif (stage < releaseStage) {\n\t\t\t//\t\tintegrate tempo\n\t\t\t//\t\tsearch from end. break when < noteoff.\n\t\t\t//\t\tremember note off sample index.\n\t\t\t//\t}\n\t\t\t//\t\n\t\t\t//\twhen there is a new stage and it is not the sustainStage\n\t\t\t//\tcompute the number of samples in the stage\n\t\t\t//\t\n\t\t\t//\tlimit n to the min(blockSize, stageSamplesRemaining, [noteOffSample])\n\t\t\t//\tafter a stage \n\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n Z g = *gate;\n gate += gateStride;\n if (stage_ >= NumStages) {\n // waiting for trigger\n if (*gate > 0.) {\n stage_ = 0;\n } else {\n out[i] = 0.;\n --framesToFill;\n continue;\n }\n }\n\t\t\t\twhile (1) { \n if (stage_ < sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1; // go into release mode\n\t\t\t\t\t\t} else if (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else if (stage_ == sustainStage_) {\n\t\t\t\t\t\tif (g <= 0.) {\n\t\t\t\t\t\t\tphase_ = 0.;\n\t\t\t\t\t\t\tstage_ = sustainStage_+1;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (phase_ >= dur_) {\n\t\t\t\t\t\t\tphase_ -= dur_;\n\t\t\t\t\t\t\t++stage_;\n\t\t\t\t\t\t} else break;\n\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tnewval_ = levels_[stage_+1];\n\t\t\t\t\tcurve_ = curves_[stage_];\n\t\t\t\t\tdur_ = durs_[stage_];\n\t\t\t\t\t\n\t\t\t\t\tcalcStep();\n\t\t\t\t}\n\n\t\t\t\tout[i] = oldval_;\n\t\t\t\tb1_ *= step_;\n\t\t\t\toldval_ = a2_ - b1_;\n\n\t\t\t\tphase_ += freqmul_;\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t\tout += n;\n\t\t\tgate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\n\nstatic void imps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"imps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Imps(th, durs, vals, rate)));\n}\n\nstatic void steps_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"steps : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Steps(th, durs, vals, rate)));\n}\n\nstatic void gates_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"gates : rate\");\n\tV hold = th.pop();\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Gates(th, durs, vals, hold, rate)));\n}\n\nstatic void lines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Lines(th, durs, vals, rate)));\n}\n\nstatic void xlines_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"xlines : rate\");\n\tV durs = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new XLines(th, durs, vals, rate)));\n}\n\nstatic void cubics_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"cubics : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Cubics(th, vals, rate)));\n}\n\nstatic void curves_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"curves : rate\");\n\tV durs = th.pop();\n\tV param = th.pop();\n\tV vals = th.pop();\n\n\tth.push(new List(new Curves(th, durs, vals, param, rate)));\n}\n\nstatic void tempo_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"tempo : rate\");\n\tV vals = th.pop();\n\n\tth.push(new List(new Tempo(th, vals, rate)));\n}\n\nstatic void beats_(Thread& th, Prim* prim)\n{\n\tV tempo = th.popZIn(\"beats : tempo\");\n\n\tth.push(new List(new Beats(th, tempo)));\n}\n\nstatic void adsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"adsr : tempo\");\n\tZ noteDur = th.popFloat(\"adsr : noteDur\");\n\tZ amp = th.popFloat(\"adsr : amp\");\n\n\tP list = th.popList(\"adsr : [attack decay sustain release]\");\n\tconst int kNumADSRStages = 4;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"adsr : [attack decay sustain release] list should have 4 elements.\");\n\t}\n\t\t\n\tZ relTime = env[3];\n\tZ susLvl = env[2];\n\tZ dcyTime = env[1];\n\tZ atkTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 2)));\n}\n\nstatic void dadsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dadsr : tempo\");\n\tZ noteDur = th.popFloat(\"dadsr : noteDur\");\n\tZ amp = th.popFloat(\"dadsr : amp\");\n\n\tP list = th.popList(\"dadsr : [delay attack decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 5;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack decay sustain release] list should have 5 elements.\");\n\t}\n\t\n\tZ relTime = env[4];\n\tZ susLvl = env[3];\n\tZ dcyTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 3)));\n}\n\nstatic void dahdsr_(Thread& th, Prim* prim)\n{\n\t\n\tV rate = th.popZIn(\"dahdsr : tempo\");\n\tZ noteDur = th.popFloat(\"dahdsr : noteDur\");\n\tZ amp = th.popFloat(\"dahdsr : amp\");\n\n\tP list = th.popList(\"dahdsr : [delay attack hold decay sustain release]\");\n\t\n\tconst int kNumADSRStages = 6;\n\tZ env[kNumADSRStages];\n\tif (list->fillz(th, kNumADSRStages, env) != kNumADSRStages) {\n\t\tpost(\"dahdsr : [delay attack hold decay sustain release] list should have 6 elements.\");\n\t}\n\t\n\tZ relTime = env[5];\n\tZ susLvl = env[4];\n\tZ dcyTime = env[3];\n\tZ hldTime = env[2];\n\tZ atkTime = env[1];\n\tZ dlyTime = env[0];\n\t\n\tZ levels[kNumADSRStages+1] = { 0., 0., amp, amp, amp*susLvl, amp*susLvl, 0. };\n\tZ durs[kNumADSRStages] = { dlyTime, atkTime, hldTime, dcyTime, noteDur, relTime };\n\tZ curves[kNumADSRStages] = { 0., -1., 0., -5., 0., -5. };\n\n\tth.push(new List(new ADSR(th, levels, durs, curves, rate, 4)));\n}\n\n\n\n\nstruct K2A : public Gen\n{\n\tint n_;\n\tint remain_;\n\tZ slopeFactor_;\n\tBothIn vals_;\n\tZ oldval_, newval_, slope_;\n\tbool once = true;\n\n\tK2A(Thread& th, int n, Arg vals) : Gen(th, itemTypeZ, vals.isFinite()), vals_(vals),\n\t\tn_(n), remain_(0), slopeFactor_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2A\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\tvals_.onez(th, oldval_);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tif (vals_.onez(th, newval_) ) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tslope_ = slopeFactor_ * (newval_ - oldval_);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = oldval_;\n\t\t\t\toldval_ += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct K2AC : public Gen\n{\n\tBothIn vals_;\n\tint n_;\n\tint remain_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ slope_;\n\tbool once = true;\n\n\tK2AC(Thread& th, int n, Arg vals)\n\t\t: Gen(th, itemTypeZ, vals.isFinite()), vals_(vals), n_(n), remain_(0),\n\t\tphase_(0), slope_(1./n)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"K2AC\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\ty0 = 0.;\n\t\t\ty1 = 0.;\n\t\t\tvals_.onez(th, y2);\n\t\t\tvals_.onez(th, y3);\n\t\t}\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\n\t\twhile (framesToFill) {\n\t\t\tif (remain_ == 0) {\n\t\t\t\tx = 0.;\n\t\t\t\ty0 = y1;\n\t\t\t\ty1 = y2;\n\t\t\t\ty2 = y3;\n\t\t\t\tif (vals_.onez(th, y3)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\tc0 = y1;\n\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\tremain_ = n_;\n\t\t\t}\n\t\t\tint n = std::min(remain_, framesToFill);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\t\t\t\tx += slope_;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tremain_ -= n;\n\t\t\tout += n;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void k2a_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV a = th.popZIn(\"kr : signal\");\n\t\n\tth.push(new List(new K2A(th, n, a)));\n}\n\nstatic void k2ac_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"krc : n\");\n\tV a = th.popZIn(\"krc : signal\");\n\t\n\tth.push(new List(new K2AC(th, n, a)));\n}\n\nP gK2A;\nP gK2AC;\n\nstatic void kr_(Thread& th, Prim* prim)\n{\n\tint n = (int)th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"kr : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2A->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\nstatic void krc_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"kr : n\");\n\tV fun = th.pop();\n\t\n\tif (n <= 0) {\n\t\tpost(\"krc : n <= 0\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (n > th.rate.blockSize) {\n\t\tpost(\"krc : n > block size\\n\");\n\t\tthrow errOutOfRange;\n\t}\n\tif (th.rate.blockSize % n != 0) {\n\t\tpost(\"krc : %d is not a divisor of the current signal block size %d\\n\", n, th.rate.blockSize);\n\t\tthrow errFailed;\n\t}\n\t\n\tV result;\n\t{\n\t\tSaveStack ss(th);\n\t\tRate subRate(th.rate, (int)n);\n\t\t{\n\t\t\tUseRate ur(th, subRate);\n\t\t\tfun.apply(th);\n\t\t}\n\t\tresult = th.pop();\n\t\t{\n\t\t\tSaveStack ss2(th);\n\t\t\tth.push(result);\n\t\t\tth.push(n);\n\t\t\tgK2AC->apply_n(th, 2);\n\t\t\tresult = th.pop();\n\t\t}\n\t}\n\tth.push(result);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LFNoise0 : public Gen\n{\n\tZIn rate_;\n\tZ val_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise0(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise0\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\tval_ = r.drand2();\n\t\t\t\t}\n\t\t\t\tout[i] = val_;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise1 : public Gen\n{\n\tZIn rate_;\n\tZ oldval_, newval_;\n\tZ slope_;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise1(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\tnewval_ = oldval_ = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise1\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\toldval_ = newval_;\n\t\t\t\t\tnewval_ = r.drand2();\n\t\t\t\t\tslope_ = newval_ - oldval_;\n\t\t\t\t}\n\t\t\t\tout[i] = oldval_ + slope_ * x;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\nstruct LFNoise3 : public Gen\n{\n\tZIn rate_;\n\tZ y0, y1, y2, y3;\n\tZ c0, c1, c2, c3;\n\tZ phase_;\n\tZ freqmul_;\n\n\tLFNoise3(Thread& th, Arg rate) : Gen(th, itemTypeZ, true), rate_(rate),\n\t\tphase_(1.), freqmul_(th.rate.invSampleRate)\n\t{\n\t\tRGen& r = th.rgen;\n\t\ty1 = r.drand2();\n\t\ty2 = r.drand2();\n\t\ty3 = r.drand2();\n\t}\n\n\tvirtual const char* TypeName() const override { return \"LFNoise3\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\t\n\t\tRGen& r = th.rgen;\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\tZ x = phase_;\n\t\tZ freqmul = freqmul_;\n\t\twhile (framesToFill) {\n\t\t\tZ* rate;\n\t\t\tint n = framesToFill;\n\t\t\tint rateStride;\n\t\t\tif (rate_(th, n, rateStride, rate)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\twhile (x >= 1.) {\n\t\t\t\t\tx -= 1.;\n\t\t\t\t\ty0 = y1;\n\t\t\t\t\ty1 = y2;\n\t\t\t\t\ty2 = y3;\n\t\t\t\t\ty3 = r.drand2() * 0.8; // 0.8 because cubic interpolation can overshoot up to 1.25 if inputs are -1,1,1,-1.\n\t\t\t\t\tc0 = y1;\n\t\t\t\t\tc1 = .5 * (y2 - y0);\n\t\t\t\t\tc2 = y0 - 2.5 * y1 + 2. * y2 - .5 * y3;\n\t\t\t\t\tc3 = 1.5 * (y1 - y2) + .5 * (y3 - y0);\n\t\t\t\t}\n\n\t\t\t\tout[i] = ((c3 * x + c2) * x + c1) * x + c0;\n\n\t\t\t\tx += *rate * freqmul;\n\t\t\t\trate += rateStride;\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\trate_.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t\tphase_ = x;\n\t}\n};\n\n\nstatic void lfnoise0_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise0 : freq\");\n\n\tth.push(new List(new LFNoise0(th, rate)));\n}\n\nstatic void lfnoise1_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise1 : freq\");\n\n\tth.push(new List(new LFNoise1(th, rate)));\n}\n\nstatic void lfnoise3_(Thread& th, Prim* prim)\n{\n\tV rate = th.popZIn(\"lfnoise3 : freq\");\n\n\tth.push(new List(new LFNoise3(th, rate)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\ntemplate \nstruct SymmetricEnv : public Gen\n{\n\tZ xinc;\n\tZ x;\n\tint64_t n_;\n\t\n\tSymmetricEnv(Thread& th, Z dur, Z scale) : Gen(th, itemTypeZ, true), x(-scale)\n\t{\n\t\tZ n = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\tn_ = (int64_t)n;\n\t\txinc = 2. * scale / n;\n\t}\n\t\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint n = (int)std::min(n_, (int64_t)mBlockSize);\n\t\tZ* out = mOut->fulfillz(n);\n\t\tstatic_cast(this)->F::calc(n, out);\n\t\tmOut = mOut->nextp();\n\t\tn_ -= n;\n\t\tif (n_ == 0) {\n\t\t\tend();\n\t\t}\n\t}\n};\n\ntemplate \nstruct TriggeredSymmetricEnv : public Gen\n{\n\tZIn trig_;\n\tBothIn dur_;\n\tBothIn amp_;\n\tZ xinc;\n\tZ x;\n\tZ scale_;\n\tZ ampval_;\n\tint64_t n_ = 0;\n\t\n\tTriggeredSymmetricEnv(Thread& th, Arg trig, Arg dur, Arg amp, Z scale)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), dur_(dur), amp_(amp), scale_(scale)\n\t{\n\t}\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (n_) {\n\t\t\t\tn = (int)std::min((int64_t)n, n_);\n\t\t\t\tstatic_cast(this)->F::calc(n, ampval_, out);\n\t\t\t\tn_ -= n;\n\t\t\t\ttrig += n * trigStride;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tZ dur;\n\t\t\t\t\t\tif (dur_.onez(th, dur)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tx = -scale_;\n\t\t\t\t\t\tZ zn = std::max(1., floor(dur * th.rate.sampleRate + .5));\n\t\t\t\t\t\tn_ = (int64_t)zn;\n\t\t\t\t\t\txinc = 2. * scale_ / zn;\n\t\t\t\t\t\tint n2 = (int)std::min((int64_t)(n-i), n_);\n\t\t\t\t\t\tstatic_cast(this)->F::calc(n2, ampval_, out+i);\n\t\t\t\t\t\tn_ -= n2;\n\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\ti += n2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct TriggeredSignal : public Gen\n{\n\tZIn trig_;\n\tZIn list_;\n\tBothIn amp_;\n\tV in_;\n\tZ ampval_;\n\tbool waiting_ = true;\n\tZ counter_ = 0.;\n\t\n\tTriggeredSignal(Thread& th, Arg trig, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, true), trig_(trig), amp_(amp), in_(in)\n\t{\n\t}\n\n\tvirtual const char* TypeName() const override { return \"TriggeredSignal\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tZ* out = mOut->fulfillz(mBlockSize);\n\t\tint framesToFill = mBlockSize;\n\t\twhile (framesToFill) {\n\t\t\tZ* trig;\n\t\t\tint n = framesToFill;\n\t\t\tint trigStride;\n\t\t\tif (trig_(th, n, trigStride, trig)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!waiting_) {\n\t\t\t\tZ* list;\n\t\t\t\tint listStride;\n\t\t\t\tif (list_(th, n, listStride, list)) {\n\t\t\t\t\twaiting_ = true;\n\t\t\t\t\tgoto waiting;\n\t\t\t\t}\n\t\t\t\tZ amp = ampval_;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = amp * *list;\n\t\t\t\t\tlist += listStride;\n\t\t\t\t}\n\t\t\t\tlist_.advance(n);\n\t\t\t} else {\n\t\twaiting:\n\t\t\t\tfor (int i = 0; i < n;) {\n\t\t\t\t\tif (*trig > 0.) {\n\t\t\t\t\t\tif (amp_.onez(th, ampval_)) {\n\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tV in = in_;\n\t\t\t\t\t\tif (in.isFunOrPrim()) {\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tth.push(counter_);\n\t\t\t\t\t\t\t\tin.apply(th);\n\t\t\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\t\t\tthrow;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tin = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcounter_ += 1.;\n\t\t\t\t\t\tlist_.set(in);\n\t\t\t\t\t\tZ* list;\n\t\t\t\t\t\tint listStride;\n\t\t\t\t\t\tint n2 = n-i;\n\t\t\t\t\t\tif (list_(th, n2, listStride, list)) {\n\t\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tZ amp = ampval_;\n\t\t\t\t\t\t\tfor (int j = i; j < i+n2; ++j) {\n\t\t\t\t\t\t\t\tout[j] = amp * *list;\n\t\t\t\t\t\t\t\tlist += listStride;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttrig += n2 * trigStride;\n\t\t\t\t\t\t\ti += n2;\n\t\t\t\t\t\t\tlist_.advance(n2);\n\t\t\t\t\t\t\twaiting_ = i < n;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tout[i] = 0.;\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\ttrig += trigStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\ttrig_.advance(n);\n\t\t}\n\t//ended:\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void tsig_(Thread& th, Prim* prim)\n{\n\tV amp = th.pop();\n\tV in = th.pop();\n\tV trig = th.popZIn(\"tsig : trig\");\n\n\tth.push(new List(new TriggeredSignal(th, trig, in, amp)));\n}\n\nstruct ParEnv : public SymmetricEnv\n{\n\tParEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"ParEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void parenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"parenv : dur\");\n\n\tth.push(new List(new ParEnv(th, dur)));\n}\n\nstruct TParEnv : public TriggeredSymmetricEnv\n{\n\tTParEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TParEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tparenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tparenv : amp\");\n\tV dur = th.popZIn(\"tparenv : dur\");\n\tV trig = th.popZIn(\"tparenv : trig\");\n\n\tth.push(new List(new TParEnv(th, trig, dur, amp)));\n}\n\nstruct QuadEnv : public SymmetricEnv\n{\n\tQuadEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"QuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = 1. - x2*x2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void quadenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"quadenv : dur\");\n\n\tth.push(new List(new QuadEnv(th, dur)));\n}\n\nstruct TQuadEnv : public TriggeredSymmetricEnv\n{\n\tTQuadEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TQuadEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tout[i] = amp * (1. - x2*x2);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tquadenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tquadenv : amp\");\n\tV dur = th.popZIn(\"tquadenv : dur\");\n\tV trig = th.popZIn(\"tquadenv : trig\");\n\n\tth.push(new List(new TQuadEnv(th, trig, dur, amp)));\n}\n\n\nstruct OctEnv : public SymmetricEnv\n{\n\tOctEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"OctEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\t\n\t\t\tout[i] = 1. - x4*x4;\n\t\t\t\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void octenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"octenv : dur\");\n\n\tth.push(new List(new OctEnv(th, dur)));\n}\n\nstruct TOctEnv : public TriggeredSymmetricEnv\n{\n\tTOctEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TOctEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ x2 = x*x;\n\t\t\tZ x4 = x2*x2;\n\t\t\tout[i] = amp * (1. - x4*x4);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void toctenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toctenv : amp\");\n\tV dur = th.popZIn(\"toctenv : dur\");\n\tV trig = th.popZIn(\"toctenv : trig\");\n\n\tth.push(new List(new TOctEnv(th, trig, dur, amp)));\n}\n\nstruct TriEnv : public SymmetricEnv\n{\n\tTriEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TriEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 1. - fabs(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trienv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trienv : dur\");\n\n\tth.push(new List(new TriEnv(th, dur)));\n}\n\nstruct TTriEnv : public TriggeredSymmetricEnv\n{\n\tTTriEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTriEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * (1. - fabs(x));\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrienv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrienv : amp\");\n\tV dur = th.popZIn(\"ttrienv : dur\");\n\tV trig = th.popZIn(\"ttrienv : trig\");\n\n\tth.push(new List(new TTriEnv(th, trig, dur, amp)));\n}\n\nstruct Tri2Env : public SymmetricEnv\n{\n\tTri2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Tri2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tri2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"tri2env : dur\");\n\n\tth.push(new List(new Tri2Env(th, dur)));\n}\n\nstruct TTri2Env : public TriggeredSymmetricEnv\n{\n\tTTri2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTri2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 1. - fabs(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttri2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttri2env : amp\");\n\tV dur = th.popZIn(\"ttri2env : dur\");\n\tV trig = th.popZIn(\"ttri2env : trig\");\n\n\tth.push(new List(new TTri2Env(th, trig, dur, amp)));\n}\n\n\nstruct TrapezEnv : public SymmetricEnv\n{\n\tTrapezEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapezenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapezenv : dur\");\n\n\tth.push(new List(new TrapezEnv(th, dur)));\n}\n\n\nstruct TTrapezEnv : public TriggeredSymmetricEnv\n{\n\tTTrapezEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapezEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapezenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapezenv : amp\");\n\tV dur = th.popZIn(\"ttrapezenv : dur\");\n\tV trig = th.popZIn(\"ttrapezenv : trig\");\n\n\tth.push(new List(new TTrapezEnv(th, trig, dur, amp)));\n}\n\n\nstruct Trapez2Env : public SymmetricEnv\n{\n\tTrapez2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Trapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void trapez2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"trapez2env : dur\");\n\n\tth.push(new List(new Trapez2Env(th, dur)));\n}\n\nstruct TTrapez2Env : public TriggeredSymmetricEnv\n{\n\tTTrapez2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TTrapez2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = 2. - fabs(x-.5) - fabs(x+.5);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void ttrapez2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"ttrapez2env : amp\");\n\tV dur = th.popZIn(\"ttrapez2env : dur\");\n\tV trig = th.popZIn(\"ttrapez2env : trig\");\n\n\tth.push(new List(new TTrapez2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct CosEnv : public SymmetricEnv\n{\n\tCosEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"CosEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void cosenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"cosenv : dur\");\n\n\tth.push(new List(new CosEnv(th, dur)));\n}\n\n\nstruct TCosEnv : public TriggeredSymmetricEnv\n{\n\tTCosEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"TCosEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = amp * cos(x);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void tcosenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tcosenv : amp\");\n\tV dur = th.popZIn(\"tcosenv : dur\");\n\tV trig = th.popZIn(\"tcosenv : trig\");\n\n\tth.push(new List(new TCosEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct HanEnv : public SymmetricEnv\n{\n\tHanEnv(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"HanEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void hanenv_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"hanenv : dur\");\n\n\tth.push(new List(new HanEnv(th, dur)));\n}\n\n\nstruct THanEnv : public TriggeredSymmetricEnv\n{\n\tTHanEnv(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THanEnv\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tout[i] = amp * y*y;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void thanenv_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"thanenv : amp\");\n\tV dur = th.popZIn(\"thanenv : dur\");\n\tV trig = th.popZIn(\"thanenv : trig\");\n\n\tth.push(new List(new THanEnv(th, trig, dur, amp)));\n}\n\n\n\nstruct Han2Env : public SymmetricEnv\n{\n\tHan2Env(Thread& th, Z dur) : SymmetricEnv(th, dur, M_PI_2) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Han2Env\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void han2env_(Thread& th, Prim* prim)\n{\n\tZ dur = th.popFloat(\"han2env : dur\");\n\n\tth.push(new List(new Han2Env(th, dur)));\n}\n\n\nstruct THan2Env : public TriggeredSymmetricEnv\n{\n\tTHan2Env(Thread& th, Arg trig, Arg dur, Arg amp) : TriggeredSymmetricEnv(th, trig, dur, amp, 1.) {}\n\t\n\tvirtual const char* TypeName() const override { return \"THan2Env\"; }\n\t\n\tvirtual void calc(int n, Z amp, Z* out)\n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y = cos(x);\n\t\t\tZ y2 = y*y;\n\t\t\tout[i] = amp * y2*y2;\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void than2env_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"than2env : amp\");\n\tV dur = th.popZIn(\"than2env : dur\");\n\tV trig = th.popZIn(\"than2env : trig\");\n\n\tth.push(new List(new THan2Env(th, trig, dur, amp)));\n}\n\n\n\nstruct GaussEnv : public SymmetricEnv\n{\n\tZ widthFactor;\n\tGaussEnv(Thread& th, Z dur, Z width) : SymmetricEnv(th, dur, 1.), widthFactor(-1. / (2. * width * width)) {}\n\t\n\tvirtual const char* TypeName() const override { return \"GaussEnv\"; }\n\t\n\tvirtual void calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = exp(x * x * widthFactor);\n\t\t\tx += xinc;\n\t\t}\n\t}\n};\n\nstatic void gaussenv_(Thread& th, Prim* prim)\n{\n\tZ width = th.popFloat(\"gaussenv : width\");\n\tZ dur = th.popFloat(\"gaussenv : dur\");\n\n\tth.push(new List(new GaussEnv(th, dur, width)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Pause : public Gen\n{\n\tZIn _in;\n\tZIn _amp;\n\t\n\tPause(Thread& th, Arg in, Arg amp)\n\t\t: Gen(th, itemTypeZ, amp.isFinite()), _in(in), _amp(amp)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pause\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *amp;\n\t\t\tint n, ampStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_amp(th, n, ampStride, amp) ) {\n\t\t\t\tsetDone();\n\t\t\t\tgoto leave;\n\t\t\t}\n\t\t\t\n\t\t\tint framesThisTime = n;\n\t\t\twhile (framesThisTime) {\n\t\t\t\tint zerolen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp <= 0.; ++i) {\n\t\t\t\t\t*out++ = 0.;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t++zerolen;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= zerolen;\n\t\t\t\t\n\t\t\t\tint seglen = 0;\n\t\t\t\tfor (int i = 0; i < framesThisTime && *amp > 0.; ++i) {\n\t\t\t\t\t++seglen;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\tamp -= seglen * ampStride;\n\n\t\t\t\tint seglenRemain = seglen;\n\t\t\t\twhile (seglenRemain) {\n\t\t\t\t\tZ *in;\n\t\t\t\t\tint n2, inStride;\n\t\t\t\t\tn2 = seglenRemain;\n\t\t\t\t\tif (_in(th, n2, inStride, in) ) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tgoto leave;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0; i < n2; ++i) {\n\t\t\t\t\t\tout[i] = *amp * *in;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t}\n\t\t\t\t\tout += n2;\n\t\t\t\t\t_in.advance(n2);\n\t\t\t\t\tseglenRemain -= n2;\n\t\t\t\t}\n\t\t\t\tframesThisTime -= seglen;\n\t\t\t\t\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\t_amp.advance(n);\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pause_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"pause : amp\");\n\tV in = th.popZIn(\"pause : in\");\n\n\tth.push(new List(new Pause(th, in, amp)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nP s_tempo;\nP s_dt;\nP s_out;\n\nclass OverlapAddInputSource;\nclass OverlapAddOutputChannel;\n\nclass OverlapAddBase : public Object\n{\nprotected:\n\tOverlapAddOutputChannel* mOutputs = nullptr;\n\tP mActiveSources;\n\tbool mFinished = false;\n\tbool mNoMoreSources = false;\n\tint mNumChannels;\npublic:\n OverlapAddBase(int numChannels);\n virtual ~OverlapAddBase();\n\n\tvirtual const char* TypeName() const override { return \"OverlapAddBase\"; }\n\n\tvirtual bool pull(Thread& th);\n\tvirtual void addNewSources(Thread& th, int blockSize) = 0;\n\n\tP createOutputs(Thread& th);\n void fulfillOutputs(int blockSize);\n void produceOutputs(int shrinkBy);\n int renderActiveSources(Thread& th, int blockSize, bool& anyDone);\n void removeInactiveSources();\n};\n\nclass OverlapAdd : public OverlapAddBase\n{\nprotected:\n\tVIn mSounds;\n\tBothIn mHops;\n\tZIn mRate;\n\tZ mBeatTime;\n\tZ mNextEventBeatTime;\n\tZ mEventCounter;\n\tZ mRateMul;\n\tint64_t mSampleTime;\n\tint64_t mPrevChaseTime;\n\t\n\tP mChasedSignals;\n\npublic:\n\tOverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels);\n\tvirtual ~OverlapAdd() {}\n\t\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n\t\t\n\tvirtual void addNewSources(Thread& th, int blockSize) override;\n\tvoid chaseToTime(Thread& th, int64_t inSampleTime);\n};\n\nclass OverlapAddInputSource : public Object\n{\npublic:\n\tP mNextSource;\n\tstd::vector mInputs;\n\tint mOffset;\n\tbool mSourceDone;\n\t\n\tOverlapAddInputSource(Thread& th, List* channels, int inOffset, P const& inNextSource) \n\t\t: mNextSource(inNextSource), mOffset(inOffset), mSourceDone(false)\n\t{\n\t\tif (channels->isVList()) {\n\t\t\tP packedChannels = channels->pack(th);\n\t\t\tArray* a = packedChannels->mArray();\n\t\t\t\n\t\t\t// put channels into mInputs\n\t\t\tmInputs.reserve(a->size());\n\t\t\tfor (int i = 0; i < a->size(); ++i) {\n\t\t\t\tZIn zin(a->v()[i]);\n\t\t\t\tmInputs.push_back(zin);\n\t\t\t}\n\t\t} else {\n\t\t\tZIn zin(channels);\n\t\t\tmInputs.push_back(zin);\n\t\t}\n\t}\n\n\tvirtual const char* TypeName() const override { return \"OverlapAdd\"; }\n};\n\nclass OverlapAddOutputChannel : public Gen\n{\n\tfriend class OverlapAddBase;\n\tP mOverlapAddBase;\n\tOverlapAddOutputChannel* mNextOutput;\n\t\npublic:\t\n\tOverlapAddOutputChannel(Thread& th, OverlapAddBase* inOverlapAdd)\n : Gen(th, itemTypeZ, false), mOverlapAddBase(inOverlapAdd), mNextOutput(nullptr)\n\t{\n\t}\n\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmOverlapAddBase = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"OverlapAddOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mOverlapAddBase->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nOverlapAddBase::OverlapAddBase(int numChannels)\n\t: mNumChannels(numChannels)\n{\n}\n\nOverlapAddBase::~OverlapAddBase()\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tOverlapAddOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nOverlapAdd::OverlapAdd(Thread& th, Arg sounds, Arg hops, Arg rate, P const& chasedSignals, int numChannels)\n\t: OverlapAddBase(numChannels),\n mSounds(sounds), mHops(hops), mRate(rate),\n\tmBeatTime(0.), mNextEventBeatTime(0.), mEventCounter(0.), mRateMul(th.rate.invSampleRate),\n\tmSampleTime(0), mPrevChaseTime(0),\n\tmChasedSignals(chasedSignals)\n{\n}\n\nP OverlapAddBase::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n OverlapAddOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n OverlapAddOutputChannel* c = new OverlapAddOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nvoid OverlapAdd::addNewSources(Thread& th, int blockSize)\n{\t\t\t\n\t// integrate tempo and add new sources.\n\tZ* rate;\n\tint rateStride;\n\tif (mRate(th, blockSize, rateStride, rate)) {\n\t\tmNoMoreSources = true;\n\t} else if (!mNoMoreSources) {\n\t\tZ beatTime = mBeatTime;\n\t\tZ nextEventBeatTime = mNextEventBeatTime;\n\t\tZ ratemul = mRateMul;\n\t\tfor (int i = 0; i < blockSize; ++i) {\n\t\t\twhile (beatTime >= nextEventBeatTime) {\n\t\t\t\n\t\t\t\tchaseToTime(th, mSampleTime + i);\n\t\t\t\n\t\t\t\tV newSource;\n\t\t\t\tif (mSounds.one(th, newSource)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\tif (newSource.isFun()) {\n\t\t\t\t\tSaveStack ss(th);\t\n\t\t\t\t\tth.push(mEventCounter);\n\t\t\t\t\tnewSource.apply(th);\n\t\t\t\t\tnewSource = th.pop();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tV out;\n\t\t\t\tZ deltaTime;\n\t\t\t\tif (mHops.onez(th, deltaTime)) {\n\t\t\t\t\tmNoMoreSources = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (newSource.isForm()) {\n\t\t\t\t\tif (mChasedSignals()) {\n\t\t\t\t\t\tV parents[2];\n\t\t\t\t\t\tparents[0] = mChasedSignals;\n\t\t\t\t\t\tparents[1] = newSource;\n\t\t\t\t\t\tnewSource = linearizeInheritance(th, 2, parents);\n\t\t\t\t\t}\n\t\t\t\t\tnewSource.dot(th, s_out, out);\n\t\t\t\t\tV hop;\n\t\t\t\t\tif (newSource.dot(th, s_dt, hop) && hop.isReal()) {\n\t\t\t\t\t\tdeltaTime = hop.f;\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\t\t\t\t\tout = newSource;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// must be a finite array with fewer than mNumChannels\n\t\t\t\tif (out.isZList() || (out.isVList() && out.isFinite())) {\n\t\t\t\t\tList* s = (List*)out.o();\n\t\t\t\t\t// create an active source:\n\t\t\t\t\tP source = new OverlapAddInputSource(th, s, i, mActiveSources);\n\t\t\t\t\tmActiveSources = source;\n\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\tnextEventBeatTime += deltaTime;\n\t\t\t\tmEventCounter += 1.;\n\t\t\t}\n\t\t\tbeatTime += *rate * ratemul;\n\t\t\trate += rateStride;\n\t\t}\n\t\tmBeatTime = beatTime;\n\t\tmNextEventBeatTime = nextEventBeatTime;\n\t\tmSampleTime += blockSize;\n\t\t\n\t\tmRate.advance(blockSize);\n\n\t\tchaseToTime(th, mSampleTime);\n\t}\n}\n\nvoid OverlapAddBase::fulfillOutputs(int blockSize)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut) {\n\t\t\tZ* out = output->mOut->fulfillz(blockSize);\n\t\t\tmemset(out, 0, output->mBlockSize * sizeof(Z));\n\t\t}\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nint OverlapAddBase::renderActiveSources(Thread& th, int blockSize, bool& anyDone)\n{\n\tint maxProduced = 0;\n\tOverlapAddInputSource* source = mActiveSources();\n\twhile (source) {\n\t\tint offset = source->mOffset;\n\t\tint pullSize = blockSize - offset;\n\t\tstd::vector& sourceChannels = source->mInputs;\n\t\tbool allOutputsDone = true; // initial value for reduction on &&\n\t\tOverlapAddOutputChannel* output = mOutputs;\n\t\tfor (size_t j = 0; j < sourceChannels.size() && output; ++j, output = output->mNextOutput) {\n\t\t\tif (output->mOut) {\n\t\t\t\tZIn& zin = sourceChannels[j];\n\t\t\t\tif (zin.mIsConstant && zin.mConstant.f == 0.)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tint n = pullSize;\n\t\t\t\tZ* out = output->mOut->mArray->z() + offset;\n\t\t\t\tif (!zin.mix(th, n, out)) {\n\t\t\t\t\tallOutputsDone = false;\n\t\t\t\t}\n\t\t\t\tmaxProduced = std::max(maxProduced, n);\n\t\t\t}\n\t\t}\n\t\tsource->mOffset = 0;\n\t\tif (allOutputsDone) {\n\t\t\t// mark for removal from mActiveSources\n\t\t\tsource->mSourceDone = true;\n anyDone = true;\n\t\t}\n\t\tsource = source->mNextSource();\n\t}\n\treturn maxProduced;\n}\n\nvoid OverlapAddBase::removeInactiveSources()\n{\n\tP source = mActiveSources();\n\tP prevSource = nullptr;\n\tmActiveSources = nullptr;\n\t\n\twhile (source) {\n\t\tP nextSource = source->mNextSource;\n\t\tsource->mNextSource = nullptr;\n\t\tif (!source->mSourceDone) {\n\t\t\tif (prevSource()) prevSource->mNextSource = source;\n\t\t\telse mActiveSources = source;\n prevSource = source;\n\t\t}\n\t\tsource = nextSource;\n\t}\n}\n\nvoid OverlapAddBase::produceOutputs(int shrinkBy)\n{\n\tOverlapAddOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nbool OverlapAddBase::pull(Thread& th)\n{\n\tif (mFinished) {\n\t\treturn mFinished;\n }\n\t\n\tOverlapAddOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\taddNewSources(th, blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n bool anyDone = false;\n\tint maxProduced = renderActiveSources(th, blockSize, anyDone);\n\t\t\t\n\tmFinished = mNoMoreSources && mActiveSources() == nullptr;\n\tint shrinkBy = mFinished ? blockSize - maxProduced : 0;\n\t\n\tproduceOutputs(shrinkBy);\n\n\tif (anyDone)\n removeInactiveSources();\n\t\n\treturn mFinished; \n}\n\nvoid OverlapAdd::chaseToTime(Thread& th, int64_t inSampleTime)\n{\n\tint64_t n = inSampleTime - mPrevChaseTime;\n\tmPrevChaseTime = inSampleTime;\n\n\tif (mChasedSignals() && n > 0) {\n\t\tmChasedSignals = mChasedSignals->chaseForm(th, n);\n\t}\n}\n\n\nconst int64_t kMaxOverlapAddChannels = 10000;\n\nstatic void ola_(Thread& th, Prim* prim)\n{\n\tint64_t numChannels = th.popInt(\"ola : numChannels\");\n\tV rate = th.pop();\n\tV hops = th.popZInList(\"ola : hops\");\n\tV sounds = th.pop();\n\n\tif (numChannels > kMaxOverlapAddChannels) {\n\t\tpost(\"ola : too many channels\\n\");\n\t\tthrow errFailed;\n\t}\n\t\n\tP chasedSignals;\n\tif (rate.isForm()) {\n\t\tchasedSignals = (Form*)rate.o();\n\t\trate = 1.;\n\t\tchasedSignals->dot(th, s_tempo, rate);\n\t}\n\n\tP ola = new OverlapAdd(th, sounds, hops, rate, chasedSignals, (int)numChannels);\n\t\n\tth.push(ola->createOutputs(th));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass ITD;\n\nclass ITD_OutputChannel : public Gen\n{\n\tfriend class ITD;\n\tP mITD;\n\t\npublic:\t\n\tITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmITD = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ITD_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nstruct ITD : public Gen\n{\n\tZIn in_;\n\tZIn pan_;\n\tZ maxdelay_;\n\tZ half;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\n\tITD_OutputChannel* mLeft;\n\tITD_OutputChannel* mRight;\n\t\n\tITD(Thread& th, Arg in, Arg pan, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), pan_(pan), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\thalf = (int32_t)ceil(sr * maxdelay * .5 + .5);\n\t\tbufSize = NEXTPOWEROFTWO(2 * (int)half + 3);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~ITD() { delete mLeft; delete mRight; free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"ITD\"; }\n\t\n\tP createOutputs(Thread& th);\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, panStride;\n\t\t\tZ *in, *pan;\n\t\t\tif (in_(th, n, inStride, in) || pan_(th, n, panStride, pan)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., *pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Lout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tZ fpos = std::max(2., -*pan * half + half);\n\t\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t*Rout = lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tRout += Routstride;\n\t\t\t\t\t}\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tpan += panStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tpan_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nITD_OutputChannel::ITD_OutputChannel(Thread& th, bool inFinite, ITD* inITD) : Gen(th, itemTypeZ, inFinite), mITD(inITD)\n{\n}\n\nvoid ITD_OutputChannel::pull(Thread& th)\n{\n\tmITD->pull(th);\n}\n\nP ITD::createOutputs(Thread& th)\n{\n\tmLeft = new ITD_OutputChannel(th, finite, this);\n\tmRight = new ITD_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\nstatic void itd_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"itd : maxdelay\");\n\tV pan = th.popZIn(\"itd : pan\");\n\tV in = th.popZIn(\"itd : in\");\n \n\tP itd = new ITD(th, in, pan, maxdelay);\n\n\tP s = itd->createOutputs(th);\n\n\tth.push(s);\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ninline Z fast_sin1(Z x)\n{\n\tx = x - floor(x + .5);\n\t\n Z y = x * (8. - 16. * fabs(x));\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\ninline Z fast_cos1(Z x)\n{\n\treturn fast_sin1(x + .25);\n}\n\ninline Z fast_pan(Z x)\n{\n\tZ y = .75 + x * (.5 - .25 * x);\n\ty = 0.225 * (y * fabs(y) - y) + y;\n\n\treturn y;\n}\n\nstruct Pan2Out;\n\nstruct Pan2 : public Object\n{\n\tZIn _in;\n\tZIn _pos;\n\t\n\tPan2Out* mLeft;\n\tPan2Out* mRight;\n\t\t\n\tPan2(Thread& th, Arg inIn, Arg inPos)\n\t\t: _in(inIn), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inIn, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Pan2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Pan2Out : public Gen\n{\n\tP mPan2;\n\t\n\tPan2Out(Thread& th, bool inFinite, P const& inPan2) : Gen(th, itemTypeZ, inFinite), mPan2(inPan2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmPan2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pan2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmPan2->pull(th);\n\t}\n\t\n};\n\nvoid Pan2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b;\n\t\tint n, aStride, bStride;\n\t\tn = framesToFill;\n\t\tif (_in(th, n, aStride, a) || _pos(th, n, bStride, b)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (bStride == 0) {\n\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * Lpan;\n\t\t\t\t*Rout = z * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*b, -1., 1.);\n\t\t\t\tZ z = *a;\n\t\t\t\t*Lout = z * fast_pan(-x);\n\t\t\t\t*Rout = z * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_in.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Pan2::createOutputs(Thread& th)\n{\n\tmLeft = new Pan2Out(th, finite, this);\n\tmRight = new Pan2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void pan2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"pan2 : pos\");\n\tV in = th.popZIn(\"pan2 : in\");\n\n\tP pan = new Pan2(th, in, pos);\n\n\tP s = pan->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Balance2Out;\n\nstruct Balance2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tBalance2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Balance2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Balance2Out : public Gen\n{\n\tP mBalance2;\n\t\n\tBalance2Out(Thread& th, bool inFinite, P const& inBalance2) : Gen(th, itemTypeZ, inFinite), mBalance2(inBalance2)\n\t{\n\t}\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmBalance2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Balance2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmBalance2->pull(th);\n\t}\n\t\n};\n\nvoid Balance2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\tZ Lpan = fast_pan(-x);\n\t\t\tZ Rpan = fast_pan(x);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t*Lout = *a * Lpan;\n\t\t\t\t*Rout = *b * Rpan;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t*Lout = *a * fast_pan(-x);\n\t\t\t\t*Rout = *b * fast_pan(x);\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Balance2::createOutputs(Thread& th)\n{\n\tmLeft = new Balance2Out(th, finite, this);\n\tmRight = new Balance2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void bal2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"bal2 : pos\");\n\tV R = th.popZIn(\"bal2 : right\");\n\tV L = th.popZIn(\"bal2 : left\");\n\n\tP bal = new Balance2(th, L, R, pos);\n\n\tP s = bal->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Rot2Out;\n\nstruct Rot2 : public Object\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\n\tP mLeft;\n\tP mRight;\n\t\t\n\tRot2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: _L(inL), _R(inR), _pos(inPos)\n\t{\n\t\tfinite = mostFinite(inL, inR, inPos);\n\t}\n\n\tP createOutputs(Thread& th);\n\n\tvirtual const char* TypeName() const override { return \"Rot2\"; }\n\n\tvirtual void pull(Thread& th);\n};\n\nstruct Rot2Out : public Gen\n{\n\tP mRot2;\n\t\n\tRot2Out(Thread& th, bool inFinite, P const& inRot2) : Gen(th, itemTypeZ, inFinite), mRot2(inRot2)\n\t{\n\t}\n\n\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmRot2 = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rot2Out\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tmRot2->pull(th);\n\t}\n\t\n};\n\nvoid Rot2::pull(Thread& th)\n{\n\tint framesToFill = mLeft->mBlockSize;\n\t\n\tZ Sink = 0.;\n\tZ* Lout;\n\tZ* Rout;\n\tint Loutstride = 1;\n\tint Routstride = 1;\n\n\tif (mLeft->mOut) {\n\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tLout = &Sink;\n\t\tLoutstride = 0;\n\t}\n\n\tif (mRight->mOut) {\n\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t} else {\n\t\tRout = &Sink;\n\t\tRoutstride = 0;\n\t}\n\t\n\twhile (framesToFill) {\n\t\tZ *a, *b, *c;\n\t\tint n, aStride, bStride, cStride;\n\t\tn = framesToFill;\n\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\tmLeft->setDone();\n\t\t\tmRight->setDone();\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (cStride == 0) {\n\t\t\tif (_L.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = - R * sn;\n\t\t\t\t\t*Rout = R * cs;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else if (_R.isZero()) {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\t*Lout = L * cs;\n\t\t\t\t\t*Rout = L * sn;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ L = *a;\n\t\t\t\t\tZ R = *b;\n\t\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ L = *a;\n\t\t\t\tZ R = *b;\n\t\t\t\tZ pos = .5 * *c;\n\t\t\t\tZ sn = -fast_sin1(pos);\n\t\t\t\tZ cs = fast_cos1(pos);\n\t\t\t\t*Lout = L * cs - R * sn;\n\t\t\t\t*Rout = L * sn + R * cs;\n\t\t\t\ta += aStride;\n\t\t\t\tb += bStride;\n\t\t\t\tc += cStride;\n\t\t\t\tLout += Loutstride;\n\t\t\t\tRout += Routstride;\n\t\t\t}\n\t\t}\n\t\tframesToFill -= n;\n\t\t_L.advance(n);\n\t\t_R.advance(n);\n\t\t_pos.advance(n);\n\t}\n\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\tif (mRight->mOut) mRight->produce(framesToFill);\n}\n\n\nP Rot2::createOutputs(Thread& th)\n{\n\tmLeft = new Rot2Out(th, finite, this);\n\tmRight = new Rot2Out(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void rot2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"rot2 : pos\");\n\tV R = th.popZIn(\"rot2 : right\");\n\tV L = th.popZIn(\"rot2 : left\");\n\n\tP rot2 = new Rot2(th, L, R, pos);\n\n\tP s = rot2->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct Fade2 : public Gen\n{\n\tZIn _L;\n\tZIn _R;\n\tZIn _pos;\n\t\t\n\tFade2(Thread& th, Arg inL, Arg inR, Arg inPos)\n\t\t: Gen(th, itemTypeZ, mostFinite(inL, inR, inPos)), _L(inL), _R(inR), _pos(inPos)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fade2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *a, *b, *c;\n\t\t\tint n, aStride, bStride, cStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_L(th, n, aStride, a) || _R(th, n, bStride, b) || _pos(th, n, cStride, c)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (cStride == 0) {\n\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\tZ Lpan = fast_pan(-x);\n\t\t\t\tZ Rpan = fast_pan(x);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a * Lpan + *b * Rpan;\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x = std::clamp(*c, -1., 1.);\n\t\t\t\t\tout[i] = *a * fast_pan(-x) + *b * fast_pan(x);\n\t\t\t\t\ta += aStride;\n\t\t\t\t\tb += bStride;\n\t\t\t\t\tc += cStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_L.advance(n);\n\t\t\t_R.advance(n);\n\t\t\t_pos.advance(n);\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void fade2_(Thread& th, Prim* prim)\n{\n\tV pos = th.popZIn(\"fade2 : pos\");\n\tV R = th.popZIn(\"fade2 : right\");\n\tV L = th.popZIn(\"fade2 : left\");\n\n\tth.push(new List(new Fade2(th, L, R, pos)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Trig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Trig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur > 0. && prev <= 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct NegTrig : public Gen\n{\n\tZIn _in;\n\tZ _prev;\n\t\n\tNegTrig(Thread& th, Arg in)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in), _prev(-1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NegTrig\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ prev = _prev;\n\t\twhile (framesToFill) {\n\t\t\tZ *in;\n\t\t\tint n, inStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\tZ cur = *in;\n\t\t\t\tout[i] = cur >= 0. && prev < 0. ? 1. : 0.;\n\t\t\t\tprev = cur;\n\t\t\t\tin += inStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t}\n\t\t\n\t\t_prev = prev;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void tr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"tr : in\");\n\n\tth.push(new List(new Trig(th, in)));\n}\n\nstatic void ntr_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"ntr : in\");\n\n\tth.push(new List(new NegTrig(th, in)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Gate : public TwoInputUGen\n{\n\tZ phase;\n\tZ freq;\n\tGate(Thread& th, Arg trig, Arg hold)\n\t\t: TwoInputUGen(th, trig, hold), phase(INFINITY), freq(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gate\"; }\n\t\n\tvoid calc(int n, Z* out, Z* trig, Z* hold, int trigStride, int holdStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ t = *trig;\n\t\t\tif (t > 0.) {\n\t\t\t\tphase = 0.;\n\t\t\t}\n\t\t\tout[i] = phase < *hold ? 1. : 0.;\n\t\t\tphase += freq;\n\t\t\ttrig += trigStride;\n\t\t\thold += holdStride;\n\t\t}\n\t}\n};\n\nstatic void gate_(Thread& th, Prim* prim)\n{\n\tV hold = th.popZIn(\"gate : hold\");\n\tV in = th.popZIn(\"gate : in\");\n\n\tth.push(new List(new Gate(th, in, hold)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct SampleAndHold : public Gen\n{\n\tZIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSampleAndHold(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"SampleAndHold\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *tr;\n\t\t\tint n, inStride, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) val = *in;\n\t\t\t\tout[i] = val;\n\t\t\t\tin += inStride;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void sah_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"sah : trigger\");\n\tV in = th.popZIn(\"sah : in\");\n\n\tth.push(new List(new SampleAndHold(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Sequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\tZ _val;\n\t\n\tSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr), _val(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Sequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ val = _val;\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tval = z;\n\t\t\t\t}\n\t\t\t\tout[i] = val;\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\t_val = val;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void seq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"seq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new Sequencer(th, in, trigger)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct ImpulseSequencer : public Gen\n{\n\tBothIn _in;\n\tZIn _tr;\n\t\n\tImpulseSequencer(Thread& th, Arg in, Arg tr)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, tr)), _in(in), _tr(tr)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ImpulseSequencer\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr;\n\t\t\tint n, trStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\tZ z;\n\t\t\t\t\tif (_in.onez(th, z)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill - i);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = z;\n\t\t\t\t} else {\n\t\t\t\t\tout[i] = 0.;\n\t\t\t\t}\n\t\t\t\ttr += trStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void iseq_(Thread& th, Prim* prim)\n{\n\tV trigger = th.popZIn(\"iseq : trigger\");\n\tV in = th.pop();\n\n\tth.push(new List(new ImpulseSequencer(th, in, trigger)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct PulseDivider : public Gen\n{\n\tZIn _tr;\n\tZIn _div;\n\tZ _count;\n\t\n\tPulseDivider(Thread& th, Arg tr, Arg div, Z start)\n\t\t: Gen(th, itemTypeZ, mostFinite(tr, div)), _tr(tr), _div(div), _count(start - 1.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PulseDivider\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tZ *tr, *div;\n\t\t\tint n, trStride, divStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_tr(th, n, trStride, tr) || _div(th, n, divStride, div)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tif (*tr > 0.) {\n\t\t\t\t\t_count += 1.;\n\t\t\t\t\tZ idiv = floor(*div + .5);\n\t\t\t\t\tif (_count >= idiv) {\n\t\t\t\t\t\t_count -= idiv;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = _count == 0. ? *tr : 0.;\n\t\t\t\t} else out[i] = 0.;\n\t\t\t\ttr += trStride;\n\t\t\t\tdiv += divStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_tr.advance(n);\n\t\t\t_div.advance(n);\n\t\t}\n\t\t\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void pdiv_(Thread& th, Prim* prim)\n{\n\tZ start = th.popFloat(\"pdiv : istart\");\n\tV div = th.popZIn(\"pdiv : n\");\n\tV in = th.popZIn(\"pdiv : in\");\n\n\tth.push(new List(new PulseDivider(th, in, div, start)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Clip : public ThreeInputUGen\n{\n\t\n\tClip(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Clip\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = std::clamp(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Wrap : public ThreeInputUGen\n{\n\t\n\tWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Wrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_wrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct Fold : public ThreeInputUGen\n{\n\t\n\tFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Fold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_fold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\n\nstruct IWrap : public ThreeInputUGen\n{\n\t\n\tIWrap(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IWrap\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_iwrap(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstruct IFold : public ThreeInputUGen\n{\n\t\n\tIFold(Thread& th, Arg a, Arg b, Arg c) : ThreeInputUGen(th, a, b, c)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IFold\"; }\n\t\n\tvoid calc(int n, Z* out, Z* a, Z* b, Z* c, int aStride, int bStride, int cStride) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = sc_ifold(*a, *b, *c);\n\t\t\ta += aStride;\n\t\t\tb += bStride;\n\t\t\tc += cStride;\n\t\t}\n\t}\n};\n\nstatic void clip_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"clip : hi\");\n\tV lo = th.popZIn(\"clip : lo\");\n\tV in = th.popZIn(\"clip : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(std::clamp(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Clip(th, in, lo, hi)));\n\t}\n}\n\nstatic void wrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"wrap : hi\");\n\tV lo = th.popZIn(\"wrap : lo\");\n\tV in = th.popZIn(\"wrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_wrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Wrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void fold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"fold : hi\");\n\tV lo = th.popZIn(\"fold : lo\");\n\tV in = th.popZIn(\"fold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_fold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new Fold(th, in, lo, hi)));\n\t}\n}\n\nstatic void iwrap_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"iwrap : hi\");\n\tV lo = th.popZIn(\"iwrap : lo\");\n\tV in = th.popZIn(\"iwrap : in\");\n\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_iwrap(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IWrap(th, in, lo, hi)));\n\t}\n}\n\nstatic void ifold_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"ifold : hi\");\n\tV lo = th.popZIn(\"ifold : lo\");\n\tV in = th.popZIn(\"ifold : in\");\n\t\n\tif (in.isReal() && lo.isReal() && hi.isReal()) {\n\t\tth.push(sc_ifold(in.f, lo.f, hi.f));\n\t} else {\n\t\tth.push(new List(new IFold(th, in, lo, hi)));\n\t}\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#include \n\nstruct MouseUGenGlobalState {\n\tfloat mouseX, mouseY;\n\tbool mouseButton;\n} gMouseUGenGlobals;\n\nstatic void* gstate_update_func(void* arg)\n{\n\tMouseUGenGlobalState* gstate = &gMouseUGenGlobals;\n\n\tCGDirectDisplayID display = kCGDirectMainDisplay; // to grab the main display ID\n\tCGRect bounds = CGDisplayBounds(display);\n\tfloat rscreenWidth = 1. / bounds.size.width;\n\tfloat rscreenHeight = 1. / bounds.size.height;\n\tfor (;;) {\n\t\tHIPoint point;\n\t\tHICoordinateSpace space = 2;\n\t\tHIGetMousePosition(space, nullptr, &point);\n\n\t\tgstate->mouseX = point.x * rscreenWidth; //(float)p.h * rscreenWidth;\n\t\tgstate->mouseY = 1. - point.y * rscreenHeight; //(float)p.v * rscreenHeight;\n\t\tgstate->mouseButton = GetCurrentButtonState();\n\t\tusleep(17000);\n\t}\n\n\treturn 0;\n}\n\nZ gMouseLagTime = .1;\nZ gMouseLagMul = log001 / gMouseLagTime;\n\nstruct MouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseX * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct MouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo + gMouseUGenGlobals.mouseY * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseX : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseX(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseX\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseX);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct ExpMouseY : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tbool _once;\n\t\n\tExpMouseY(Thread& th, Arg lo, Arg hi) : TwoInputUGen(th, lo, hi), _b1(1. + gMouseLagMul * th.rate.invSampleRate), _once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MouseY\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tif (_once) {\n\t\t\t_once = false;\n\t\t\t_y1 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t}\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = *lo * pow(*hi / *lo, gMouseUGenGlobals.mouseY);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void mousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousex : hi\");\n\tV lo = th.popZIn(\"mousex : lo\");\n\t\n\tth.push(new List(new MouseX(th, lo, hi)));\n}\n\nstatic void mousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"mousey : hi\");\n\tV lo = th.popZIn(\"mousey : lo\");\n\t\n\tth.push(new List(new MouseY(th, lo, hi)));\n}\n\nstatic void xmousex_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousex : hi\");\n\tV lo = th.popZIn(\"xmousex : lo\");\n\t\n\tth.push(new List(new ExpMouseX(th, lo, hi)));\n}\n\nstatic void xmousey_(Thread& th, Prim* prim)\n{\n\tV hi = th.popZIn(\"xmousey : hi\");\n\tV lo = th.popZIn(\"xmousey : lo\");\n\t\n\tth.push(new List(new ExpMouseY(th, lo, hi)));\n}\n\nstatic void mousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousex1 : hi\");\n\tZ lo = th.popFloat(\"mousex1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseX * (hi - lo);\n\tth.push(z);\n}\n\nstatic void mousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mousey1 : hi\");\n\tZ lo = th.popFloat(\"mousey1 : lo\");\n\t\n\tZ z = lo + gMouseUGenGlobals.mouseY * (hi - lo);\n\tth.push(z);\n}\n\nstatic void xmousex1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousex1 : hi\");\n\tZ lo = th.popFloat(\"xmousex1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseX);\n\tth.push(z);\n}\n\nstatic void xmousey1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmousey1 : hi\");\n\tZ lo = th.popFloat(\"xmousey1 : lo\");\n\t\n\tZ z = lo * pow(hi / lo, gMouseUGenGlobals.mouseY);\n\tth.push(z);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps();\nvoid AddOscilUGenOps();\nvoid AddDelayUGenOps();\n\nvoid AddUGenOps()\n{\n\ts_tempo = getsym(\"tempo\");\n\ts_dt = getsym(\"dt\");\n\ts_out = getsym(\"out\");\n\n\tpthread_t mouseListenThread;\n\tpthread_create (&mouseListenThread, nullptr, gstate_update_func, (void*)0);\n\n\tvm.addBifHelp(\"\\n*** unit generators ***\");\n\tvm.defmcx(\"*+\", 3, madd_, \"(a b c --> out) multiply add. a b * c +\");\n\n AddOscilUGenOps();\n AddFilterUGenOps();\n AddDelayUGenOps();\n\t\n\tvm.addBifHelp(\"\\n*** plugs ***\");\n\n\tvm.addBifHelp(\"\\n*** control rate subgraphs ***\");\n\tgK2A = automap(\"zk\", 2, new Prim(k2a_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tgK2AC = automap(\"zk\", 2, new Prim(k2ac_, V(0.), 2, 1, \"\", \"\"), \"\", \"\");\n\tDEF(kr, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then linearly upsamples all returned signals by n.\")\n\tDEF(krc, 2, \"(fun n --> out) evaluates fun with the current sample rate divided by n, then cubically upsamples all returned signals by n.\")\n\t\n\tvm.addBifHelp(\"\\n*** control function unit generators ***\");\n\tDEFAM(imps, aaz, \"(values durs rate --> out) single sample impulses.\");\n\tDEFAM(steps, aaz, \"(values durs rate --> out) steps\");\n\tDEFAM(gates, aaaz, \"(values durs holds rate --> out) gates\");\n\tDEFAM(lines, aaz, \"(values durs rate --> out) lines\");\n\tDEFAM(xlines, aaz, \"(values durs rate --> out) exponential lines\");\n\tDEFAM(cubics, az, \"(values rate --> out) cubic splines\");\n\tDEFAM(curves, aaaz, \"(values curvatures durs rate --> out) curves.\");\n\t\n\n\tvm.addBifHelp(\"\\n*** random control unit generators ***\");\n\tDEFMCX(lfnoise0, 1, \"(freq --> out) step noise source.\");\n\tDEFMCX(lfnoise1, 1, \"(freq --> out) ramp noise source.\");\n\tDEFMCX(lfnoise3, 1, \"(freq --> out) cubic spline noise source.\");\n\t\n\tvm.addBifHelp(\"\\n*** tempo unit generators ***\");\n\tDEFAM(tempo, az, \"([bps dur bps dur ...] rate --> out) returns a signal of tempo vs time given a list of interleaved tempos (in beats per second) and durations (in beats).\");\n\tDEFAM(beats, z, \"(tempo --> beats) integrates a tempo signal to produce a signal of the time in beats.\");\n\n\tvm.addBifHelp(\"\\n*** envelope unit generators ***\");\n\tvm.addBifHelp(\"\\nFor asr, adsr, dadsr, dahdsr envelopes, the arguments are as follows:\");\n\tvm.addBifHelp(\" delay - a time in seconds. a period of time before the attack segment where the amplitude is zero.\");\n\tvm.addBifHelp(\" attack - a time in seconds to rise from zero to the level specified by the amp argument.\");\n\tvm.addBifHelp(\" hold - a time in seconds to hold at the level specified by the amp argument.\");\n\tvm.addBifHelp(\" delay - a time in seconds to fall from amp to the sustain level.\");\n\tvm.addBifHelp(\" sustain - a level from zero to one which is multiplied by the amp argument. The envelope holds at this level until released.\");\n\tvm.addBifHelp(\" release - a time in seconds to fall from the current level to zero. A release begins whenever the beat time (the integral of tempo), exceeds dur.\");\n\tvm.addBifHelp(\" amp - an amplitude that scales the peak and sustain levels of the envelope.\");\n\tvm.addBifHelp(\" dur - a time in beats to release the envelope.\");\n\tvm.addBifHelp(\" tempo - a signal giving the tempo in beats per second versus time.\");\n\tvm.addBifHelp(\"\");\n\n\tDEFAM(adsr, akkz, \"([attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dadsr, akkz, \"([delay attack decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tDEFAM(dahdsr, akkz, \"([delay attack hold decay sustain release] amp dur tempo --> envelope) an envelope generator.\")\n\tvm.addBifHelp(\"\");\n \n\tDEFAM(endfade, zkkkk, \"(in startupTime holdTime fadeTime threshold --> out) after startupTime has elapsed, fade out the sound when peak amplitude has dropped below threshold for more than the holdTime.\");\n\tDEFAM(fadeout, zkk, \"(in sustainTime fadeTime --> out) fadeout after sustain.\");\n\tDEFAM(fadein, zk, \"(in fadeTime --> out) fade in.\");\n\tDEFAM(parenv, k, \"(dur --> out) parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(quadenv, k, \"(dur --> out) 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(octenv, k, \"(dur --> out) 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(trienv, k, \"(dur --> out) triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(tri2env, k, \"(dur --> out) triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(trapezenv, k, \"(dur --> out) trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(trapez2env, k, \"(dur --> out) trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(cosenv, k, \"(dur --> out) cosine envelope.\")\n\tDEFAM(hanenv, k, \"(dur --> out) hanning envelope.\")\n\tDEFAM(han2env, k, \"(dur --> out) hanning squared envelope.\")\n\tDEFAM(gaussenv, kk, \"(dur width --> out) gaussian envelope. exp(x^2/(-2*width^2)) for x from -1 to 1\")\n\n\tDEFAM(tsig, zza, \"(trig signal amp --> out) trigger a signal.\")\n\n\tDEFAM(tparenv, zaa, \"(trig dur amp --> out) triggered parabolic envelope. 1-x^2 for x from -1 to 1\")\n\tDEFAM(tquadenv, zaa, \"(trig dur amp --> out) triggered 4th order envelope. 1-x^4 for x from -1 to 1\")\n\tDEFAM(toctenv, zaa, \"(trig dur amp --> out) triggered 8th order envelope. 1-x^8 for x from -1 to 1\")\n\tDEFAM(ttrienv, zaa, \"(trig dur amp --> out) triggered triangular envelope. 1-|x| for x from -1 to 1\")\n\tDEFAM(ttri2env, zaa, \"(trig dur amp --> out) triggered triangle squared envelope. (1-|x|)^2 for x from -1 to 1\")\n\tDEFAM(ttrapezenv, zaa, \"(trig dur amp --> out) triggered trapezoidal envelope. (2 - |x-.5| - |x+.5|) for x from -1 to 1\")\n\tDEFAM(ttrapez2env, zaa, \"(trig dur amp --> out) triggered trapezoid squared envelope. (2 - |x-.5| - |x+.5|)^2 for x from -1 to 1\")\n\n\tDEFAM(tcosenv, zaa, \"(trig dur amp --> out) triggered cosine envelope.\")\n\tDEFAM(thanenv, zaa, \"(trig dur amp --> out) triggered hanning envelope.\")\n\tDEFAM(than2env, zaa, \"(trig dur amp --> out) triggered hanning squared envelope.\")\n\t\n\tvm.addBifHelp(\"\\n*** spawn unit generators ***\");\n\tDEF(ola, 4, \"(sounds hops rate numChannels --> out) overlap add. This is the basic operator for polyphony. \")\n\n\tvm.addBifHelp(\"\\n*** pause unit generator ***\");\n\tDEFMCX(pause, 2, \"(in amp --> out) pauses the input when amp is <= 0, otherwise in is multiplied by amp.\")\n\n\tvm.addBifHelp(\"\\n*** panner unit generators ***\");\n\tDEFAM(itd, zzk, \"(in pan maxdelay --> out) interaural time delay.\");\n\tDEFMCX(pan2, 2, \"(in pos --> [left right]) stereo pan. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(rot2, 3, \"(left right pos --> [left right]) stereo rotation. pos 0 is no rotation, +/-1 is 180 degrees, -.5 is -90 degrees, +.5 is +90 degrees.\")\n\tDEFMCX(bal2, 3, \"(left right pos --> [left right]) stereo balance control. pos 0 is center. pos -1 is full left, pos +1 is full right.\")\n\tDEFMCX(fade2, 3, \"(left right pos --> out) cross fade between two inputs. pos 0 is equal mix. pos -1 is all left, pos +1 is all right.\")\n\n\t\n\tvm.addBifHelp(\"\\n*** trigger unit generators ***\");\n\tDEFMCX(tr, 1, \"(in --> out) transitions from nonpositive to positive become single sample impulses.\")\n\tDEFMCX(ntr, 1, \"(in --> out) transitions from negative to nonnegative become single sample impulses.\")\n\tDEFMCX(gate, 1, \"(in hold --> out) outputs 1 for hold seconds after each trigger, else outputs zero.\")\n\tDEFMCX(sah, 2, \"(in trigger --> out) sample and hold\")\n\tDEFAM(seq, az, \"(in trigger --> out) pulls one value from the input for each trigger. output sustains at that level until the next trigger.\")\n\tDEFAM(iseq, az, \"(in trigger --> out) pulls one value from the input for each trigger. outputs that value for one sample. outputs zero when there is no trigger.\")\n\tDEFMCX(pdiv, 3, \"(in n istart --> out) pulse divider. outputs one impulse from the output for each n impulses in the input. istart is an offset. istart = 0 outputs a pulse on the first input pulse.\")\n\t\n\t\n\tvm.addBifHelp(\"\\n*** bounds unit generators ***\");\n\tDEFMCX(clip, 3, \"(in lo hi --> out) constrain the input to the bounds by clipping.\")\n\tDEFMCX(wrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping.\")\n\tDEFMCX(fold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges.\")\n\tDEFMCX(iwrap, 3, \"(in lo hi --> out) constrain the input to the bounds by wrapping. all inputs treated as integers.\")\n\tDEFMCX(ifold, 3, \"(in lo hi --> out) constrain the input to the bounds by folding at the edges. all inputs treated as integers.\")\n\n\tvm.addBifHelp(\"\\n*** mouse control unit generators ***\");\n\tDEFMCX(mousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex, 2, \"(lo hi --> out) returns a signal of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey, 2, \"(lo hi --> out) returns a signal of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\n\n\tDEFMCX(mousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(mousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the linear range lo to hi.\");\n\tDEFMCX(xmousex1, 2, \"(lo hi --> out) returns the current value of the X coordinate of the mouse mapped to the exponential range lo to hi.\");\n\tDEFMCX(xmousey1, 2, \"(lo hi --> out) returns the current value of the Y coordinate of the mouse mapped to the exponential range lo to hi.\");\t\n}\n"], ["/sapf/src/DelayUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"DelayUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass DelayN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\n\tDelayN(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n int32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n out[i] = buf[(bufPos-offset) & bufMask];\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayn_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayn : maxdelay\");\n\tV delay = th.popZIn(\"delayn : delay\");\n\tV in = th.popZIn(\"delayn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayN(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayL(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n out[i] = a + frac * (b - a);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayl_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayl : maxdelay\");\n\tV delay = th.popZIn(\"delayl : delay\");\n\tV in = th.popZIn(\"delayl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayL(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass DelayC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tDelayC(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~DelayC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"DelayC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (delayStride == 0) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n ++bufPos;\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n out[i] = lagrangeInterpolate(frac, a, b, c, d);\n buf[bufPos & bufMask] = *in;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void delayc_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"delayc : maxdelay\");\n\tV delay = th.popZIn(\"delayc : delay\");\n\tV in = th.popZIn(\"delayc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"delayc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new DelayC(th, in, delay, maxdelay)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass Flange : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlange(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flange() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flange\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) - zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flangep : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tint32_t half;\n Z fhalf;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tFlangep(Thread& th, Arg in, Arg delay, Z maxdelay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tfhalf = ceil(sr * maxdelay + .5);\n\t\thalf = (int32_t)fhalf;\n\t\tbufSize = NEXTPOWEROFTWO(2 * half);\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~Flangep() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"Flangep\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride;\n\t\t\tZ *in, *delay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\tZ fpos = std::max(2., zdelay * sr + fhalf);\n\t\t\t\t\tZ ipos = floor(fpos);\n\t\t\t\t\tZ frac = fpos - ipos;\n\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\tZ zin = buf[(bufPos-half) & bufMask];\n\t\t\t\t\tout[i] = lagrangeInterpolate(frac, a, b, c, d) + zin;\n\t\t\t\t\tbuf[bufPos & bufMask] = *in;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t++bufPos;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void flange_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flange : maxdelay\");\n\tV delay = th.popZIn(\"flange : delay\");\n\tV in = th.popZIn(\"flange : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flange : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flange(th, in, delay, maxdelay)));\n}\n\nstatic void flangep_(Thread& th, Prim* prim)\n{\n\tZ maxdelay = th.popFloat(\"flangep : maxdelay\");\n\tV delay = th.popZIn(\"flangep : delay\");\n\tV in = th.popZIn(\"flangep : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"flangep : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new Flangep(th, in, delay, maxdelay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass CombN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay + 1.));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(std::abs(zdelay) * sr + .5));\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(std::abs(zdelay) * sr + .5);\n\t\t\t\t\t\tZ z = fb * buf[(bufPos-offset) & bufMask];\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combn : decay\");\n\tZ maxdelay = th.popFloat(\"combn : maxdelay\");\n\tV delay = th.popZIn(\"combn : delay\");\n\tV in = th.popZIn(\"combn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z z = fb * (a + frac * (b - a));\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[offset & bufMask];\n Z b = buf[(offset-1) & bufMask];\n\t\t\t\t\t\tZ z = fb * (a + frac * (b - a));\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combl : decay\");\n\tZ maxdelay = th.popFloat(\"combl : maxdelay\");\n\tV delay = th.popZIn(\"combl : delay\");\n\tV in = th.popZIn(\"combl : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass CombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~CombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"CombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n out[i] = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n\t\t\t\t\t\tZ z = fb * lagrangeInterpolate(frac, a, b, c, d);\n\t\t\t\t\t\tout[i] = z;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = *in + z;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void combc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"combc : decay\");\n\tZ maxdelay = th.popFloat(\"combc : maxdelay\");\n\tV delay = th.popZIn(\"combc : delay\");\n\tV in = th.popZIn(\"combc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"combc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new CombC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass LPCombC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZIn lpfreq_;\n\tZ maxdelay_;\n\tZ y1_;\n\tZ freqmul_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tLPCombC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay, Arg lpfreq) : Gen(th, itemTypeZ, false),\n\t\t\tin_(in), delay_(delay), decay_(decay), lpfreq_(lpfreq), maxdelay_(maxdelay), y1_(0.), freqmul_(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~LPCombC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"LPCombC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tZ y1 = y1_;\n\t\tZ freqmul = freqmul_;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride, lpfreqStride;\n\t\t\tZ *in, *delay, *decay, *lpfreq;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay) || lpfreq_(th, n, lpfreqStride, lpfreq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n if (lpfreqStride == 0) {\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n } else {\n if (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n int32_t offset2 = bufPos-offset;\n Z a = buf[(offset2+1) & bufMask];\n Z b = buf[(offset2 ) & bufMask];\n Z c = buf[(offset2-1) & bufMask];\n Z d = buf[(offset2-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n } else {\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z z = fb * lagrangeInterpolate(frac, a, b, c, d);\n Z b1 = t_firstOrderCoeff(*lpfreq * freqmul);\n z = z + b1 * (y1 - z);\n out[i] = y1 = z;\n buf[bufPos & bufMask] = *in + z;\n in += inStride;\n delay += delayStride;\n lpfreq += lpfreqStride;\n ++bufPos;\n }\n }\n }\n\t\t\t\ty1_ = y1;\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tlpfreq_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void lpcombc_(Thread& th, Prim* prim)\n{\n\tV lpfreq = th.popZIn(\"lpcombc : lpfreq\");\n\tV decay = th.popZIn(\"lpcombc : decay\");\n\tZ maxdelay = th.popFloat(\"lpcombc : maxdelay\");\n\tV delay = th.popZIn(\"lpcombc : delay\");\n\tV in = th.popZIn(\"lpcombc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"lpcombc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new LPCombC(th, in, delay, maxdelay, decay, lpfreq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nclass AllpassN : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassN(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassN() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassN\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n\t\t\t\t\tdouble rdecay = 1. / *decay;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay * rdecay);\n\t\t\t\t\t\tint32_t offset = std::max(1,(int32_t)floor(zdelay * sr + .5));\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n\t\t\t\t\t\tint32_t offset = (int32_t)floor(zdelay * sr + .5);\n Z drd = buf[(bufPos-offset) & bufMask];\n Z dwr = drd * fb + *in;\n\t\t\t\t\t\tbuf[bufPos & bufMask] = dwr;\n\t\t\t\t\t\tout[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tdecay += decayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasn_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasn : decay\");\n\tZ maxdelay = th.popFloat(\"alpasn : maxdelay\");\n\tV delay = th.popZIn(\"alpasn : delay\");\n\tV in = th.popZIn(\"alpasn : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasn : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassN(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassL : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassL(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassL() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassL\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n Z a = buf[(offset2) & bufMask];\n Z b = buf[(offset2-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(1., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset) & bufMask];\n Z b = buf[(offset-1) & bufMask];\n Z drd = a + frac * (b - a);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasl_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasl : decay\");\n\tZ maxdelay = th.popFloat(\"alpasl : maxdelay\");\n\tV delay = th.popZIn(\"alpasl : delay\");\n\tV in = th.popZIn(\"alpasl : in\");\n \t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasl : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassL(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass AllpassC : public Gen\n{\n\tZIn in_;\n\tZIn delay_;\n\tZIn decay_;\n\tZ maxdelay_;\n\tint32_t bufSize;\n\tint32_t bufMask;\n\tint32_t bufPos;\n\tZ* buf;\n\tZ sr;\npublic:\n\t\n\tAllpassC(Thread& th, Arg in, Arg delay, Z maxdelay, Arg decay) : Gen(th, itemTypeZ, false), in_(in), delay_(delay), decay_(decay), maxdelay_(maxdelay)\n\t{\n\t\tsr = th.rate.sampleRate;\n\t\tbufSize = NEXTPOWEROFTWO((int32_t)ceil(sr * maxdelay));\n\t\tbufMask = bufSize - 1;\n\t\tbufPos = 0;\n\t\tbuf = (Z*)calloc(bufSize, sizeof(Z));\n\t}\n\t\n\t~AllpassC() { free(buf); }\n\t\n\tvirtual const char* TypeName() const override { return \"AllpassC\"; }\n \n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, delayStride, decayStride;\n\t\t\tZ *in, *delay, *decay;\n\t\t\tif (in_(th, n, inStride, in) || delay_(th, n, delayStride, delay) || decay_(th, n, decayStride, decay)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (decayStride == 0) {\n if (delayStride == 0) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n int32_t offset = (int32_t)ipos;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tint32_t offset2 = bufPos-offset;\n\t\t\t\t\t\t\tZ a = buf[(offset2+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset2 ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset2-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset2-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n ++bufPos;\n }\n } else {\n double rdecay = 1. / *decay;\n for (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n Z fb = calcDecay(zdelay * rdecay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n\t\t\t\t\t\t\tZ a = buf[(offset+1) & bufMask];\n\t\t\t\t\t\t\tZ b = buf[(offset ) & bufMask];\n\t\t\t\t\t\t\tZ c = buf[(offset-1) & bufMask];\n\t\t\t\t\t\t\tZ d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n in += inStride;\n delay += delayStride;\n ++bufPos;\n }\n }\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ zdelay = *delay;\n\t\t\t\t\t\tzdelay = std::clamp(zdelay, -maxdelay_, maxdelay_);\n\t\t\t\t\t\tZ fb = calcDecay(zdelay / *decay);\n Z fpos = std::max(2., zdelay * sr);\n Z ipos = floor(fpos);\n Z frac = fpos - ipos;\n\t\t\t\t\t\tint32_t offset = bufPos-(int32_t)ipos;\n Z a = buf[(offset+1) & bufMask];\n Z b = buf[(offset ) & bufMask];\n Z c = buf[(offset-1) & bufMask];\n Z d = buf[(offset-2) & bufMask];\n Z drd = lagrangeInterpolate(frac, a, b, c, d);\n Z dwr = drd * fb + *in;\n buf[bufPos & bufMask] = dwr;\n out[i] = drd - fb * dwr;\n\t\t\t\t\t\tin += inStride;\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\t++bufPos;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tdelay_.advance(n);\n\t\t\t\tdecay_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void alpasc_(Thread& th, Prim* prim)\n{\n\tV decay = th.popZIn(\"alpasc : decay\");\n\tZ maxdelay = th.popFloat(\"alpasc : maxdelay\");\n\tV delay = th.popZIn(\"alpasc : delay\");\n\tV in = th.popZIn(\"alpasc : in\");\n\t\n\tif (maxdelay == 0.) {\n\t\tif (delay.isReal()) {\n\t\t\tmaxdelay = delay.f;\n\t\t} else {\n\t\t\tpost(\"alpasc : maxdelay is zero and delay is a signal\\n\");\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n \n\tth.push(new List(new AllpassC(th, in, delay, maxdelay, decay)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\nclass FDN;\n\nclass FDN_OutputChannel : public Gen\n{\n\tfriend class FDN;\n\tP mFDN;\n\t\npublic:\t\n\tFDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN);\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr;\n\t\tmFDN = nullptr;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FDN_OutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override;\n};\n\nclass FDN : public Object\n{\n\tZIn in_;\n\tZIn wet_;\n\tZ decayLo_;\n\tZ decayMid_;\n\tZ decayHi_;\n\tZ mindelay_;\n\tZ maxdelay_;\n\tZ sr_;\n\t\n\tZ a1Lo, a1Hi;\n\tZ scaleLoLPF, scaleLoHPF, scaleHiLPF, scaleHiHPF;\n\tFDN_OutputChannel* mLeft;\n\tFDN_OutputChannel* mRight;\n\t\n\tstatic const int kNumDelays = 16;\n\t\n\tstruct FDNDelay\n\t{\n\t\tZ* buf;\n\t\tint size, mask, rpos, wpos, offset;\n\t\tZ delay, gain;\n\t\tZ fbLo, fbMid, fbHi;\n\t\tZ x1A, x1B, x1C, x1D;\n\t\tZ y1A, y1B, y1C, y1D;\n\t\t\n\t\tFDNDelay()\n\t\t{\n\t\t}\n\t\t~FDNDelay() { free(buf); }\n\t\t\n\t\tvoid set(Thread& th, const FDN& fdn, Z inDelay, int& ioSampleDelay)\n\t\t{\n\t\t\tint sampleDelay = (int)(th.rate.sampleRate * inDelay);\n\t\t\tif (sampleDelay <= ioSampleDelay) sampleDelay = ioSampleDelay + 2;\n\t\t\tsampleDelay = (int)nextPrime(sampleDelay);\n\t\t\tioSampleDelay = sampleDelay;\n\t\t\tZ actualDelay = (Z)sampleDelay * th.rate.invSampleRate;\n\t\t\tsize = NEXTPOWEROFTWO(sampleDelay);\n\t\t\tmask = size - 1;\n\t\t\tprintf(\"delay %6d %6d %6d %f\\n\", sampleDelay, size, mask, actualDelay);\n\t\t\trpos = 0;\n\t\t\twpos = sampleDelay;\n\t\t\tbuf = (Z*)calloc(size, sizeof(Z));\n\t\t\tconst Z n1 = 1. / sqrt(kNumDelays);\n\t\t\t//const Z n1 = 1. / kNumDelays;\n\t\t\tfbLo = n1 * calcDecay(actualDelay / fdn.decayLo_);\n\t\t\tfbMid = n1 * calcDecay(actualDelay / fdn.decayMid_);\n\t\t\tfbHi = n1 * calcDecay(actualDelay / fdn.decayHi_);\n\t\t\ty1A = 0.;\n\t\t\ty1B = 0.;\n\t\t\ty1C = 0.;\n\t\t\ty1D = 0.;\n\t\t\tx1A = 0.;\n\t\t\tx1B = 0.;\n\t\t\tx1C = 0.;\n\t\t\tx1D = 0.;\n\t\t}\n\t};\n\npublic:\n\n\tFDNDelay mDelay[kNumDelays];\n\t\n\tFDN(Thread& th, Arg in, Arg wet, Z mindelay, Z maxdelay, Z decayLo, Z decayMid, Z decayHi, Z seed)\n\t\t: in_(in), wet_(wet),\n\t\tdecayLo_(decayLo), decayMid_(decayMid), decayHi_(decayHi),\n\t\tmindelay_(mindelay), maxdelay_(maxdelay)\n\t{\n\t\tsr_ = th.rate.sampleRate;\n\t\tZ freqmul = th.rate.invNyquistRate * kFirstOrderCoeffScale;\n\t\ta1Lo = t_firstOrderCoeff(freqmul * 200.);\n\t\ta1Hi = t_firstOrderCoeff(freqmul * 2000.);\n\t\tscaleLoLPF = .5 * (1. - a1Lo);\n\t\tscaleLoHPF = .5 * (1. + a1Lo);\n\t\tscaleHiLPF = .5 * (1. - a1Hi);\n\t\tscaleHiHPF = .5 * (1. + a1Hi);\n\t\t\n\t\tZ delay = mindelay;\n\t\tZ ratio = maxdelay / mindelay;\n\t\tZ interval = pow(ratio, 1. / (kNumDelays - 1.));\n\t\tint prevSampleDelay = 0;\n\t\tfor (int i = 0; i < kNumDelays; ++i) {\n\t\t\tdouble expon = (random() / 2147483647. - .5) * 0.8;\n\t\t\tdouble deviation = pow(interval, expon);\n\t\t\tmDelay[i].set(th, *this, delay * deviation, prevSampleDelay);\n\t\t\tdelay *= interval;\n\t\t}\n\t\t\n\t}\n\t\n\t~FDN() { delete mLeft; delete mRight; }\n\t\n\tvirtual const char* TypeName() const override { return \"FDN\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tvoid matrix(Z x[kNumDelays])\n\t{\n\t\tZ a0 = x[ 0];\n\t\tZ a1 = x[ 1];\n\t\tZ a2 = x[ 2];\n\t\tZ a3 = x[ 3];\n\t\tZ a4 = x[ 4];\n\t\tZ a5 = x[ 5];\n\t\tZ a6 = x[ 6];\n\t\tZ a7 = x[ 7];\n\t\tZ a8 = x[ 8];\n\t\tZ a9 = x[ 9];\n\t\tZ a10 = x[10];\n\t\tZ a11 = x[11];\n\t\tZ a12 = x[12];\n\t\tZ a13 = x[13];\n\t\tZ a14 = x[14];\n\t\tZ a15 = x[15];\n\n\t\tZ b0 = a0 + a1;\n\t\tZ b1 = a0 - a1;\n\t\tZ b2 = a2 + a3;\n\t\tZ b3 = a2 - a3;\n\t\tZ b4 = a4 + a5;\n\t\tZ b5 = a4 - a5;\n\t\tZ b6 = a6 + a7;\n\t\tZ b7 = a6 - a7;\n\t\tZ b8 = a8 + a9;\n\t\tZ b9 = a8 - a9;\n\t\tZ b10 = a10 + a11;\n\t\tZ b11 = a10 - a11;\n\t\tZ b12 = a12 + a13;\n\t\tZ b13 = a12 - a13;\n\t\tZ b14 = a14 + a15;\n\t\tZ b15 = a14 - a15;\n\n\t\tZ c0 = b0 + b2;\n\t\tZ c1 = b1 + b3;\n\t\tZ c2 = b0 - b2;\n\t\tZ c3 = b1 - b3;\n\t\tZ c4 = b4 + b6;\n\t\tZ c5 = b5 + b7;\n\t\tZ c6 = b4 - b6;\n\t\tZ c7 = b5 - b7;\n\t\tZ c8 = b8 + b10;\n\t\tZ c9 = b9 + b11;\n\t\tZ c10 = b8 - b10;\n\t\tZ c11 = b9 - b11;\n\t\tZ c12 = b12 + b14;\n\t\tZ c13 = b13 + b15;\n\t\tZ c14 = b12 - b14;\n\t\tZ c15 = b13 - b15;\n\n\t\tZ d0 = c0 + c4;\n\t\tZ d1 = c1 + c5;\n\t\tZ d2 = c2 + c6;\n\t\tZ d3 = c3 + c7;\n\t\tZ d4 = c0 - c4;\n\t\tZ d5 = c1 - c5;\n\t\tZ d6 = c2 - c6;\n\t\tZ d7 = c3 - c7;\n\t\tZ d8 = c8 + c12;\n\t\tZ d9 = c9 + c13;\n\t\tZ d10 = c10 + c14;\n\t\tZ d11 = c11 + c15;\n\t\tZ d12 = c8 - c12;\n\t\tZ d13 = c9 - c13;\n\t\tZ d14 = c10 - c14;\n\t\tZ d15 = c11 - c15;\n\n\t\tx[ 0] = d0 + d8;\n\t\tx[ 1] = d1 + d9;\n\t\tx[ 2] = d2 + d10;\n\t\tx[ 3] = d3 + d11;\n\t\tx[ 4] = d4 + d12;\n\t\tx[ 5] = d5 + d13;\n\t\tx[ 6] = d6 + d14;\n\t\tx[ 7] = d7 + d15;\n\t\tx[ 8] = d0 - d8;\n\t\tx[ 9] = d1 - d9;\n\t\tx[10] = d2 - d10;\n\t\tx[11] = d3 - d11;\n\t\tx[12] = d4 - d12;\n\t\tx[13] = d5 - d13;\n\t\tx[14] = d6 - d14;\n\t\tx[15] = d7 - d15;\n\t}\n \n\tvirtual void pull(Thread& th) \n\t{\n\t\tint framesToFill = mLeft->mBlockSize;\n\n\t\tZ Sink = 0.;\n\t\tZ* Lout;\n\t\tZ* Rout;\n\t\tint Loutstride = 1;\n\t\tint Routstride = 1;\n\n\t\tif (mLeft->mOut) {\n\t\t\tLout = mLeft->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tLout = &Sink;\n\t\t\tLoutstride = 0;\n\t\t}\n\n\t\tif (mRight->mOut) {\n\t\t\tRout = mRight->mOut->fulfillz(framesToFill);\n\t\t} else {\n\t\t\tRout = &Sink;\n\t\t\tRoutstride = 0;\n\t\t}\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint inStride, wetStride;\n\t\t\tZ *in;\n\t\t\tZ *wet;\n\t\t\tif (in_(th, n, inStride, in) || wet_(th, n, wetStride, wet)) {\n\t\t\t\tmLeft->setDone();\n\t\t\t\tmRight->setDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x[kNumDelays];\n\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\n\t\t\t\t\t\t// read from delay line\n\t\t\t\t\t\tZ x0 = d.buf[d.rpos & d.mask];\n\n\t\t\t\t\t\t// attenuate and filter the output of the delay line.\n\t\t\t\t\t\t\n\t\t\t\t\t\t// high crossover\n\t\t\t\t\t\tZ x0A = scaleHiHPF * x0;\n\t\t\t\t\t\tZ x0B = scaleHiLPF * x0 ;\n\t\t\t\t\t\tZ y0A = x0A - d.x1A + a1Hi * d.y1A;\t// hpf -> high band\n\t\t\t\t\t\tZ y0B = x0B + d.x1B + a1Hi * d.y1B;\t// lpf -> low + mid\n\t\t\t\t\t\td.y1A = y0A;\n\t\t\t\t\t\td.y1B = y0B;\n\t\t\t\t\t\td.x1A = x0A;\n\t\t\t\t\t\td.x1B = x0B;\n\t\t\t\t\t\t\n\t\t\t\t\t\t// low crossover\n\t\t\t\t\t\tZ x0C = scaleLoHPF * y0B;\n\t\t\t\t\t\tZ x0D = scaleLoLPF * y0B;\n\t\t\t\t\t\tZ y0C = x0C - d.x1C + a1Lo * d.y1C;\t// hpf -> mid band\n\t\t\t\t\t\tZ y0D = x0D + d.x1D + a1Lo * d.y1D;\t// lpf -> low band\n\t\t\t\t\t\td.y1C = y0C;\n\t\t\t\t\t\td.y1D = y0D;\n\t\t\t\t\t\td.x1C = x0C;\n\t\t\t\t\t\td.x1D = x0D;\n\t\t\t\t\t\t\n\t\t\t\t\t\tx[j] = d.fbLo * y0D + d.fbMid * y0C + d.fbHi * y0A;\n\n\t\t\t\t\t\t++d.rpos;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tmatrix(x);\n\t\t\t\t\t\n\t\t\t\t\tZ ini = *in;\n\t\t\t\t\tZ w = *wet;\n\t\t\t\t\t*Lout = ini + w * (x[1] - ini);\n\t\t\t\t\t*Rout = ini + w * (x[2] - ini);\n\t\t\t\t\tLout += Loutstride;\n\t\t\t\t\tRout += Routstride;\n\n\t\t\t\t\t// write back to delay line\n\t\t\t\t\tfor (UInt32 j = 0; j < kNumDelays; ++j) \n\t\t\t\t\t{\n\t\t\t\t\t\tFDNDelay& d = mDelay[j];\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\td.buf[d.wpos & d.mask] = x[j] + ini;\n\t\t\t\t\t\t++d.wpos;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tin += inStride;\n\t\t\t\t\twet += wetStride;\n\t\t\t\t}\n\t\t\t\tin_.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t}\n\t\t}\n\n\t\tif (mLeft->mOut) mLeft->produce(framesToFill);\n\t\tif (mRight->mOut) mRight->produce(framesToFill);\n\t}\n};\n\nFDN_OutputChannel::FDN_OutputChannel(Thread& th, bool inFinite, FDN* inFDN)\n : Gen(th, itemTypeZ, inFinite), mFDN(inFDN)\n{\n}\n\nvoid FDN_OutputChannel::pull(Thread& th)\n{\n\tmFDN->pull(th);\n}\n\nP FDN::createOutputs(Thread& th)\n{\n\tmLeft = new FDN_OutputChannel(th, finite, this);\n\tmRight = new FDN_OutputChannel(th, finite, this);\n\t\n\tP left = mLeft;\n\tP right = mRight;\n\t\n\tP s = new List(itemTypeV, 2);\n\tP a = s->mArray;\n\ta->add(new List(left));\n\ta->add(new List(right));\n\t\n\treturn s;\n}\n\n\nstatic void fdn_(Thread& th, Prim* prim)\n{\n\tZ seed = th.popFloat(\"fdn : seed\");\n\tZ maxdelay = th.popFloat(\"fdn : maxdelay\");\n\tZ mindelay = th.popFloat(\"fdn : mindelay\");\n\tZ decayHi = th.popFloat(\"fdn : decayHi\");\n\tZ decayMid = th.popFloat(\"fdn : decayMid\");\n\tZ decayLo = th.popFloat(\"fdn : decayLo\");\n\tV wet = th.popZIn(\"fdn : wet\");\n\tV in = th.popZIn(\"fdn : in\");\n \n\tP fdn = new FDN(th, in, wet, mindelay, maxdelay, decayLo, decayMid, decayHi, seed);\n\t\n\tP s = fdn->createOutputs(th);\n\n\tth.push(s);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddDelayUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** delay unit generators ***\");\n\tDEFAM(delayn, zzk, \"(in delay maxdelay --> out) delay line with no interpolation.\");\n\tDEFAM(delayl, zzk, \"(in delay maxdelay --> out) delay line with linear interpolation.\");\n\tDEFAM(delayc, zzk, \"(in delay maxdelay --> out) delay line with cubic interpolation.\");\n\tDEFAM(flange, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. delay can be negative. latency is maxdelay.\");\n\tDEFAM(flangep, zzk, \"(in delay maxdelay --> out) flanger with cubic interpolation. adds delayed signal instead of subtracts.\");\n\t\n\tDEFAM(combn, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with no interpolation.\");\n\tDEFAM(combl, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with linear interpolation.\");\n\tDEFAM(combc, zzkz, \"(in delay maxdelay decayTime --> out) comb delay filter with cubic interpolation.\");\n\tDEFAM(lpcombc, zzkzz, \"(in delay maxdelay decayTime lpfreq --> out) low pass comb delay filter with cubic interpolation.\");\n\t\n\tDEFAM(alpasn, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with no interpolation.\");\n\tDEFAM(alpasl, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with linear interpolation.\");\n\tDEFAM(alpasc, zzkz, \"(in delay maxdelay decayTime --> out) all pass delay filter with cubic interpolation.\");\n\t//DEFAM(fdn, zzkkkkkk, \"(in wet decayLo decayMid decayHi mindelay maxdelay rseed --> out) feedback delay network reverb.\");\n}\n\n\n"], ["/sapf/src/MathOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathOps.hpp\"\n#include \"clz.hpp\"\n#include \n#include \"primes.hpp\"\n#include \n\n\n\nV BinaryOp::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpGen(th, this, a, b));\n}\n\nV BinaryOp::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpZGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeVList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n}\n\nV BinaryOpLink::makeZList(Thread& th, Arg a, Arg b)\n{\n\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n}\n\nvoid UnaryOp::loop(Thread& th, int n, V *a, int astride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->unaryOp(th, this);\n\t\ta += astride;\n\t} \n}\n\nvoid BinaryOp::loop(Thread& th, int n, V *a, int astride, V *b, int bstride, V *out)\n{\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, *b);\n\t\ta += astride;\n\t\tb += bstride;\n\t} \n}\n\nvoid BinaryOp::loopzv(Thread& th, int n, Z *aa, int astride, V *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa;\n\t\tArg b = *bb; \n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\nvoid BinaryOp::loopvz(Thread& th, int n, V *aa, int astride, Z *bb, int bstride, V *out) \n{\n\tLOOP(i,n) { \n\t\tArg a = *aa; \n\t\tArg b = *bb;\n\t\tout[i] = a.binaryOp(th, this, b); \n\t\taa += astride; \n\t\tbb += bstride; \n\t}\n}\n\n\nvoid BinaryOp::scan(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = x = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::pairs(Thread& th, int n, V& z, V *a, int astride, V *out)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tout[i] = a->binaryOp(th, this, x);\n\t\tx = *a;\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\nvoid BinaryOp::reduce(Thread& th, int n, V& z, V *a, int astride)\n{\n\tV x = z;\n\tLOOP(i, n) {\n\t\tx = x.binaryOp(th, this, *a);\n\t\ta += astride;\n\t}\n\tz = x;\n}\n\n\nvoid UnaryOpZGen::pull(Thread& th) {\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ *a;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, out);\n\t\t\t_a.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nvoid BinaryOpZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a) || _b(th, n,bstride, b)) {\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\nvoid BinaryOpLinkZGen::pull(Thread& th)\n{\n\tint framesToFill = mBlockSize;\n\tZ* out = mOut->fulfillz(framesToFill);\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride, bstride;\n\t\tZ *a, *b;\n\t\tif (_a(th, n,astride, a)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_b.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else if (_b(th, n,bstride, b)) {\n\t\t\tproduce(framesToFill);\n\t\t\t_a.link(th, mOut);\n\t\t\tsetDone();\n\t\t\tbreak;\n\t\t} else {\n\t\t\top->loopz(n, a, astride, b, bstride, out);\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t}\n\tproduce(framesToFill);\n}\n\n\nstatic void DoPairwise(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new PairsOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new PairsOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoScan(Thread& th, BinaryOp* op)\n{\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new ScanOpGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new ScanOpZGen(th, a, op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIPairwise(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IPairsOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IPairsOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"^ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoIScan(Thread& th, BinaryOp* op)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tO s = new List(new IScanOpGen(th, a, b, op));\n\t\tth.push(s);\n\t} else if (a.isZList()) {\n\t\tO s = new List(new IScanOpZGen(th, a, b.asFloat(), op));\n\t\tth.push(s);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n\nstatic void DoReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z, *x;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = kDefaultVBlockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = 0., *x;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\tn = 1;\n\t\tif (!_a(th, n,xstride,x)) {\n\t\t\tz = *x;\n\t\t\t_a.advance(n);\n\t\t\twhile(1) {\n\t\t\t\tn = th.rate.blockSize;\n\t\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\t\top->reducez(n, z, x, xstride);\n\t\t\t\t_a.advance(n);\n\t\t\t}\t\n\t\t}\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\nstatic void DoIReduce(Thread& th, BinaryOp* op)\n{\n\tint n;\n\tV b = th.pop();\n\tV a = th.pop();\n\tif (a.isVList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tV z = b, *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tVIn _a(a);\n\t\twhile(1) {\n\t\t\tn = kDefaultVBlockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reduce(th, n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isZList()) {\n\t\tif (!a.isFinite()) indefiniteOp(op->Name(), \"/\");\n\t\tZ z = b.asFloat(), *x;\n\t\tb = 0.;\n\t\tint xstride;\n\t\tZIn _a(a);\n\t\twhile(1) {\n\t\t\tn = th.rate.blockSize;\n\t\t\tif (_a(th, n,xstride, x)) break;\n\t\t\top->reducez(n, z, x, xstride);\n\t\t\t_a.advance(n);\n\t\t}\t\n\t\tth.push(z);\n\t} else if (a.isReal() || a.isString()) {\n\t\tth.push(a);\n\t} else {\n\t\tstd::string s = op->Name();\n\t\ts += \"\\\\ : a\";\n\t\twrongType(s.c_str(), \"Real, List or String\", a);\n\t}\n}\n\n#define UNARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.unaryOp(th, &gUnaryOp_##NAME); \\\n\t\tth.push(c); \\\n\t} \\\n\n\n#define BINARY_OP_PRIM(NAME) \\\n\tstatic void NAME##_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tV b = th.pop(); \\\n\t\tV a = th.pop(); \\\n\t\tV c = a.binaryOp(th, &gBinaryOp_##NAME, b); \\\n\t\tth.push(c); \\\n\t} \\\n\tstatic void NAME##_reduce_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoReduce(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_scan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_pairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_iscan_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIScan(th, &gBinaryOp_##NAME); \\\n\t} \\\n\tstatic void NAME##_ipairs_(Thread& th, Prim* prim) \\\n\t{ \\\n\t\tDoIPairwise(th, &gBinaryOp_##NAME); \\\n\t} \\\n\n#define DEFINE_UNOP_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV(NAME, CODE, VVNAME) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *x, int astride, Z *y) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVNAME(y, x, &n); \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *x; y[i] = CODE; x += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_FLOATVV2(NAME, CODE, VVCODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tif (astride == 1) { \\\n\t\t\t\tVVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; aa += astride; } \\\n\t\t\t} \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (Z)(CODE); aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n#define DEFINE_UNOP_BOOL_FLOAT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n#define DEFINE_UNOP_BOOL_INT(NAME, CODE) \\\n\tstruct UnaryOp_##NAME : public UnaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\treturn (CODE) ? 1. : 0.; \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t} \\\n\t}; \\\n\tUnaryOp_##NAME gUnaryOp_##NAME; \\\n\tUnaryOp* gUnaryOpPtr_##NAME = &gUnaryOp_##NAME; \\\n\tUNARY_OP_PRIM(NAME)\n\n\n\n\n\n\n\n#define DEFINE_BINOP_FLOAT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOAT_STRING(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE); \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_FLOATVV(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tVVCODE; \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_FLOATVV1(NAME, CODE, VVCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return CODE; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tif (astride == 1 && bstride == 1) { \\\n\t\t\t\t VVCODE; \\\n\t\t\t} else { \\\n\t\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = CODE; aa += astride; bb += bstride; } \\\n\t\t\t} \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = CODE; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\n#define DEFINE_BINOP_INT(NAME, CODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double aa, double bb) { \\\n\t\t\tint64_t a = (int64_t)aa; \\\n\t\t\tint64_t b = (int64_t)bb; \\\n\t\t\treturn (double)(CODE); \\\n\t\t} \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; int64_t b = (int64_t)*bb; out[i] = (Z)(CODE); aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t b = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t a = (int64_t)*aa; out[i] = CODE; b = a; aa += astride; } \\\n\t\t\tz = (Z)b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; Z x = CODE; out[i] = x; a = (int64_t)x; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tint64_t a = (int64_t)z; \\\n\t\t\tLOOP(i,n) { int64_t b = (int64_t)*aa; a = (int64_t)(CODE); aa += astride; } \\\n\t\t\tz = (Z)a; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n#define DEFINE_BINOP_BOOL_FLOAT(NAME, CODE, STRCODE) \\\n\tstruct BinaryOp_##NAME : public BinaryOp { \\\n\t\tvirtual const char *Name() { return #NAME; } \\\n\t\tvirtual double op(double a, double b) { return (CODE) ? 1. : 0.; } \\\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) { \\\n\t\t\tLOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = (CODE) ? 1. : 0.; aa += astride; bb += bstride; } \\\n\t\t} \\\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ b = z; \\\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = (CODE) ? 1. : 0.; b = a; aa += astride; } \\\n\t\t\tz = b; \\\n\t\t} \\\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) { \\\n\t\t\tZ a = z; \\\n\t\t\tLOOP(i,n) { Z b = *aa; a = (CODE) ? 1. : 0.; aa += astride; } \\\n\t\t\tz = a; \\\n\t\t} \\\n\t\tvirtual V stringOp(P const& aa, P const& bb) { \\\n\t\t\tconst char* a = aa->s; \\\n\t\t\tconst char* b = bb->s; \\\n\t\t\treturn (STRCODE) ? 1. : 0.; \\\n\t\t} \\\n\t}; \\\n\tBinaryOp_##NAME gBinaryOp_##NAME; \\\n\tBinaryOp* gBinaryOpPtr_##NAME = &gBinaryOp_##NAME; \\\n\tBINARY_OP_PRIM(NAME)\n\n\nDEFINE_UNOP_BOOL_INT(isalnum, isalnum((int)a))\nDEFINE_UNOP_BOOL_INT(isalpha, isalpha((int)a))\nDEFINE_UNOP_BOOL_INT(isblank, isblank((int)a))\nDEFINE_UNOP_BOOL_INT(iscntrl, iscntrl((int)a))\nDEFINE_UNOP_BOOL_INT(isdigit, isdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isgraph, isgraph((int)a))\nDEFINE_UNOP_BOOL_INT(islower, islower((int)a))\nDEFINE_UNOP_BOOL_INT(isprint, isprint((int)a))\nDEFINE_UNOP_BOOL_INT(ispunct, ispunct((int)a))\nDEFINE_UNOP_BOOL_INT(isspace, isspace((int)a))\nDEFINE_UNOP_BOOL_INT(isupper, isupper((int)a))\nDEFINE_UNOP_BOOL_INT(isxdigit, isxdigit((int)a))\nDEFINE_UNOP_BOOL_INT(isascii, isascii((int)a))\n\nDEFINE_UNOP_BOOL_FLOAT(not, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonneg, a >= 0.)\nDEFINE_UNOP_BOOL_FLOAT(nonpos, a <= 0.)\nDEFINE_UNOP_BOOL_FLOAT(isneg, a < 0.)\nDEFINE_UNOP_BOOL_FLOAT(ispos, a > 0.)\nDEFINE_UNOP_BOOL_FLOAT(iszero, a == 0.)\nDEFINE_UNOP_BOOL_FLOAT(isint, (a - floor(a)) == 0.)\nDEFINE_UNOP_BOOL_INT(iseven, !(a & 1))\nDEFINE_UNOP_BOOL_INT(isodd, (a & 1))\nDEFINE_UNOP_BOOL_INT(isprime, isprime(a))\n\nDEFINE_UNOP_BOOL_FLOAT(isfinite, std::isfinite(a))\nDEFINE_UNOP_BOOL_FLOAT(isinf, std::isinf(a))\nDEFINE_UNOP_BOOL_FLOAT(isnormal, std::isnormal(a))\nDEFINE_UNOP_BOOL_FLOAT(isnan, std::isnan(a))\nDEFINE_UNOP_BOOL_FLOAT(signbit, std::signbit(a))\n\nstruct UnaryOp_ToZero : public UnaryOp {\n\tvirtual const char *Name() { return \"ToZero\"; }\n\tvirtual double op(double a) { return 0.; }\n\tvirtual void loopz(int n, const Z *aa, int astride, Z *out) {\n\t\tLOOP(i,n) { out[i] = 0.; }\n\t}\n};\nUnaryOp_ToZero gUnaryOp_ToZero; \n\nDEFINE_UNOP_FLOATVV2(neg, -a, vDSP_vnegD(const_cast(aa), astride, out, 1, n))\nDEFINE_UNOP_FLOAT(sgn, sc_sgn(a))\nDEFINE_UNOP_FLOATVV(abs, fabs(a), vvfabs)\n\nDEFINE_UNOP_INT(tolower, tolower((int)a))\nDEFINE_UNOP_INT(toupper, toupper((int)a))\nDEFINE_UNOP_INT(toascii, toascii((int)a))\n\nDEFINE_UNOP_FLOATVV2(frac, a - floor(a), vvfloor(out, aa, &n); vDSP_vsubD(out, 1, aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV(floor, floor(a), vvfloor)\nDEFINE_UNOP_FLOATVV(ceil, ceil(a), vvceil)\nDEFINE_UNOP_FLOATVV(rint, rint(a), vvnint)\n\nDEFINE_UNOP_FLOAT(erf, erf(a))\nDEFINE_UNOP_FLOAT(erfc, erfc(a))\n\nDEFINE_UNOP_FLOATVV(recip, 1./a, vvrec)\nDEFINE_UNOP_FLOATVV(sqrt, sc_sqrt(a), vvsqrt)\nDEFINE_UNOP_FLOATVV(rsqrt, 1./sc_sqrt(a), vvrsqrt)\nDEFINE_UNOP_FLOAT(cbrt, cbrt(a))\nDEFINE_UNOP_FLOATVV2(ssq, copysign(a*a, a), vDSP_vssqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOATVV2(sq, a*a, vDSP_vsqD(aa, astride, out, 1, n))\nDEFINE_UNOP_FLOAT(cb, a*a*a)\nDEFINE_UNOP_FLOAT(pow4, sc_fourth(a))\nDEFINE_UNOP_FLOAT(pow5, sc_fifth(a))\nDEFINE_UNOP_FLOAT(pow6, sc_sixth(a))\nDEFINE_UNOP_FLOAT(pow7, sc_seventh(a))\nDEFINE_UNOP_FLOAT(pow8, sc_eighth(a))\nDEFINE_UNOP_FLOAT(pow9, sc_ninth(a))\n\nDEFINE_UNOP_FLOATVV(exp, exp(a), vvexp)\nDEFINE_UNOP_FLOATVV(exp2, exp2(a), vvexp2)\nDEFINE_UNOP_FLOAT(exp10, pow(10., a))\nDEFINE_UNOP_FLOATVV(expm1, expm1(a), vvexpm1)\nDEFINE_UNOP_FLOATVV(log, sc_log(a), vvlog)\nDEFINE_UNOP_FLOATVV(log2, sc_log2(a), vvlog2)\nDEFINE_UNOP_FLOATVV(log10, sc_log10(a), vvlog10)\nDEFINE_UNOP_FLOATVV(log1p, log1p(a), vvlog1p)\nDEFINE_UNOP_FLOATVV(logb, logb(a), vvlogb)\n\nDEFINE_UNOP_FLOAT(sinc, sc_sinc(a))\n\nDEFINE_UNOP_FLOATVV(sin, sin(a), vvsin)\nDEFINE_UNOP_FLOATVV(cos, cos(a), vvcos)\nDEFINE_UNOP_FLOATVV2(sin1, sin(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvsin(out, out, &n))\nDEFINE_UNOP_FLOATVV2(cos1, cos(a * kTwoPi), Z b = kTwoPi; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vvcos(out, out, &n))\nDEFINE_UNOP_FLOATVV(tan, tan(a), vvtan)\nDEFINE_UNOP_FLOATVV(asin, asin(a), vvasin)\nDEFINE_UNOP_FLOATVV(acos, acos(a), vvacos)\nDEFINE_UNOP_FLOATVV(atan, atan(a), vvatan)\nDEFINE_UNOP_FLOATVV(sinh, sinh(a), vvsinh)\nDEFINE_UNOP_FLOATVV(cosh, cosh(a), vvcosh)\nDEFINE_UNOP_FLOATVV(tanh, tanh(a), vvtanh)\nDEFINE_UNOP_FLOATVV(asinh, asinh(a), vvasinh)\nDEFINE_UNOP_FLOATVV(acosh, acosh(a), vvacosh)\nDEFINE_UNOP_FLOATVV(atanh, atanh(a), vvatanh)\n\nDEFINE_UNOP_FLOAT(J0, j0(a))\nDEFINE_UNOP_FLOAT(J1, j1(a))\nDEFINE_UNOP_FLOAT(Y0, y0(a))\nDEFINE_UNOP_FLOAT(Y1, y1(a))\n\nDEFINE_UNOP_FLOAT(tgamma, tgamma(a))\nDEFINE_UNOP_FLOAT(lgamma, lgamma(a))\n\nstatic void sc_clipv(int n, const Z* in, Z* out, Z a, Z b)\n{\n\tfor (int i = 0; i < n; ++i) {\n\t\tout[i] = std::clamp(in[i], a, b);\n\t}\n}\n\nDEFINE_UNOP_FLOATVV2(inc, a+1, Z b = 1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(dec, a-1, Z b = -1.; vDSP_vsaddD(const_cast(aa), astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(half, a*.5, Z b = .5; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(twice, a*2., Z b = 2.; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n))\n\n\nDEFINE_UNOP_FLOATVV2(biuni, a*.5+.5, Z b = .5; vDSP_vsmulD(const_cast(aa), astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibi, a*2.-1., Z b = 2.; Z c = -1.; vDSP_vsmulD(aa, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOATVV2(biunic, std::clamp(a,-1.,1.)*.5+.5, Z b = .5; sc_clipv(n, aa, out, -1., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(unibic, std::clamp(a,0.,1.)*2.-1., Z b = 2.; Z c = -1.; sc_clipv(n, aa, out, 0., 1.); vDSP_vsmulD(out, astride, &b, out, 1, n); vDSP_vsaddD(out, 1, &c, out, 1, n))\nDEFINE_UNOP_FLOAT(cmpl, 1.-a)\n\nDEFINE_UNOP_FLOATVV2(ampdb, sc_ampdb(a), Z b = 1.; vDSP_vdbconD(const_cast(aa), astride, &b, out, 1, n, 1))\nDEFINE_UNOP_FLOAT(dbamp, sc_dbamp(a))\n\nDEFINE_UNOP_FLOAT(hzo, sc_hzoct(a))\nDEFINE_UNOP_FLOAT(ohz, sc_octhz(a))\n\nDEFINE_UNOP_FLOAT(hzst, sc_hzkey(a))\nDEFINE_UNOP_FLOAT(sthz, sc_keyhz(a))\n\nDEFINE_UNOP_FLOAT(hznn, sc_hznn(a))\nDEFINE_UNOP_FLOAT(nnhz, sc_nnhz(a))\n\nDEFINE_UNOP_FLOAT(centsratio, sc_centsratio(a))\nDEFINE_UNOP_FLOAT(ratiocents, sc_ratiocents(a))\n\nDEFINE_UNOP_FLOAT(semiratio, sc_semiratio(a))\nDEFINE_UNOP_FLOAT(ratiosemi, sc_ratiosemi(a))\n\nDEFINE_UNOP_FLOATVV2(degrad, a*kDegToRad, Z b = kDegToRad; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(raddeg, a*kRadToDeg, Z b = kRadToDeg; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(minsec, a*kMinToSecs, Z b = kMinToSecs; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(secmin, a*kSecsToMin, Z b = kSecsToMin; vDSP_vsmulD(aa, astride, &b, out, 1, n))\nDEFINE_UNOP_FLOATVV2(bpmsec, kMinToSecs / a, Z b = kMinToSecs; vDSP_svdivD(&b, const_cast(aa), astride, out, 1, n))\n\nDEFINE_UNOP_FLOAT(distort, sc_distort(a))\nDEFINE_UNOP_FLOAT(softclip, sc_softclip(a))\n\nDEFINE_UNOP_FLOAT(rectWin, sc_rectWindow(a))\nDEFINE_UNOP_FLOAT(triWin, sc_triWindow(a))\nDEFINE_UNOP_FLOAT(bitriWin, sc_bitriWindow(a))\nDEFINE_UNOP_FLOAT(hanWin, sc_hanWindow(a))\nDEFINE_UNOP_FLOAT(sinWin, sc_sinWindow(a))\nDEFINE_UNOP_FLOAT(ramp, sc_ramp(a))\nDEFINE_UNOP_FLOAT(scurve, sc_scurve(a))\nDEFINE_UNOP_FLOAT(sigm,\t\ta/sqrt(1.+a*a))\n\nDEFINE_UNOP_FLOAT(zapgremlins, zapgremlins(a))\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nDEFINE_BINOP_BOOL_FLOAT(lt, a < b, strcmp(a, b) < 0)\nDEFINE_BINOP_BOOL_FLOAT(le, a <= b, strcmp(a, b) <= 0)\nDEFINE_BINOP_BOOL_FLOAT(gt, a > b, strcmp(a, b) > 0)\nDEFINE_BINOP_BOOL_FLOAT(ge, a >= b, strcmp(a, b) >= 0)\nDEFINE_BINOP_BOOL_FLOAT(eq, a == b, strcmp(a, b) == 0)\nDEFINE_BINOP_BOOL_FLOAT(ne, a != b, strcmp(a, b) != 0)\nDEFINE_BINOP_FLOAT_STRING(cmp, sc_cmp(a, b), sc_sgn(strcmp(a, b)))\n\nDEFINE_BINOP_FLOATVV1(copysign, copysign(a, b), vvcopysign(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\nDEFINE_BINOP_FLOATVV1(nextafter, nextafter(a, b), vvnextafter(out, const_cast(aa), bb, &n)) // bug in vForce.h requires const_cast\n\n// identity optimizations of basic operators.\n\n\tstruct BinaryOp_plus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus gBinaryOp_plus;\n\tBinaryOp* gBinaryOpPtr_plus = &gBinaryOp_plus;\n\tBINARY_OP_PRIM(plus)\n\n\n\tstruct BinaryOp_plus_link : public BinaryOp {\n\t\tvirtual const char *Name() { return \"plus\"; }\n\t\tvirtual double op(double a, double b) { return a + b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 0.) {\n\t\t\t\t\tmemcpy(out, bb, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(bb), bstride, const_cast(aa), out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tif (*bb == 0.) {\n\t\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsaddD(const_cast(aa), astride, const_cast(bb), out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vaddD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a + b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a + b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return b;\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpLinkZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_plus_link gBinaryOp_plus_link;\n\tBinaryOp* gBinaryOpPtr_plus_link = &gBinaryOp_plus_link;\n\tBINARY_OP_PRIM(plus_link)\n\n\n\tstruct BinaryOp_minus : public BinaryOp {\n\t\tvirtual const char *Name() { return \"minus\"; }\n\t\tvirtual double op(double a, double b) { return a - b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\tif (*aa != 0.) {\n\t\t\t\t\tvDSP_vnegD(const_cast(bb), bstride, out, 1, n);\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, const_cast(aa), out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t}\n\t\t\t} else if (bstride == 0 ) {\n\t\t\t\tmemcpy(out, aa, n * sizeof(Z));\n\t\t\t\tif (*bb != 0.) {\n\t\t\t\t\tZ b = -*bb;\n\t\t\t\t\tvDSP_vsaddD(const_cast(out), 1, &b, out, 1, n);\n\t\t\t\t\t//LOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vsubD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a + b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a - b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a - b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\tif (b.isReal() && b.f == 0.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_minus gBinaryOp_minus;\n\tBinaryOp* gBinaryOpPtr_minus = &gBinaryOp_minus;\n\tBINARY_OP_PRIM(minus)\n\n\n\n\tstruct BinaryOp_mul : public BinaryOp {\n\t\tvirtual const char *Name() { return \"mul\"; }\n\t\tvirtual double op(double a, double b) { return a * b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0) {\n\t\t\t\tif (*aa == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *bb; bb += bstride; }\n\t\t\t\t} else if (*aa == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(bb, bstride, aa, out, 1, n);\n\t\t\t\t}\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += astride; }\n\t\t\t\t} else if (*bb == 0.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t\t} else {\n\t\t\t\t\tvDSP_vsmulD(aa, astride, bb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a * b; aa += astride; bb += bstride; }\n\t\t\t\tvDSP_vmulD(aa, astride, bb, bstride, out, 1, n);\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a * b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a * b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\t\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal()) {\n\t\t\t\tif (a.f == 1.) return b;\n\t\t\t\tif (a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\t\tif (a.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, b));\n\t\t\t}\n\t\t\tif (b.isReal()) {\n\t\t\t\tif (b.f == 1.) return a;\n\t\t\t\tif (b.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, a));\n\t\t\t\tif (b.f == -1.) return new List(new UnaryOpZGen(th, &gUnaryOp_neg, a));\n\t\t\t}\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_mul gBinaryOp_mul;\n\tBinaryOp* gBinaryOpPtr_mul = &gBinaryOp_mul;\n\tBINARY_OP_PRIM(mul)\n\n\n\tstruct BinaryOp_div : public BinaryOp {\n\t\tvirtual const char *Name() { return \"div\"; }\n\t\tvirtual double op(double a, double b) { return a / b; }\n\t\tvirtual void loopz(int n, const Z *aa, int astride, const Z *bb, int bstride, Z *out) {\n\t\t\tif (astride == 0 && *aa == 0.) {\n\t\t\t\tLOOP(i,n) { out[i] = 0.; }\n\t\t\t} else if (bstride == 0) {\n\t\t\t\tif (*bb == 1.) {\n\t\t\t\t\tLOOP(i,n) { out[i] = *aa; aa += bstride; }\n\t\t\t\t} else {\n\t\t\t\t\tZ rb = 1. / *bb;\n\t\t\t\t\tvDSP_vsmulD(const_cast(aa), astride, &rb, out, 1, n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvDSP_vdivD(const_cast(bb), bstride, const_cast(aa), astride, out, 1, n);\n\t\t\t\t//LOOP(i,n) { Z a = *aa; Z b = *bb; out[i] = a / b; aa += astride; bb += bstride; }\n\t\t\t}\n\t\t}\n\t\tvirtual void pairsz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ b = z;\n\t\t\tLOOP(i,n) { Z a = *aa; out[i] = a / b; b = a; aa += astride; }\n\t\t\tz = b;\n\t\t}\n\t\tvirtual void scanz(int n, Z& z, Z *aa, int astride, Z *out) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; out[i] = a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual void reducez(int n, Z& z, Z *aa, int astride) {\n\t\t\tZ a = z;\n\t\t\tLOOP(i,n) { Z b = *aa; a = a / b; aa += astride; }\n\t\t\tz = a;\n\t\t}\n\t\tvirtual V makeVList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpGen(th, this, a, b));\n\t\t}\n\n\t\tvirtual V makeZList(Thread& th, Arg a, Arg b)\n\t\t{\n\t\t\tif (a.isReal() && a.f == 0.) return new List(new UnaryOpZGen(th, &gUnaryOp_ToZero, b));\n\t\t\tif (b.isReal() && b.f == 1.) return a;\n\t\t\treturn new List(new BinaryOpZGen(th, this, a, b));\n\t\t}\n\t};\n\tBinaryOp_div gBinaryOp_div;\n\tBinaryOp* gBinaryOpPtr_div = &gBinaryOp_div;\n\tBINARY_OP_PRIM(div)\n\nDEFINE_BINOP_FLOAT(mod, sc_fmod(a, b))\nDEFINE_BINOP_FLOAT(remainder, remainder(a, b))\n\nDEFINE_BINOP_INT(idiv, sc_div(a, b))\nDEFINE_BINOP_INT(imod, sc_imod(a, b))\n\nDEFINE_BINOP_FLOATVV1(pow, sc_pow(a, b), vvpow(out, bb, aa, &n))\nDEFINE_BINOP_FLOATVV1(atan2, atan2(a, b), vvatan2(out, aa, bb, &n))\n\nDEFINE_BINOP_FLOAT(Jn, jn((int)b, a))\nDEFINE_BINOP_FLOAT(Yn, yn((int)b, a))\n\nDEFINE_BINOP_FLOATVV(min, fmin(a, b), vDSP_vminD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOATVV(max, fmax(a, b), vDSP_vmaxD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(dim, fdim(a, b))\nDEFINE_BINOP_FLOAT(xor, fdim(a, b))\n\nDEFINE_BINOP_FLOAT(avg2, (a + b) * .5)\nDEFINE_BINOP_FLOAT(absdif, fabs(a - b))\nDEFINE_BINOP_FLOATVV(hypot, hypot(a, b), vDSP_vdistD(const_cast(aa), astride, const_cast(bb), bstride, out, 1, n))\nDEFINE_BINOP_FLOAT(sumsq, a*a + b*b)\nDEFINE_BINOP_FLOAT(difsq, a*a - b*b)\nDEFINE_BINOP_FLOAT(sqsum, sc_squared(a + b))\nDEFINE_BINOP_FLOAT(sqdif, sc_squared(a - b))\n\nDEFINE_BINOP_FLOAT(thresh, a < b ? 0. : a)\nDEFINE_BINOP_FLOAT(absthresh, fabs(a) < b ? 0. : a)\nDEFINE_BINOP_FLOAT(amclip, b <= 0. ? 0. : a * b)\nDEFINE_BINOP_FLOAT(scaleneg, a < 0. ? a * b : a)\n\nDEFINE_BINOP_FLOAT(ring1, a * b + a)\nDEFINE_BINOP_FLOAT(ring2, a * b + a + b)\nDEFINE_BINOP_FLOAT(ring3, a*a*b)\nDEFINE_BINOP_FLOAT(ring4, a*b*(a - b))\n\nDEFINE_BINOP_INT(gcd, sc_gcd(a, b))\nDEFINE_BINOP_INT(lcm, sc_lcm(a, b))\n\nDEFINE_BINOP_FLOAT(clip2, std::clamp(a, -b, b))\nDEFINE_BINOP_FLOAT(wrap2, sc_wrap(a, -b, b))\nDEFINE_BINOP_FLOAT(fold2, sc_fold(a, -b, b))\nDEFINE_BINOP_INT(iwrap2, sc_iwrap(a, -b, b))\nDEFINE_BINOP_INT(ifold2, sc_ifold(a, -b, b))\nDEFINE_BINOP_FLOAT(excess, a - std::clamp(a, -b, b))\n\nDEFINE_BINOP_FLOAT(clip0, std::clamp(a, 0., b))\nDEFINE_BINOP_FLOAT(wrap0, sc_wrap(a, 0., b))\nDEFINE_BINOP_FLOAT(fold0, sc_fold(a, 0., b))\n\nDEFINE_BINOP_FLOAT(round, sc_round(a, b))\nDEFINE_BINOP_FLOAT(roundUp, sc_roundUp(a, b))\nDEFINE_BINOP_FLOAT(trunc, sc_trunc(a, b))\n\n\n#define DEFN(FUNNAME, OPNAME, HELP) \tvm.def(OPNAME, 1, 1, FUNNAME##_, \"(x --> z) \" HELP);\n#define DEFNa(FUNNAME, OPNAME, HELP) \tDEFN(FUNNAME, #OPNAME, HELP)\n#define DEF(NAME, HELP) \tDEFNa(NAME, NAME, HELP); \n\n#define DEFNa2(FUNNAME, OPNAME, HELP) \t\\\n\t(vm.def(#OPNAME, 2, 1, FUNNAME##_, \"(x y --> z) \" HELP), \\\n\tvm.def(#OPNAME \"/\", 1, 1, FUNNAME##_reduce_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\\", 1, 1, FUNNAME##_scan_, nullptr), \\\n\tvm.def(#OPNAME \"^\", 1, 1, FUNNAME##_pairs_, nullptr), \\\n\tvm.def(#OPNAME \"\\\\i\", 2, 1, FUNNAME##_iscan_, nullptr), \\\n\tvm.def(#OPNAME \"^i\", 1, 1, FUNNAME##_ipairs_, nullptr));\n\n#define DEF2(NAME, HELP) \tDEFNa2(NAME, NAME, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMathOps();\nvoid AddMathOps()\n{\t\n\tfillSineTable();\n\tfillDBAmpTable();\n\tfillDecayTable();\n fillFirstOrderCoeffTable();\n\n\tvm.addBifHelp(\"\\n*** unary math ops ***\");\n\tDEF(isalnum, \"return whether an ASCII value is alphanumeric.\")\n\tDEF(isalpha, \"return whether an ASCII value is alphabetic.\")\n\tDEF(isblank, \"return whether an ASCII value is a space or tab character.\")\n\tDEF(iscntrl, \"return whether an ASCII value is a control character.\")\n\tDEF(isdigit, \"return whether an ASCII value is a digit.\")\n\tDEF(isgraph, \"return whether an ASCII value is a graphic character.\");\n\tDEF(islower, \"return whether an ASCII value is lower case.\")\n\tDEF(isprint, \"return whether an ASCII value is a printable character.\")\n\tDEF(ispunct, \"return whether an ASCII value is a punctuation character.\")\n\tDEF(isspace, \"return whether an ASCII value is a graphic character.\")\n\tDEF(isupper, \"return whether an ASCII value is upper case.\")\n\tDEF(isxdigit, \"return whether an ASCII value is a hexadecimal digit.\")\n\tDEF(isascii, \"return whether a value is ASCII\")\n\n\tDEF(tolower, \"convert an ASCII character value to lower case.\")\n\tDEF(toupper, \"convert an ASCII character value to upper case.\")\n\tDEF(toascii, \"convert a value to ASCII by stripping the upper bits.\")\n\n\tDEFN(nonpos, \"0<=\", \"less than or equal to zero.\")\n\tDEFN(nonneg, \"0>=\", \"greater than or equal to zero.\")\n\tDEFN(isneg, \"0<\", \"less than zero.\")\n\tDEFN(ispos, \"0>\", \"greater than zero.\")\n\tDEFN(iszero, \"0=\", \"equal to zero.\")\n\tDEFN(iseven, \"even?\", \"is even.\")\n\tDEFN(isodd, \"odd?\", \"is odd.\")\n\tDEFN(isprime, \"prime?\", \"is prime.\")\n\tDEFN(isint, \"int?\", \"is integer.\")\n\t\n\tDEF(isfinite, \"is x a finite number.\")\n\tDEF(isinf, \"is x an infinity.\")\n\tDEF(isnan, \"is x not a number.\")\n\tDEF(isnormal, \"is x a normalized number (as opposed to denormals).\")\n\tDEF(signbit, \"sign bit of x.\")\n\t\t\n\tDEF(abs, \"absolute value.\")\n\tDEF(sgn, \"signum function. returns -1 when x < 0, 0 when x == 0, 1 when x > 0.\")\n\tDEFN(not, \"~\", \"logical negation. returns 1 when x == 0, else returns 0.\")\n\tDEF(neg, \"negative. -x\")\n\tDEF(sqrt, \"square root.\")\n\tDEF(cbrt, \"cube root.\")\n\tDEF(rsqrt, \"reciprocal square root.\")\n\tDEF(sq, \"square. x x *\")\n\tDEF(ssq, \"signed square. x x abs *\")\n\tDEF(cb, \"x cubed. x 3 ^\")\n\tDEFN(sq, \"^2\", \"x squared. x x *\")\n\tDEFN(cb, \"^3\", \"x cubed. x 3 ^\")\n\tDEFN(pow4, \"^4\", \"x to the fourth power. x 4 ^\")\n\tDEFN(pow5, \"^5\", \"x to the fifth power. x 5 ^\")\n\tDEFN(pow6, \"^6\", \"x to the sixth power. x 6 ^\")\n\tDEFN(pow7, \"^7\", \"x to the seventh power. x 7 ^\")\n\tDEFN(pow8, \"^8\", \"x to the eighth power. x 8 ^\")\n\tDEFN(pow9, \"^9\", \"x to the ninth power. x 9 ^\")\n\n\tDEF(recip, \"reciprocal.\")\n\tDEFN(recip, \"1/\", \"reciprocal. 1 x /\")\n\tDEF(exp, \"e to the x.\")\n\tDEF(exp2, \"2 to the x.\")\n\tDEF(exp10, \"10 to the x.\")\n\tDEFN(exp, \"e^\", \"e to the x.\")\n\tDEFN(exp2, \"2^\", \"2 to the x.\")\n\tDEFN(exp10, \"10^\", \"10 to the x.\")\n\tDEF(expm1, \"computes exp(x-1) accurately even for very small values of x.\")\n\tDEF(log, \"base e log of x.\")\n\tDEF(log2, \"base 2 log of x.\")\n\tDEF(log10, \"base 10 log of x.\")\n\tDEF(log1p, \"computes the value of log(1+x) accurately even for very small values of x.\")\n\tDEF(logb, \"x log2 floor\")\n\n\tDEF(frac, \"fractional part.\")\n\tDEF(floor, \"nearest integer <= x.\")\n\tDEF(ceil, \"nearest integer >= x.\")\n\tDEF(rint, \"nearest integer.\")\n\tDEF(erf, \"the error function.\")\n\tDEF(erfc, \"the complement of the error function.\")\n\n\tDEF(sinc, \"sinc. x sin x /\")\n\tDEF(sin, \"sine.\")\n\tDEF(cos, \"cosine.\")\n\tDEF(sin1, \"sine(x * 2pi).\")\n\tDEF(cos1, \"cosine(x * 2pi).\")\n\tDEF(tan, \"tangent.\")\n\tDEF(asin, \"arcsine.\")\n\tDEF(acos, \"arccosine.\")\n\tDEF(atan, \"arctangent.\")\n\tDEF(sinh, \"hyperbolic sine.\")\n\tDEF(cosh, \"hyperbolic cosine.\")\n\tDEF(tanh, \"hyperbolic tangent.\")\n\tDEF(asinh, \"hyperbolic arcsine.\")\n\tDEF(acosh, \"hyperbolic arccosine.\")\n\tDEF(atanh, \"hyperbolic arctangent.\")\n\t\n\tDEF(J0, \"zeroth Bessel function of the first kind evaluated at x.\")\n\tDEF(J1, \"first Bessel function of the first kind evaluated at x.\")\n\tDEF(Y0, \"zeroth Bessel function of the second kind evaluated at x.\")\n\tDEF(Y1, \"first Bessel function of the second kind evaluated at x.\")\n\n\tDEF(tgamma, \"the gamma function.\")\n\tDEF(lgamma, \"natural logarithm of the absolute value of the gamma function.\")\n\n\tDEF(inc, \"increment. x 1 +\")\n\tDEF(dec, \"decrement. x 1 -\")\n\tDEF(half, \"x .5 *\")\n\tDEF(twice, \"x 2 *\")\n\tDEFN(inc, \"++\", \"increment. x 1 +\")\n\tDEFN(dec, \"--\", \"decrement. x 1 -\")\n\tDEFN(half, \"/2\", \"half.\")\n\tDEFN(twice, \"*2\", \"twice.\")\n\tDEF(biuni, \"convert bipolar to unipolar. .5 * .5 +\")\n\tDEF(unibi, \"convert unipolar to bipolar. 2 * 1 -\")\n\tDEF(biunic, \"convert bipolar to unipolar with clipping to range. -1 1 clip .5 * .5 +\")\n\tDEF(unibic, \"convert unipolar to bipolar with clipping to range. 0 1 clip 2 * 1 -\")\n\tDEF(cmpl, \"unipolar complement. 1 x -\")\n\n\tDEF(ampdb, \"convert linear amplitude to decibels.\")\n\tDEF(dbamp, \"convert decibels to linear amplitude.\")\n\t\n\tDEF(ohz, \"convert octaves to Hertz. Octave 0.0 is middle C.\")\n\tDEF(hzo, \"convert Hertz to octaves. Octave 0.0 is middle C.\")\n\tDEF(nnhz, \"convert MIDI note numbers to Hertz. 60 is middle C.\")\n\tDEF(hznn, \"convert Hertz to MIDI note numbers. 60 is middle C.\")\n\n\tDEF(centsratio, \"convert an interval in cents to a ratio.\")\n\tDEF(ratiocents, \"convert a ratio to an interval in cents.\")\n\n\tDEF(semiratio, \"convert an interval in semitones to a ratio.\")\n\tDEF(ratiosemi, \"a ratio to an interval in semitones.\")\n\n\tDEF(minsec, \"convert from minutes to seconds. also for converting from bps to bpm\")\n\tDEF(secmin, \"convert from seconds to minutes. also for converting from bpm to bps.\")\n\tDEF(bpmsec, \"convert from beats per minute to a period in seconds(e.g. for delay times)\")\n\tDEF(degrad, \"convert from degrees to radians.\")\n\tDEF(raddeg, \"convert from radians to degrees.\")\n\n\tDEF(distort, \"sigmoid wave distortion function. x/sqrt(1 + x^2)\")\n\tDEF(softclip, \"sigmoid wave distortion function. returns x when abs(x) < .5, else returns (abs(x) - .25) / x\")\n\tDEF(sigm, \"sigmoid wave distortion function. x/sqrt(1+x*x).\")\n\n\tDEF(rectWin, \"rectangular window for x in the interval [0,1].\")\n\tDEF(triWin, \"triangular window for x in the interval [0,1].\")\n\tDEF(bitriWin, \"triangular window for x in the interval [-1,1]\")\n\tDEF(hanWin, \"hanning window for x in the interval [0,1]\")\n\tDEF(sinWin, \"sine window for x in the interval [0,1]\")\n\tDEF(ramp, \"return 0 when x <= 0, return x when 0 < x < 1, return 1 when x > 1.\")\n\tDEF(scurve, \"return 0 when x <= 0, return 3*x*x - 2*x*x*x when 0 < x < 1, return 1 when x > 1.\")\n\n\tDEF(zapgremlins, \"\")\n\n\t/////////////////////////////////////////////////////\n\n\tvm.addBifHelp(\"\\n*** binary math ops ***\");\n\tvm.addBifHelp(\"\\n All built-in binary math operators have the following variations defined:\");\n\tvm.addBifHelp(\" op/ (list --> z) reducing math operator.\");\n\tvm.addBifHelp(\" op\\\\ (list --> z) scanning math operator.\");\n\tvm.addBifHelp(\" op^ (list --> z) pairwise math operator.\");\n\tvm.addBifHelp(\" op/i (list init --> z) reducing math operator with initial value.\");\n\tvm.addBifHelp(\" op\\\\i (list init --> z) scanning math operator with initial value.\");\n\tvm.addBifHelp(\" op^i (list init --> z) pairwise math operator with initial value.\");\n\tvm.addBifHelp(\" For example, + has the following variations: +/ +\\\\ +^ +/i +\\\\i +^i\");\n\tvm.addBifHelp(\"\");\n\t\n\n\tvm.plusFun = DEFNa2(plus, +, \"addition.\")\n\tDEFNa2(plus_link, +>, \"addition. For lists, acts as if shorter list were extended with zeroes.\")\n\tDEFNa2(minus, -, \"subtraction.\")\n\tvm.mulFun = DEFNa2(mul, *, \"multiplication.\")\n\tDEFNa2(div, /, \"real division.\")\n\tDEFNa2(mod, %, \"modulo.\")\n\tDEF2(idiv, \"integer division.\")\n\tDEF2(imod, \"integer modulo.\")\n\tDEF2(remainder, \"remainder.\")\n\n\tDEFNa2(lt, <, \"less than.\")\n\tDEFNa2(le, <=, \"less than or equal.\")\n\tDEFNa2(gt, >, \"greater than.\")\n\tDEFNa2(ge, >=, \"greater than or equal.\")\n\tDEFNa2(eq, ==, \"equal.\")\n\tDEFNa2(ne, !=, \"not equal.\")\n\n\tDEF2(cmp, \"returns -1 when x < y, returns 1 when x > y, returns 0 when x == y.\")\n\n\tDEF2(copysign, \"copy the sign of y to the value of x.\")\n\tDEF2(nextafter, \"return the next machine representable number from x in direction y.\")\n\n\tDEF2(pow, \"x to the power y.\")\n\tDEFNa2(pow, ^, \"x to the power y.\")\n\tDEF2(atan2, \"arctangent of y/x.\")\n\t\n\tDEF2(Jn, \"yth Bessel function of the first kind evaluated at x.\")\n\tDEF2(Yn, \"yth Bessel function of the second kind evaluated at x.\")\n\n\tvm.minFun = DEFNa2(min, &, \"return the minimum of x and y. functions as logical AND.\")\n\tvm.maxFun = DEFNa2(max, |, \"return the maximum of x and y. functions as logical OR.\")\n\n\tDEF2(avg2, \"x y + .5 *\")\n\tDEF2(dim, \"positive difference of x and y. x y - 0 |\")\n\tDEF2(absdif, \"x y - abs\")\n\tDEF2(hypot, \"x sq y sq + sqrt\")\n\tDEF2(sumsq, \"x sq y sq +\")\n\tDEF2(difsq, \"x sq y sq -\")\n\tDEF2(sqsum, \"x y + sq\")\n\tDEF2(sqdif, \"x y - sq\")\n\n\tDEF2(thresh, \"returns 0 when x < y, else returns x.\")\n\tDEF2(absthresh, \"returns 0 when |x| < y, else returns x.\")\n\tDEF2(amclip, \"returns 0 when y <= 0, else returns x*y.\")\n\tDEF2(scaleneg, \"returns x*y when x < 0, else returns x.\")\n\n\tDEF2(ring1, \"x y * x +\")\n\tDEF2(ring2, \"x y * x + y +\")\n\tDEF2(ring3, \"x sq y *\")\n\tDEF2(ring4, \"x y * x y - *\")\n\n\tDEF2(gcd, \"greatest common divisor.\")\n\tDEF2(lcm, \"least common multiple.\")\n\n\tDEF2(clip0, \"clip x between 0 and y.\")\n\tDEF2(wrap0, \"wrap x between 0 and y.\")\n\tDEF2(fold0, \"fold x between 0 and y.\")\n\n\tDEF2(clip2, \"clip x between -y and y.\")\n\tDEF2(wrap2, \"wrap x between -y and y.\")\n\tDEF2(fold2, \"fold x between -y and y.\")\n\tDEF2(iwrap2, \"wrap integer x between -y and y.\")\n\tDEF2(ifold2, \"fold integer x between -y and y.\")\n\tDEF2(excess, \"return the excess after clipping. x x y clip2 -\")\n\n\tDEF2(round, \"round x to nearest multiple of y.\")\n\tDEF2(roundUp, \"round x to nearest multiple of y >= x.\")\n\tDEF2(trunc, \"round x to nearest multiple of y <= x\")\n\n}\n\n"], ["/sapf/src/RandomOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n#include \n#include \"MultichannelExpansion.hpp\"\n#include \"UGen.hpp\"\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark RANDOM STREAMS\n\n\ntemplate \nvoid swapifgt(T& a, T& b) { \n\tif (a > b) {\n\t\tT t = a;\n\t\ta = b;\n\t\tb = t;\n\t}\n}\n\n\nstruct URand : ZeroInputGen\n{\t\n RGen r;\n \n\tURand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct URandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tURandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"URandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\n\nstruct NURand : NZeroInputGen\n{\t\n RGen r;\n \n\tNURand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct NURandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNURandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NURandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand();\n\t\t}\n\t}\n};\n\nstruct BRand : ZeroInputGen\n{\t\n RGen r;\n \n\tBRand(Thread& th) : ZeroInputGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct BRandz : ZeroInputUGen\n{\t\n RGen r;\n \n\tBRandz(Thread& th) : ZeroInputUGen(th, false) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct NBRand : NZeroInputGen\n{\t\n RGen r;\n \n\tNBRand(Thread& th, int64_t n) : NZeroInputGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\nstruct NBRandz : NZeroInputUGen\n{\t\n RGen r;\n \n\tNBRandz(Thread& th, int64_t n) : NZeroInputUGen(th, n) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NBRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = r.drand2();\n\t\t}\n\t}\n};\n\n\nstruct Rand : TwoInputGen\n{\t\n RGen r;\n \n\tRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Randz : TwoInputUGen\n{\t\n RGen r;\n \n\tRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Randz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = a + (b - a) * r.drand();\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void urands_(Thread& th, Prim* prim)\n{\n\tGen* g = new URand(th);\n\tth.push(new List(g));\n}\n\nstatic void urandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new URandz(th);\n\tth.push(new List(g));\n}\n\nstatic void brands_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRand(th);\n\tth.push(new List(g));\n}\n\nstatic void brandz_(Thread& th, Prim* prim)\n{\n\tGen* g = new BRandz(th);\n\tth.push(new List(g));\n}\n\nstatic void nurands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurands : n\");\n\tGen* g = new NURand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nurandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nurandz : n\");\n\tGen* g = new NURandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrands_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrands : n\");\n\tGen* g = new NBRand(th, n);\n\tth.push(new List(g));\n}\n\nstatic void nbrandz_(Thread& th, Prim* prim)\n{\n\tint64_t n = th.popInt(\"nbrandz : n\");\n\tGen* g = new NBRandz(th, n);\n\tth.push(new List(g));\n}\n\nstatic void rands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new Rand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void randz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"randz : hi\");\n\tV a = th.popZIn(\"randz : lo\");\n\t\n\tGen* g = new Randz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrands : n\");\n\t\n\tGen* g = new NRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nrandz : hi\");\n\tV a = th.popZIn(\"nrandz : lo\");\n\tint64_t n = th.popInt(\"nrandz : n\");\n\t\n\tGen* g = new NRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void urand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand();\n\tth.push(z);\n}\n\nstatic void brand_(Thread& th, Prim* prim)\n{\n\tZ z = th.rgen.drand2();\n\tth.push(z);\n}\n\n\nstatic void newseed_(Thread& th, Prim* prim)\n{\n\tV v;\n\tv.i = timeseed();\n\tth.push(v);\n}\n\nstatic void setseed_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tif (!v.isReal()) wrongType(\"setseed : seed\", \"Float\", v);\n\tth.rgen.init(v.i);\n}\n\nstatic void rand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"rand : hi\");\n\tZ a = th.popFloat(\"rand : lo\");\n\t\n\tswapifgt(a, b);\n\tZ z = th.rgen.rand(a, b);\n\tth.push(z);\n}\n\nstruct Coin : OneInputGen\n{\t\n RGen r;\n \n\tCoin(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Coinz : OneInputUGen\n{\t\n RGen r;\n \n\tCoinz(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Coinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoin : NOneInputGen\n{\t\n RGen r;\n \n\tNCoin(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoin\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NCoinz : NOneInputUGen\n{\t\n RGen r;\n \n\tNCoinz(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NCoinz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = r.coin(a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void coin_(Thread& th, Prim* prim)\n{\n\tZ p = th.popFloat(\"coin : p\");\n\t\n\tZ z = th.rgen.coin(p);\n\tth.push(z);\n}\n\nstatic void coins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coin(th, a);\n\tth.push(new List(g));\n}\n\nstatic void coinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Coinz(th, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoins_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoins : n\");\n\t\n\tGen* g = new NCoin(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void ncoinz_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"ncoinz : n\");\n\t\n\tGen* g = new NCoinz(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstruct IRand : TwoInputGen\n{\t\n RGen r;\n \n\tIRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tIRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NIRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNIRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)aa->asInt();\n\t\t\tint32_t b = (int32_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)aa->asInt(); aa += astride;\n\t\t\t\tint32_t b = (int32_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNIRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint32_t a = (int32_t)*aa;\n\t\t\tint32_t b = (int32_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint32_t a = (int32_t)*aa; aa += astride;\n\t\t\t\tint32_t b = (int32_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new IRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"irandz : hi\");\n\tV a = th.popZIn(\"irandz : lo\");\n\t\n\tGen* g = new IRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirands : n\");\n\t\n\tGen* g = new NIRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nirandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nirandz : hi\");\n\tV a = th.popZIn(\"nirandz : lo\");\n\tint64_t n = th.popInt(\"nirandz : n\");\n\t\n\tGen* g = new NIRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void irand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"irand : hi\");\n\tint64_t a = th.popInt(\"irand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tswapifgt(a, b);\n\tZ z = (Z)r.irand(a, b);\n\tth.push(z);\n}\n\n\nstruct ExcRand : TwoInputGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExcRandz : TwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tExcRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExcRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\t\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExcRand : NTwoInputGen\n{\t\n RGen r;\n \tint64_t prev;\n \n\tNExcRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExcRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n \n\t\t\t\tint64_t x = r.irand(a, b);\n\t\t\t\tif (x == prev) x = b;\n\t\t\t\tprev = x;\n\t\t\t\tout[i] = (Z)x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExcRandz : NTwoInputUGen\n{\t\n RGen r;\n\tint64_t prev;\n \n\tNExcRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b), prev(INT32_MIN)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void eprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExcRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void eprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprandz : hi\");\n\tV a = th.popZIn(\"eprandz : lo\");\n\t\n\tGen* g = new ExcRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"neprands : n\");\n\t\n\tGen* g = new NExcRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void neprandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"eprands : hi\");\n\tV a = th.popZIn(\"eprands : lo\");\n\tint64_t n = th.popInt(\"neprandz : n\");\n\t\n\tGen* g = new NExcRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstruct ExpRand : TwoInputGen\n{\t\n RGen r;\n \n\tExpRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ExpRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tExpRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NExpRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNExpRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NExpRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNExpRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NExpRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.xrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void xrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ExpRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"xrandz : hi\");\n\tV a = th.popZIn(\"xrandz : lo\");\n\t\n\tGen* g = new ExpRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nxrands : n\");\n\t\n\tGen* g = new NExpRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nxrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nxrandz : hi\");\n\tV a = th.popZIn(\"nxrandz : lo\");\n\tint64_t n = th.popInt(\"xrandz : n\");\n\t\n\tGen* g = new NExpRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void xrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"xrand : hi\");\n\tZ a = th.popFloat(\"xrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.xrand(a, b);\n\tth.push(z);\n}\n\nstruct ILinRand : TwoInputGen\n{\t\n RGen r;\n \n\tILinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.irand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct ILinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tILinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NILinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNILinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)aa->asInt();\n\t\t\tint64_t b = (int64_t)bb->asInt();\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)aa->asInt(); aa += astride;\n\t\t\t\tint64_t b = (int64_t)bb->asInt(); bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NILinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNILinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NILinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int astride, int bstride) \n\t{\n\t\tif (astride == 0 && bstride == 0) {\n\t\t\tint64_t a = (int64_t)*aa;\n\t\t\tint64_t b = (int64_t)*bb;\n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t a = (int64_t)*aa; aa += astride;\n\t\t\t\tint64_t b = (int64_t)*bb; bb += bstride;\n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = (Z)r.ilinrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void ilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new ILinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"ilinrandz : hi\");\n\tV a = th.popZIn(\"ilinrandz : lo\");\n\t\n\tGen* g = new ILinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nilinrands : n\");\n\t\n\tGen* g = new NILinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nilinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"nilinrandz : hi\");\n\tV a = th.popZIn(\"nilinrandz : lo\");\n\tint64_t n = th.popInt(\"nilinrandz : n\");\n\t\n\tGen* g = new NILinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void ilinrand_(Thread& th, Prim* prim)\n{\n\tint64_t b = th.popInt(\"ilinrand : hi\");\n\tint64_t a = th.popInt(\"ilinrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tint64_t x;\n\tif (b < a) { x = a; a = b; b = x; }\n\tZ z = (Z)r.ilinrand(a, b);\n\tth.push(z);\n}\n\n\n\nstruct LinRand : TwoInputGen\n{\t\n RGen r;\n \n\tLinRand(Thread& th, Arg a, Arg b) : TwoInputGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct LinRandz : TwoInputUGen\n{\t\n RGen r;\n \n\tLinRandz(Thread& th, Arg a, Arg b) : TwoInputUGen(th, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct NLinRand : NTwoInputGen\n{\t\n RGen r;\n \n\tNLinRand(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRand\"; }\n \n\tvoid calc(int n, V* out, V* aa, V* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ b = bb->asFloat(); \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tZ b = bb->asFloat(); bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NLinRandz : NTwoInputUGen\n{\t\n RGen r;\n \n\tNLinRandz(Thread& th, int64_t n, Arg a, Arg b) : NTwoInputUGen(th, n, a, b) \n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NLinRandz\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, Z* bb, int aStride, int bStride) \n\t{\n\t\tif (aStride == 0 && bStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ b = *bb; \n\t\t\tswapifgt(a, b);\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ b = *bb; bb += bStride; \n\t\t\t\tswapifgt(a, b);\n\t\t\t\tout[i] = r.linrand(a, b);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void linrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\t\n\tGen* g = new LinRand(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\t\n\tGen* g = new LinRandz(th, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrands_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"linrandz : n\");\n\t\n\tGen* g = new NLinRand(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void nlinrandz_(Thread& th, Prim* prim)\n{\n\tV b = th.popZIn(\"linrandz : hi\");\n\tV a = th.popZIn(\"linrandz : lo\");\n\tint64_t n = th.popInt(\"randz : n\");\n\t\n\tGen* g = new NLinRandz(th, n, a, b);\n\tth.push(new List(g));\n}\n\nstatic void linrand_(Thread& th, Prim* prim)\n{\n\tZ b = th.popFloat(\"linrand : hi\");\n\tZ a = th.popFloat(\"linrand : lo\");\n\tRGen& r = th.rgen;\n\t\n\tif (b < a) { Z x; x = a; a = b; b = x; }\n\tZ z = r.linrand(a, b);\n\tth.push(z);\n}\n\n\nstruct Rand2 : OneInputGen\n{\t\n RGen r;\n \n\tRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Rand2z : OneInputUGen\n{\t\n RGen r;\n \n\tRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Rand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct XorNoise1 : OneInputUGen\n{\t\n uint64_t x = 0xA40203C12F2AD936LL;\n\t\n\tXorNoise1(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise1\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tx = xorshift64star(x);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstruct XorNoise2 : OneInputUGen\n{\t\n uint64_t s[2] = { 0xA40203C12F2AD936LL, 0x9E390BD16B74D6D3LL };\n\t\n\tXorNoise2(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XorNoise2\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint64_t x = xorshift128plus(s);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint32_t raprng(uint64_t i, uint64_t seed)\n{\n// http://cessu.blogspot.com/2008/11/random-access-pseudo-random-numbers.html\n uint64_t r = (2857720171ULL * ((uint32_t) i)) ^ 0x1EF57D8A7B344E7BULL;\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n r += r >> 32;\n r = (2857720171ULL * ((uint32_t) (i ^ r))) ^ (0xD9EA571C8AF880B6ULL + seed);\n r ^= r >> 29;\n r += r << 16;\n r ^= r >> 21;\n return uint32_t(r + (r >> 32));\n}\n\n\nstruct RandomAccessNoise : OneInputUGen\n{\n uint64_t seed = 0xA40203C12F2AD936LL;\n\tuint64_t k = 0;\n\t\n\tRandomAccessNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RandomAccessNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = raprng(k++, seed);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t hash64shift(uint64_t key)\n{\n key = (~key) + (key << 21); // key = (key << 21) - key - 1;\n key = key ^ (key >> 24);\n key = (key + (key << 3)) + (key << 8); // key * 265\n key = key ^ (key >> 14);\n key = (key + (key << 2)) + (key << 4); // key * 21\n key = key ^ (key >> 28);\n key = key + (key << 31);\n return key;\n}\n\nstruct WangNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tWangNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WangNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)hash64shift(k++);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\ninline uint64_t Hash128to64(uint64_t x, uint64_t y) {\n\tconst uint64_t kMul = 0x9ddfea08eb382d69ULL;\n\tuint64_t a = (x ^ y) * kMul;\n\ta ^= (a >> 47);\n\tuint64_t b = (y ^ a) * kMul;\n\tb ^= (b >> 47);\n\tb *= kMul;\n\treturn b;\n}\n\n\nstruct CityNoise : OneInputUGen\n{\t\n\tuint64_t k = 0xA40203C12F2AD936LL;\n\t\n\tCityNoise(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"CityNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tuint32_t x = (uint32_t)Hash128to64(k++, 0x1EF57D8A7B344E7BULL);\n\t\t\t\tout[i] = itof2(x,a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Violet : OneInputUGen\n{\t\n RGen r;\n\tZ prev;\n \n\tViolet(Thread& th, Arg a) : OneInputUGen(th, a), prev(0.)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Violet\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = .5 * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x = a * r.drand() - a2;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tZ x = a * r.drand() - .5 * a;\n\t\t\t\tout[i] = x - prev;\n\t\t\t\tprev = x;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2 = 2. * a;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = a2 * r.drand() - a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = 2. * a * r.drand() - a;\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void rand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2s : n\");\n\t\n\tGen* g = new NRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nrand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nrand2z : n\");\n\t\n\tGen* g = new NRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\n\nstatic void white_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Rand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void wangwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"wangwhite : a\");\n\tGen* g = new WangNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void citywhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"citywhite : a\");\n\tGen* g = new CityNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void rawhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"rawhite : a\");\n\tGen* g = new RandomAccessNoise(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite : a\");\n\tGen* g = new XorNoise1(th, a);\n\tth.push(new List(g));\n}\n\nstatic void xorwhite2_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"xorwhite2 : a\");\n\tGen* g = new XorNoise2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void violet_(Thread& th, Prim* prim)\n{\n\t// synonym for rand2z\n\tV a = th.popZIn(\"white : a\");\n\tGen* g = new Violet(th, a);\n\tth.push(new List(g));\n}\n\n\nstatic void rand2_(Thread& th, Prim* prim)\n{\n\tZ a = th.popFloat(\"rand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = 2. * a * r.drand() - a;\n\tth.push(z);\n}\n\nstruct IRand2 : OneInputGen\n{\t\n RGen r;\n \n\tIRand2(Thread& th, Arg a) : OneInputGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct IRand2z : OneInputUGen\n{\t\n RGen r;\n \n\tIRand2z(Thread& th, Arg a) : OneInputUGen(th, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"IRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2 : NOneInputGen\n{\t\n RGen r;\n \n\tNIRand2(Thread& th, int64_t n, Arg a) : NOneInputGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2\"; }\n \n\tvoid calc(int n, V* out, V* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = aa->asFloat();\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = aa->asFloat(); aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NIRand2z : NOneInputUGen\n{\t\n RGen r;\n \n\tNIRand2z(Thread& th, int64_t n, Arg a) : NOneInputUGen(th, n, a)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NIRand2z\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa;\n\t\t\tZ a2p1 = 2. * a + 1.;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = floor(a2p1 * r.drand() - a);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa; aa += aStride;\n\t\t\t\tout[i] = floor((2. * a + 1.) * r.drand() - a);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\nstatic void irand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2(th, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\t\n\tGen* g = new IRand2z(th, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2s_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2s : n\");\n\t\n\tGen* g = new NIRand2(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void nirand2z_(Thread& th, Prim* prim)\n{\n\tV a = th.pop();\n\tint64_t n = th.popInt(\"nirand2z : n\");\n\t\n\tGen* g = new NIRand2z(th, n, a);\n\tth.push(new List(g));\n}\n\nstatic void irand2_(Thread& th, Prim* prim)\n{\n\tint64_t a = th.popInt(\"irand2 : a\");\n\tRGen& r = th.rgen;\n\t\n\tZ z = floor((2. * a + 1.) * r.drand() - a);\n\tth.push(z);\n}\n\n\nstruct Pick : ZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPick(Thread& th, P const& array) : ZeroInputGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct Pickz : ZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tPickz(Thread& th, P const& array) : ZeroInputUGen(th, false), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Pickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstruct NPick : NZeroInputGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPick(Thread& th, int64_t n, P const& array) : NZeroInputGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = items[r.irand0(hi)];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NPickz : NZeroInputUGen\n{\n\tP _array;\n\tRGen r;\n\t\n\tNPickz(Thread& th, int64_t n, P const& array) : NZeroInputUGen(th, n), _array(array)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t hi = _array->size();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = items[r.irand0(hi)];\n\t\t}\n\t}\n};\n\nstatic void picks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"picks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"picks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pick(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new Pickz(th, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npicks_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npicks : list\");\n\tint64_t n = th.popInt(\"npicks : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npicks : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPick(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void npickz_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"npickz : list\");\n\tint64_t n = th.popInt(\"npickz : n\");\n \n\tif (!a->isFinite())\n\t\tindefiniteOp(\"npickz : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\t\n\tGen* g = new NPickz(th, n, a->mArray);\n\tth.push(new List(g));\n}\n\nstatic void pick_(Thread& th, Prim* prim)\n{\n\tP a = th.popList(\"pick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"pick : list must be finite\",\"\");\n \n\ta = a->pack(th);\n\tint64_t n = a->mArray->size();\n\tth.push(a->at(th.rgen.irand0(n)));\n}\n\nstatic int64_t weightIndex(int64_t n, Z* z, Z r)\n{\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += z[i];\n\t\tif (r < sum) {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn n-1;\n}\n\nstruct WPick : ZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPick(Thread& th, P const& array, P const& weights) : ZeroInputGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct WPickz : ZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tWPickz(Thread& th, P const& array, P const& weights) : ZeroInputUGen(th, false), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstruct NWPick : NZeroInputGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPick(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPick\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tif (_array->isZ()) {\n\t\t\tZ* items = _array->z();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t} else {\n\t\t\tV* items = _array->v();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\t\tout[i] = items[j];\n\t\t\t}\n\t\t}\n\t}\n};\n\nstruct NWPickz : NZeroInputUGen\n{\n\tP _array;\n\tP _weights;\n\tRGen r;\n\t\n\tNWPickz(Thread& th, int64_t n, P const& array, P const& weights) : NZeroInputUGen(th, n), _array(array), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWPickz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t an = _array->size();\n\t\tZ* w = _weights->z();\n\t\tZ* items = _array->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint64_t j = weightIndex(an, w, r.drand());\n\t\t\tout[i] = items[j];\n\t\t}\n\t}\n};\n\nstatic P sumWeights(P& weights)\n{\n\tconst int64_t n = weights->size();\n\n\tP summedWeights = new Array(itemTypeZ, n);\n\tsummedWeights->setSize(n);\n\t\n\tZ sum = 0.;\n\tZ* z = summedWeights->z();\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += weights->atz(i);\n\t\tz[i] = sum;\n\t}\n\tZ scale = 1. / sum;\n\t\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tz[i] *= scale;\n\t}\n\t\n\treturn summedWeights;\n}\n\nstatic void wpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpicks : weights\");\n\tP a = th.popList(\"wpicks : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new WPick(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void wpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpickz : weights\");\n\tP a = th.popList(\"wpickz : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n \n\tGen* g = new WPickz(th, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpicks_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpicks : weights\");\n\tP a = th.popList(\"nwpicks : list\");\n\tint64_t n = th.popInt(\"nwpicks : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpicks : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpicks : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPick(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwpickz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwpickz : weights\");\n\tP a = th.popList(\"nwpickz : list\");\n\tint64_t n = th.popInt(\"nwpickz : n\");\n\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"nwpickz : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwpickz : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->packz(th);\n\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\n\tif (aa->size() != wa->size()) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tGen* g = new NWPickz(th, n, aa, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wpick_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wpick : weights\");\n\tP a = th.popList(\"wpick : list\");\n\tif (!a->isFinite())\n\t\tindefiniteOp(\"wpick : list must be finite\",\"\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wpick : weights must be finite\",\"\");\n\t\n\ta = a->pack(th);\n\tw = w->pack(th);\n\t\n\tP aa = a->mArray;\n\tP wa = w->mArray;\n\tconst int64_t n = aa->size();\n\tconst int64_t wn = wa->size();\n\n\tif (n != wn) {\n\t\tpost(\"list and weights are not the same length.\\n\");\n\t\tthrow errFailed;\n\t}\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push(aa->at(i));\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push(aa->at(n-1));\n}\n\n\nstruct WRand : ZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRand(Thread& th, P const& weights) : ZeroInputGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct WRandz : ZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tWRandz(Thread& th, P const& weights) : ZeroInputUGen(th, false), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"WRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRand : NZeroInputGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRand(Thread& th, int64_t n, P const& weights) : NZeroInputGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRand\"; }\n \n\tvoid calc(int n, V* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\nstruct NWRandz : NZeroInputUGen\n{\n\tP _weights;\n\tRGen r;\n\t\n\tNWRandz(Thread& th, int64_t n, P const& weights) : NZeroInputUGen(th, n), _weights(weights)\n\t{\n\t\tr.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"NWRandz\"; }\n \n\tvoid calc(int n, Z* out) \n\t{\n\t\tint64_t wn = _weights->size();\n\t\tZ* w = _weights->z();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = (Z)weightIndex(wn, w, r.drand());\n\t\t}\n\t}\n};\n\n\nstatic void wrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrands : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRand(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void wrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrandz : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new WRandz(th, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrands_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrands : weights\");\n\tint64_t n = th.popInt(\"nwrands : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrands : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRand(th, n, wa);\n\tth.push(new List(g));\n}\n\nstatic void nwrandz_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"nwrandz : weights\");\n\tint64_t n = th.popInt(\"nwrandz : n\");\n\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"nwrandz : weights must be finite\",\"\");\n\t\n\tw = w->packz(th);\n\n\tP wa = w->mArray;\n\n\tGen* g = new NWRandz(th, n, wa);\n\tth.push(new List(g));\n}\n\n\nstatic void wrand_(Thread& th, Prim* prim)\n{\n\tP w = th.popList(\"wrand : weights\");\n\tif (!w->isFinite())\n\t\tindefiniteOp(\"wrand : weights must be finite\",\"\");\n\t\n\tw = w->pack(th);\n\t\n\tP wa = w->mArray;\n\tconst int64_t n = wa->size();\n\n\tconst Z r = th.rgen.drand();\n\tZ sum = 0.;\n\tfor (int64_t i = 0; i < n-1; ++i) {\n\t\tsum += wa->atz(i);\n\t\tif (r < sum) {\n\t\t\tth.push((Z)i);\n\t\t\treturn;\n\t\t}\n\t}\n\tth.push((Z)(n-1));\n}\n\n\nstruct GrayNoise : OneInputUGen\n{\t\n RGen r;\n\tint32_t counter_;\n \n\tGrayNoise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"GrayNoise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 4.65661287308e-10f;\n\t\tint32_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= int32_t(1) << (r.trand() & 31);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstruct Gray64Noise : OneInputUGen\n{\t\n RGen r;\n\tint64_t counter_;\n \n\tGray64Noise(Thread& th, Arg a) : OneInputUGen(th, a), counter_(0)\n\t{\n r.init(th.rgen.trand());\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Gray64Noise\"; }\n \n\tvoid calc(int n, Z* out, Z* aa, int aStride) \n\t{\n\t\tZ K = 1.084202172485504434e-19;\n\t\tint64_t counter = counter_;\n\t\tif (aStride == 0) {\n\t\t\tZ a = *aa * K;\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ a = *aa * K; aa += aStride;\n\t\t\t\tcounter ^= 1LL << (r.trand() & 63);\n\t\t\t\tout[i] = counter * a;\n\t\t\t}\n\t\t}\n\t\tcounter_ = counter;\n\t}\n};\n\nstatic void gray_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray : a\");\n\t\n\tth.push(new List(new GrayNoise(th, a)));\n}\n\nstatic void gray64_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"gray64 : a\");\n\t\n\tth.push(new List(new Gray64Noise(th, a)));\n}\n\nstruct PinkNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tout[i] = *aa * (u.f - 3.);\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct PinkNoise0 : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\t\n\tPinkNoise0(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tdice[i] = 0;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"PinkNoise0\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\tconst double scale = pow(2.,-47.)/17.;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tout[i] = *aa * (scale * double(total + newrand)) - 1;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct BlueNoise : Gen\n{\n\tZIn _a;\n\tuint64_t dice[16];\n\tuint64_t total_;\n\tZ prev;\n\t\n\tBlueNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a), prev(0.)\n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\tfor (int i = 0; i < 16; ++i) {\n\t\t\tint64_t x = (uint64_t)r.trand() >> 16;\n\t\t\ttotal_ += x;\n\t\t\tdice[i] = x;\n\t\t}\n\t}\n \n\tvirtual const char* TypeName() const override { return \"BlueNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tuint64_t total = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tuint64_t newrand = r.trand(); // Magnus Jonsson's suggestion.\n\t\t\t\t\tuint32_t counter = (uint32_t)newrand;\n\t\t\t\t\tnewrand = newrand >> 16;\n\t\t\t\t\tint k = (CTZ(counter)) & 15;\n\t\t\t\t\tuint64_t prevrand = dice[k];\n\t\t\t\t\tdice[k] = newrand;\n\t\t\t\t\ttotal += (newrand - prevrand);\n\t\t\t\t\tnewrand = (uint64_t)r.trand() >> 16;\n\t\t\t\t\tunion { int64_t i; double f; } u;\n\t\t\t\t\tu.i = (total + newrand) | 0x4000000000000000LL;\n\t\t\t\t\tZ x = 4. * *aa * (u.f - 3.);\n\t\t\t\t\tout[i] = x - prev;\n\t\t\t\t\tprev = x;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = total;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void pink_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink : a\");\n\t\n\tth.push(new List(new PinkNoise(th, a)));\n}\n\nstatic void pink0_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"pink0 : a\");\n\t\n\tth.push(new List(new PinkNoise0(th, a)));\n}\n\nstatic void blue_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"blue : a\");\n\t\n\tth.push(new List(new BlueNoise(th, a)));\n}\n\n\nstruct BrownNoise : Gen\n{\n\tZIn _a;\n\tZ total_;\n\t\n\tBrownNoise(Thread& th, Arg a)\n : Gen(th, itemTypeZ, a.isFinite()), _a(a) \n\t{\n\t\ttotal_ = 0;\n\t\tRGen& r = th.rgen;\n\t\ttotal_ = r.drand2();\n \n\t}\n \n\tvirtual const char* TypeName() const override { return \"BrownNoise\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ z = total_;\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *aa;\n\t\t\tif (_a(th, n,astride, aa)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tz += r.drand16();\n\t\t\t\t\tif (z > 1.) z = 2. - z;\n\t\t\t\t\telse if (z < -1.) z = -2. - z;\n\t\t\t\t\tout[i] = *aa * z;\n\t\t\t\t\taa += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\ttotal_ = z;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void brown_(Thread& th, Prim* prim)\n{\n\tV a = th.popZIn(\"brown : a\");\n\t\n\tth.push(new List(new BrownNoise(th, a)));\n}\n\nstruct Dust : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * z / thresh : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Dust2 : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tDust2(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Dust2\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? *amp * (2. * z / thresh - 1.) : 0.;\n\t\t\t\t\tdensity += densityStride;\n\t\t\t\t\tamp += ampStride;\n\t\t\t\t}\n\t\t\t\t_density.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Velvet : Gen\n{\n\tZIn _density;\n\tZIn _amp;\n\tZ _densmul;\n\t\n\tVelvet(Thread& th, Arg density, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(density, amp)), _density(density), _amp(amp), _densmul(th.rate.invSampleRate)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Velvet\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tRGen& r = th.rgen;\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint densityStride, ampStride;\n\t\t\tZ *density, *amp;\n\t\t\tif (_density(th, n, densityStride, density) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ thresh = *density * _densmul;\n\t\t\t\t\tZ thresh2 = .5 * thresh;\n\t\t\t\t\tZ z = r.drand();\n\t\t\t\t\tout[i] = z < thresh ? (zfulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x - y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct TooshPlus : Gen\n{\n\tZIn _delay;\n\tZIn _amp;\n\tint64_t _counter;\n\tZ sampleRate;\n\t\n\tTooshPlus(Thread& th, Arg delay, Arg amp)\n : Gen(th, itemTypeZ, mostFinite(delay, amp)), _delay(delay), _amp(amp), sampleRate(th.rate.sampleRate)\n\t{\n\t\t_counter = th.rgen.trand();\n\t}\n \n\tvirtual const char* TypeName() const override { return \"TooshPlus\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint delayStride, ampStride;\n\t\t\tZ *delay, *amp;\n\t\t\tif (_delay(th, n, delayStride, delay) || _amp(th, n, ampStride, amp)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tif (delayStride) {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tdelay += delayStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tint64_t delaySamples = (int64_t)floor(sampleRate * *delay + .5);\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ x = HashRand(_counter);\n\t\t\t\t\t\tZ y = HashRand(_counter - delaySamples);\n\t\t\t\t\t\tout[i] = .5 * *amp * (x + y);\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t++_counter;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_delay.advance(n);\n\t\t\t\t_amp.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic void toosh_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"toosh : amp\");\n\tV delay = th.popZIn(\"toosh : delay\");\n \n\tth.push(new List(new Toosh(th, delay, amp)));\n}\n\nstatic void tooshp_(Thread& th, Prim* prim)\n{\n\tV amp = th.popZIn(\"tooshp : amp\");\n\tV delay = th.popZIn(\"tooshp : delay\");\n \n\tth.push(new List(new TooshPlus(th, delay, amp)));\n}\n\nstruct Crackle : Gen\n{\n\tZIn _param;\n\tZ _y1, _y2;\n\t\n\tCrackle(Thread& th, Arg param) \n : Gen(th, itemTypeZ, param.isFinite()), _param(param), _y1(th.rgen.drand()), _y2(0.)\n\t{\n\t}\n \n\tvirtual const char* TypeName() const override { return \"Crackle\"; }\n\t\n\tvirtual void pull(Thread& th) override {\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint paramStride;\n\t\t\tZ *param;\n\t\t\tif (_param(th, n, paramStride, param)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n Z y1 = _y1;\n Z y2 = _y2;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n Z y0 = fabs(y1 * *param - y2 - 0.05);\n y2 = y1; y1 = y0;\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\tparam += paramStride;\n\t\t\t\t}\n _y1 = y1;\n _y2 = y2;\n\t\t\t\t_param.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void crackle_(Thread& th, Prim* prim)\n{\n\tV param = th.popZIn(\"cracke : param\");\n \n\tth.push(new List(new Crackle(th, param)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD RANDOM OPS\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n\nvoid AddRandomOps();\nvoid AddRandomOps()\n{\n\tvm.addBifHelp(\"\\n*** random number generation ***\");\n\n\tDEFnoeach(newseed, 0, 1, \"(--> seed) make a new random seed.\");\n\tDEFnoeach(setseed, 1, 0, \"(seed -->) set the random seed.\");\n\n\t\n\tvm.addBifHelp(\"\\n*** single random numbers ***\");\n\tDEFAM(rand, kk, \"(a b --> r) return a uniformly distributed random real value from a to b.\")\n\tDEFAM(coin, k, \"(p --> r) return 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(rand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(irand, kk, \"(a b --> r) return a uniformly distributed random integer value from a to b.\")\n\tDEFAM(irand2, k, \"(a --> r) return a uniformly distributed random real value from -a to +a.\")\n\tDEFAM(xrand, kk, \"(a b --> r) return a exponentially distributed random real value from a to b.\") \n\tDEFAM(linrand, kk, \"(a b --> r) return a linearly distributed random real value from a to b.\")\t \n\tDEFAM(ilinrand, kk, \"(a b --> r) return a linearly distributed random integer value from a to b.\") \n\tDEF(wrand, 1, 1, \"(w --> r) return a randomly chosen index from a list of probability weights. w should sum to one.\") \n\tDEF(pick, 1, 1, \"(a --> r) return a randomly chosen element from the finite list a.\") \n\tDEF(wpick, 2, 1, \"(a w --> r) return a randomly chosen element from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random streams ***\");\n\tDEFAM(rands, kk, \"(a b --> r) return a stream of uniformly distributed random real values from a to b.\")\n\tDEFAM(coins, k, \"(p --> r) return a stream of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(eprands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b, excluding the previously returned value.\")\t\n\tDEFAM(rand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(irands, kk, \"(a b --> r) return a stream of uniformly distributed random integer values from a to b.\")\n\tDEFAM(irand2s, k, \"(a --> r) return a stream of uniformly distributed random real values from -a to +a.\")\n\tDEFAM(xrands, kk, \"(a b --> r) return a stream of exponentially distributed random real values from a to b.\")\n\tDEFAM(linrands, kk, \"(a b --> r) return a stream of linearly distributed random real values from a to b.\")\n\tDEFAM(ilinrands, kk, \"(a b --> r) return a stream of linearly distributed random integer values from a to b.\")\n\tDEF(wrands, 1, 1, \"(w --> r) return a stream of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEF(picks, 1, 1, \"(a --> r) return a stream of randomly chosen elements from the finite list a.\") \n\tDEF(wpicks, 2, 1, \"(a w --> r) return a stream of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** random signals ***\");\n\tDEFMCX(randz, 2, \"(a b --> r) return a signal of uniformly distributed random real values from a to b.\")\n\tDEFMCX(coinz, 1, \"(p --> r) return a signal of 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(eprandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(rand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(irandz, 2, \"(a b --> r) return a signal of uniformly distributed random integer values from a to b.\")\n\tDEFMCX(irand2z, 1, \"(a --> r) return a signal of uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(xrandz, 2, \"(a b --> r) return a signal of exponentially distributed random real values from a to b.\")\n\tDEFMCX(linrandz, 2, \"(a b --> r) return a signal of linearly distributed random real values from a to b.\")\n\tDEFMCX(ilinrandz, 2, \"(a b --> r) return a signal of linearly distributed random integer values from a to b.\")\n\tDEFMCX(wrandz, 1, \"(w --> r) return a signal of randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(pickz, 1, \"(a --> r) return a signal of randomly chosen elements from the finite list a.\") \n\tDEFMCX(wpickz, 2, \"(a w --> r) return a signal of randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** finite random streams ***\");\n\tDEFAM(nrands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random real values from a to b.\")\n\tDEFAM(ncoins, kk, \"(n p --> r) return a stream of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFAM(neprands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b, excluding the previously returned value.\")\n\tDEFAM(nrand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nirands, kkk, \"(n a b --> r) return a stream of n uniformly distributed random integer values from a to b.\")\n\tDEFAM(nirand2s, kk, \"(n a --> r) return a stream of n uniformly distributed random real values from -a to +a.\")\n\tDEFAM(nxrands, kkk, \"(n a b --> r) return a stream of n exponentially distributed random real values from a to b.\")\n\tDEFAM(nlinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random real values from a to b.\")\n\tDEFAM(nilinrands, kkk, \"(n a b --> r) return a stream of n linearly distributed random integer values from a to b.\")\n\tDEFAM(nwrands, ka, \"(n w --> r) return a stream of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFAM(npicks, ka, \"(n a --> r) return a stream of n randomly chosen elements from the finite list a.\") \n\tDEFAM(nwpicks, kaa, \"(n a w --> r) return a stream of n randomly chosen elements from the finite list a using probability weights from w. w must be the same length as a and should sum to one.\") \n\t\n\tvm.addBifHelp(\"\\n*** finite random signals ***\");\n\tDEFMCX(nrandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random real values from a to b.\")\n\tDEFMCX(ncoinz, 2, \"(n p --> r) return a signal of n 1 with probability p, or 0 with probability (1-p).\")\n\tDEFMCX(neprandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b, excluding the previously returned value\")\n\tDEFMCX(nrand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nirandz, 3, \"(n a b --> r) return a signal of n uniformly distributed random integer values from a to b.\")\n\tDEFMCX(nirand2z, 2, \"(n a --> r) return a signal of n uniformly distributed random real values from -a to +a.\")\n\tDEFMCX(nxrandz, 3, \"(n a b --> r) return a signal of n exponentially distributed random real values from a to b.\")\n\tDEFMCX(nlinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random real values from a to b.\")\n\tDEFMCX(nilinrandz, 3, \"(n a b --> r) return a signal of n linearly distributed random integer values from a to b.\")\t\n\tDEFMCX(nwrandz, 2, \"(n w --> r) return a signal of n randomly chosen indices from a list of probability weights. w should sum to one.\") \n\tDEFMCX(npickz, 2, \"(n a --> r) return a signal of n randomly chosen elements from the finite signal a.\") \n\tDEFMCX(nwpickz, 3, \"(n a w --> r) return a signal of n randomly chosen elements from the finite signal a using probability weights from w. w must be the same length as a and should sum to one.\") \n \n\tvm.addBifHelp(\"\\n*** noise unit generators ***\");\n\tDEFMCX(violet, 1, \"(amp --> z) violet noise\")\n\tDEFMCX(blue, 1, \"(amp --> z) blue noise\")\n\tDEFMCX(xorwhite, 1, \"(amp --> z) white noise\")\n\tDEFMCX(xorwhite2, 1, \"(amp --> z) white noise\")\n\tDEFMCX(rawhite, 1, \"(amp --> z) white noise based on Cessu's random access random numbers\")\n\tDEFMCX(wangwhite, 1, \"(amp --> z) white noise based on Thomas Wang's integer hash\")\n\tDEFMCX(citywhite, 1, \"(amp --> z) white noise based on a function from CityHash\")\n\tDEFMCX(white, 1, \"(amp --> z) white noise\")\n\tDEFMCX(pink, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(pink0, 1, \"(amp --> z) pink noise\")\n\tDEFMCX(brown, 1, \"(amp --> z) brown noise\")\n\tDEFMCX(gray, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(gray64, 1, \"(amp --> z) bit flip noise\")\n\tDEFMCX(dust, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from 0 to a and whose average density is in impulses per second.\")\t\n\tDEFMCX(dust2, 2, \"(density amp --> z) a stream of impulses whose amplitude is random from -a to +a and whose average density is in impulses per second.\")\n\tDEFMCX(velvet, 2, \"(density amp --> z) a stream of impulses whose amplitude is randomly either -a or +a and whose average density is in impulses per second.\")\n\tDEFMCX(toosh, 2, \"(delay amp --> z) flanged noise. difference of two white noise sources with a delay.\")\n\tDEFMCX(tooshp, 2, \"(delay amp--> z) flanged noise. sum of two white noise sources with a delay. no null at delay == 0. \")\n\tDEFMCX(crackle, 1, \"(param --> z) a chaotic generator.\")\t\n}\n\n\n"], ["/sapf/src/FilterUGens.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"FilterUGens.hpp\"\n#include \"UGen.hpp\"\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// classes for specializing feedback\n\nstruct NormalFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return x; }\n};\n\nstruct TanhApproximationFeedback : public Gen\n{\n\tstatic inline double feedback(double x) { return sc_tanh_approx(x); }\n};\n\nstruct UnityHardClipFeedback : public Gen\n{\n\tstatic inline double feedback(double x)\n\t{\n\t\tif (x <= -1.) return -1.;\n\t\tif (x >= 1.) return 1.;\n\t\treturn x;\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag : lagTime\");\n\tV in = th.popZIn(\"lag : in\");\n\n\tth.push(new List(new Lag(th, in, lagTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag2 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag2(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag2_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag2 : lagTime\");\n\tV in = th.popZIn(\"lag2 : in\");\n\n\tth.push(new List(new Lag2(th, in, lagTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Lag3 : public Gen\n{\n\tZIn _in;\n\tZIn _lagTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLag3(Thread& th, Arg in, Arg lagTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, lagTime)), _in(in), _lagTime(lagTime), _y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Lag3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *lagTime;\n\t\t\tint n, inStride, lagTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _lagTime(th, n, lagTimeStride, lagTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (lagTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + b1 * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + b1 * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + b1 * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tlagTime += lagTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_lagTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lag3_(Thread& th, Prim* prim)\n{\n\tV lagTime = th.popZIn(\"lag3 : lagTime\");\n\tV in = th.popZIn(\"lag3 : in\");\n\n\tth.push(new List(new Lag3(th, in, lagTime)));\n}\n\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\nstruct LagUD : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), _y1(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1);\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ b1 = y0 > y1 ? b1r : b1f;\n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0 = *in;\n\t\t\t\t\tZ lagTime = y0 > y1 ? *riseTime : *fallTime;\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / lagTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud : fallTime\");\n\tV riseTime = th.popZIn(\"lagud : riseTime\");\n\tV in = th.popZIn(\"lagud : in\");\n\n\tth.push(new List(new LagUD(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD2 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD2(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t}\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\tout[i] = y1b;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud2_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud2 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud2 : riseTime\");\n\tV in = th.popZIn(\"lagud2 : in\");\n\n\tth.push(new List(new LagUD2(th, in, riseTime, fallTime)));\n}\n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LagUD3 : public Gen\n{\n\tZIn _in;\n\tZIn _riseTime;\n\tZIn _fallTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _y1c;\n\tZ _lagmul;\n\tbool once;\n\t\n\tLagUD3(Thread& th, Arg in, Arg riseTime, Arg fallTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, riseTime, fallTime)), _in(in), _riseTime(riseTime), _fallTime(fallTime), \n\t\t\t_y1a(0.), _y1b(0.), _y1c(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LagUD3\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (once) {\n\t\t\tonce = false;\n\t\t\t_in.peek(th, _y1a);\n\t\t\t_y1b = _y1a;\n\t\t\t_y1c = _y1a;\n\t\t}\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ y1c = _y1c;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *riseTime, *fallTime;\n\t\t\tint n, inStride, riseTimeStride, fallTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _riseTime(th, n, riseTimeStride, riseTime) || _fallTime(th, n, fallTimeStride, fallTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (riseTimeStride == 0 && fallTimeStride == 0) {\n\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1r = std::max(0., 1. + lagmul / *riseTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime) \n\t\t\t\t\tZ b1f = std::max(0., 1. + lagmul / *fallTime); \n\n\t\t\t\t\tZ y0a = *in;\n\t\t\t\t\ty1a = y0a + (y0a > y1a ? b1r : b1f) * (y1a - y0a);\n\t\t\t\t\ty1b = y1a + (y1a > y1b ? b1r : b1f) * (y1b - y1a);\n\t\t\t\t\ty1c = y1b + (y1b > y1c ? b1r : b1f) * (y1c - y1b);\n\t\t\t\t\tout[i] = y1c;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\triseTime += riseTimeStride;\n\t\t\t\t\tfallTime += fallTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_riseTime.advance(n);\n\t\t\t_fallTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\t_y1c = y1c;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void lagud3_(Thread& th, Prim* prim)\n{\n\tV fallTime = th.popZIn(\"lagud3 : fallTime\");\n\tV riseTime = th.popZIn(\"lagud3 : riseTime\");\n\tV in = th.popZIn(\"lagud3 : in\");\n\n\tth.push(new List(new LagUD3(th, in, riseTime, fallTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct FirstOrderLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. - a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 + x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct FirstOrderHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tFirstOrderHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invNyquistRate * kFirstOrderCoeffScale)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"FirstOrderHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ a1 = t_firstOrderCoeff(*freq * freqmul);\n\t\t\t\t\tZ scale = .5 * (1. + a1);\n\t\t\t\t\n\t\t\t\t\tZ x0 = scale * *in;\n\t\t\t\t\tZ y0 = x0 - x1 + a1 * y1;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstatic void lpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf1 : freq\");\n\tV in = th.popZIn(\"lpf1 : in\");\n\n\tth.push(new List(new FirstOrderLPF(th, in, freq)));\n}\n\nstatic void hpf1_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf1 : freq\");\n\tV in = th.popZIn(\"hpf1 : in\");\n\n\tth.push(new List(new FirstOrderHPF(th, in, freq)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct LPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0inv = 1. / a0;\n\t\t\t\tZ a1 = a0inv * (-2. * cs);\n\t\t\t\tZ a2 = a0inv * (1. - alpha);\n\t\t\t\tZ b1 = a0inv * (1. - cs);\n\t\t\t\tZ b0 = a0inv * (.5 * b1);\n\t\t\t\tZ b2 = a0inv * b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct LPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\t\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ w0 = std::max(1e-3, *freq) * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\nstruct HPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstruct HPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHPF2(Thread& th, Arg in, Arg freq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq)), _in(in), _freq(freq), \n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq;\n\t\t\tint n, inStride, freqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (freqStride == 0) {\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\tZ sn, cs;\n\t\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\t\tZ a0r = 1./a0;\n\t\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\t\tZ b2 = b0;\n\t\t\t\t\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\t\t\n\t\t\t\t\tout[i] = z0;\n\t\t\t\t\tz2 = z1;\n\t\t\t\t\tz1 = z0;\n\t\t\t\t\ty2 = y1;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx2 = x1;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tfreq += freqStride;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\t_in.advance(n);\n\t\t\t\t_freq.advance(n);\n\t\t\t}\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\ntemplate \nstruct RLPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RLPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRLPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = 1. - cs;\n\t\t\t\tZ b0 = .5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\ntemplate \nstruct RHPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRHPF(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2)/a0;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\ntemplate \nstruct RHPF2 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2, _z1, _z2;\n\tZ _freqmul;\n\t\n\tRHPF2(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _z1(0.), _z2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RHPF2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ z1 = _z1;\n\t\tZ z2 = _z2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * *rq * .5;\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b1 = -1. - cs;\n\t\t\t\tZ b0 = -.5 * b1;\n\t\t\t\tZ b2 = b0;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) * a0r;\n\t\t\t\ty0 = Feedback::feedback(y0);\n\t\t\t\tZ z0 = (b0 * y0 + b1 * y1 + b2 * y2 - a1 * z1 - a2 * z2) * a0r;\n\t\t\t\tz0 = Feedback::feedback(z0);\n\t\t\t\t\n\t\t\t\tout[i] = z0;\n\t\t\t\tz2 = z1;\n\t\t\t\tz1 = z0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\t_z1 = z1;\n\t\t_z2 = z2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\nstruct BPF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BPF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\tZ b0 = alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * (x0 - x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\nstruct BSF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tBSF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"BSF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (x0 + x2 + a1 * (x1 - y1) - a2 * y2) * a0r;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n\n\n\nstruct APF : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tAPF(Thread& th, Arg in, Arg freq, Arg bw)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw)), _in(in), _freq(freq), _bw(bw),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"APF\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw;\n\t\t\tint n, inStride, freqStride, bwStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\t\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2; \n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alpha;\n\t\t\t\tZ a0r = 1./a0;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alpha;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (a2 * (x0 - y2) + a1 * (x1 - y1)) * a0r + x2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct PEQ : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tPEQ(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, bw, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"PEQ\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alphaA = alpha * A;\n\t\t\t\tZ alphaOverA = alpha / A;\n\t\t\t\t\n\t\t\t\tZ a0 = 1. + alphaOverA;\n\t\t\t\tZ a1 = -2. * cs;\n\t\t\t\tZ a2 = 1. - alphaOverA;\n\t\t\t\n\t\t\t\tZ b0 = 1. + alphaA;\n\t\t\t\tZ b2 = 1. - alphaA;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + a1 * (x1 - y1) + b2 * x2 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tLowShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct HighShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\tZ _alphamul;\n\t\n\tHighShelf(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega), _alphamul(.5 * M_SQRT2)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"HighShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ alphamul = _alphamul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\t\t\t\tZ alpha = sn * alphamul;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = ( Ap1 + Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ b2 = ( Ap1 + Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 - Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = 2.*( Am1 - Ap1cs );\n\t\t\t\tZ a2 = Ap1 - Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (A*(b0 * x0 + b1 * x1 + b2 * x2) - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LowShelf1 : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _gain;\n\tZ _x1, _y1;\n\tZ _freqmul;\n\t\n\tLowShelf1(Thread& th, Arg in, Arg freq, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _gain(gain),\n\t\t\t_x1(0.), _y1(0.), _freqmul(th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LowShelf1\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *gain;\n\t\t\tint n, inStride, freqStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ sqrt_g = t_dbamp(.25 * *gain);\n\t\t\t\tZ d = *freq * freqmul;\n\t\t\t\t\n\t\t\t\tZ p = 1. - d*sqrt_g;\n\t\t\t\tZ q = 1. - d/sqrt_g;\n\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tZ y0 = x0 + q * x1 - p * y1;\n\t\t\t\t\n\t\t\t\t\tout[i] = y0;\n\t\t\t\t\ty1 = y0;\n\t\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct RLowShelf : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _bw;\n\tZIn _gain;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tRLowShelf(Thread& th, Arg in, Arg freq, Arg bw, Arg gain)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, gain)), _in(in), _freq(freq), _bw(bw), _gain(gain),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample * gInvSineTableOmega)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"RLowShelf\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *bw, *gain;\n\t\t\tint n, inStride, freqStride, bwStride, gainStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _bw(th, n, bwStride, bw) || _gain(th, n, gainStride, gain)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\n\t\t\t\tZ A = t_dbamp(.5 * *gain);\n\t\t\t\tZ Ap1 = A + 1.;\n\t\t\t\tZ Am1 = A - 1.;\n\t\t\t\tZ Asqrt = t_dbamp(.25 * *gain);\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ sn, cs;\n\t\t\t\ttsincosx(w0, sn, cs);\n\n\t\t\t\t// bw * log(2) is the first term of the taylor series for 2*sinh(log(2)/2 * bw) == 1/Q. \n\t\t\t\t// the log(2) is combined with the .5 term in the formula for alpha.\n\t\t\t\tZ alpha = sn * *bw * log2o2;\n\t\t\t\tZ alpha2Asqrt = 2. * alpha * Asqrt;\n\t\t\t\tZ Am1cs = Am1*cs;\n\t\t\t\tZ Ap1cs = Ap1*cs;\n\t\t\t\t\n\t\t\t\tZ b0 = A*( Ap1 - Am1cs + alpha2Asqrt );\n\t\t\t\tZ b1 = 2.*A*( Am1 - Ap1cs );\n\t\t\t\tZ b2 = A*( Ap1 - Am1cs - alpha2Asqrt );\n\t\t\t\tZ a0 = Ap1 + Am1cs + alpha2Asqrt;\n\t\t\t\tZ a1 = -2.*( Am1 + Ap1cs );\n\t\t\t\tZ a2 = Ap1 + Am1cs - alpha2Asqrt;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = (b0 * x0 + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2) / a0;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tbw += bwStride;\n\t\t\t\tgain += gainStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_bw.advance(n);\n\t\t\t_gain.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n\nstatic void lpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf : freq\");\n\tV in = th.popZIn(\"lpf : in\");\n\n\tth.push(new List(new LPF(th, in, freq)));\n}\n\nstatic void lpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"lpf2 : freq\");\n\tV in = th.popZIn(\"lpf2 : in\");\n\n\tth.push(new List(new LPF2(th, in, freq)));\n}\n\nstatic void hpf_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf : freq\");\n\tV in = th.popZIn(\"hpf : in\");\n\n\tth.push(new List(new HPF(th, in, freq)));\n}\n\nstatic void hpf2_(Thread& th, Prim* prim)\n{\n\tV freq = th.popZIn(\"hpf2 : freq\");\n\tV in = th.popZIn(\"hpf2 : in\");\n\n\tth.push(new List(new HPF2(th, in, freq)));\n}\n\n\n\nstatic void rlpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf : rq\");\n\tV freq = th.popZIn(\"rlpf : freq\");\n\tV in = th.popZIn(\"rlpf : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2 : rq\");\n\tV freq = th.popZIn(\"rlpf2 : freq\");\n\tV in = th.popZIn(\"rlpf2 : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpf_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf : rq\");\n\tV freq = th.popZIn(\"rhpf : freq\");\n\tV in = th.popZIn(\"rhpf : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2 : rq\");\n\tV freq = th.popZIn(\"rhpf2 : freq\");\n\tV in = th.popZIn(\"rhpf2 : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\nstatic void rlpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpfc : rq\");\n\tV freq = th.popZIn(\"rlpfc : freq\");\n\tV in = th.popZIn(\"rlpfc : in\");\n\n\tth.push(new List(new RLPF(th, in, freq, rq)));\n}\n\nstatic void rlpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rlpf2c : rq\");\n\tV freq = th.popZIn(\"rlpf2c : freq\");\n\tV in = th.popZIn(\"rlpf2c : in\");\n\n\tth.push(new List(new RLPF2(th, in, freq, rq)));\n}\n\nstatic void rhpfc_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpfc : rq\");\n\tV freq = th.popZIn(\"rhpfc : freq\");\n\tV in = th.popZIn(\"rhpfc : in\");\n\n\tth.push(new List(new RHPF(th, in, freq, rq)));\n}\n\nstatic void rhpf2c_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"rhpf2c : rq\");\n\tV freq = th.popZIn(\"rhpf2c : freq\");\n\tV in = th.popZIn(\"rhpf2c : in\");\n\n\tth.push(new List(new RHPF2(th, in, freq, rq)));\n}\n\n\nstatic void bpf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bpf : bw\");\n\tV freq = th.popZIn(\"bpf : freq\");\n\tV in = th.popZIn(\"bpf : in\");\n\n\tth.push(new List(new BPF(th, in, freq, bw)));\n}\n\nstatic void bsf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"bsf : bw\");\n\tV freq = th.popZIn(\"bsf : freq\");\n\tV in = th.popZIn(\"bsf : in\");\n\n\tth.push(new List(new BSF(th, in, freq, bw)));\n}\n\nstatic void apf_(Thread& th, Prim* prim)\n{\n\tV bw = th.popZIn(\"apf : bw\");\n\tV freq = th.popZIn(\"apf : freq\");\n\tV in = th.popZIn(\"apf : in\");\n\n\tth.push(new List(new APF(th, in, freq, bw)));\n}\n\nstatic void peq_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"peq : gain\");\n\tV bw = th.popZIn(\"peq : bw\");\n\tV freq = th.popZIn(\"peq : freq\");\n\tV in = th.popZIn(\"peq : in\");\n\n\tth.push(new List(new PEQ(th, in, freq, bw, gain)));\n}\n\nstatic void lsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf(th, in, freq, gain)));\n}\n\nstatic void hsf_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"hsf : gain\");\n\tV freq = th.popZIn(\"hsf : freq\");\n\tV in = th.popZIn(\"hsf : in\");\n\n\tth.push(new List(new HighShelf(th, in, freq, gain)));\n}\n\n\nstatic void lsf1_(Thread& th, Prim* prim)\n{\n\tV gain = th.popZIn(\"lsf : gain\");\n\tV freq = th.popZIn(\"lsf : freq\");\n\tV in = th.popZIn(\"lsf : in\");\n\n\tth.push(new List(new LowShelf1(th, in, freq, gain)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Resonz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _rq;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul;\n\t\n\tResonz(Thread& th, Arg in, Arg freq, Arg rq)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, rq)), _in(in), _freq(freq), _rq(rq),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Resonz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *rq;\n\t\t\tint n, inStride, freqStride, rqStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _rq(th, n, rqStride, rq)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. - .5 * w0 * *rq;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\trq += rqStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_rq.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct Ringz : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _ringTime;\n\tZ _x1, _x2, _y1, _y2;\n\tZ _freqmul, _K;\n\t\n\tRingz(Thread& th, Arg in, Arg freq, Arg ringTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, ringTime)), _in(in), _freq(freq), _ringTime(ringTime),\n\t\t\t_x1(0.), _x2(0.), _y1(0.), _y2(0.), _freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Ringz\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ x2 = _x2;\n\t\tZ y1 = _y1;\n\t\tZ y2 = _y2;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *ringTime;\n\t\t\tint n, inStride, freqStride, ringTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\tZ a2 = -(R * R);\n\t\t\t\tZ b0 = .5;\n\t\t\t\t\n\t\t\t\tZ x0 = *in;\n\t\t\t\tZ y0 = b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\n\t\t\t\tout[i] = y0;\n\t\t\t\ty2 = y1;\n\t\t\t\ty1 = y0;\n\t\t\t\tx2 = x1;\n\t\t\t\tx1 = x0;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tringTime += ringTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_ringTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_x2 = x2;\n\t\t_y1 = y1;\n\t\t_y2 = y2;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct Formlet : public Gen\n{\n\tZIn _in;\n\tZIn _freq;\n\tZIn _atkTime;\n\tZIn _dcyTime;\n\tZ _x1a, _x2a, _y1a, _y2a;\n\tZ _x1b, _x2b, _y1b, _y2b;\n\tZ _freqmul, _K;\n\t\n\tFormlet(Thread& th, Arg in, Arg freq, Arg atkTime, Arg dcyTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, freq, atkTime, dcyTime)),\n\t\t\t_in(in), _freq(freq), _atkTime(atkTime), _dcyTime(dcyTime),\n\t\t\t_x1a(0.), _x2a(0.), _y1a(0.), _y2a(0.),\n\t\t\t_x1b(0.), _x2b(0.), _y1b(0.), _y2b(0.),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Formlet\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1a = _x1a;\n\t\tZ x2a = _x2a;\n\t\tZ y1a = _y1a;\n\t\tZ y2a = _y2a;\n\t\tZ x1b = _x1b;\n\t\tZ x2b = _x2b;\n\t\tZ y1b = _y1b;\n\t\tZ y2b = _y2b;\n\t\tZ freqmul = _freqmul;\n\t\tZ K = _K;\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *freq, *atkTime, *dcyTime;\n\t\t\tint n, inStride, freqStride, atkTimeStride, dcyTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _freq(th, n, freqStride, freq) || _atkTime(th, n, atkTimeStride, atkTime) || _dcyTime(th, n, dcyTimeStride, dcyTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\t\t\t\t\n\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\tZ Ra = 1. + K / *atkTime;\n\t\t\t\tZ Rb = 1. + K / *dcyTime;\n\t\t\t\tZ cs = tcos(w0);\n\t\t\t\tZ a1a = 2. * Ra * cs;\n\t\t\t\tZ a2a = -(Ra * Ra);\n\t\t\t\tZ a1b = 2. * Rb * cs;\n\t\t\t\tZ a2b = -(Rb * Rb);\n\t\t\t\tZ b0 = .5;\n\t\t\t\n\t\t\t\tZ x0a = *in;\n\t\t\t\tZ y0a = b0 * (x0a - x2a) + a1a * y1a + a2a * y2a;\n\t\t\t\n\t\t\t\tZ x0b = *in;\n\t\t\t\tZ y0b = b0 * (x0b - x2b) + a1b * y1b + a2b * y2b;\n\t\t\t\t\n\t\t\t\tout[i] = y0b - y0a;\n\t\t\t\ty2a = y1a;\n\t\t\t\ty1a = y0a;\n\t\t\t\tx2a = x1a;\n\t\t\t\tx1a = x0a;\n\n\t\t\t\ty2b = y1b;\n\t\t\t\ty1b = y0b;\n\t\t\t\tx2b = x1b;\n\t\t\t\tx1b = x0b;\n\t\t\t\t\n\t\t\t\tin += inStride;\n\t\t\t\tfreq += freqStride;\n\t\t\t\tatkTime += atkTimeStride;\n\t\t\t\tdcyTime += dcyTimeStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_freq.advance(n);\n\t\t\t_atkTime.advance(n);\n\t\t\t_dcyTime.advance(n);\n\t\t}\n\t\t\n\t\t_x1a = x1a;\n\t\t_x2a = x2a;\n\t\t_y1a = y1a;\n\t\t_y2a = y2a;\n\t\t\n\t\t_x1b = x1b;\n\t\t_x2b = x2b;\n\t\t_y1b = y1b;\n\t\t_y2b = y2b;\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct KlankFilter\n{\n\tKlankFilter(V f, V a, V r) : \n\t\tfreq(f), amp(a), ringTime(r),\n\t\tx1(0.), x2(0.), y1(0.), y2(0.) {}\n\t\n\tZIn freq, amp, ringTime;\n\tZ x1, x2, y1, y2;\n\t\n};\n\nstruct Klank : public Gen\n{\n\tZIn _in;\n\tstd::vector _filters;\n\tZ _freqmul, _K;\n\tZ* inputBuffer;\n\t\n\tKlank(Thread& th, Arg in, V freqs, V amps, V ringTimes)\n\t\t: Gen(th, itemTypeZ, in.isFinite()), _in(in),\n\t\t\t_freqmul(th.rate.radiansPerSample),\n\t\t\t_K(log001 * th.rate.invSampleRate)\n\t{\n\t\tinputBuffer = new Z[mBlockSize];\n\t\n\t\tint64_t numFilters = LONG_MAX;\n\t\tif (freqs.isVList()) { \n\t\t\tfreqs = ((List*)freqs.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, freqs.length(th)); \n\t\t}\n\t\tif (amps.isVList()) { \n\t\t\tamps = ((List*)amps.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, amps.length(th)); \n\t\t}\n\t\tif (ringTimes.isVList()) { \n\t\t\tringTimes = ((List*)ringTimes.o())->pack(th); \n\t\t\tnumFilters = std::min(numFilters, ringTimes.length(th)); \n\t\t}\n\t\t\n\t\tif (numFilters == LONG_MAX) numFilters = 1;\n\t\t\n\t\tfor (ssize_t i = 0; i < numFilters; ++i) {\n\t\t\tKlankFilter kf(freqs.at(i), amps.at(i), ringTimes.at(i));\n\t\t\t_filters.push_back(kf);\n\t\t}\n\t\t\n\t}\n\t\n\tvirtual ~Klank()\n\t{\n\t\tdelete [] inputBuffer;\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Klank\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\t\t\n\t\t\n\t\t// copy input\n\t\tint numInputFrames = mBlockSize;\n\t\tif (_in.fill(th, numInputFrames, inputBuffer, 1))\n\t\t{\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tint maxToFill = 0;\n\n\t\tZ* out0 = mOut->fulfillz(numInputFrames);\n\t\tmemset(out0, 0, numInputFrames * sizeof(Z));\n\t\t\n\t\tZ freqmul = _freqmul;\n\t\tZ K = log001 * th.rate.invSampleRate;\n\t\t\n\t\tfor (size_t filter = 0; filter < _filters.size(); ++filter) {\n\t\t\tint framesToFill = numInputFrames;\n\t\t\tKlankFilter& kf = _filters[filter];\n\t\t\t\t\n\t\t\tZ x1 = kf.x1;\n\t\t\tZ x2 = kf.x2;\n\t\t\tZ y1 = kf.y1;\n\t\t\tZ y2 = kf.y2;\n\n\t\t\tZ* in = inputBuffer;\n\t\t\tZ* out = out0;\n\t\t\twhile (framesToFill) {\n\t\t\t\tZ *freq, *amp, *ringTime;\n\t\t\t\tint n, freqStride, ampStride, ringTimeStride;\n\t\t\t\tn = framesToFill;\n\t\t\t\tif (kf.freq(th, n, freqStride, freq) || kf.amp(th, n, ampStride, amp) || kf.ringTime(th, n, ringTimeStride, ringTime)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tmaxToFill = std::max(maxToFill, framesToFill);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\n\t\t\t\tif (freqStride == 0) {\n\t\t\t\t\tif (ringTimeStride == 0) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t++in;\n\t\t\t\t\t\t\t++out;\n\t\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tZ b0 = .5;\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tZ w0 = *freq * freqmul;\n\t\t\t\t\t\tZ R = 1. + K / *ringTime;\n\t\t\t\t\t\tZ cs = tcos(w0);\n\t\t\t\t\t\tZ a1 = 2. * R * cs;\n\t\t\t\t\t\tZ a2 = -(R * R);\n\t\t\t\t\t\t\n\t\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\t\tZ y0 = *amp * b0 * (x0 - x2) + a1 * y1 + a2 * y2;\n\t\t\t\t\t\t\n\t\t\t\t\t\t*out += y0;\n\t\t\t\t\t\ty2 = y1;\n\t\t\t\t\t\ty1 = y0;\n\t\t\t\t\t\tx2 = x1;\n\t\t\t\t\t\tx1 = x0;\n\t\t\t\t\t\t\n\t\t\t\t\t\t++in;\n\t\t\t\t\t\t++out;\n\t\t\t\t\t\tfreq += freqStride;\n\t\t\t\t\t\tamp += ampStride;\n\t\t\t\t\t\tringTime += ringTimeStride;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t\tkf.freq.advance(n);\n\t\t\t\tkf.amp.advance(n);\n\t\t\t\tkf.ringTime.advance(n);\n\t\t\t}\n\t\t\tkf.x1 = x1;\n\t\t\tkf.x2 = x2;\n\t\t\tkf.y1 = y1;\n\t\t\tkf.y2 = y2;\n\t\t}\n\t\tproduce(maxToFill);\n\t}\n};\n\n\nstatic void resonz_(Thread& th, Prim* prim)\n{\n\tV rq = th.popZIn(\"resonz : rq\");\n\tV freq = th.popZIn(\"resonz : freq\");\n\tV in = th.popZIn(\"resonz : in\");\n\n\tth.push(new List(new Resonz(th, in, freq, rq)));\n}\n\nstatic void ringz_(Thread& th, Prim* prim)\n{\n\tV ringTime = th.popZIn(\"ringz : ringTime\");\n\tV freq = th.popZIn(\"ringz : freq\");\n\tV in = th.popZIn(\"ringz : in\");\n\n\tth.push(new List(new Ringz(th, in, freq, ringTime)));\n}\n\nstatic void formlet_(Thread& th, Prim* prim)\n{\n\tV dcyTime = th.popZIn(\"formlet : dcyTime\");\n\tV atkTime = th.popZIn(\"formlet : atkTime\");\n\tV freq = th.popZIn(\"formlet : freq\");\n\tV in = th.popZIn(\"formlet : in\");\n\n\tth.push(new List(new Formlet(th, in, freq, atkTime, dcyTime)));\n}\n\n\nstatic void klank_(Thread& th, Prim* prim)\n{\n\tV ringTimes = th.popZInList(\"klank : ringTimes\");\n\tV amps\t\t= th.popZInList(\"klank : amps\");\n\tV freqs = th.popZInList(\"klank : freqs\");\n\tV in\t\t= th.popZIn(\"klank : in\");\n\t\n\tif (freqs.isVList() && !freqs.isFinite())\n\t\tindefiniteOp(\"klank : freqs\", \"\");\n\n\tif (amps.isVList() && !amps.isFinite())\n\t\tindefiniteOp(\"klank : amps\", \"\");\n\n\tif (ringTimes.isVList() && !ringTimes.isFinite())\n\t\tindefiniteOp(\"klank : ringTimes\", \"\");\n\n\tth.push(new List(new Klank(th, in, freqs, amps, ringTimes)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakDC : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _x1, _y1;\n\t\n\tLeakDC(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_x1(0.), _y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakDC\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ x1 = _x1;\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 - x1 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tx1 = x0;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_x1 = x1;\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leakdc_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leakdc : leak\");\n\tV in = th.popZIn(\"leakdc : in\");\n\n\tth.push(new List(new LeakDC(th, in, leak)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct LeakyIntegrator : public Gen\n{\n\tZIn _in;\n\tZIn _leak;\n\tZ _y1;\n\t\n\tLeakyIntegrator(Thread& th, Arg in, Arg leak)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, leak)), _in(in), _leak(leak), \n\t\t\t_y1(0.)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"LeakyIntegrator\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *leak;\n\t\t\tint n, inStride, leakStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _leak(th, n, leakStride, leak)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tZ x0 = *in;\n\t\t\t\ty1 = x0 + *leak * y1;\n\t\t\t\tout[i] = y1;\n\t\t\t\tin += inStride;\n\t\t\t\tleak += leakStride;\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_leak.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void leaky_(Thread& th, Prim* prim)\n{\n\tV leak = th.popZIn(\"leaky : leak\");\n\tV in = th.popZIn(\"leaky : in\");\n\n\tth.push(new List(new LeakyIntegrator(th, in, leak)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay : public Gen\n{\n\tZIn _in;\n\tZIn _decayTime;\n\tZ _y1;\n\tZ _lagmul;\n\t\n\t\n\tDecay(Thread& th, Arg in, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, decayTime)), _in(in), _decayTime(decayTime), \n\t\t\t_y1(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1 = _y1;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *decayTime;\n\t\t\tint n, inStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (decayTimeStride == 0) {\n\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1 = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\tout[i] = y1 = x0 + b1 * y1;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1 = y1;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay : decayTime\");\n\tV in = th.popZIn(\"decay : in\");\n\n\tth.push(new List(new Decay(th, in, decayTime)));\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Decay2 : public Gen\n{\n\tZIn _in;\n\tZIn _attackTime;\n\tZIn _decayTime;\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\t\n\t\n\tDecay2(Thread& th, Arg in, Arg attackTime, Arg decayTime)\n\t\t: Gen(th, itemTypeZ, mostFinite(in, attackTime, decayTime)), _in(in), _attackTime(attackTime), _decayTime(decayTime), \n\t\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Decay2\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\t\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\tZ y1a = _y1a;\n\t\tZ y1b = _y1b;\n\t\tZ lagmul = _lagmul;\n\t\twhile (framesToFill) {\n\t\t\tZ *in, *attackTime, *decayTime;\n\t\t\tint n, inStride, attackTimeStride, decayTimeStride;\n\t\t\tn = framesToFill;\n\t\t\tif (_in(th, n, inStride, in) || _attackTime(th, n, attackTimeStride, attackTime) || _decayTime(th, n, decayTimeStride, decayTime)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (attackTimeStride == 0 && decayTimeStride == 0) {\n\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tZ b1a = std::max(0., 1. + lagmul / *attackTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ b1b = std::max(0., 1. + lagmul / *decayTime); // this is an approximation to exp(log001 * th.rate.invSampleRate / *lagTime) \n\t\t\t\t\tZ x0 = *in;\n\t\t\t\t\ty1a = x0 + b1a * y1a;\n\t\t\t\t\ty1b = x0 + b1b * y1b;\n\t\t\t\t\tout[i] = y1b - y1a;\n\t\t\t\t\tin += inStride;\n\t\t\t\t\tattackTime += attackTimeStride;\n\t\t\t\t\tdecayTime += decayTimeStride;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t\t_in.advance(n);\n\t\t\t_attackTime.advance(n);\n\t\t\t_decayTime.advance(n);\n\t\t}\n\t\t\n\t\t_y1a = y1a;\n\t\t_y1b = y1b;\n\t\tproduce(framesToFill);\n\t}\n\t\n};\n\nstatic void decay2_(Thread& th, Prim* prim)\n{\n\tV decayTime = th.popZIn(\"decay2 : decayTime\");\n\tV attackTime = th.popZIn(\"decay2 : attackTime\");\n\tV in = th.popZIn(\"decay2 : in\");\n\n\tth.push(new List(new Decay2(th, in, attackTime, decayTime)));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nstruct Phase90A : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90A(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90A\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z1;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct Phase90B : public OneInputUGen\n{\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1_ = 0.;\n\tZ v2_ = 0.;\n\tZ w1_ = 0.;\n\tZ w2_ = 0.;\n\tZ x1_ = 0.;\n\tZ x2_ = 0.;\n\tZ y1_ = 0.;\n\tZ y2_ = 0.;\n\tZ z1_ = 0.;\n\tZ z2_ = 0.;\n\t\n\tPhase90B(Thread& th, Arg in) : OneInputUGen(th, in)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"Phase90B\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1 = c1_;\n\t\tZ c2 = c2_;\n\t\tZ c3 = c3_;\n\t\tZ c4 = c4_;\n\t\t\n\t\tZ v1 = v1_;\n\t\tZ v2 = v2_;\n\t\tZ w1 = w1_;\n\t\tZ w2 = w2_;\n\t\tZ x1 = x1_;\n\t\tZ x2 = x2_;\n\t\tZ y1 = y1_;\n\t\tZ y2 = y2_;\n\t\tZ z1 = z1_;\n\t\tZ z2 = z2_;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\tZ w0 = c1 * (v0 + w2) - v2;\n\t\t\tZ x0 = c2 * (w0 + x2) - w2;\n\t\t\tZ y0 = c3 * (x0 + y2) - x2;\n\t\t\tZ z0 = c4 * (y0 + z2) - y2;\n\t\t\tout[i] = z0;\n\t\t\tv2 = v1;\n\t\t\tw2 = w1;\n\t\t\tx2 = x1;\n\t\t\ty2 = y1;\n\t\t\tz2 = z1;\n\t\t\tv1 = v0;\n\t\t\tw1 = w0;\n\t\t\tx1 = x0;\n\t\t\ty1 = y0;\n\t\t\tz1 = z0;\n\t\t}\n\t\tv1_ = v1;\n\t\tv2_ = v2;\n\t\tw1_ = w1;\n\t\tw2_ = w2;\n\t\tx1_ = x1;\n\t\tx2_ = x2;\n\t\ty1_ = y1;\n\t\ty2_ = y2;\n\t\tz1_ = z1;\n\t\tz2_ = z2;\n\t}\n};\n\nstruct AmpFollow : public OneInputUGen\n{\n\tZ _y1a;\n\tZ _y1b;\n\tZ _lagmul;\n\tbool once;\n\n\t// filters by Olli Niemitalo\n\tconstexpr static Z c1a_ = 0.47940086558884; // sq(.6923878);\n\tconstexpr static Z c2a_ = 0.87621849353931; // sq(.9360654322959);\n\tconstexpr static Z c3a_ = 0.9765975895082; // sq(.9882295226860);\n\tconstexpr static Z c4a_ = 0.99749925593555; // sq(.9987488452737);\n\tZ v1a_ = 0.;\n\tZ v2a_ = 0.;\n\tZ w1a_ = 0.;\n\tZ w2a_ = 0.;\n\tZ x1a_ = 0.;\n\tZ x2a_ = 0.;\n\tZ y1a_ = 0.;\n\tZ y2a_ = 0.;\n\tZ z1a_ = 0.;\n\tZ z2a_ = 0.;\n\n\tconstexpr static Z c1b_ = 0.1617584983677; // sc_squared(.4021921162426);\n\tconstexpr static Z c2b_ = 0.73302893234149; // sc_squared(.8561710882420);\n\tconstexpr static Z c3b_ = 0.94534970032911; // sc_squared(.9722909545651);\n\tconstexpr static Z c4b_ = 0.99059915668453; // sc_squared(.9952884791278);\n\tZ v1b_ = 0.;\n\tZ v2b_ = 0.;\n\tZ w1b_ = 0.;\n\tZ w2b_ = 0.;\n\tZ x1b_ = 0.;\n\tZ x2b_ = 0.;\n\tZ y1b_ = 0.;\n\tZ y2b_ = 0.;\n\tZ z1b_ = 0.;\n\tZ z2b_ = 0.;\n\n\tZ b1r_;\n\tZ b1f_;\n\t\n\tZ l1a_ = 0.;\n\tZ l1b_ = 0.;\n\n\tAmpFollow(Thread& th, Arg in, Z atk, Z dcy)\n\t\t: OneInputUGen(th, in),\n\t\t_y1a(0.), _y1b(0.), _lagmul(log001 * th.rate.invSampleRate), once(true)\n\t{\n\t\tb1r_ = atk == 0. ? 0. : std::max(0., 1. + _lagmul / atk); // this is an approximation to exp(log001 * th.rate.invSampleRate / *riseTime)\n\t\tb1f_ = dcy == 0. ? 0. : std::max(0., 1. + _lagmul / dcy);\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"AmpFollow\"; }\n\t\n\tvoid calc(int n, Z* out, Z* in, int inStride)\n\t{\n\t\tZ c1a = c1a_;\n\t\tZ c2a = c2a_;\n\t\tZ c3a = c3a_;\n\t\tZ c4a = c4a_;\n\t\t\n\t\tZ v1a = v1a_;\n\t\tZ v2a = v2a_;\n\t\tZ w1a = w1a_;\n\t\tZ w2a = w2a_;\n\t\tZ x1a = x1a_;\n\t\tZ x2a = x2a_;\n\t\tZ y1a = y1a_;\n\t\tZ y2a = y2a_;\n\t\tZ z1a = z1a_;\n\t\tZ z2a = z2a_;\n\n\t\tZ c1b = c1b_;\n\t\tZ c2b = c2b_;\n\t\tZ c3b = c3b_;\n\t\tZ c4b = c4b_;\n\t\t\n\t\tZ v1b = v1b_;\n\t\tZ v2b = v2b_;\n\t\tZ w1b = w1b_;\n\t\tZ w2b = w2b_;\n\t\tZ x1b = x1b_;\n\t\tZ x2b = x2b_;\n\t\tZ y1b = y1b_;\n\t\tZ y2b = y2b_;\n\t\tZ z1b = z1b_;\n\t\tZ z2b = z2b_;\n\t\t\n\t\tZ l1a = l1a_;\n\t\tZ l1b = l1b_;\n\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ v0 = *in; in += inStride;\n\t\t\t{\n\t\t\t\tZ w0 = c1a * (v0 + w2a) - v2a;\n\t\t\t\tZ x0 = c2a * (w0 + x2a) - w2a;\n\t\t\t\tZ y0 = c3a * (x0 + y2a) - x2a;\n\t\t\t\tZ z0 = c4a * (y0 + z2a) - y2a;\n\t\t\t\tv2a = v1a;\n\t\t\t\tw2a = w1a;\n\t\t\t\tx2a = x1a;\n\t\t\t\ty2a = y1a;\n\t\t\t\tz2a = z1a;\n\t\t\t\tv1a = v0;\n\t\t\t\tw1a = w0;\n\t\t\t\tx1a = x0;\n\t\t\t\ty1a = y0;\n\t\t\t\tz1a = z0;\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tZ w0 = c1b * (v0 + w2b) - v2b;\n\t\t\t\tZ x0 = c2b * (w0 + x2b) - w2b;\n\t\t\t\tZ y0 = c3b * (x0 + y2b) - x2b;\n\t\t\t\tZ z0 = c4b * (y0 + z2b) - y2b;\n\t\t\t\tv2b = v1b;\n\t\t\t\tw2b = w1b;\n\t\t\t\tx2b = x1b;\n\t\t\t\ty2b = y1b;\n\t\t\t\tz2b = z1b;\n\t\t\t\tv1b = v0;\n\t\t\t\tw1b = w0;\n\t\t\t\tx1b = x0;\n\t\t\t\ty1b = y0;\n\t\t\t\tz1b = z0;\n\t\t\t}\n\t\t\t\n\t\t\tZ l0a = hypot(z1a, z1b); // vectorize this\n\n\t\t\tl1a = l0a + (l0a > l1a ? b1r_ : b1f_) * (l1a - l0a);\n\t\t\tl1b = l1a + (l1a > l1b ? b1r_ : b1f_) * (l1b - l1a);\n\t\t\tout[i] = l1b;\n\t\t}\n\t\tv1a_ = v1a;\n\t\tv2a_ = v2a;\n\t\tw1a_ = w1a;\n\t\tw2a_ = w2a;\n\t\tx1a_ = x1a;\n\t\tx2a_ = x2a;\n\t\ty1a_ = y1a;\n\t\ty2a_ = y2a;\n\t\tz1a_ = z1a;\n\t\tz2a_ = z2a;\n\n\t\tv1b_ = v1b;\n\t\tv2b_ = v2b;\n\t\tw1b_ = w1b;\n\t\tw2b_ = w2b;\n\t\tx1b_ = x1b;\n\t\tx2b_ = x2b;\n\t\ty1b_ = y1b;\n\t\ty2b_ = y2b;\n\t\tz1b_ = z1b;\n\t\tz2b_ = z2b;\n\t\t\n\t\tl1a_ = l1a;\n\t\tl1b_ = l1b;\n\t}\n};\n\nstatic void hilbert_(Thread& th, Prim* prim)\n{\n\tV in = th.popZIn(\"hilbert : in\");\n\t\n\tth.push(new List(new Phase90A(th, in)));\n\tth.push(new List(new Phase90B(th, in)));\n}\n\nstatic void ampf_(Thread& th, Prim* prim)\n{\n\tZ dcy = th.popFloat(\"ampf : dcyTime\");\n\tZ atk = th.popFloat(\"ampf : atkTime\");\n\tV in = th.popZIn(\"ampf : in\");\n\t\n\tth.push(new List(new AmpFollow(th, in, atk, dcy)));\n}\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddFilterUGenOps()\n{\n\tvm.addBifHelp(\"\\n*** filter unit generators ***\");\n\tDEFMCX(lag, 2, \"(in decayTime --> out) one pole lag filter. decayTime determines rate of convergence.\")\n\tDEFMCX(lag2, 2, \"(in decayTime --> out) cascade of two one pole lag filters. decayTime determines rate of convergence.\")\n\tDEFMCX(lag3, 2, \"(in decayTime --> out) cascade of three one pole lag filters. decayTime determines rate of convergence.\")\n\n\tDEFMCX(lagud, 3, \"(in upDecayTime, downDecayTime --> out) one pole lag filter. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud2, 3, \"(in upDecayTime, downDecayTime --> out) cascade of two one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\tDEFMCX(lagud3, 3, \"(in upDecayTime, downDecayTime --> out) cascade of three one pole lag filters. up/down DecayTimes determines rate of convergence up/down.\")\n\t\n\tDEFMCX(lpf1, 2, \"(in freq --> out) low pass filter. 6 dB/oct.\")\n\tDEFMCX(hpf1, 2, \"(in freq --> out) high pass filter. 6 dB/oct.\")\n\tDEFMCX(lpf, 2, \"(in freq --> out) low pass filter. 12 dB/oct.\")\n\tDEFMCX(hpf, 2, \"(in freq --> out) high pass filter. 12 dB/oct.\")\n\tDEFMCX(lpf2, 2, \"(in freq --> out) low pass filter. 24 dB/oct.\")\n\tDEFMCX(hpf2, 2, \"(in freq --> out) high pass filter. 24 dB/oct.\")\n\t\n\tDEFMCX(rlpf, 3, \"(in freq rq --> out) resonant low pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf, 3, \"(in freq rq --> out) resonant high pass filter. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2, 3, \"(in freq rq --> out) resonant low pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2, 3, \"(in freq rq --> out) resonant high pass filter. 24 dB/oct slope. rq is 1/Q.\")\n\t\n\tDEFMCX(rlpfc, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpfc, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 12 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rlpf2c, 3, \"(in freq rq --> out) resonant low pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\tDEFMCX(rhpf2c, 3, \"(in freq rq --> out) resonant high pass filter with saturation. 24 dB/oct slope. rq is 1/Q.\")\n\n\tDEFMCX(bpf, 3, \"(in freq bw --> out) band pass filter. bw is bandwidth in octaves.\")\n\tDEFMCX(bsf, 3, \"(in freq bw --> out) band stop filter. bw is bandwidth in octaves.\")\n\tDEFMCX(apf, 3, \"(in freq bw --> out) all pass filter. bw is bandwidth in octaves.\")\n\t\n\tDEFMCX(peq, 4, \"(in freq bw gain --> out) parametric equalization filter. bw is bandwidth in octaves.\")\n\tDEFMCX(lsf, 3, \"(in freq gain --> out) low shelf filter.\")\n\tDEFMCX(hsf, 3, \"(in freq gain --> out) high shelf filter.\")\n\tDEFMCX(lsf1, 3, \"(in freq gain --> out) low shelf filter.\")\n\n\tDEFMCX(resonz, 3, \"(in freq rq --> out) resonant filter.\")\n\tDEFMCX(ringz, 3, \"(in freq ringTime --> out) resonant filter specified by a ring time in seconds.\")\n\tDEFMCX(formlet, 4, \"(in freq atkTime dcyTime --> out) a formant filter whose impulse response is a sine grain.\")\n\tDEFAM(klank, zaaa, \"(in freqs amps ringTimes --> out) a bank of ringz filters. freqs amps and ringTimes are arrays.\")\n\n\tDEFMCX(leakdc, 2, \"(in coef --> out) leaks away energy at 0 Hz.\")\n\tDEFMCX(leaky, 2, \"(in coef --> out) leaky integrator.\")\n\tDEFMCX(decay, 2, \"(in decayTime --> out) outputs an exponential decay for impulses at the input.\")\n\tDEFMCX(decay2, 3, \"(in atkTime dcyTime --> out) outputs an exponential attack and decay for impulses at the input.\")\n\n\tDEFMCX(hilbert, 1, \"(in --> outA outB) returns two signals that are 90 degrees phase shifted from each other.\")\n\tDEFMCX(ampf, 3, \"(in atkTime dcyTime --> out) amplitude follower.\")\n}\n\n\n\n"], ["/sapf/src/Midi.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Midi.hpp\"\n#include \"VM.hpp\"\n#include \"UGen.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n#include \n#include \n\n\nstruct MidiChanState\n{\n\tuint8_t control[128];\n\tuint8_t polytouch[128];\n\tuint8_t keyvel[128];\n\tuint32_t numKeysDown;\n\tuint16_t bend;\n\tuint8_t touch;\n\tuint8_t program;\n\tuint8_t lastkey;\n\tuint8_t lastvel;\n};\n\nconst int kMaxMidiPorts = 16;\nMidiChanState gMidiState[kMaxMidiPorts][16];\nbool gMidiDebug = false;\nMIDIClientRef gMIDIClient = 0;\nMIDIPortRef gMIDIInPort[kMaxMidiPorts], gMIDIOutPort[kMaxMidiPorts];\nint gNumMIDIInPorts = 0, gNumMIDIOutPorts = 0;\nbool gMIDIInitialized = false;\n\nstatic bool gSysexFlag = false;\nstatic Byte gRunningStatus = 0;\nstd::vector gSysexData;\n\nstatic void sysexBegin() {\n\tgRunningStatus = 0; // clear running status\n\t//gSysexData.clear();\n\tgSysexFlag = true;\n}\n\nstatic void sysexEnd(int lastUID) {\n\tgSysexFlag = false;\n}\n\nstatic void sysexEndInvalid() {\n\tgSysexFlag = false;\n}\n\nstatic int midiProcessSystemPacket(MIDIPacket *pkt, int chan) {\n\tint index, data;\n\tswitch (chan) {\n\tcase 7: // added cp: Sysex EOX must be taken into account if first on data packet\n\tcase 0:\n\t\t{\n\t\tint last_uid = 0;\n\t\tint m = pkt->length;\n\t\tByte* p_pkt = pkt->data;\n\t\tByte pktval;\n\n\t\twhile(m--) {\n\t\t\tpktval = *p_pkt++;\n\t\t\tif(pktval & 0x80) { // status byte\n\t\t\t\tif(pktval == 0xF7) { // end packet\n\t\t\t\t\tgSysexData.push_back(pktval); // add EOX\n\t\t\t\t\tif(gSysexFlag)\n\t\t\t\t\t\tsysexEnd(last_uid); // if last_uid != 0 rebuild the VM.\n\t\t\t\t\telse\n\t\t\t\t\t\tsysexEndInvalid(); // invalid 1 byte with only EOX can happen\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if(pktval == 0xF0) { // new packet\n\t\t\t\t\tif(gSysexFlag) {// invalid new one/should not happen -- but handle in case\n\t\t\t\t\t\t// store the last uid value previous to invalid data to rebuild VM after sysexEndInvalid call\n\t\t\t\t\t\t// since it may call sysexEnd() just after it !\n\t\t\t\t\t\tsysexEndInvalid();\n\t\t\t\t\t}\n\t\t\t\t\tsysexBegin(); // new sysex in\n\t\t\t\t\t//gSysexData.push_back(pktval); // add SOX\n\t\t\t\t}\n\t\t\t\telse {// abnormal data in middle of sysex packet\n\t\t\t\t\t//gSysexData.push_back(pktval); // add it as an abort message\n\t\t\t\t\tsysexEndInvalid(); // flush invalid\n\t\t\t\t\tm = 0; // discard all packet\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(gSysexFlag) {\n\t\t\t\t//gSysexData.push_back(pktval); // add Byte\n\t\t\t} else { // garbage - handle in case - discard it\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn (pkt->length-m);\n\t\t}\n\tbreak;\n\n\tcase 1 :\n\t\tindex = pkt->data[1] >> 4;\n\t\tdata = pkt->data[1] & 0xf;\n\t\tswitch (index) { case 1: case 3: case 5: case 7: { data = data << 4; } }\n\t\treturn 2;\n\n\tcase 2 : \t//songptr\n\t\treturn 3;\n\n\tcase 3 :\t// song select\n\t\treturn 2;\n\n\tcase 8 :\t//clock\n\tcase 10:\t//start\n\tcase 11:\t//continue\n\tcase 12: \t//stop\n\tcase 15:\t//reset\n\t\tgRunningStatus = 0; // clear running status\n\t\treturn 1;\n\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn (1);\n}\n\n\n\n\nstatic void midiProcessPacket(MIDIPacket *pkt, int srcIndex)\n{\n\tif(pkt) {\n\t\tint i = 0; \n\t\twhile (i < pkt->length) {\n\t\t\tuint8_t status = pkt->data[i] & 0xF0;\n\t\t\tuint8_t chan = pkt->data[i] & 0x0F;\n\t\t\tuint8_t a, b;\n\n\t\t\tif(status & 0x80) // set the running status for voice messages\n\t\t\t\tgRunningStatus = ((status >> 4) == 0xF) ? 0 : pkt->data[i]; // keep also additional info\n\t\tL:\n\t\t\tswitch (status) {\n\t\t\tcase 0x80 : //noteOff\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note off %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = 0;\n\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0x90 : //noteOn\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi note on %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tif (b) {\n\t\t\t\t\tgMidiState[srcIndex][chan].lastkey = a;\n\t\t\t\t\tgMidiState[srcIndex][chan].lastvel = b;\n\t\t\t\t\t++gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t} else {\n\t\t\t\t\t--gMidiState[srcIndex][chan].numKeysDown;\n\t\t\t\t}\n\t\t\t\tgMidiState[srcIndex][chan].keyvel[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xA0 : //polytouch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi poly %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].polytouch[a] = b;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xB0 : //control\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi control %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].control[a] = b;\n\t\t\t\tif (a == 120 || (a >= 123 && a <= 127)) {\n\t\t\t\t\t// all notes off\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].keyvel, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].numKeysDown = 0;\n\t\t\t\t} else if (a == 121) {\n\t\t\t\t\t// reset ALL controls to zero, don't follow MMA recommended practices.\n\t\t\t\t\tmemset(gMidiState[srcIndex][chan].control, 0, 128);\n\t\t\t\t\tgMidiState[srcIndex][chan].bend = 0x4000;\n\t\t\t\t}\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xC0 : //program\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tgMidiState[srcIndex][chan].program = a;\n\t\t\t\tif (gMidiDebug) printf(\"midi program %d %d %d\\n\", srcIndex, chan+1, a);\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xD0 : //touch\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tprintf(\"midi touch %d %d\\n\", chan+1, a);\n\t\t\t\tgMidiState[srcIndex][chan].touch = a;\n\t\t\t\ti += 2;\n\t\t\t\tbreak;\n\t\t\tcase 0xE0 : //bend\n\t\t\t\ta = pkt->data[i+1];\n\t\t\t\tb = pkt->data[i+2];\n\t\t\t\tif (gMidiDebug) printf(\"midi bend %d %d %d %d\\n\", srcIndex, chan+1, a, b);\n\t\t\t\tgMidiState[srcIndex][chan].bend = ((b << 7) | a) - 8192;\n\t\t\t\ti += 3;\n\t\t\t\tbreak;\n\t\t\tcase 0xF0 :\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\tdefault :\t// data byte => continuing sysex message\n\t\t\t\tif(gRunningStatus && !gSysexFlag) { // modified cp: handling running status. may be we should here\n\t\t\t\t\tstatus = gRunningStatus & 0xF0; // accept running status only inside a packet beginning\n\t\t\t\t\tchan = gRunningStatus & 0x0F;\t// with a valid status byte ?\n\t\t\t\t\t--i;\n\t\t\t\t\tgoto L; // parse again with running status set\n\t\t\t\t}\n\t\t\t\tchan = 0;\n\t\t\t\ti += midiProcessSystemPacket(pkt, chan);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nstatic void midiReadProc(const MIDIPacketList *pktlist, void* readProcRefCon, void* srcConnRefCon)\n{\n\tMIDIPacket *pkt = (MIDIPacket*)pktlist->packet;\n\tint srcIndex = (int)(size_t) srcConnRefCon;\n\tfor (uint32_t i=0; inumPackets; ++i) {\n\t\tmidiProcessPacket(pkt, srcIndex);\n\t\tpkt = MIDIPacketNext(pkt);\n\t}\n}\n\nstatic void midiNotifyProc(const MIDINotification *message, void *refCon)\n{\n\tprintf(\"midi notification %d %d\\n\", (int)message->messageID, (int)message->messageSize);\n}\n\nstatic struct mach_timebase_info machTimebaseInfo() {\n struct mach_timebase_info info;\n mach_timebase_info(&info);\n return info;\n}\n\nstatic MIDITimeStamp midiTime(float latencySeconds)\n{\n // add the latency expressed in seconds, to the current host time base.\n static struct mach_timebase_info info = machTimebaseInfo(); // cache the timebase info.\n Float64 latencyNanos = 1000000000 * latencySeconds;\n MIDITimeStamp latencyMIDI = (latencyNanos / (Float64)info.numer) * (Float64)info.denom;\n return (MIDITimeStamp)mach_absolute_time() + latencyMIDI;\n}\n\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late);\nvoid sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late)\n{\n\tMIDIPacketList mpktlist;\n\tMIDIPacketList * pktlist = &mpktlist;\n\tMIDIPacket * pk = MIDIPacketListInit(pktlist);\n\tByteCount nData = (ByteCount) length;\n\tpk->data[0] = (Byte) (hiStatus & 0xF0) | (loStatus & 0x0F);\n\tpk->data[1] = (Byte) aval;\n\tpk->data[2] = (Byte) bval;\n\tpk = MIDIPacketListAdd(pktlist, sizeof(struct MIDIPacketList) , pk, midiTime(late), nData, pk->data);\n\t/*OSStatus error =*/ MIDISend(gMIDIOutPort[port], dest, pktlist );\n}\n\n\nstatic int midiCleanUp()\n{\n\t/*\n\t* do not catch errors when disposing ports\n\t* MIDIClientDispose should normally dispose the ports attached to it\n\t* but clean up the pointers in case\n\t*/\n\tint i = 0;\n\tfor (i=0; i= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\t//pass the uid to the midiReadProc to identify the src\n\tvoid* p = (void*)(uintptr_t)inputIndex;\n\tMIDIPortConnectSource(gMIDIInPort[inputIndex], src, p);\n\n\treturn errNone;\n}\n\n\nstatic int prDisconnectMIDIIn(int uid, int inputIndex)\n{\n\tif (inputIndex < 0 || inputIndex >= gNumMIDIInPorts) return errOutOfRange;\n\n\tMIDIEndpointRef src=0;\n\tMIDIObjectType mtype;\n\tMIDIObjectFindByUniqueID(uid, (MIDIObjectRef*)&src, &mtype);\n\tif (mtype != kMIDIObjectType_Source) return errFailed;\n\n\tMIDIPortDisconnectSource(gMIDIInPort[inputIndex], src);\n\n\treturn errNone;\n}\n\n\nstatic void midiStart_(Thread& th, Prim* prim)\n{\n\tmidiInit(16, 19);\n}\n\nstatic void midiRestart_(Thread& th, Prim* prim)\n{\n\tMIDIRestart();\n}\n\nstatic void midiStop_(Thread& th, Prim* prim)\n{\n\tmidiCleanUp();\n}\n\nstatic void midiList_(Thread& th, Prim* prim)\n{\n\tprListMIDIEndpoints();\n}\n\nstatic void midiConnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiConnectInput : port\");\n\tint uid = (int)th.popInt(\"midiConnectInput : sourceUID\");\n\tprConnectMIDIIn(uid, index);\n}\n\nstatic void midiDisconnectInput_(Thread& th, Prim* prim)\n{\n\tint index = (int)th.popInt(\"midiDisconnectInput : port\");\n\tint uid = (int)th.popInt(\"midiDisconnectInput : sourceUID\");\n\tprDisconnectMIDIIn(uid, index);\n}\n\nstatic void midiDebug_(Thread& th, Prim* prim)\n{\n gMidiDebug = th.popFloat(\"midiDebug : onoff\") != 0.;\n}\n\nconst Z kOneOver127 = 1./127.;\nconst Z kOneOver8191 = 1./8191.;\n\nstatic void mctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl1 : hi\");\n\tZ lo = th.popFloat(\"mctl1 : lo\");\n\n\tint cnum = th.popInt(\"mctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmctl1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl1 : hi\");\n\tZ lo = th.popFloat(\"xmctl1 : lo\");\n\n\tint cnum = th.popInt(\"xmctl1 : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl1 : srcIndex\") & 15;\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].control[cnum];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly1 : hi\");\n\tZ lo = th.popFloat(\"mpoly1 : lo\");\n\n\tint key = th.popInt(\"mpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"mpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmpoly1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly1 : hi\");\n\tZ lo = th.popFloat(\"xmpoly1 : lo\");\n\n\tint key = th.popInt(\"xmpoly1 : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmpoly1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].polytouch[key];\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mgate1_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate1 : key\") & 127;\n\tint chan = (th.popInt(\"mgate1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mgate1 : srcIndex\") & 15;\n\n\tth.pushBool(gMidiState[srcIndex][chan].keyvel[key] > 0);\n}\n\nstatic void mtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch1 : hi\");\n\tZ lo = th.popFloat(\"mtouch1 : lo\");\n\n\tint chan = (th.popInt(\"mtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmtouch1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch1 : hi\");\n\tZ lo = th.popFloat(\"xmtouch1 : lo\");\n\n\tint chan = (th.popInt(\"xmtouch1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmtouch1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].touch;\n\tth.push(lo * pow(hi / lo, z));\n}\n\nstatic void mprog1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mprog1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].touch);\n}\n\nstatic void mlastkey1_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastkey1 : srcIndex\") & 15;\n\n\tth.push(gMidiState[srcIndex][chan].lastkey);\n}\n\nstatic void mlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel1 : hi\");\n\tZ lo = th.popFloat(\"mlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"mlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo + z * (hi - lo));\n}\n\nstatic void xmlastvel1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel1 : hi\");\n\tZ lo = th.popFloat(\"xmlastvel1 : lo\");\n \n\tint chan = (th.popInt(\"xmlastvel1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmlastvel1 : srcIndex\") & 15;\n\n\tZ z = kOneOver127 * gMidiState[srcIndex][chan].lastvel;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nstatic void mbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend1 : hi\");\n\tZ lo = th.popFloat(\"mbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo + z * (hi - lo));\n}\nstatic void xmbend1_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend1 : hi\");\n\tZ lo = th.popFloat(\"xmbend1 : lo\");\n\n\tint chan = (th.popInt(\"mbend1 : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"xmbend1 : srcIndex\") & 15;\n\n\tZ z = kOneOver8191 * gMidiState[srcIndex][chan].bend;\n\tth.push(lo * pow(hi / lo, z));\t\n}\n\n\nZ gMidiLagTime = .1;\nZ gMidiLagMul = log001 / gMidiLagTime;\n\nstruct MCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMCtl : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMCtl(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMCtl\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].control[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMPoly : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n int _cnum;\n\t\n\tXMPoly(Thread& th, int srcIndex, int chan, int cnum, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan), _cnum(cnum)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMPoly\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].polytouch[_cnum];\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMTouch : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMTouch(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMTouch\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].touch;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct XMBend : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMBend(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMBend\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint16_t& ctl = gMidiState[_srcIndex][_chan].bend;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver8191 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo + z * (*hi - *lo);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstruct XMLastVel : public TwoInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n int _srcIndex;\n int _chan;\n\n\tXMLastVel(Thread& th, int srcIndex, int chan, Arg lo, Arg hi)\n : TwoInputUGen(th, lo, hi), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"XMLastVel\"; }\n\t\n\tvoid calc(int n, Z* out, Z* lo, Z* hi, int loStride, int hiStride) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastvel;\n\t\tfor (int i = 0; i < n; ++i) {\n Z z = kOneOver127 * ctl;\n\t\t\tZ y0 = *lo * pow(*hi / *lo, z);\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t\tlo += loStride;\n\t\t\thi += hiStride;\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\n\nstruct MLastKey : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMLastKey(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MLastKey\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].lastkey;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MProg : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n\n\tMProg(Thread& th, int srcIndex, int chan)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MProg\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].program;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl;\n\t\t}\n\t}\n};\n\nstruct MGate : public ZeroInputUGen\n{\n int _srcIndex;\n int _chan;\n int _key;\n\t\n\tMGate(Thread& th, int srcIndex, int chan, int key)\n : ZeroInputUGen(th, false),\n _srcIndex(srcIndex), _chan(chan), _key(key)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"MGate\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n uint8_t& ctl = gMidiState[_srcIndex][_chan].keyvel[_key];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tout[i] = ctl > 0 ? 1. : 0.;\n\t\t}\n\t}\n};\n\n\nstruct ZCtl : public ZeroInputUGen\n{\n\tZ _b1;\n\tZ _y1;\n\tZ _lagmul;\n P zref;\n\t\n\tZCtl(Thread& th, P const& inZRef)\n : ZeroInputUGen(th, false), _b1(1. + gMidiLagMul * th.rate.invSampleRate),\n zref(inZRef)\n\t{\n\t}\n\t\n\tvirtual const char* TypeName() const override { return \"ZCtl\"; }\n\t\n\tvoid calc(int n, Z* out) \n\t{\n\t\tZ y1 = _y1;\n\t\tZ b1 = _b1;\n Z& ctl = zref->z;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tZ y0 = ctl;\n\t\t\tout[i] = y1 = y0 + b1 * (y1 - y0);\n\t\t}\n\t\t_y1 = y1;\n\t}\n};\n\nstatic void zctl_(Thread& th, Prim* prim)\n{\n\tP zref = th.popZRef(\"mctl : zref\");\n\n\tth.push(new List(new ZCtl(th, zref)));\n}\n\n\nstatic void mctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mctl : hi\");\n\tZ lo = th.popFloat(\"mctl : lo\");\n\n\tint cnum = th.popInt(\"mctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"mctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void xmctl_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmctl : hi\");\n\tZ lo = th.popFloat(\"xmctl : lo\");\n\n\tint cnum = th.popInt(\"xmctl : ctlNum\") & 127;\n\tint chan = (th.popInt(\"xmctl : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMCtl(th, srcIndex, chan, cnum, lo, hi)));\n}\n\nstatic void mpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mpoly : hi\");\n\tZ lo = th.popFloat(\"mpoly : lo\");\n\n\tint key = th.popInt(\"mpoly : key\") & 127;\n\tint chan = (th.popInt(\"mpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void xmpoly_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmpoly : hi\");\n\tZ lo = th.popFloat(\"xmpoly : lo\");\n\n\tint key = th.popInt(\"xmpoly : key\") & 127;\n\tint chan = (th.popInt(\"xmpoly : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMPoly(th, srcIndex, chan, key, lo, hi)));\n}\n\nstatic void mtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mtouch : hi\");\n\tZ lo = th.popFloat(\"mtouch : lo\");\n\n\tint chan = (th.popInt(\"mtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmtouch_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmtouch : hi\");\n\tZ lo = th.popFloat(\"xmtouch : lo\");\n\n\tint chan = (th.popInt(\"xmtouch : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMTouch(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mbend : hi\");\n\tZ lo = th.popFloat(\"mbend : lo\");\n\n\tint chan = (th.popInt(\"mbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MBend(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void xmbend_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmbend : hi\");\n\tZ lo = th.popFloat(\"xmbend : lo\");\n\n\tint chan = (th.popInt(\"xmbend : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMBend(th, srcIndex, chan, lo, hi)));\n}\n\n\nstatic void mprog_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mprog : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MProg(th, srcIndex, chan)));\n}\n\nstatic void mgate_(Thread& th, Prim* prim)\n{\n\tint key = th.popInt(\"mgate : key\") & 127;\n\tint chan = (th.popInt(\"mgate : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MGate(th, srcIndex, chan, key)));\n}\n\n\nstatic void mlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"mlastvel : hi\");\n\tZ lo = th.popFloat(\"mlastvel : lo\");\n\n\tint chan = (th.popInt(\"mlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastVel(th, srcIndex, chan, lo, hi)));\n}\n\nstatic void mlastkey_(Thread& th, Prim* prim)\n{\n\tint chan = (th.popInt(\"mlastkey : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new MLastKey(th, srcIndex, chan)));\n}\n\nstatic void xmlastvel_(Thread& th, Prim* prim)\n{\n\tZ hi = th.popFloat(\"xmlastvel : hi\");\n\tZ lo = th.popFloat(\"xmlastvel : lo\");\n\n\tint chan = (th.popInt(\"xmlastvel : chan\") - 1) & 15;\n\tint srcIndex = th.popInt(\"mctl : srcIndex\") & 15;\n\tth.push(new List(new XMLastVel(th, srcIndex, chan, lo, hi)));\n}\n\n#define DEF(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddMidiOps()\n{\n\tvm.addBifHelp(\"\\n*** MIDI control ***\");\n\tDEF(midiStart, 0, 0, \"(-->) start up MIDI services\");\n\tDEF(midiRestart, 0, 0, \"(-->) rescan MIDI services\");\n\tDEF(midiStop, 0, 0, \"(-->) stop MIDI services\");\n\tDEF(midiList, 0, 0, \"(-->) list MIDI endpoints\");\n\tDEF(midiConnectInput, 2, 0, \"(sourceUID index -->) connect a MIDI source\");\n\tDEF(midiDisconnectInput, 2, 0, \"(sourceUID index -->) disconnect a MIDI source\");\n\tDEF(midiDebug, 1, 0, \"(onoff -->) turn on or off midi input monitoring\");\n\t\n\tvm.addBifHelp(\"\\n*** MIDI instantaneous value ***\");\n\tDEFMCX(mctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mprog1, 2, \"(srcIndex chan --> out) value of midi channel program 0-127.\");\n\tDEFMCX(mgate1, 3, \"(srcIndex chan key --> out) value of midi key state. 1 if key is down, 0 if key is up.\");\n\tDEFMCX(mlastkey1, 2, \"(srcIndex chan --> out) value of key of most recent midi note on.\");\n\tDEFMCX(mlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(xmctl1, 5, \"(srcIndex chan ctlnum lo hi --> out) value of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly1, 5, \"(srcIndex chan key lo hi --> out) value of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch1, 4, \"(srcIndex chan lo hi --> out) value of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend1, 4, \"(srcIndex chan lo hi --> out) value of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel1, 4, \"(srcIndex chan lo hi --> out) value of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** MIDI control signal ***\");\n\tDEFMCX(mctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the linear range [lo,hi].\");\n\tDEFMCX(mpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the linear range [lo,hi].\");\n\tDEFMCX(mbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the linear range [lo,hi].\");\n\tDEFMCX(mlastkey, 2, \"(srcIndex chan --> out) signal of key of most recent midi note on.\");\n\tDEFMCX(mlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the linear range [lo,hi].\");\n\n\tDEFMCX(mprog, 2, \"(srcIndex chan --> out) signal of midi channel program 0-127.\");\n\tDEFMCX(mgate, 3, \"(srcIndex chan key --> out) signal of midi key state. 1 if key is down, 0 if key is up.\");\n\n\tDEFMCX(xmctl, 5, \"(srcIndex chan ctlnum lo hi --> out) signal of midi controller mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmpoly, 5, \"(srcIndex chan key lo hi --> out) signal of midi poly key pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmtouch, 4, \"(srcIndex chan lo hi --> out) signal of midi channel pressure mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmbend, 4, \"(srcIndex chan lo hi --> out) signal of midi pitch bend mapped to the exponential range [lo,hi].\");\n\tDEFMCX(xmlastvel, 4, \"(srcIndex chan lo hi --> out) signal of velocity of most recent midi note on mapped to the exponential range [lo,hi].\");\n\n\tvm.addBifHelp(\"\\n*** ZRef control signal ***\");\n\tDEFMCX(zctl, 1, \"(zref --> out) makes a smoothed control signal from a zref.\");\n}\n\n\n"], ["/sapf/src/CoreOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Parser.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// stack shufflers\n#pragma mark STACK OPS\n\nstatic void clear_(Thread& th, Prim* prim)\n{\n\tth.clearStack();\n}\n\nstatic void cleard_(Thread& th, Prim* prim)\n{\n\tV v = th.top();\n\tth.clearStack();\n\tth.push(v);\n}\n\nstatic void stackDepth_(Thread& th, Prim* prim)\n{\n\tth.push(th.stackDepth());\n}\n\nstatic void ba_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[0] = sp[-1];\n\tsp[-1] = b;\n}\n\nstatic void bac_(Thread& th, Prim* prim) \n{\n\t// swapd\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = a;\n\tsp[0] = c;\n}\n\nstatic void cab_(Thread& th, Prim* prim)\n{\n\t// rrot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = a;\n\tsp[0] = b;\n}\n\nstatic void bca_(Thread& th, Prim* prim)\n{\n\t// rot\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = b;\n\tsp[-1] = c;\n\tsp[0] = a;\n}\n\nstatic void cba_(Thread& th, Prim* prim)\n{\n\t// reverse top 3\n\tif (th.stackDepth() < 3)\n\t\tthrow errStackUnderflow;\n\tV* sp = &th.top();\n\tV a = sp[-2];\n\tV b = sp[-1];\n\tV c = sp[0];\n\tsp[-2] = c;\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n}\n\nstatic void aaa_(Thread& th, Prim* prim)\n{\n\t// dup\n\tV v = th.top();\n\tth.push(v);\n\tth.push(v);\n}\n\nstatic void aba_(Thread& th, Prim* prim)\n{\n\t// over\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tth.push(sp[-1]);\n}\n\nstatic void bab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\n\n\tsp[-1] = b;\n\tsp[0] = a;\n}\n\nstatic void aab_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n}\n\nstatic void aabb_(Thread& th, Prim* prim)\n{\n\t// tuck\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n \n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(b);\t\n\tsp[0] = a;\n\tth.push(b);\t\n}\n\nstatic void abab_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV a = sp[-1];\n\tV b = sp[0];\n\tth.push(a);\t\n\tth.push(b);\t\n}\n\nstatic void nip_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < 2)\n\t\tthrow errStackUnderflow;\n\n\tV* sp = &th.top();\n\tV b = sp[0];\n\tsp[-1] = b;\n\tth.pop();\n}\n\n\nstatic void pop_(Thread& th, Prim* prim)\n{\n\tth.pop();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark INHERIT\n\nstatic bool hasItem(int64_t size, Table** a, Table* item)\n{\n\tfor (int64_t i = 0; iIdentical(item))\n\t\t\treturn true;\n\t}\n\treturn false;\n}\n\nstatic void Envir_merge2(Thread& th, int64_t asize, Table** a, int64_t bsize, Table** b, int64_t& csize, Table** c0)\n{\n\n\tTable** c = c0;\n\tTable** aend = a + asize;\n\tTable** bend = b + bsize;\n\twhile (a < aend && b < bend) {\t\n\t\tif ((*a)->Identical(*b)) {\n\t\t\t*c++ = *a++;\n\t\t\tb++;\n\t\t} else if (!hasItem(bend-b-1, b+1, *a)) {\n\t\t\t*c++ = *a++;\n\t\t} else if (!hasItem(aend-a-1, a+1, *b)) {\n\t\t\t*c++ = *b++;\n\t\t} else {\n\t\t\tthrow errInconsistentInheritance;\n\t\t}\n\t}\n\twhile (a < aend) { *c++ = *a++; }\n\twhile (b < bend) { *c++ = *b++; }\n\tcsize = c - c0;\n}\n\t\nstatic int64_t Envir_toVec(O list, int64_t maxSize, Table** vec)\n{\n\tint64_t i = 0;\n\tfor (; list && i < maxSize-1;) {\n\t\tvec[i++] = ((Form*)list)->mTable();\n\t\tlist = ((Form*)list)->mNextForm();\n\t}\n\treturn i;\n}\n\nstatic P Envir_fromVec(int64_t size, Table** a)\n{\n\tif (size == 0) return vm._ee;\n\t\n\tP list;\n\tfor (int64_t i = size-1; i >= 0; --i) {\n\t\tlist = consForm(a[i], list);\n\t}\n\treturn list;\n}\n\n\nP linearizeInheritance(Thread& th, size_t numArgs, V* args)\n{\n\tif (numArgs == 0) return vm._ee;\n\tif (numArgs == 1) {\n\t\tif (args[0].isForm()) {\n\t\t\treturn (Form*)args[0].asObj();\n\t\t} else {\n\t\t\treturn vm._ee;\n\t\t}\n\t}\n\t\n\tconst size_t maxSize = 1024;\n\tTable* t[3][maxSize];\n\t\n\tint ai = 0;\n\tint bi = 1;\n\tint ci = 2;\n\n\tint64_t asize = Envir_toVec(args[0].asObj(), maxSize, t[ai]);\n\tfor (size_t i = 1; i < numArgs; ++i) {\n\t\tint64_t bsize = Envir_toVec(args[i].asObj(), maxSize, t[bi]);\n\t\tint64_t csize;\n\t\tEnvir_merge2(th, asize, t[ai], bsize, t[bi], csize, t[ci]);\n\t\tint temp = ci;\n\t\tci = ai;\n\t\tai = temp;\n\t\tasize = csize;\n\t}\n\treturn Envir_fromVec(asize, t[ai]);\n}\n\nP asParent(Thread& th, V& v)\n{\n\tP parent;\n\tif (v.isReal()) {\n\t\tparent = nullptr;\n\t} else if (v.isForm()) {\n\t\tif (v.o() == vm._ee()) parent = nullptr;\n\t\telse parent = (Form*)v.o();\n\t} else if (v.isFunOrPrim()) {\n\t\tSaveStack save(th);\n\t\tv.apply(th);\n\t\t\n\t\tsize_t n = th.stackDepth();\n\t\tV* args = &th.top() - (n - 1);\n\n\t\tparent = linearizeInheritance(th, n, args);\n\t\n\t\tth.popn(n);\n\t} else if (v.isVList()) {\n\t\tif (!v.isFinite())\n\t\t\tindefiniteOp(\"\", \"{} : parent\");\n\t\t\t\n\t\tP const& a = ((List*)v.o())->mArray;\n\t\tsize_t n = a->size();\n\t\tparent = linearizeInheritance(th, n, a->v());\n\t} else {\n\t\twrongType(\"new : parent\", \"Form, Fun or VList\", v);\n\t\treturn NULL; // never gets here, but otherwise gcc warns about parent uninitialized.\n\t}\n\treturn parent;\n}\n\nstruct Binding\n{\n\tV key;\n\tBothIn value;\n};\n\nstruct Bind : public Gen\n{\n\tP mMap;\n\tP mParent;\n\tstd::vector _bindings;\n\t\n\tBind(Thread& th, P& parent, P const& bindings, bool inIsFinite) \n\t\t: Gen(th, itemTypeV, inIsFinite), mParent(parent)\n\t{\n\t\tint64_t m = bindings->length(th);\n\t\tfor (int64_t i = 0; i+1 < m; i += 2) {\n\t\t\tBinding b;\n\t\t\tb.key = bindings->at(i);\n\t\t\tb.value.set(bindings->at(i+1));\n\t\t\t_bindings.push_back(b);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Bind\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tint n = framesToFill;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tP e = consForm(new Table(mMap), mParent);\n\t\t\t\n\t\t\tint64_t m = _bindings.size();\n\t\t\tfor (int64_t j = 0; j < m; ++j) {\n\t\t\t\tBinding& b = _bindings[j];\n\t\t\t\tV val;\n\t\t\t\tif (b.value.one(th, val)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tgoto leave;\n\t\t\t\t}\n\t\t\t\te->put(j, val); // ok, single threaded mutation\n\t\t\t}\n\t\t\t\n\t\t\tout[i] = e;\n\t\t\t--framesToFill;\n\t\t}\nleave:\n\t\tproduce(framesToFill);\n\t}\n};\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark REF OPS\n\n\nstatic void ref_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tV ref = new Ref(value);\n\tth.push(ref);\n}\n\nstatic void zref_(Thread& th, Prim* prim)\n{\n\tZ z = th.popFloat(\"zref : value\");\n\tth.push(new ZRef(z));\n}\n\n\nstatic void set_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tif (ref.isRef()) {\n\t\tV value = th.pop();\n\t\t((Ref*)ref.o())->set(value);\n\t} else if (ref.isZRef()) {\n\t\tZ value = th.popFloat(\"set : value\");\n\t\t((ZRef*)ref.o())->set(value);\n\t} else if (ref.isPlug()) {\n\t\tV value = th.pop();\n\t\t((Plug*)ref.o())->setPlug(value);\n\t} else if (ref.isZPlug()) {\n\t\tV value = th.popZIn(\"set : value\");\n\t\t((ZPlug*)ref.o())->setPlug(value);\n\t} else if (ref.isVList() && ref.isFinite()) {\n\t\tV value = th.pop();\n\t\tP refList = ((List*)ref.o())->pack(th);\n\t\tP refArray = refList->mArray;\n\t\tV* refs = refArray->v();\n\t\tif (value.isVList() && value.isFinite()) {\n\t\t\tP valueList = ((List*)value.o())->pack(th);\n\t\t\tP valueArray = valueList->mArray;\n\t\t\tV* vals = valueArray->v();\n\t\t\tsize_t n = std::min(refArray->size(), valueArray->size());\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(vals[i]);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t} else {\n\t\t\tsize_t n = refArray->size();\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(value);\n\t\t\t\tth.push(refs[i]);\n\t\t\t\tset_(th, prim);\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"set : ref\", \"Ref, ZRef, Plug or ZPlug\", ref);\n\t}\n}\n\nstatic void get_(Thread& th, Prim* prim)\n{\n\tV ref = th.pop();\n\tth.push(ref.deref());\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// printing ops\n#pragma mark PRINTING\n\nstatic void pr_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().print(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void prdebug_(Thread& th, Prim* prim)\n{\n\tstd::string s;\n\tth.pop().printDebug(th, s);\n\tpost(\"%s\", s.c_str());\n}\n\nstatic void cr_(Thread& th, Prim* prim)\n{\n\tpost(\"\\n\");\n}\n\nstatic void tab_(Thread& th, Prim* prim)\n{\n\tpost(\"\\t\");\n}\n\nstatic void sp_(Thread& th, Prim* prim)\n{\n\tpost(\" \");\n}\n\nstatic void prstk_(Thread& th, Prim* prim)\n{\n\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n}\n\n\nstatic void printLength_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printLength);\n}\n\nstatic void printDepth_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printDepth);\n}\n\nstatic void printTotalItems_(Thread& th, Prim* prim)\n{\n\tth.push(vm.printTotalItems);\n}\n\nstatic void setPrintLength_(Thread& th, Prim* prim)\n{\n\tvm.printLength = (int)th.popInt(\"setPrintLength : length\");\n}\n\nstatic void setPrintDepth_(Thread& th, Prim* prim)\n{\n\tvm.printDepth = (int)th.popInt(\"setPrintDepth : depth\");\n}\n\nstatic void setPrintTotalItems_(Thread& th, Prim* prim)\n{\n\tvm.printTotalItems = (int)th.popInt(\"setPrintTotalItems : numItems\");\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// string ops\n#pragma mark STRINGS\n\nstatic void str_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.print(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void debugstr_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tstd::string s;\n\tv.printDebug(th, s);\n\tth.push(new String(s.c_str()));\n}\n\nstatic void strcat_(Thread& th, Prim* prim)\n{\n\tP sep = th.popString(\"strcat : separator\");\n\tP list = th.popVList(\"strcat : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strcat : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tif (i != 0) s += sep->s;\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\nstatic void strlines_(Thread& th, Prim* prim)\n{\n\tP list = th.popVList(\"strlines : list\");\n\tif (!list->isFinite())\n\t\tindefiniteOp(\"strlines : list\", \"\");\n\t\n\tstd::string s;\n\t\n\tlist = list->pack(th);\n\tP array = list->mArray;\n\t\n\tfor (int i = 0; i < array->size(); ++i) {\n\t\tV v = array->at(i);\n\t\tv.print(th, s);\n\t\ts += \"\\n\";\n\t}\n\t\n\tth.push(new String(s.c_str()));\t\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n// loops\n#pragma mark LOOPS\n\nstatic void while_(Thread& th, Prim* prim)\n{\n\tV body = th.pop();\n\tV test = th.pop();\n\twhile (1) {\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\ttest.apply(th);\n\t\t\tif (th.pop().isTrue()) break;\n\t\t}\n\t\t{\n\t\t\tSaveStack ss(th);\n\t\t\tbody.apply(th);\n\t\t}\n\t}\n}\n\n\nstatic void eachDoer(Thread& th, int level, uint32_t mask, BothIn& in, V& fun)\n{\n\tint nextLevel = level - 1;\n\tif (level == 0) {\n\t\twhile (1) {\n\t\t\tSaveStack ss(th);\n\t\t\tV v;\n\t\t\tif (in.one(th, v)) \n\t\t\t\treturn;\n\n\t\t\tth.push(v);\n\t\t\tfun.apply(th);\n\t\t}\n\t} else {\n\t\tint bit = 1 << level;\n\n\t\twhile (1) {\n\t\t\tV argv;\n\t\t\tif (in.one(th, argv))\n\t\t\t\treturn;\n\n\t\t\tbool isConstant = !(argv.isList() && (mask & bit));\n\t\t\t\n\t\t\tif (isConstant) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tth.push(argv);\n\t\t\t\tfun.apply(th);\n\t\t\t} else {\n\t\t\t\tBothIn subin;\n\t\t\t\tV v = argv;\n\t\t\t\tif (mask & bit) {\n\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\t\t\t\n\t\t\t\t\tsubin.set(v);\n\t\t\t\t} else {\n\t\t\t\t\tsubin.setConstant(v);\n\t\t\t\t}\n\t\t\t\n\t\t\t\teachDoer(th, nextLevel, mask, subin, fun);\n\t\t\t}\n\t\t}\n\t}\n};\n\nstatic void do_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tV item = th.pop();\n\t\n\tif (item.isEachOp()) {\n\t\tP p = (EachOp*)item.o();\n\t\tif (!p->v.isFinite())\n\t\t\tindefiniteOp(\"do : list\", \"\");\n\t\t\t\n\t\tBothIn in(p->v);\n\t\tint numLevels = p->mask <= 1 ? 0 : LOG2CEIL(p->mask) - 1;\n\t\teachDoer(th, numLevels, p->mask, in, f);\n\t} else if (item.isList()) {\n\t\n\t\tP s = (List*)item.o();\n\t\tif (!s->isFinite())\n\t\t\tindefiniteOp(\"do\", \"\");\n\n\t\tif (s->isVList()) {\n\t\t\tVIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = kDefaultVBlockSize;\n\t\t\t\tint astride;\n\t\t\t\tV *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tZIn _a(s());\n\t\t\twhile (1) {\n\t\t\t\tint n = th.rate.blockSize;\n\t\t\t\tint astride;\n\t\t\t\tZ *a;\n\t\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tSaveStack save(th);\n\t\t\t\t\t\tth.push(*a);\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t\tf.apply(th);\n\t\t\t\t\t}\n\t\t\t\t\t_a.advance(n);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\twrongType(\"do : list\", \"List\", item);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark CONDITIONALS\n\nstatic void equals_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(a.Equals(th, b));\n}\n\nstatic void less_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) < 0);\n}\n\nstatic void greater_(Thread& th, Prim* prim)\n{\n\tV b = th.pop();\n\tV a = th.pop();\n\tth.pushBool(Compare(th, a, b) > 0);\n}\n\nstatic void if_(Thread& th, Prim* prim)\n{\n\tV elseCode = th.pop();\n\tV thenCode = th.pop();\n\tV test = th.pop();\n\tif (test.isTrue()) {\n\t\tthenCode.apply(th);\n\t} else {\n\t\telseCode.apply(th);\n\t}\n}\n\nstatic void dip_(Thread& th, Prim* prim)\n{\n V temp = th.pop();\n V fun = th.pop();\n fun.apply(th);\n th.push(temp);\n}\n\nstatic void not_(Thread& th, Prim* prim)\n{\n\tV p = th.pop();\n\tth.pushBool(p.isFalse());\n}\n\nstatic void protect_(Thread& th, Prim* prim)\n{\n\tV protectCode = th.pop();\n\tV tryCode = th.pop();\n\n\t\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tprotectCode.apply(th);\n\t\tthrow;\n\t}\n\n\tprotectCode.apply(th);\n}\n\nstatic void try_(Thread& th, Prim* prim)\n{\n\tV catchCode = th.pop();\n\tV tryCode = th.pop();\n\ttry {\n\t\ttryCode.apply(th);\n\t} catch (...) {\n\t\tcatchCode.apply(th);\n\t\tthrow;\n\t}\n}\n\nstatic void throw_(Thread& th, Prim* prim)\n{\n\tthrow -1;\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ENVIR OPS\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tth.push(asParent(th, v));\n}\n\nstatic void pushWorkspace_(Thread& th, Prim* prim)\n{\n\tth.mWorkspace = consForm(new GTable(), th.mWorkspace);\n}\n\nstatic void popWorkspace_(Thread& th, Prim* prim)\n{\n if (!th.mWorkspace->mNextForm()) {\n post(\"Must not pop top level workspace!\\n\");\n return;\n }\n\tth.mWorkspace = th.mWorkspace->mNextForm;\n}\n\n\nstatic void has_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV list = th.pop();\n\t\n\tV value;\n\tbool has = list.get(th, key, value);\n\tth.pushBool(has);\n}\n\nstatic void keys_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(keys[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\nstatic void values_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"keys : e\")->mTable;\n\t\n\tP a = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\ta->add(vals[i]);\n\t}\n\t\n\tth.push(new List(a));\n}\n\n\nstatic void kv_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"values : e\")->mTable;\n\t\n\tP ka = new Array(itemTypeV, t->mMap->mSize);\n\tP va = new Array(itemTypeV, t->mMap->mSize);\n\t\n\tV* keys = t->mMap->mKeys;\n\tV* vals = t->mValues;\n\tfor (size_t i = 0; i < t->mMap->mSize; ++i) {\n\t\tka->add(keys[i]);\n\t\tva->add(vals[i]);\n\t}\n\n\tth.push(new List(ka));\n\tth.push(new List(va));\n}\n\nstatic void local_(Thread& th, Prim* prim)\n{\n\tP
t = th.popForm(\"local : e\")->mTable;\n\t\n\tth.push(new Form(t));\n}\n\nstatic void parent_(Thread& th, Prim* prim)\n{\n\tP form = th.popForm(\"values : e\");\n\t\n\tth.push(form->mNextForm ? form->mNextForm : vm._ee);\n}\n\nstatic void dot_(Thread& th, Prim* prim)\n{\n\tV key = th.pop();\n\tV e = th.pop();\n\t\t\n\tif (!key.isVList()) {\n\t\tV v;\n\t\te.dot(th, key, v);\n\t\tth.push(v);\n\t} else {\n\t\tif (!key.isFinite())\n\t\t\tindefiniteOp(\"dot : key\", \"\");\n\t\tList* ks = (List*)key.o();\n\t\tks = ks->pack(th);\n\n\t\tP ka = ks->mArray;\n\t\tint64_t size = ka->size();\n\t\tP va = new Array(itemTypeV, size);\n\t\tva->setSize(size);\n\t\tfor (int64_t i = 0; i < size; ++i) {\n\t\t\tV v;\n\t\t\te.dot(th, key, v);\n\t\t\tth.push(v);\n\t\t}\n\t\tth.push(new List(va));\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark APPLY\n\nstatic void noeach_(Thread& th, Prim* prim)\n{\n\tV fun = th.top();\n\t\n\tfun.SetNoEachOps();\n}\n\nstatic void apply_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\tv.apply(th);\n}\n\nstatic void applyEvent_(Thread& th, Prim* prim)\n{\n\tP fun = th.popFun(\"!e : fun\");\n\tP form = th.popForm(\"!e : form\");\n\t\n\tfor (auto const& name : fun->mDef->mArgNames) {\n\t\tV argValue;\n\t\tif (!form->dot(th, name, argValue)) {\n\t\t\tnotFound(name);\n\t\t}\n\t\tth.push(argValue);\n\t}\n\t\n\tfun->apply(th);\n}\n\nstatic void type_(Thread& th, Prim* prim)\n{\n\tth.push(getsym(th.pop().TypeName()));\n}\n\nstatic void load_(Thread& th, Prim* prim)\n{\n\tP filename = th.popString(\"load : filename\");\n\tloadFile(th, filename->s);\n}\n\nstatic void compile_(Thread& th, Prim* prim)\n{\n\tP s = th.popString(\"compile : string\");\n\tconst char* ss = s->s;\n\t\n\tP fun;\n\tif (!th.compile(ss, fun, false)) {\n\t\tth.push(0.);\n\t} else {\n\t\tth.push(fun);\n\t}\n}\n\nstatic void y_combinator_call_(Thread& th, Prim* prim)\n{\n\tth.push(prim);\n\tprim->v.apply(th);\n}\n\nstatic void Y_(Thread& th, Prim* prim)\n{\n\tV f = th.pop();\n\tif (f.takes() < 1) {\n\t\tpost(\"Y : fun. function must take at least one argument.\\n\");\n\t\tthrow errFailed;\n\t}\n\tth.push(new Prim(y_combinator_call_, f, f.takes()-1, f.leaves(), NULL, NULL));\n}\n\n\nstatic void* gofun(void* ptr)\n{\n Thread* th = (Thread*)ptr;\n th->fun->run(*th);\n delete th;\n return NULL;\n}\n\nstatic void go_(Thread& th, Prim* prim)\n{\n P fun = th.popFun(\"go : fun\");\n \n Thread* newThread = new Thread (th, fun); \n \n pthread_t pt;\n pthread_create(&pt, NULL, gofun, newThread);\n}\n\nstatic void sleep_(Thread& th, Prim* prim)\n{\n Z t = th.popFloat(\"sleep : secs\");\n \n usleep((useconds_t)floor(1e6 * t + .5));\n}\n\n#if COLLECT_MINFO\nstatic void minfo_(Thread& th, Prim* prim)\n{\n\tpost(\"signal generators %qd\\n\", vm.totalSignalGenerators.load());\n\tpost(\"stream generators %qd\\n\", vm.totalStreamGenerators.load());\n\tpost(\"objects live %qd\\n\", vm.totalObjectsAllocated.load() - vm.totalObjectsFreed.load());\n\tpost(\"objects allocated %qd\\n\", vm.totalObjectsAllocated.load());\n\tpost(\"objects freed %qd\\n\", vm.totalObjectsFreed.load());\n\tpost(\"retains %qd\\n\", vm.totalRetains.load());\n\tpost(\"releases %qd\\n\", vm.totalReleases.load());\n}\n#endif\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark SAMPLE RATES\n\nstatic void sr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate);\n}\n\nstatic void nyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.sampleRate * .5);\n}\n\nstatic void isr_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invSampleRate);\n}\n\nstatic void rps_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.radiansPerSample);\n}\n\nstatic void inyq_(Thread& th, Prim* prim)\n{\t\n\tth.push(th.rate.invNyquistRate);\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark HELP\n\nstatic void listdump_(Thread& th, Prim* prim)\n{\t\n\tP list = th.popList(\"listdump : seq\");\n\t\n\tpost(\"[\\n\");\n\twhile (list()) {\n\t\tpost(\"list %p %p %d\\n\", list(), list->mArray(), list->mArray() ? (int)list->mArray->size() : -1);\n\t\tlist = list->next();\n\t}\n\tpost(\"]\\n\");\n}\n\nstatic void help_(Thread& th, Prim* prim)\n{\n\tV v = th.pop();\n\n\tconst char* mask = v.GetAutoMapMask();\n\tconst char* help = v.OneLineHelp();\n\t\n\tif (mask) {\n\t\tpost(\"@%s \", mask);\n\t}\n\tif (help) {\n\t\tpost(\"%s\\n\", help);\n\t} else {\n\t\tpost(\"no help available.\\n\");\n\t}\n\n}\n\nstatic void helpbifs_(Thread& th, Prim* prim)\n{\n post(\"\\nBUILT IN FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.bifHelp.size(); ++i) {\n\t\tstd::string& s = vm.bifHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpLine_(Thread& th, Prim* prim)\n{\n\tP str = th.popString(\"helpLine : string\");\n\tvm.addUdfHelp(str->s);\n}\n\nstatic void helpudfs_(Thread& th, Prim* prim)\n{\n post(\"\\nUSER DEFINED FUNCTIONS\\n\\n\");\n\n\tfor (size_t i = 0; i < vm.udfHelp.size(); ++i) {\n\t\tstd::string& s = vm.udfHelp[i];\n\t\tpost(\" %s\\n\", s.c_str());\n\t}\n}\n\nstatic void helpall_(Thread& th, Prim* prim)\n{\n helpbifs_(th, prim);\n helpudfs_(th, prim);\n}\n\n\nstatic void prelude_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.prelude_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.prelude_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no prelude file.\\n\");\n\t}\n}\n\nstatic void examples_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* examples_file = getenv(\"SAPF_EXAMPLES\");\n\tif (examples_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", examples_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no examples file.\\n\");\n\t}\n}\n\nstatic void readme_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tconst char* readme_file = getenv(\"SAPF_README\");\n\tif (readme_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", readme_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no readme file.\\n\");\n\t}\n}\n\nstatic void logfile_(Thread& th, Prim* prim)\n{\n static const size_t cmdMaxLen = 2048;\n\tchar cmd[cmdMaxLen];\n\t\n\tif (vm.log_file) {\n\t\tsnprintf(cmd, cmdMaxLen, \"open %s\\n\", vm.log_file);\n\t\tsystem(cmd);\n\t} else {\n\t\tprintf(\"no log file.\\n\");\n\t}\n}\n\nstatic void trace_(Thread& th, Prim* prim)\n{\n\tvm.traceon = th.pop().isTrue();\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PLUGS\n\nstruct PlugOut : Gen\n{\n\tP _plug;\n\t\n\tPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeV, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"PlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tVIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\nstruct ZPlugOut : Gen\n{\n\tP _plug;\n\t\n\tZPlugOut(Thread& th, P& inPlug) : Gen(th, itemTypeZ, false), _plug(inPlug)\n\t{\n\t}\n\tvirtual const char* TypeName() const override { return \"ZPlugOut\"; }\n \t\n\tvirtual void pull(Thread& th) override {\n\t\tZIn in;\n\t\tint changeCount;\n\t\t_plug->getPlug(in, changeCount);\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (in(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = *a;\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\tin.advance(n);\n\t\t\t\tframesToFill -= n;\n\t\t\t\tout += n;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t\t_plug->setPlug(in, changeCount);\n\t}\n};\n\n\nstatic void plug_(Thread& th, Prim* prim)\n{\n\tV in = th.pop();\n\tP plug = new Plug(in);\n\tth.push(new List(new PlugOut(th, plug)));\n\tth.push(plug);\n}\n\nstatic void zplug_(Thread& th, Prim* prim)\n{\n\tV value = th.pop();\n\tif (value.isVList() && value.isFinite()) {\n\t\tP valueList = ((List*)value.o())->pack(th);\n\t\tP valueArray = valueList->mArray;\n\t\tV* vals = valueArray->v();\n\t\tsize_t n = valueArray->size();\n\t\t\n\t\tP plugList = new List(itemTypeV, n);\n\t\tP outList = new List(itemTypeV, n);\n\t\t\n\t\tP plugArray = plugList->mArray;\n\t\tP outArray = outList->mArray;\n\t\t\n\t\tplugArray->setSize(n);\n\t\toutArray->setSize(n);\n\t\t\n\t\tV* plugItems = plugArray->v();\n\t\tV* outItems = outArray->v();\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tth.push(vals[i]);\n\t\t\tzplug_(th, prim);\n\t\t\tplugItems[i] = th.pop();\n\t\t\toutItems[i] = th.pop();\n\t\t}\n\t\t\n\t\tth.push(outList);\n\t\tth.push(plugList);\n\t} else if (value.isZIn()) {\n\t\tP plug = new ZPlug(value);\n\t\tth.push(new List(new ZPlugOut(th, plug)));\n\t\tth.push(plug);\n\t} else {\n\t\twrongType(\"zplug : ref\", \"VList or UGen input\", value);\n\t}\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark GLOB\n\n#include \n\nstatic void glob_(Thread& th, Prim* prim)\n{\n\tP pat = th.popString(\"glob : pattern\");\n\t\n\tglob_t g;\n\tmemset(&g, 0, sizeof(g));\n\tglob(pat->s, GLOB_MARK, nullptr, &g);\n\t\n\tP a = new Array(itemTypeV, g.gl_matchc);\n\tfor (int i = 0; i < g.gl_matchc; ++i) {\n\t\ta->add(new String(g.gl_pathv[i]));\n\t}\n\tglobfree(&g);\n\t\n\tth.push(new List(a));\n}\n\n////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark ADD CORE OPS\n\n\n#define DEFN(NAME, N, FUN, HELP) \tvm.def(NAME, N, 1, FUN, HELP);\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, 1, NAME##_, HELP);\n#define DEF2(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP);\n#define DEFnoeach(NAME, TAKES, LEAVES, HELP) \tvm.def(#NAME, TAKES, LEAVES, NAME##_, HELP, V(0.), true);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddCoreOps();\nvoid AddCoreOps()\n{\n\t// stack ops\n\tvm.addBifHelp(\"\\n*** stack ops ***\");\n\tDEFnoeach(clear, 0, 0, \"(... -->) clears everything off the stack.\");\n\tDEFnoeach(cleard, 0, 1, \"(... a --> a) clears all but the top item from the stack.\")\n\tDEFnoeach(stackDepth, 0, 1, \"(--> n) returns the size of the stack.\")\n\t\n\tDEFnoeach(aa, 1, 2, \"(a --> a a) push the top item on stack again.\")\n\tDEFnoeach(aaa, 1, 3, \"(a --> a a a) push the top item on stack two more times.\")\n\tDEFnoeach(ba, 2, 2, \"(a b --> b a) swap top two items.\")\n\t\n\tDEFnoeach(bac, 3, 3, \"(a b c --> b a c) reorder items on stack.\")\n\tDEFnoeach(cba, 3, 3, \"(a b c --> c b a) reorder items on stack.\")\n\tDEFnoeach(bca, 3, 3, \"(a b c --> b c a) reorder items on stack.\")\n\tDEFnoeach(cab, 3, 3, \"(a b c --> c a b) reorder items on stack.\")\n\n\tDEFnoeach(bab, 2, 3, \"(a b --> b a b) reorder items on stack.\")\n\tDEFnoeach(aba, 2, 3, \"(a b --> a b a) reorder items on stack.\")\n\n\tDEFnoeach(aab, 2, 3, \"(a b --> a a b) reorder items on stack.\")\n\tDEFnoeach(aabb, 2, 4, \"(a b --> a a b b) reorder items on stack.\")\n\tDEFnoeach(abab, 2, 4, \"(a b --> a b a b) reorder items on stack.\")\n\n\tDEFnoeach(nip, 2, 1, \"(a b --> b) remove second item on stack.\")\n\tDEFnoeach(pop, 1, 0, \"(a -->) remove top item on stack.\")\n\t\n\t// loops\n\tvm.addBifHelp(\"\\n*** loops ***\");\n\t//DEFnoeach(while, 2, \"(A B --> ..) While applying A returns true, apply B.\")\n\tDEFnoeach(do, 2, 0, \"(list \\\\item[..] -->) applies the function to each item of a finite list. Useful for side effects like printing or file writing.\")\n\n\t// conditional ops\n\tvm.addBifHelp(\"\\n*** conditional ops ***\");\n\tDEF(equals, 2, \"(a b --> bool) returns 1 if a and b are structurally equivalent. If the data structures are cyclic then this may never terminate.\")\n\tDEF(less, 2, \"(a b --> bool) returns 1 if a is less than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF(greater, 2, \"(a b --> bool) returns 1 if a is greater than b structurally. If the data structures are cyclic then this may never terminate.\")\n\tDEF2(if, 3, -1, \"(A B C --> ..) if A is true then apply B else apply C.\")\n\n\tDEF(not, 1, \"(A --> bool) returns 0 if A is true and 1 if A is false.\")\n\t//DEF2(dip, 1, -1, \"(x A --> ..) pops x from stack, applies A, pushes x back on stack.\")\n\n\tDEFnoeach(try, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied.\")\n\tDEFnoeach(throw, 0, 0, \"(a -->) throw an exception.\")\n\tDEFnoeach(protect, 2, -1, \"(A B --> ..) apply function A. if an exception is thrown, function B is applied and the exception is rethrown. Otherwise function B is applied and control continues as normal.\")\n\n\t// form ops\n\tvm.addBifHelp(\"\\n*** form ops ***\");\n\tDEFAM(has, kk, \"(form key --> bool) return whether a form contains the key.\")\n \n\tDEFAM(keys, k, \"(form --> keys) return an array of the keys of the form.\")\n\tDEFAM(values, k, \"(form --> values) return an array of the values of the form.\")\n\tDEFAM(kv, k, \"(form --> keys values) return two arrays of the keys and values of the form.\") /// !!!! returns two values. can't be auto mapped.\n\tDEFAM(local, k, \"(form --> local) return the head of the prototype inheritance list.\")\n\tDEFAM(parent, k, \"(form --> parent) return the tail of the prototype inheritance list.\")\n\tDEFAM(dot, ka, \"(form key --> item) return the value for the key.\")\n \n DEFnoeach(pushWorkspace, 0, 0, \"(-->) pushes a new outer scope onto the workspace. New bindings will be made in the new outer scope.\");\n DEFnoeach(popWorkspace, 0, 0, \"(-->) pops a scope from the workspace. All bindings in the outer scope will be forgotten.\");\n\t\n\tvm.addBifHelp(\"\\n*** ref ops ***\");\n\tDEFAM(get, k, \"(r --> a) return the value store in a ref.\")\n\tDEFnoeach(set, 1, 0, \"(a r -->) store the value a in the ref r.\")\n\tvm.def(\"R\", 1, 1, ref_, \"(a --> r) create a new Ref with the inital value a\");\n\tvm.def(\"ZR\", 1, 1, zref_, \"(z --> r) create a new ZRef with the inital value z. A ZRefs is a mutable reference to a real number.\");\n\tvm.def(\"P\", 1, 2, plug_, \"(a --> out in) create a new stream plug pair with the inital value a\");\n\tvm.def(\"ZP\", 1, 2, zplug_, \"(a --> out in) create a new signal plug pair with the inital value a.\");\n\t\n\t\n\t//DEF(bind, 2, \"deprecated\")\n\t\n\t// apply ops\n\tvm.addBifHelp(\"\\n*** function ops ***\");\n\tDEF(Y, 1, \"(funA --> funB) Y combinator. funB calls funA with the last argument being funB itself. Currently the only way to do recursion. \\n\\t\\te.g. \\\\x f [x 2 < \\\\[1] \\\\[ x x -- f *] if] Y = factorial 7 factorial --> 5040\")\n\tDEF(noeach, 1, \"(fun --> fun) sets a flag in the function so that it will pass through arguments with @ operators without mapping them.\")\n\tvm.def(\"!\", 1, -1, apply_, \"(... f --> ...) apply the function to its arguments, observing @ arguments as appropriate.\");\n\tvm.def(\"!e\", 2, -1, applyEvent_, \"(form fun --> ...) for each argument in the function, find the same named fields in the form and push those values as arguments to the function.\");\n\tDEF(compile, 1, \"(string --> fun) compile the string and return a function.\")\n\t\n\tvm.addBifHelp(\"\\n*** printing ops ***\");\n\tDEFnoeach(printLength, 0, 1, \"(--> length) return the number of items printed for lists.\");\n\tDEFnoeach(printDepth, 0, 1, \"(--> depth) return the number of levels of nesting printed for lists.\");\n\tDEFnoeach(setPrintLength, 1, 0, \"(length --> ) set the number of items printed for lists.\");\n\tDEFnoeach(setPrintDepth, 1, 0, \"(depth -->) set the number of levels of nesting printed for lists.\");\n\t\n\tDEFnoeach(pr, 1, 0, \"(A -->) print the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(prdebug, 1, 0, \"(A -->) print debug version of the top item on the stack. (no space or carriage return is printed)\")\n\tDEFnoeach(cr, 0, 0, \"(-->) print a carriage return.\")\n\tDEFnoeach(sp, 0, 0, \"(-->) print a space character.\")\n\tDEFnoeach(tab, 0, 0, \"(-->) print a tab.\")\n\tDEFnoeach(prstk, 0, 0, \"(-->) print the stack.\")\n\n#if COLLECT_MINFO\n\tDEFnoeach(minfo, 0, 0, \"(-->) print memory management info.\")\n#endif\n\tDEFnoeach(listdump, 1, 0, \"(list -->) prints information about a list.\");\n\n\tvm.addBifHelp(\"\\n*** string ops ***\");\n\tDEF(str, 1, \"(x --> string) convert x to a string.\");\n\tDEF(debugstr, 1, \"(x --> string) convert x to a debug string.\");\n\tDEFAM(strcat, ak, \"(list separator --> string) convert elements of list to a string with separator string between each.\");\n\tDEF(strlines, 1, \"(list --> string) convert elements of list to a newline separated string.\");\n\tDEFAM(glob, k, \"(pattern --> paths) return a list of file path names that match.\");\n\n\tvm.addBifHelp(\"\\n*** sample rate ops ***\");\n\tDEFnoeach(sr, 0, 1, \"(--> sampleRate) returns the sample rate. samples per second. \")\n\tDEFnoeach(nyq, 0, 1, \"(--> sampleRate/2) returns the nyquist rate\")\n\tDEFnoeach(isr, 0, 1, \"(--> 1/sampleRate) returns the inverse sample rate\")\n\tDEFnoeach(inyq, 0, 1, \"(--> 2/sampleRate) returns the inverse nyquist rate.\")\n\tDEFnoeach(rps, 0, 1, \"(--> 2pi/sampleRate) returns the radians per sample\")\n\n\n\tvm.addBifHelp(\"\\n*** help ops ***\");\n\n\tDEFnoeach(help, 1, 0, \"(fun -->) prints help for a function.\");\n\tDEFnoeach(helpbifs, 0, 0, \"(-->) prints help for all built in functions.\");\n\tDEFnoeach(helpudfs, 0, 0, \"(-->) prints help for all user defined functions.\");\n\tDEFnoeach(helpall, 0, 0, \"(-->) prints help for all built in and user defined functions.\");\n DEF(helpLine, 1, \"(string -->) add a line to the user defined function help.\");\n\t\n\tvm.addBifHelp(\"\\n*** thread ops ***\");\n DEFnoeach(go, 1, 0, \"(fun -->) launches the function in a new thread.\");\n DEFnoeach(sleep, 1, 0, \"(seconds -->) sleeps the current thread for the time given.\");\n\n\tvm.addBifHelp(\"\\n*** misc ***\");\n\tDEF(type, 1, \"(a --> symbol) return a symbol naming the type of the value a.\")\n\tDEFnoeach(trace, 1, 0, \"(bool -->) turn tracing on/off in the interpreter.\")\n\n\tvm.addBifHelp(\"\\n*** text files ***\");\n\tDEFnoeach(load, 1, 0, \"(filename -->) compiles and executes a text file.\")\t\n\tDEFnoeach(prelude, 0, 0, \"(-->) opens the prelude file in the default text editor.\")\n\tDEFnoeach(examples, 0, 0, \"(-->) opens the examples file in the default text editor.\")\n\tDEFnoeach(logfile, 0, 0, \"(-->) opens the log file in the default text editor.\")\n\tDEFnoeach(readme, 0, 0, \"(-->) opens the README file in the default text editor.\")\n\n}\n\n"], ["/sapf/src/VM.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"Opcode.hpp\"\n#include \"Parser.hpp\"\n#include \"MultichannelExpansion.hpp\"\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nVM vm;\n\npthread_mutex_t gHelpMutex = PTHREAD_MUTEX_INITIALIZER;\n\nstd::atomic randSeedCounter = 77777;\n\nuint64_t timeseed()\n{\n\tstruct timeval tv;\n\tgettimeofday(&tv, 0);\n\tint32_t counter = ++randSeedCounter;\n\treturn Hash64(tv.tv_sec) + Hash64(tv.tv_usec) + Hash64(counter);\n}\n\n\nThread::Thread()\n :rate(vm.ar), stackBase(0), localBase(0),\n\tmWorkspace(new GForm()),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent)\n :rate(inParent.rate), stackBase(0), localBase(0),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::Thread(const Thread& inParent, P const& inFun)\n :rate(vm.ar), stackBase(0), localBase(0),\n fun(inFun),\n mWorkspace(inParent.mWorkspace),\n parsingWhat(parsingWords),\n fromString(false),\n line(NULL)\n{\n\trgen.init(timeseed());\n}\n\nThread::~Thread() {}\n\n//////////////////////\n\nstatic void inherit_(Thread& th, Prim* prim)\n{\n\tV vparent = th.pop();\n\tP form = asParent(th, vparent);\n\tth.push(form);\n}\n\nP extendFormByOne(Thread& th, P const& parent, P const& tmap, Arg value)\n{\t\n\tP
table = new Table(tmap);\n\tP form = new Form(table, parent);\n\ttable->put(0, value);\n\treturn form;\n}\n\nstatic void newForm_(Thread& th, Prim* prim)\n{\n\tTableMap* tmap = (TableMap*)th.pop().o();\n\tsize_t numArgs = tmap->mSize;\n\t\n\tV* args = &th.top() - numArgs + 1;\n\t\n\tP
table = new Table(tmap);\n\tV vparent = args[-1];\n\tP parent = asParent(th, vparent);\n\t\n\tP form = new Form(table, parent);\n\t\n\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\ttable->put(i, args[i]);\n\t}\n\t\n\tth.popn(numArgs+1);\n\t\n\tth.push(form);\n}\n\nstatic void newVList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilv;\n\t} else {\n\t\tseq = new List(itemTypeV, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\tth.push(seq);\t\t\n}\n\nstatic void newZList_(Thread& th, Prim* prim)\n{\n\tsize_t n = th.stackDepth();\n\t\n\tP seq;\n\tif (n == 0) {\n\t\tseq = vm._nilz;\n\t} else {\n\t\tseq = new List(itemTypeZ, n);\n\t\tV* ssp = &th.top() - n + 1;\n\t\t\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tseq->add(ssp[i]);\n\t\t}\n\t}\n\t\n\tth.popn(n);\n\t\n\tth.push(seq);\t\t\n}\n\n//////////////////////\n\n\nVM::VM()\n\t:\n\tprelude_file(NULL),\n\tlog_file(NULL),\n\t_ee(0),\n\t\t\n\tprintLength(20),\n\tprintDepth(8),\n\t\n\tar(kDefaultSampleRate, kDefaultZBlockSize),\n\tkr(ar, kDefaultControlBlockSize),\n\t\n\tVblockSize(kDefaultVBlockSize),\n\t\n#if COLLECT_MINFO\n\ttotalRetains(0),\n\ttotalReleases(0),\n\ttotalObjectsAllocated(0),\n\ttotalObjectsFreed(0),\n\ttotalSignalGenerators(0),\n\ttotalStreamGenerators(0)\n#endif\n{\n\tinitElapsedTime();\n\t\n\t_ee = new Form(0, NULL);\n\t\t\n\tbuiltins = new GTable();\n\t\n\t// add built in funs\n\t\t\n\t_nilz = new List(itemTypeZ);\n\t_nilv = new List(itemTypeV);\n\t\n\t_anilz = _nilz->mArray;\n\t_anilv = _nilv->mArray;\n\t\n\tnewForm = new Prim(newForm_, 0., 0, 1, NULL, NULL);\n\tinherit = new Prim(inherit_, 0., 0, 1, NULL, NULL);\n\n\tnewVList = new Prim(newVList_, 0., 0, 1, NULL, NULL);\n\tnewZList = new Prim(newZList_, 0., 0, 1, NULL, NULL);\n}\n\nVM::~VM()\n{\n}\n\n#if USE_LIBEDIT\nstatic const char* prompt(EditLine *e) \n{\n return \"sapf> \";\n}\nstatic const char* promptParen(EditLine *e) \n{\n return \"(sapf> \";\n}\nstatic const char* promptSquareBracket(EditLine *e) \n{\n return \"[sapf> \";\n}\nstatic const char* promptCurlyBracket(EditLine *e) \n{\n return \"{sapf> \";\n}\nstatic const char* promptLambda(EditLine *e) \n{\n return \"\\\\sapf> \";\n}\nstatic const char* promptString(EditLine *e) \n{\n return \"\\\"sapf> \";\n}\n#endif\n\nvoid Thread::getLine()\n{\t\n\tif (fromString) return;\n\tswitch (parsingWhat) {\n\t\tdefault: case parsingWords : el_set(el, EL_PROMPT, &prompt); break;\n\t\tcase parsingString : el_set(el, EL_PROMPT, &promptString); break;\n\t\tcase parsingParens : el_set(el, EL_PROMPT, &promptParen); break;\n\t\tcase parsingLambda : el_set(el, EL_PROMPT, &promptLambda); break;\n\t\tcase parsingArray : el_set(el, EL_PROMPT, &promptSquareBracket); break;\n\t\tcase parsingEnvir : el_set(el, EL_PROMPT, &promptCurlyBracket); break;\n\t}\n\tline = el_gets(el, &linelen);\n\tlinepos = 0;\n\tif (strncmp(line, \"quit\", 4)==0 || strncmp(line, \"..\", 2)==0) { line = NULL; throw errUserQuit; }\n\tif (line && linelen) {\n\t\thistory(myhistory, &ev, H_ENTER, line);\n\t\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\t\tif (logfilename) {\n\t\t\tFILE* logfile = fopen(logfilename, \"a\");\n\t\t\tlogTimestamp(logfile);\n\t\t\tfwrite(line, 1, strlen(line), logfile);\n\t\t\tfclose(logfile);\n\t\t}\n\t}\n}\n\nvoid Thread::logTimestamp(FILE* logfile)\n{\n\ttimeval tv;\n\tgettimeofday(&tv, NULL);\n\tif (previousTimeStamp == 0 || tv.tv_sec - previousTimeStamp > 3600) {\n\t\tpreviousTimeStamp = tv.tv_sec;\n\t\tchar date[32];\n\t\tctime_r(&tv.tv_sec, date);\n\t\tfprintf(logfile, \";;;;;;;; %s\", date);\n\t\tfflush(logfile);\n\t}\n}\n\nchar Thread::getc() { \n\tif (fromString) {\n\t\tif (line == NULL) return 0;\n\t\treturn line[linepos++];\n\t} else {\n\t\twhile (1) {\t\n\t\t\tif (line == NULL) {\n\t\t\t\tgetLine();\n\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t} else if (line[linepos] == 0) {\n\t\t\t\tif (parsingWhat == parsingWords) {\n\t\t\t\t\treturn 0;\n\t\t\t\t} else {\n\t\t\t\t\tgetLine();\n\t\t\t\t\tif (linelen == 0 || strcmp(line, \"\\n\") == 0) {\n\t\t\t\t\t\tline = NULL;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (line == NULL || linelen == 0) return 0;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn line[linepos++];\n\t\t\t}\n\t\t}\n\t}\n\treturn 0; // never gets here, but compiler too dumb to figure this out.\n}\n\nvoid Thread::repl(FILE* infile, const char* inLogfilename)\n{\n\tThread& th = *this;\n\n\tlogfilename = inLogfilename;\n\t\n\tpreviousTimeStamp = 0;\n\n#if USE_LIBEDIT\n\tel = el_init(\"sc\", stdin, stdout, stderr);\n\tel_set(el, EL_PROMPT, &prompt);\n\tel_set(el, EL_EDITOR, \"emacs\");\n\tel_set(el, EL_BIND, \"-s\", \"\\t\", \" \", NULL);\n\n\tmyhistory = history_init();\n\tif (myhistory == 0) {\n\t\tpost(\"history could not be initialized\\n\");\n\t\treturn;\n\t}\n\n\tconst char* envHistoryFileName = getenv(\"SAPF_HISTORY\");\n\tif (envHistoryFileName) {\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s\", envHistoryFileName);\n\t} else {\n\t\tconst char* homeDir = getenv(\"HOME\");\n\t\tsnprintf(historyfilename, PATH_MAX, \"%s/sapf-history.txt\", homeDir);\n\t}\n\thistory(myhistory, &ev, H_SETSIZE, 800);\n\thistory(myhistory, &ev, H_LOAD, historyfilename);\n\thistory(myhistory, &ev, H_SETUNIQUE, 1);\n\tel_set(el, EL_HIST, history, myhistory);\n#endif\n\t\n\tfflush(infile);\n\tbool running = true;\n\n\tpost(\"Type 'helpall' to get a list of all built-in functions.\\n\");\n\tpost(\"Type 'quit' to quit.\\n\");\n\t\n\tdo {\n\t\ttry {\n\t\t\tif (stackDepth()) {\n\t\t\t\tprintStack();\n\t\t\t\tpost(\"\\n\");\n\t\t\t}\n\t\t} catch (int err) {\n\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"\\nunknown error\\n\");\n\t\t}\n\t\t\t\t\n\t\ttry {\n\t\t\t// PARSE\n\t\t\t{\n\t\t\t\tP compiledFun;\n\t\t\t\tif (compile(NULL, compiledFun, true)) {\n\t\t\t\t// EVAL\n\t\t\t\t\tcompiledFun->runREPL(th);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (V& v) {\n post(\"error: \");\n v.print(th);\n\t\t\tpost(\"\\n\");\n\t\t} catch (int err) {\n\t\t\tif (err == errUserQuit) {\n\t\t\t\tpost(\"good bye\\n\");\n\t\t\t\trunning = false;\n\t\t\t} else if (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t\t} else {\n\t\t\t\tpost(\"error: %d\\n\", err);\n\t\t\t}\n\t\t} catch (std::bad_alloc& xerr) {\n\t\t\tpost(\"not enough memory\\n\");\n\t\t} catch (...) {\n\t\t\tpost(\"unknown error\\n\");\n\t\t}\n\n\t} while (running);\n\t\n\n#if USE_LIBEDIT\n\thistory(myhistory, &ev, H_SAVE, historyfilename);\n\thistory_end(myhistory);\n\tel_end(el);\n#endif\n}\n\n\ntemplate \nclass AutoFree\n{\n\tT* p;\npublic:\n\tAutoFree(T* _p) : p(_p) {}\n\t~AutoFree() { free(p); }\n\t\n\tT* operator()() { return p; }\n\tT* operator*() { return p; }\n\tT* operator->() { return p; }\n};\n\nvoid loadFile(Thread& th, const char* filename)\n{\n post(\"loading file '%s'\\n\", filename);\n\tFILE* f = fopen(filename, \"r\");\n\tif (!f) {\n\t\tpost(\"could not open '%s'\\n\", filename);\n\t\treturn;\n\t}\n\n\tfseek(f, 0, SEEK_END);\n\tint64_t fileSize = ftell(f);\n\tfseek(f, 0, SEEK_SET);\n\t\n\tAutoFree buf = (char*)malloc(fileSize + 1);\n\tconst char* p = buf();\n\tfread(buf(), 1, fileSize, f);\n\tbuf()[fileSize - 1] = 0;\n\t\t\n\ttry {\n\t\t{\n\t\t\tP compiledFun;\n\t\t\tif (th.compile(p, compiledFun, true)) {\n\t\t\t\tpost(\"compiled OK.\\n\");\n\t\t\t\tcompiledFun->run(th);\n\t\t\t\tpost(\"done loading file\\n\");\n\t\t\t}\n\t\t}\n } catch (V& v) {\n post(\"error: \");\n v.print(th);\n post(\"\\n\");\n\t} catch (int err) {\n\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\tpost(\"error: %s\\n\", errString[-1000 - err]);\n\t\t} else {\n\t\t\tpost(\"error: %d\\n\", err);\n\t\t}\n\t} catch (std::bad_alloc& xerr) {\n\t\tpost(\"not enough memory\\n\");\n\t} catch (...) {\n\t\tpost(\"unknown error\\n\");\n\t}\n}\n\nvoid Thread::printStack()\n{\n\tbool between = false;\n\tsize_t n = stackDepth();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &stack[stackBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid Thread::printLocals()\n{\n\tbool between = false;\n\tsize_t n = numLocals();\n\tfor (size_t i = 0; i < n; ++i) {\n\t\tV* s = &local[localBase+i];\n\t\tif (between) post(\" \");\n\t\telse between = true;\n\t\tstd::string cppstring;\n\t\ts->print(*this, cppstring);\n\t\tpost(\"%s\", cppstring.c_str());\n\t}\n}\n\nvoid VM::setSampleRate(double inSampleRate)\n{\n\tar = Rate(inSampleRate, ar.blockSize);\n\tkr = Rate(ar, kDefaultControlBlockSize);\n}\n\nV VM::def(Arg key, Arg value)\n{\n\tbuiltins->putImpure(key, value); \n V dummy;\n assert(builtins->getInner(key, dummy));\n\treturn value;\n}\n\nV VM::def(const char* name, Arg value)\n{\n\tdef(V(getsym(name)), value);\n\treturn value;\n}\n\nV VM::def(const char* name, int takes, int leaves, PrimFun pf, const char* help, Arg value, bool setNoEach)\n{\n\tV aPrim = new Prim(pf, value, takes, leaves, name, help);\n\tdef(name, aPrim);\n\t\n\tif (setNoEach) aPrim.SetNoEachOps();\n\t\n\tif (help)\n\t\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\t\t\n\treturn aPrim;\n}\n\nV VM::defmcx(const char* name, int numArgs, PrimFun pf, const char* help, Arg value)\n{\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = mcx(numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\nV VM::defautomap(const char* name, const char* mask, PrimFun pf, const char* help, Arg value)\n{\n\tint numArgs = (int)strlen(mask);\n\tV aPrim = new Prim(pf, value, numArgs, 1, name, help);\n\taPrim = automap(mask, numArgs, aPrim, name, help);\n\tdef(name, aPrim);\n\t\t\n\taddBifHelp(name, aPrim.GetAutoMapMask(), help);\n\treturn aPrim;\n}\n\n\n#pragma mark STACK\n\n#define POPREFTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n ApplyIfFun(v); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\n#define POPFUNTYPEDEF(TYPE) \\\nP Thread::pop##TYPE(const char* msg) \\\n{ \\\n\tV v = pop().deref(); \\\n\tif (!v.is##TYPE()) wrongType(msg, #TYPE, v); \\\n\treturn reinterpret_cast (v.o()); \\\n}\n\nPOPREFTYPEDEF(Ref);\nPOPTYPEDEF(ZRef);\nPOPTYPEDEF(String);\nPOPTYPEDEF(List);\nPOPFUNTYPEDEF(Fun);\nPOPTYPEDEF(Form);\n\nvoid Thread::ApplyIfFun(V& v)\n{\n if (v.isFunOrPrim()) {\n SaveStack ss(*this);\n v.apply(*this);\n v = pop();\n }\n}\n\n\nV Thread::popZInList(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn() && !p.isVList()) {\n\t\twrongType(msg, \"Real or Signal or List of Reals or Signals\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popZIn(const char* msg)\n{\n\tV p = pop();\n\tif (p.isRef() || p.isZRef()) p = p.deref();\n ApplyIfFun(p);\n\tif (!p.isZIn()) {\n\t\twrongType(msg, \"Real or Signal\", p);\n\t}\n\treturn p;\n}\n\nV Thread::popValue()\n{\n\tV p = pop().deref();\n ApplyIfFun(p);\n\treturn p;\n}\n\nP Thread::popVList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isVList()) {\n\t\twrongType(msg, \"Stream\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nP Thread::popZList(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isZList()) {\n\t\twrongType(msg, \"Signal\", v);\n\t}\n\treturn (List*)v.o();\n}\n\nint64_t Thread::popInt(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Real\", v);\n\t\n\tdouble f = v.f;\n\tint64_t i;\n\tif (f >= (double)LLONG_MAX) i = LLONG_MAX;\n\telse if (f <= (double)LLONG_MIN) i = LLONG_MIN;\n\telse i = (int64_t)f;\n\treturn i;\n}\n\ndouble Thread::popFloat(const char* msg)\n{\n\tV v = pop().deref();\n ApplyIfFun(v);\n\tif (!v.isReal()) wrongType(msg, \"Float\", v);\n\treturn v.f;\n}\n\nvoid Thread::tuck(size_t n, Arg v)\n{\n\tstack.push_back(V(0.));\n\tV* sp = &stack.back();\n\t\n\tfor (size_t i = 0; i < n; ++i)\n\t\tsp[-i] = sp[-i-1];\n\t\n\tsp[-n] = v;\n}\n\n///////////////////////////////////////\n\nbool Thread::compile(const char* inString, P& compiledFun, bool inTopLevel)\n{\t\n\tThread& th = *this;\n\tSaveCompileScope scs(th);\n\tif (inTopLevel) {\n\t\tmCompileScope = new TopCompileScope();\n\t} else {\n\t\tmCompileScope = new InnerCompileScope(new TopCompileScope());\n\t}\n\t\n\tP code;\n\tsetParseString(inString);\n\tgetLine();\n\tbool ok = parseElems(th, code);\n\tif (!ok || !code) {\n\t\tpost(\"parse error. %d\\n\", ok);\n\t\treturn false;\n\t}\n\t\t\n\tcompiledFun = new Fun(*this, new FunDef(*this, code, 0, th.mCompileScope->numLocals(), th.mCompileScope->numVars(), NULL));\n\t\n\treturn true;\n}\n\nint TopCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = CompileScope::directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) return scope;\n\n\tfor (size_t i = 0; i < mWorkspaceVars.size(); ++i) {\n\t\tif (mWorkspaceVars[i].mName() == inName()) {\n\t\t\treturn scopeWorkspace;\n\t\t}\n\t}\n\t\n\tV value;\n\tif (th.mWorkspace->get(th, inName(), value)) {\n\t\treturn scopeWorkspace;\n\t} else if (vm.builtins->get(th, inName, value)) {\n\t\toutBuiltIn = value;\n\t\treturn scopeBuiltIn;\n\t}\n\n\treturn scopeUndefined;\n}\n\n\nint CompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tfor (size_t i = 0; i < mLocals.size(); ++i) {\n\t\tif (mLocals[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeLocal;\n\t\t}\n\t}\n\tfor (size_t i = 0; i < mVars.size(); ++i) {\n\t\tif (mVars[i].mName() == inName()) {\n\t\t\toutIndex = i;\n\t\t\treturn scopeFunVar;\n\t\t}\n\t}\n\t\n\treturn scopeUndefined;\n}\n\n\nint TopCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint InnerCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\tint scope = directLookup(th, inName, outIndex, outBuiltIn);\n\tif (scope != scopeUndefined) \n\t\treturn scope;\n\n\tsize_t outerIndex;\n\tscope = mNext->indirectLookup(th, inName, outerIndex, outBuiltIn);\n\tif (scope == scopeUndefined) \n\t\treturn scopeUndefined;\n\t\n\tif (scope == scopeLocal || scope == scopeFunVar) {\n\t\tVarDef def;\n\t\tdef.mName = inName;\n\t\tdef.mIndex = mVars.size();\n\t\tdef.mFromScope = scope;\n\t\tdef.mFromIndex = outerIndex;\n\t\toutIndex = mVars.size();\n\t\tmVars.push_back(def);\n\t\treturn scopeFunVar;\n\t}\n\t\n\treturn scope;\n}\n\nint TopCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope != scopeUndefined && scope != scopeBuiltIn) \n\t\treturn scope; // already defined\n\t\t\n\tWorkspaceDef def;\n\tdef.mName = inName;\n\tmWorkspaceVars.push_back(def);\n\n\treturn scopeWorkspace;\n}\n\nint CompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\tV v;\n\tint scope = directLookup(th, inName, outIndex, v);\n\tif (scope == scopeFunVar) {\n\t\tpost(\"Name %s is already in use in this scope as a free variable.\\n\", inName->cstr());\n\t\tthrow errSyntax;\n\t}\n\t\n\tif (scope == scopeUndefined) {\t\t\n\t\tLocalDef def;\n\t\tdef.mName = inName;\n\t\toutIndex = def.mIndex = mLocals.size();\n\t\tmLocals.push_back(def);\n\t}\n\treturn scopeLocal;\n}\n\nint InnerCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn innerBindVar(th, inName, outIndex);\n}\n\nCompileScope* ParenCompileScope::nextNonParen() const\n{\n\tCompileScope* scope = mNext();\n\twhile (scope->isParen()) {\n\t\tscope = scope->mNext();\n\t}\n\treturn scope;\n}\n\nint ParenCompileScope::directLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->directLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::indirectLookup(Thread& th, P const& inName, size_t& outIndex, V& outBuiltIn)\n{\n\treturn mNext->indirectLookup(th, inName, outIndex, outBuiltIn);\n}\n\nint ParenCompileScope::innerBindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\nint ParenCompileScope::bindVar(Thread& th, P const& inName, size_t& outIndex)\n{\n\treturn mNext->innerBindVar(th, inName, outIndex);\n}\n\n//////////////////////\n\n\n\n\n"], ["/sapf/src/dsp.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"dsp.hpp\"\n#include \n#include \n#include \n\n\nFFTSetupD fftSetups[kMaxFFTLogSize+1];\n\nvoid initFFT()\n{\n\tfor (int i = kMinFFTLogSize; i <= kMaxFFTLogSize; ++i) {\n\t\tfftSetups[i] = vDSP_create_fftsetupD(i, kFFTRadix2);\n\t}\n}\n\nvoid fft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid ifft(int n, double* inReal, double* inImag, double* outReal, double* outImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zopD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n);\n}\n\nvoid fft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\nvoid ifft(int n, double* ioReal, double* ioImag)\n{\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex io;\n\t\n\tio.realp = ioReal;\n\tio.imagp = ioImag;\n\n\tvDSP_fft_zipD(fftSetups[log2n], &io, 1, log2n, FFT_INVERSE);\n\t\n\tdouble scale = .5;\n\tvDSP_vsmulD(ioReal, 1, &scale, ioReal, 1, n);\n\tvDSP_vsmulD(ioImag, 1, &scale, ioImag, 1, n);\n}\n\n\nvoid rfft(int n, double* inReal, double* outReal, double* outImag)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\tDSPDoubleSplitComplex out;\n\n vDSP_ctozD((DSPDoubleComplex*)inReal, 1, &in, 1, n2);\n\t\n\tout.realp = outReal;\n\tout.imagp = outImag;\n\n\tvDSP_fft_zropD(fftSetups[log2n], &in, 1, &out, 1, log2n, FFT_FORWARD);\n\n\tdouble scale = 2. / n;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n2);\n\tvDSP_vsmulD(outImag, 1, &scale, outImag, 1, n2);\n \n out.realp[n2] = out.imagp[0];\n out.imagp[0] = 0.;\n out.imagp[n2] = 0.;\n}\n\n\nvoid rifft(int n, double* inReal, double* inImag, double* outReal)\n{\n int n2 = n/2;\n\tint log2n = n == 0 ? 0 : 64 - __builtin_clzll(n - 1);\n\n\tDSPDoubleSplitComplex in;\n\t\n\tin.realp = inReal;\n\tin.imagp = inImag;\n\t\n //in.imagp[0] = in.realp[n2];\n in.imagp[0] = 0.;\n\n\tvDSP_fft_zripD(fftSetups[log2n], &in, 1, log2n, FFT_INVERSE);\n\n vDSP_ztocD(&in, 1, (DSPDoubleComplex*)outReal, 2, n2);\n\n\tdouble scale = .5;\n\tvDSP_vsmulD(outReal, 1, &scale, outReal, 1, n); \n}\n\n\n#define USE_VFORCE 1\n\ninline void complex_expD_conj(double& re, double& im)\n{\n\tdouble rho = expf(re);\n\tre = rho * cosf(im);\n\tim = rho * sinf(im);\n}\n\n"], ["/sapf/src/Parser.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Parser.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n#include \n\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n#pragma mark PARSER\n\nbool parseElem(Thread& th, P& code);\nbool parseWord(Thread& th, P& code);\nstatic void bindVar(Thread& th, P const& name, P& code);\n\nclass ParsingWhat\n{\n\tThread& th;\n\tint what;\npublic:\t\n\tParsingWhat(Thread& inThread, int newMode) : th(inThread), what(th.parsingWhat)\n\t{\n\t\tth.parsingWhat = newMode;\n\t} \n\t~ParsingWhat()\n\t{\n\t\tth.parsingWhat = what;\n\t}\n};\n\n\nstatic bool skipSpace(Thread& th)\n{\n\t//ScopeLog sl(\"skipSpace\");\n\tfor (;;) {\n\t\tint c = th.getc();\n\t\tif (c == ';') {\n\t\t\tc = th.getc();\n\t\t\twhile (c && c != '\\n') { c = th.getc(); }\n\t\t\tif (c == 0) { th.unget(1); return true; }\n\t\t}\n\t\tif (c == 0) { th.unget(1); return true; }\n\t\tbool skip = isspace(c) || iscntrl(c);\n\t\tif (!skip) { th.unget(1); break; }\n\t}\n\treturn false;\n}\n\nconst char* nonnamechars = \";()[]{}.`,:\\\"\\n\";\n\nstatic bool endOfWord(int c)\n{\n\treturn c == 0 || isspace(c) || strchr(nonnamechars, c) != nullptr;\n}\n\nstatic bool parseHexNumber(Thread& th, P& code)\n{\n\tconst char* start = th.curline();\n\tint64_t z = 0;\n\t\n\tth.getc();\n\tth.getc();\n\tint c = th.getc();\n\twhile(isxdigit(c)) {\n\t\tif (isdigit(c)) z = z*16 + c - '0';\n\t\telse z = z*16 + toupper(c) - 'A' + 10;\n\t\tc = th.getc();\n\t}\n\n\tif (!endOfWord(c)) {\n\t\t// even though it starts out like a number it continues as some other token\n\t\tth.unget(start);\n\t\treturn false;\n\t} else {\n\t\tth.unget(1);\n\t}\n\t\n\tcode->add(opPushImmediate, z);\n\t\n\treturn true;\n}\n\n\nstatic bool parseFloat(Thread& th, Z& result)\n{\t\n\t//ScopeLog sl(\"parseFloat\");\n\tconst char* start = th.curline();\n\tint c = th.getc();\n \n if (c == 'p' && th.c() == 'i') {\n th.getc();\n result = M_PI;\n return true;\n }\n \n\tif (c == '+' || c == '-') \n\t\tc = th.getc();\n\n\tint digits = 0;\n\tbool sawdot = false;\n\tfor ( ; ; ) {\n\t\tif (isdigit(c)) digits++;\n\t\telse if (c == '.') {\n\t\t\tif (sawdot) break;\n\t\t\tsawdot = true; \n\t\t}\n\t\telse break;\n\t\tc = th.getc(); \n\t}\n\tif (digits == 0) {\n\t\tth.unget(start);\n\t\treturn false;\n\t}\n\t\n\tif (c == 'e' || c == 'E') {\n\t\tc = th.getc();\n\t\tif (c == '+' || c == '-') \n\t\t\tc = th.getc();\n\t\twhile (isdigit(c)) { c = th.getc(); }\n\t}\n\n\tth.toToken(start, (int)(th.curline() - start));\n\t\n\tbool sawpi = false;\n\tbool sawmega = false;\n\tbool sawkilo = false;\n\tbool sawhecto = false;\n\tbool sawcenti = false;\n\tbool sawmilli = false;\n\tbool sawmicro = false;\n\t\n\t\n\tif (c == 'p' && th.c() == 'i') {\n\t\tsawpi = true;\n\t\tth.getc();\n\t} else if (c == 'M') {\n\t\tsawmega = true;\n\t} else if (c == 'k') {\n\t\tsawkilo = true;\n\t} else if (c == 'h') {\n\t\tsawhecto = true;\n\t} else if (c == 'c') {\n\t\tsawcenti = true;\n\t} else if (c == 'm') {\n\t\tsawmilli = true;\n\t} else if (c == 'u') {\n\t\tsawmicro = true;\n\t} else {\n\t\tth.unget(1);\n\t}\n\n\tdouble x = strtod(th.token, nullptr);\n\tif (sawpi) x *= M_PI;\n\telse if (sawmega) x *= 1e6;\n\telse if (sawkilo) x *= 1e3;\n\telse if (sawhecto) x *= 1e2;\n\telse if (sawcenti) x *= 1e-2;\n\telse if (sawmilli) x *= 1e-3;\n\telse if (sawmicro) x *= 1e-6;\n\n\tresult = x;\n\treturn true;\n}\n\nstatic bool parseNumber(Thread& th, Z& result)\n{\n\tconst char* start = th.curline();\n\n\tZ a, b;\n\tif (parseFloat(th, a)) {\n\t\tif (th.c() == '/') {\n\t\t\tth.getc();\n\t\t\tif (parseFloat(th, b) && endOfWord(th.c())) {\n\t\t\t\tresult = a/b;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (endOfWord(th.c())) {\n\t\t\tresult = a;\n\t\t\treturn true;\n\t\t}\n\t}\n\tth.unget(start);\n\treturn false;\n}\n\nstatic bool parseNumber(Thread& th, P& code)\n{\n Z x;\n if (parseNumber(th, x)) {\n \t\tcode->add(opPushImmediate, x);\n return true;\n }\n return false;\n}\n\nstatic bool parseSymbol(Thread& th, P& result);\nstatic bool parseItemList(Thread& th, P& code, int endbrace);\n\n\nstatic bool parseQuote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after quote\");\n\t\n\tV vname(name);\n\tcode->add(opPushImmediate, vname);\n\n\treturn true; \n}\n\nstatic bool parseBackquote(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after backquote\");\n\n\n\tV vname(name);\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\tswitch (scope) {\n\t\tcase scopeLocal :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushLocalVar, val);\n\t\t\tbreak;\n\t\tcase scopeFunVar :\n\t\t\tval.i = index;\n\t\t\tcode->add(opPushFunVar, val);\n\t\t\tbreak;\n\t\tcase scopeBuiltIn :\n\t\t\tcode->add(opPushImmediate, val);\n\t\t\tbreak;\n\t\tcase scopeWorkspace :\n\t\t\tcode->add(opPushWorkspaceVar, vname);\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tpost(\"backquote error: \\\"%s\\\" is an undefined word\\n\", name->s);\n\t\t\tsyntaxError(\"undefined word\");\n\t}\n\n\treturn true; \n}\n\nstatic bool parseDot(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opDot, vname);\n\n\treturn true; \n}\n\nstatic bool parseComma(Thread& th, P& code)\n{\n\tth.getc();\n\tP name;\n\n\tif (!parseSymbol(th, name)) \n\t\tsyntaxError(\"expected symbol after dot\");\n\t\n\tV vname(name);\n\tcode->add(opComma, vname);\n\n\treturn true; \n}\n\nstatic bool parseColon(Thread& th, P& code)\n{\n\tth.getc();\n\n P name;\n\n if (!parseSymbol(th, name)) \n syntaxError(\"expected symbol after colon\");\n \n code->keys.push_back(name);\n\n\treturn true;\n}\n\nstatic bool parseEachOp(Thread& th, P& code)\n{\n\t\n\tint64_t mask = 0;\n\tint level = 0;\n\n\tth.getc();\n\tint c = th.getc();\n\t\n\tif (c == '@') {\n\t\tmask = 1; \n\t\t++level;\n\t\tdo {\n\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '@');\n\t} else if (c >= '2' && c <= '9') {\n\t\tmask = 1LL << (c - '1');\n\t\tc = th.getc();\n\t} else if (c == '0' || c == '1') {\n\t\tdo { \n\t\t\tif (c == '1')\n\t\t\t\tmask |= 1LL << level;\n\t\t\t++level;\n\t\t\tc = th.getc();\n\t\t} while (c == '0' || c == '1');\n\t} else {\n\t\tmask = 1;\n\t}\n\tif (isdigit(c)) {\n\t\tsyntaxError(\"unexpected extra digit after @\");\n\t}\n\t\n\tth.unget(1);\n\n\tV v;\n\tv.i = mask;\n\t\n\tcode->add(opEach, v);\n\t\n\t\n\treturn true; \n}\n\n\nstatic bool parseNewForm(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingEnvir);\n\tP code2 = new Code(8);\n\tth.getc();\n\t\n\tparseItemList(th, code2, '}');\n\t\n\tif (code2->keys.size()) {\n\n\t\tP tmap = new TableMap(code2->keys.size());\n\t\t\n\t\tint i = 0;\n\t\tfor (Arg key : code2->keys) {\n tmap->put(i, key, key.Hash());\n\t\t\t++i;\n\t\t}\n\n\t\tcode2->keys.clear();\n\t\tcode2->add(opPushImmediate, V(tmap));\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\n\t\tcode->add(opNewForm, V(code2));\n\t} else {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opInherit, V(code2));\n\t}\n\t\t\t\n\treturn true;\n}\n\nstatic String* parseString(Thread& th);\n\nstatic bool parseStackEffect(Thread& th, int& outTakes, int& outLeaves)\n{\n\toutTakes = 0;\n\toutLeaves = 1;\n\tskipSpace(th);\n\tint c = th.c();\n\tif (!isdigit(c)) return true;\n\toutLeaves = 0;\n\t\n\twhile(isdigit(c)) {\n\t\toutTakes = outTakes * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\tif (c != '.') return false;\n\tc = th.getc();\n\twhile(isdigit(c)) {\n\t\toutLeaves = outLeaves * 10 + c - '0';\n\t\tc = th.getc();\n\t}\n\treturn true;\n}\n\nstatic bool parseLambda(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseLambda\");\n\tParsingWhat pw(th, parsingLambda);\n\tth.getc();\n\tstd::vector > args;\n\t\t\n\tSaveCompileScope scs(th);\n\t\n\tP cs = new InnerCompileScope(th.mCompileScope);\n\tth.mCompileScope = cs();\n\t\n\twhile (1) {\n\t\tP name;\n\t\tif (!parseSymbol(th, name)) break;\n\t\targs.push_back(name);\n\t\t\n\t\tint takes, leaves;\n\t\tif (!parseStackEffect(th, takes, leaves)) {\n\t\t\tsyntaxError(\"incorrectly formatted function argument stack effect annotation.\");\n\t\t}\n\t\t\n\t\tLocalDef def;\n\t\tdef.mName = name;\n\t\tdef.mIndex = cs->mLocals.size();\n\t\tdef.mTakes = takes;\n\t\tdef.mLeaves = leaves;\n\t\tcs->mLocals.push_back(def);\n\t}\n\t\n\tskipSpace(th);\n\t\n\tP help = parseString(th);\n\n\tskipSpace(th);\n\t\n\tint c = th.getc();\t\n\tif (c != '[') {\n post(\"got char '%c' %d\\n\", c, c);\n\t\tsyntaxError(\"expected open square bracket after argument list\");\n\t}\n\t\t\n\tP code2 = new Code(8);\t\n\tparseItemList(th, code2, ']');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\t\n\t\t\n\t// compile code to push all fun vars\n\tfor (size_t i = 0; i < cs->mVars.size(); ++i) {\n\t\tVarDef& def = cs->mVars[i];\n\t\tV vindex;\n\t\tvindex.i = def.mFromIndex;\n\t\t\n\t\tif (def.mFromScope == scopeLocal) {\n\t\t\tcode->add(opPushLocalVar, vindex);\n\t\t} else {\n\t\t\tcode->add(opPushFunVar, vindex);\n\t\t}\n\t}\n\tif (args.size() > USHRT_MAX || cs->mLocals.size() > USHRT_MAX || cs->mVars.size() > USHRT_MAX)\n\t{\n\t\tpost(\"Too many variables!\\n\");\n\t\tthrow errSyntax;\n\t}\n\n FunDef* def = new FunDef(th, code2, args.size(), cs->mLocals.size(), cs->mVars.size(), help);\n\tdef->mArgNames = args;\n\tcode->add(opPushFun, def);\n\n\treturn true;\n}\n\n#define COMPILE_PARENS 1\n\nstatic bool parseParens(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingParens);\n\tth.getc();\n\n#if COMPILE_PARENS\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ')');\n\n\tcode2->add(opReturn, 0.);\n\tcode2->shrinkToFit();\n\tcode->add(opParens, V(code2));\n#else\n\tparseItemList(th, code, ')');\n#endif\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseArray(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseArray\");\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewVList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilv));\n\t}\n\n\t\t\t\n\treturn true;\n}\n\nstatic bool parseZArray(Thread& th, P& code)\n{\n\tParsingWhat pw(th, parsingArray);\n\tth.getc();\n\tth.getc();\n\tP code2 = new Code(8);\n\tparseItemList(th, code2, ']');\n\n\tif (code2->size()) {\n\t\tcode2->add(opReturn, 0.);\n\t\tcode2->shrinkToFit();\n\t\tcode->add(opNewZList, V(code2));\n\t} else {\n\t\tcode->add(opPushImmediate, V(vm._nilz));\n\t}\n\t\t\t\n\treturn true;\n}\n\nbool parseItemList(Thread& th, P& code, int endbrace)\n{\t\n\t//ScopeLog sl(\"parseItemList\");\n\t\n\twhile (1) {\n\t\tskipSpace(th);\n\t\tint c = th.c();\n\t\tif (c == endbrace) break;\n\t\tif (!parseElem(th, code)) {\n\t\t\tif (endbrace == ']') syntaxError(\"expected ']'\");\n\t\t\tif (endbrace == '}') syntaxError(\"expected '}'\");\n\t\t\tif (endbrace == ')') syntaxError(\"expected ')'\");\n\t\t}\n\t}\n\tth.getc(); // skip end brace\n\t\n\treturn true;\n}\n\n\nbool parseSymbol(Thread& th, P& result)\n{\n\t//ScopeLog sl(\"parseSymbol\");\n\tskipSpace(th);\n\tconst char* start = th.curline();\n\tint c = th.getc();\n\t\n\twhile(!endOfWord(c)) {\n\t\tc = th.getc();\n\t}\n\tth.unget(1);\n\n\tsize_t len = th.curline() - start;\n\tif (len == 0) return false;\n\n\tth.toToken(start, (int)len);\n\t\n\tresult = getsym(th.token);\n\n\treturn true;\n}\n\nstatic void bindVar(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t index;\n\tint scope = th.mCompileScope->bindVar(th, name, index);\n\n\tV vname(name);\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tcode->add(opBindWorkspaceVar, vname);\n\t} else {\n\t\tval.i = index;\n\t\tcode->add(opBindLocal, val);\n\t}\n}\n\nstatic void bindVarFromList(Thread& th, P const& name, P& code)\n{\n\tV val;\n\tsize_t varIndex;\n\tint scope = th.mCompileScope->bindVar(th, name, varIndex);\n\n\tif (scope == scopeWorkspace) {\n\t\t// compiling at top level\n\t\tV vname(name);\n\t\tcode->add(opBindWorkspaceVarFromList, vname);\n\t} else {\n\t\tval.i = varIndex;\n\t\tcode->add(opBindLocalFromList, val);\n\t}\n}\n\nbool parseWord(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseWord\");\n\tP name;\n\n\tif (!parseSymbol(th, name)) return false;\n\t\t\n\tif (strcmp(name->cstr(), \"=\")==0) {\n\n\t\tskipSpace(th);\t\t\n\t\tif (th.c() == '(') {\n\t\t\tth.getc();\n\t\t\t// parse multiple assign\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ('\\n\");\n\t\t\t}\n\t\t\tfor (int64_t i = names.size()-1; i>=0; --i) {\n\t\t\t\tbindVar(th, names[i], code);\n\t\t\t}\n\t\t\tskipSpace(th);\n\t\t\tif (th.c() != ')') {\n\t\t\t\tsyntaxError(\"expected ')' after '= ('\\n\");\n\t\t\t}\n\t\t\tth.getc();\n\t\t\tcode->add(opNone, 0.);\n\t\t} else if (th.c() == '[') {\n\t\t\tth.getc();\n\t\t\t// parse assign from array\n\t\t\tstd::vector> names;\n\t\t\t{\n\t\t\t\tP name2;\n\t\t\t\twhile (parseSymbol(th, name2)) {\n\t\t\t\t\tnames.push_back(name2);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (names.size() == 0) {\n\t\t\t\tsyntaxError(\"expected a name after '= ['\\n\");\n\t\t\t}\n\t\t\tfor (size_t i = 0; iadd(opNone, 0.);\n\t\t} else {\n\t\t\tP name2;\n\t\t\tif (!parseSymbol(th, name2)) {\n\t\t\t\tsyntaxError(\"expected a name after '='\\n\");\n\t\t\t}\n\t\t\tbindVar(th, name2, code);\n\t\t}\n\t} else {\n\t\tV val;\n\t\tsize_t index;\n\t\tint scope = th.mCompileScope->indirectLookup(th, name, index, val);\n\t\tV vname(name);\n\t\tswitch (scope) {\n\t\t\tcase scopeLocal :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallLocalVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeFunVar :\n\t\t\t\tval.i = index;\n\t\t\t\tcode->add(opCallFunVar, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeBuiltIn :\n\t\t\t\tcode->add(opCallImmediate, val);\n\t\t\t\tbreak;\n\t\t\tcase scopeWorkspace :\n\t\t\t\tcode->add(opCallWorkspaceVar, vname);\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"\\\"%s\\\" is an undefined word\\n\", name->cstr());\n\t\t\t\tsyntaxError(\"undefined word\");\n\t\t\t\t\n\t\t}\n\n\t}\n\t\n\treturn true;\n}\n\nstatic bool parseString(Thread& th, P& code)\n{\n\t//ScopeLog sl(\"parseString\");\n\tParsingWhat pw(th, parsingString);\n\t\n\tV string = parseString(th);\t\n\tcode->add(opPushImmediate, string);\n\n\treturn true;\n}\n\nstatic String* parseString(Thread& th)\n{\n\tif (th.c() != '\"') return nullptr;\n\n\tParsingWhat pw(th, parsingString);\n\tth.getc();\n\tint c = th.getc();\n\tstd::string str;\n\t\t\n\twhile (true) {\n\t\tif (c == 0) {\n\t\t\tsyntaxError(\"end of input in string\");\n\t\t} else if (c == '\\\\' && th.c() == '\\\\') {\n\t\t\tth.getc();\n\t\t\tc = th.getc();\n\t\t\tswitch (c) {\n\t\t\t\tcase 'n' : str += '\\n'; break;\n\t\t\t\tcase 'r' : str += '\\r'; break;\n\t\t\t\tcase 'f' : str += '\\f'; break;\n\t\t\t\tcase 'v' : str += '\\v'; break;\n\t\t\t\tcase 't' : str += '\\t'; break;\n\t\t\t\tdefault : str += c; break;\n\t\t\t}\n\t\t\tc = th.getc();\n\t\t} else if (c == '\"') {\n\t\t\tif (th.c() == '\"') {\n\t\t\t\tc = th.getc();\n\t\t\t\tstr += '\"';\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tstr += c;\n\t\t\tc = th.getc();\n\t\t}\n\t}\n\t\n\treturn new String(str.c_str());\n}\n\nbool parseElem(Thread& th, P& code)\n{\t\n\tskipSpace(th);\n\tint c = th.c();\n\tif (c == 0)\n\t\treturn false;\n\tif (c == ']' || c == ')' || c == '}') {\n\t\tpost(\"unexpected '%c'.\\n\", c);\n\t\tthrow errSyntax;\n\t}\n\tif (c == '@')\n\t\t return parseEachOp(th, code);\n\tif (c == '(')\n\t\t return parseParens(th, code);\n\tif (c == '[')\n\t\t return parseArray(th, code);\n\tif (c == '{')\n\t\t return parseNewForm(th, code);\n\tif (c == '\\\\')\n\t\t return parseLambda(th, code);\n\tif (c == '\"')\n\t\treturn parseString(th, code);\n\tif (c == '\\'') \n\t\treturn parseQuote(th, code);\n\tif (c == '`') \n\t\treturn parseBackquote(th, code);\n\tif (c == ',') \n\t\treturn parseComma(th, code);\n\tif (c == ':')\n\t\treturn parseColon(th, code);\n\n\tif (c == '0' && th.d() == 'x') \n\t\treturn parseHexNumber(th, code) || parseWord(th, code);\n\n\tif (isdigit(c) || c == '+' || c == '-')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n \n if (c == 'p' && th.d() == 'i')\n\t\treturn parseNumber(th, code) || parseWord(th, code);\n\n\tif (c == '.')\n\t\treturn parseNumber(th, code) || parseDot(th, code);\n\n\n\tif (c == '#') {\n\t\tint d = th.d();\n\t\tif (!d) syntaxError(\"end of input after '#'\");\n\t\tif (d == '[') {\n\t\t\treturn parseZArray(th, code);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\treturn parseWord(th, code);\n}\n\n\nbool parseElems(Thread& th, P& code)\n{\n\tcode = new Code(8);\n\twhile (1) {\n\t\tif (!parseElem(th, code)) break;\n\t}\n\t\n\tcode->add(opReturn, 0.);\n\tcode->shrinkToFit();\n\t\t\n\treturn true;\n}\n\n/////////////////////////\n\n#pragma mark PRINTI\n\n#include \n\n///////////////////////// 1 2 3 4 5 6\n/////////////////////////1234567890123456789012345678901234567890123456789012345678901234\nconst char* s64Spaces = \" \";\nconst int kNumSpaces = 64;\n\nstatic void printSpaces(std::ostream& ost, int n)\n{\n\twhile (n >= kNumSpaces) {\n\t\tost << s64Spaces;\n\t\tn -= kNumSpaces;\n\t}\n\tif (n) {\n\t\tost << (s64Spaces + kNumSpaces - n);\n\t}\n}\n\nvoid printi(std::ostream& ost, int indent, const char* fmt, ...)\n{\n\tprintSpaces(ost, indent);\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n\nvoid prints(std::ostream& ost, const char* fmt, ...)\n{\n ssize_t final_n, n = 256;\n std::string str;\n std::unique_ptr formatted;\n va_list ap;\n while(1)\n\t{\n formatted.reset(new char[n]); /* wrap the plain char array into the unique_ptr */\n strcpy(&formatted[0], fmt);\n va_start(ap, fmt);\n final_n = vsnprintf(&formatted[0], n, fmt, ap);\n va_end(ap);\n if (final_n < 0)\n\t\t\treturn; // error\n\t\tif (n <= final_n) {\n n = final_n;\n } else {\n\t\t\tost << formatted.get();\n\t\t\treturn;\n\t\t}\n }\n}\n//////////////////////////////////\n\n"], ["/sapf/src/Object.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Object.hpp\"\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n#include \"MathOps.hpp\"\n#include \"Opcode.hpp\"\n#include \n#include \n\nvoid post(const char* fmt, ...)\n{\n va_list vargs;\n va_start(vargs, fmt);\n vprintf(fmt, vargs);\n}\n\nvoid zprintf(std::string& out, const char* fmt, ...)\n{\n\tchar s[1024];\n\tva_list args;\n\tva_start(args, fmt);\n\tvsnprintf(s, 1024, fmt, args);\n\tout += s;\n}\n\n#pragma mark ERROR HANDLING\n\n\nThread gDummyThread;\n\n[[noreturn]] void notFound(Arg key)\n{\n\tpost(\"notFound \");\n\tkey.print(gDummyThread); // keys are either symbols or numbers neither of which will use the thread argument to print.\n\tpost(\"\\n\");\n\tthrow errNotFound;\n}\n\n[[noreturn]] void wrongType(const char* msg, const char* expected, Arg got)\n{\n\tpost(\"error: wrong type for %s . expected %s. got %s.\\n\", msg, expected, got.TypeName());\n\tthrow errWrongType;\n}\n\n[[noreturn]] void syntaxError(const char* msg)\n{\n\tpost(\"syntax error: %s\\n\", msg);\n\tthrow errSyntax;\n}\n\n[[noreturn]] void indefiniteOp(const char* msg1, const char* msg2)\n{\n\tpost(\"error: operation on indefinite object %s%s\\n\", msg1, msg2);\n\tthrow errIndefiniteOperation;\n}\n\n#pragma mark OBJECT\n\n\nObject::Object()\n\t: scratch(0), elemType(0), finite(false), flags(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nObject::~Object()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\nvoid Ref::set(Arg inV)\n{\n\tO oldval = nullptr;\n\tif (inV.isObject()) {\n\t\tO newval = inV.o();\n\t\n\t\tnewval->retain();\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = newval;\n\t\t}\n\t} else {\n\t\tZ newval = inV.f;\n\t\t{\n\t\t\tSpinLocker lock(mSpinLock);\n\t\t\toldval = o;\n\t\t\to = nullptr;\n\t\t\tz = newval;\n\t\t}\n\t}\n\tif (oldval)\n\t\toldval->release();\n}\n\nvoid ZRef::set(Z inZ)\n{\n\tz = inZ;\n}\n\nV Ref::deref() const\n{\n\tV out;\n\t{\n\t\tSpinLocker lock(mSpinLock);\n\t\tif (o) {\n\t\t\tout = o;\n\t\t\tif (o) o->retain();\n\t\t}\n\t\telse out = z;\n\t}\n\treturn out;\n}\n\nV ZRef::deref() const\n{\n\treturn z;\n}\n\nZ Object::derefz() const\n{\n\treturn asFloat();\n}\n\nZ ZRef::derefz() const\n{\n\treturn z;\n}\n\n\nForm::Form(P
const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nvolatile int64_t gTreeNodeSerialNumber;\n\nGForm::GForm(P const& inTable, P const& inNext)\n\t: Object(), mTable(inTable), mNextForm(inNext)\n{\n}\n\nGForm::GForm(P const& inNext)\n\t: Object(), mNextForm(inNext)\n{ \n\tmTable = new GTable();\n}\n\nP consForm(P const& inTable, P const& inNext) { return new GForm(inTable, inNext); }\nP consForm(P
const& inTable, P const& inNext) { return new Form(inTable, inNext); }\n\nvoid Object::apply(Thread& th) {\n\tth.push(this);\n}\n\nclass PushFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nclass PushREPLFunContext\n{\n\tThread& th;\n\tP fun;\n\tsize_t stackBase, localBase;\npublic:\n\tPushREPLFunContext(Thread& inThread, P const& inFun)\n\t\t: th(inThread), fun(th.fun),\n\t\tstackBase(th.stackBase), localBase(th.localBase)\n\t{\n\t}\n\t~PushREPLFunContext()\n\t{\n\t\tth.popLocals();\n\t\tth.fun = fun;\n\t\tth.setStackBaseTo(stackBase);\n\t\tth.setLocalBase(localBase);\n\t}\n};\n\nvoid Fun::runREPL(Thread& th)\n{\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushREPLFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::run(Thread& th)\n{\t\n\tif (th.stackDepth() < NumArgs()) {\n\t\tpost(\"expected %qd args on stack. Only have %qd\\n\", (int64_t)NumArgs(), (int64_t)th.stack.size());\n\t\tthrow errStackUnderflow;\n\t}\n\n\tPushFunContext pfc(th, this);\n\n\tth.setLocalBase();\n\n\tif (NumArgs()) {\n\t\tth.local.insert(th.local.end(), th.stack.end() - NumArgs(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumArgs(), th.stack.end());\n\t}\n\tsize_t numLocalVars = NumLocals() - NumArgs();\n\tif (numLocalVars) {\n\t\tV v;\n\t\tth.local.insert(th.local.end(), numLocalVars, v);\n\t}\n\t\n\tth.setStackBase();\n\n\tth.fun = this;\n\t\n\tth.run(mDef->mCode->getOps());\n}\n\nvoid Fun::apply(Thread& th) \n{ \n\tint numArgs = NumArgs();\n\n\tif (th.stackDepth() < (size_t)numArgs) {\n\t\tthrow errStackUnderflow;\n\t}\n\n\tif (NoEachOps()) {\n\t\trun(th);\n\t} else {\n\t\tif (th.stackDepth()) {\n\t\t\tbool haveEachOps = false;\n\t\t\tV* args = &th.top() - numArgs + 1;\n\n\t\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, numArgs, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\trun(th);\n\t\t\t}\n\t\t} else {\n\t\t\trun(th);\n\t\t}\n\t}\n}\n\nFun::Fun(Thread& th, FunDef* def)\n\t: mDef(def), mWorkspace(def->Workspace())\n{\n\tif (NumVars()) {\n\t\tmVars.insert(mVars.end(), th.stack.end() - NumVars(), th.stack.end());\n\t\tth.stack.erase(th.stack.end() - NumVars(), th.stack.end());\n\t}\n}\n\nFunDef::FunDef(Thread& th, P const& inCode, uint16_t inNumArgs, uint16_t inNumLocals, uint16_t inNumVars, P const& inHelp) \n\t: mCode(inCode), mNumArgs(inNumArgs), mNumLocals(inNumLocals), mNumVars(inNumVars), \n mWorkspace(th.mWorkspace),\n mHelp(inHelp)\n{\n}\n\nFun::~Fun()\n{\n}\n\nvoid Prim::apply(Thread& th) \n{\n\tapply_n(th, mTakes);\n}\n\nvoid Prim::apply_n(Thread& th, size_t n)\n{ \n\tif (th.stackDepth() < n)\n\t\tthrow errStackUnderflow;\n\t\n\tif (NoEachOps()) {\n\t\tprim(th, this); \n\t} else {\n\t\n\t\tif (n) {\n\t\t\tV* args = &th.top() - n + 1;\n\n\t\t\tbool haveEachOps = false;\n\t\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\t\tif (args[i].isEachOp()) {\n\t\t\t\t\thaveEachOps = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (haveEachOps) {\n\t\t\t\tList* s = handleEachOps(th, (int)n, this);\n\t\t\t\tth.push(s);\n\t\t\t} else {\n\t\t\t\tprim(th, this); \n\t\t\t}\n\t\t} else {\n\t\t\tprim(th, this); \n\t\t}\n\t}\n}\n\nbool Form::get(Thread& th, Arg key, V& value) const\n{\n const Form* e = this;\n\tint64_t hash = key.Hash();\n do {\n if (e->mTable->getWithHash(th, key, hash, value)) {\n return true;\n }\n e = (Form*)e->mNextForm();\n } while (e);\n return false;\n}\n\n\nV Form::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\nbool GForm::get(Thread& th, Arg key, V& value) const\n{\n const GForm* e = this;\n do {\n if (e->mTable->get(th, key, value)) {\n return true;\n }\n e = (GForm*)e->mNextForm();\n } while (e);\n return false;\n}\n\nGForm* GForm::putImpure(Arg key, Arg value)\n{\n\tif (mTable->putImpure(key, value)) return this;\n\treturn putPure(key, value);\n}\n\nGForm* GForm::putPure(Arg inKey, Arg inValue)\n{\n\tint64_t inKeyHash = inKey.Hash();\n\treturn new GForm(mTable->putPure(inKey, inKeyHash, inValue), mNextForm);\n}\n\nV GForm::mustGet(Thread& th, Arg key) const\n{\n\tV value;\n\tif (!get(th, key, value)) {\n\t\tpost(\"not found: \");\n\t\tthrow errNotFound; \n\t}\n\treturn value;\n}\n\n\nGTable* GTable::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n auto tree = mTree.load();\n\tif (tree) {\n\t\treturn new GTable(tree->putPure(inKey, inKeyHash, inValue));\n\t} else {\n\t\tint64_t serialNo = ++gTreeNodeSerialNumber;\n\t\treturn new GTable(new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n\t}\n}\n\nTreeNode* TreeNode::putPure(Arg inKey, int64_t inKeyHash, Arg inValue)\n{\n\tif (inKeyHash == mHash && inKey.Identical(mKey)) {\n\t\treturn new TreeNode(mKey, mHash, inValue, mSerialNumber, mLeft, mRight);\n\t} \n auto left = mLeft.load();\n auto right = mRight.load();\n if (inKeyHash < mHash) {\n if (left) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left->putPure(inKey, inKeyHash, inValue), right);\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr), right);\n }\n\t} else {\n if (right) {\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, right->putPure(inKey, inKeyHash, inValue));\n } else {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n return new TreeNode(mKey, mHash, mValue, mSerialNumber, left, new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr));\n }\n\t}\n}\n\nstatic bool TreeNodeEquals(Thread& th, TreeNode* a, TreeNode* b)\n{\n while (1) {\n if (!a) return !b;\n if (!b) return false;\n \n if (!a->mKey.Equals(th, b->mKey)) return false;\n if (!a->mValue.Equals(th, b->mValue)) return false;\n if (a->mLeft == 0) {\n if (b->mLeft != 0) return false;\n } else {\n if (b->mLeft == 0) return false;\n if (!TreeNodeEquals(th, a->mLeft, b->mLeft)) return false;\n }\n a = a->mRight;\n b = b->mRight;\n }\n}\n\nbool GTable::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isGTable()) return false;\n\tif (this == v.o()) return true;\n\tGTable* that = (GTable*)v.o();\n return TreeNodeEquals(th, mTree.load(), that->mTree.load());\n}\n\nvoid GTable::print(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tzprintf(out, \" \");\n\t\tp->mValue.print(th, out);\n\t\tzprintf(out, \" :\");\n\t\tp->mKey.print(th, out);\n\t\tzprintf(out, \"\\n\");\n\t}\n}\n\nvoid GTable::printSomethingIWant(Thread& th, std::string& out, int depth)\n{\n\tstd::vector > vec = sorted();\n\tfor (size_t i = 0; i < vec.size(); ++i) {\n\t\tP& p = vec[i];\n\t\tif (p->mValue.leaves() != 0 && p->mValue.leaves() != 1) {\n\t\t\tzprintf(out, \" \");\n\t\t\tp->mKey.print(th, out);\n\t\t\tzprintf(out, \" : \");\n\t\t\tp->mValue.print(th, out);\n\t\t\tzprintf(out, \"\\n\");\n\t\t}\n\t}\n}\n\nbool GTable::get(Thread& th, Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nbool GTable::getInner(Arg inKey, V& outValue) const\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tTreeNode* tree = mTree.load();\n\twhile (1) {\n\t\tif (tree == nullptr) return false;\n\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\tif (inKeyHash == treeKeyHash) {\n\t\t\toutValue = tree->mValue;\n\t\t\treturn true;\n\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\ttree = tree->mLeft.load();\n\t\t} else {\n\t\t\ttree = tree->mRight.load();\n\t\t}\n\t}\n}\n\nV GTable::mustGet(Thread& th, Arg inKey) const\n{\n\tV value;\n\tif (get(th, inKey, value)) return value;\n\t\n\tthrow errNotFound;\n}\n\nbool GTable::putImpure(Arg inKey, Arg inValue)\n{\n\tint32_t inKeyHash = inKey.Hash();\n\tvolatile std::atomic* treeNodePtr = &mTree;\n\twhile (1) {\n\t\tTreeNode* tree = treeNodePtr->load();\n\t\tif (tree == nullptr) {\n int64_t serialNo = ++gTreeNodeSerialNumber;\n\t\t\tTreeNode* newNode = new TreeNode(inKey, inKeyHash, inValue, serialNo, nullptr, nullptr);\n\t\t\tnewNode->retain();\n TreeNode* nullNode = nullptr;\n if (treeNodePtr->compare_exchange_weak(nullNode, newNode)) {\n break;\n }\n newNode->release();\n\t\t} else {\n\t\t\tint32_t treeKeyHash = tree->mKey.Hash();\n\t\t\tif (treeKeyHash == inKeyHash) {\n\t\t\t\treturn false; // cannot rebind an existing value.\n\t\t\t} else if (inKeyHash < treeKeyHash) {\n\t\t\t\ttreeNodePtr = &tree->mLeft;\n\t\t\t} else {\n\t\t\t\ttreeNodePtr = &tree->mRight;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\n\nvoid TreeNode::getAll(std::vector >& vec)\n{\n\tP node = this;\n\tdo {\n\t\tvec.push_back(node);\n auto left = node->mLeft.load();\n\t\tif (left) left->getAll(vec);\n\t\tnode = node->mRight.load();\n\t} while (node());\n}\n\nstatic bool compareTreeNodes(P const& a, P const& b)\n{\n\treturn a->mSerialNumber < b->mSerialNumber;\n}\n\nstd::vector > GTable::sorted() const\n{\n\tstd::vector > vec;\n auto tree = mTree.load();\n\tif (tree) {\n\t\ttree->getAll(vec);\n\t\tsort(vec.begin(), vec.end(), compareTreeNodes);\n\t}\n\treturn vec;\n}\n\n/////////\n\n\nV List::unaryOp(Thread& th, UnaryOp* op)\n{\n\tif (isVList())\n\t\treturn new List(new UnaryOpGen(th, op, this));\n\telse\n\t\treturn new List(new UnaryOpZGen(th, op, this));\n\t\t\n}\n\nV List::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a)\n{\n\tif (isVList())\n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nV List::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a)\n{\n\treturn op->makeVList(th, _a, this);\n}\n\nV List::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a)\n{\n\tif (isVList()) \n\t\treturn op->makeVList(th, _a, this);\n\telse\n\t\treturn op->makeZList(th, _a, this);\n}\n\nvoid V::apply(Thread& th)\n{\n\tif (o) {\n\t\to->apply(th);\n\t} else {\n\t\tth.push(*this);\n\t}\n}\n\nV V::deref()\n{\n\tif (o) {\n\t\treturn o->deref();\n\t} else {\n\t\treturn *this;\n\t}\n}\n\nV V::mustGet(Thread& th, Arg key) const\n{\n\tif (o) {\n\t\treturn o->mustGet(th, key);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nbool V::get(Thread& th, Arg key, V& value) const\n{\n\tif (o) {\n\t\treturn o->get(th, key, value);\n\t} else {\n\t\tnotFound(key);\n\t\tthrow errNotFound;\n\t}\n}\n\nint V::Hash() const \n{\n\tif (o) {\n\t\treturn o->Hash();\n\t} else {\n union {\n double f;\n uint64_t i;\n } u;\n u.f = f;\n\t\treturn (int)::Hash64(u.i);\n\t}\n}\n\nV V::unaryOp(Thread& th, UnaryOp* op) const\n{\n\treturn !o ? V(op->op(f)) : o->unaryOp(th, op);\n}\n\nV V::binaryOp(Thread& th, BinaryOp* op, Arg _b) const\n{\n\treturn !o ? _b.binaryOpWithReal(th, op, f) : o->binaryOp(th, op, _b);\n}\n\nV V::binaryOpWithReal(Thread& th, BinaryOp* op, Z _a) const\n{\n\treturn !o ? V(op->op(_a, f)) : o->binaryOpWithReal(th, op, _a);\n}\n\nV V::binaryOpWithVList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeVList(th, _a, *this) : o->binaryOpWithVList(th, op, _a);\n}\n\nV V::binaryOpWithZList(Thread& th, BinaryOp* op, List* _a) const\n{\n\treturn !o ? op->makeZList(th, _a, *this) : o->binaryOpWithZList(th, op, _a);\n}\n\nvoid Object::printDebug(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::printShort(Thread& th, int depth)\n{ \n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid Object::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"#%s\", TypeName());\n\tout += s; \n}\n\nvoid Object::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %p}\", TypeName(), this);\n\tout += s; \n}\n\nvoid Prim::print(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\nvoid Prim::printDebug(Thread& th, std::string& out, int depth)\n{ \n\tchar s[64];\n\tsnprintf(s, 64, \"{%s, %s}\", TypeName(), mName);\n\tout += s; \n}\n\n\nvoid Ref::print(Thread& th, std::string& out, int depth)\n{\n\tV v = deref();\n\tv.print(th, out, depth);\n\tzprintf(out, \" R\");\n\t\n}\n\nvoid ZRef::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%g ZR\", z);\t\n}\n\nvoid String::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"%s\", (char*)s);\n}\n\nvoid String::printDebug(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"\\\"%s\\\"\", (char*)s);\n}\n\nvoid GForm::print(Thread& th, std::string& out, int depth)\n{\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n zprintf(out, \"new\\n\");\n\t} else {\n\t\tzprintf(out, \"New\\n\");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n}\n\nvoid Form::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"{...} \");\n\t\treturn;\n\t}\n\t\n\tzprintf(out, \"{\");\n\tif (mNextForm) {\n\t\tmNextForm->print(th, out, depth);\n\t\tzprintf(out, \" \");\n\t}\n\t\n\tmTable->print(th, out, depth+1);\n\t\n\tzprintf(out, \"}\");\n}\n\n\nvoid EachOp::print(Thread& th, std::string& out, int inDepth)\n{\n\tv.print(th, out, inDepth);\n\tzprintf(out, \" \");\n\t\n\t// try to print as concisely as possible.\n\tif (mask == 1) {\n\t\tzprintf(out, \"@\");\n\t} else if (ONES(mask) == 1 && 1 + CTZ(mask) <= 9) {\n\t\tzprintf(out, \"@%d\", 1 + CTZ(mask));\n\t} else if (CTZ(mask) == 0) {\n\t\tint n = CTZ(~mask);\n\t\twhile (n--) \n\t\t\tzprintf(out, \"@\");\n\t} else {\n\t\tzprintf(out, \"@\");\n\t\tint32_t m = mask;\n\t\twhile (m) {\n\t\t\tzprintf(out, \"%c\", '0' + (m&1));\n\t\t\tm >>= 1;\n\t\t}\n\t}\n}\n\n\nvoid Code::print(Thread& th, std::string& out, int depth)\n{\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"#Code{...}\");\n\t\treturn;\n\t}\n\n\tzprintf(out, \"#Code %d{\\n\", size());\n\tOpcode* items = getOps();\n\tfor (int i = 0; i < size(); ++i) {\n\t\tzprintf(out, \"%4d %s \", i, opcode_name[items[i].op]);\n\t\titems[i].v.printShort(th, out, depth+1);\n\t\tout += \"\\n\";\n\t}\n\tzprintf(out, \"}\\n\");\n}\n\nvoid List::print(Thread& th, std::string& out, int depth)\n{\n\tif (isV()) {\n\t\tzprintf(out, \"[\");\n\t} else {\n\t\tzprintf(out, \"#[\");\n\t}\n\t\n\tif (depth >= vm.printDepth) {\n\t\tzprintf(out, \"...]\");\n\t\treturn;\n\t}\n\t\n\tbool once = true;\n\tList* list = this;\n\t\n\tfor (int i = 0; list && i < vm.printLength;) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tfor (int j = 0; j < a->size() && i < vm.printLength; ++j, ++i) {\n\t\t\tif (!once) zprintf(out, \" \");\n\t\t\tonce = false;\n\t\t\tif (a->isV()) {\n\t\t\t\ta->v()[j].print(th, out, depth+1);\n\t\t\t} else {\n\t\t\t\n\t\t\t\tzprintf(out, \"%g\", a->z()[j]);\n\t\t\t}\n\t\t}\n\t\tif (i >= vm.printLength) {\n\t\t\tzprintf(out, \" ...]\");\n\t\t\treturn;\n\t\t}\n\t\tlist = list->nextp();\n\t}\n\tif (list && list->mNext) {\n\t\tzprintf(out, \" ...]\");\n\t} else {\n\t\tzprintf(out, \"]\");\n\t}\n}\n\nvoid V::print(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->print(th, out, depth);\n}\n\nvoid V::printShort(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printShort(th, out, depth);\n}\n\nvoid V::printDebug(Thread& th, std::string& out, int depth) const\n{\n\tif (!o) zprintf(out, \"%g\", f);\n\telse o->printDebug(th, out, depth);\n}\n\n\nvoid V::print(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprint(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printShort(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintShort(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nvoid V::printDebug(Thread& th, int depth) const\n{\n\tstd::string s;\n\tprintDebug(th, s, depth);\n\tpost(\"%s\", s.c_str());\n}\n\nGen::Gen(Thread& th, int inItemType, bool inFinite)\n\t: mDone(false), mOut(0), mBlockSize(inItemType == itemTypeV ? vm.VblockSize : th.rate.blockSize)\n{\n\telemType = inItemType;\n\tsetFinite(inFinite);\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t++vm.totalStreamGenerators;\n\telse\n\t\t++vm.totalSignalGenerators;\n#endif\n}\n\nGen::~Gen()\n{\n#if COLLECT_MINFO\n\tif (elemType == itemTypeV)\n\t\t--vm.totalStreamGenerators;\n\telse\n\t\t--vm.totalSignalGenerators;\n#endif\n}\n\nvoid Gen::end() \n{\n\tsetDone();\n\tmOut->end();\n}\n\n\nvoid Gen::produce(int shrinkBy)\n{\n\tmOut->mArray->addSize(-shrinkBy);\n\tmOut = mOut->nextp();\n}\n\nvoid List::end()\n{\n\tassert(mGen);\n\tmNext = nullptr;\n\tmGen = nullptr;\n\tmArray = vm.getNilArray(elemType);\n}\n\nV* List::fulfill(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next();\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nV* List::fulfill(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->v();\n}\n\nZ* List::fulfillz(int n)\n{\n\tassert(mGen);\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz_link(int n, P const& next)\n{\n\tmArray = new Array(elemType, n);\n\tmArray->setSize(n);\n\tmNext = next;\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nZ* List::fulfillz(P const& inArray)\n{\n\tassert(mGen);\n\tassert(elemType == inArray->elemType);\n\tmArray = inArray;\n\tmNext = new List(mGen);\n\tmGen = nullptr;\n\treturn mArray->z();\n}\n\nvoid List::link(Thread& th, List* inList)\n{\n\tassert(mGen);\n\tif (!inList) return;\n\tinList->force(th);\n\tmNext = inList->mNext;\n\tmArray = inList->mArray;\n\tmGen = nullptr;\n}\n\nvoid List::force(Thread& th)\n{\t\n\tSpinLocker lock(mSpinLock);\n\tif (mGen) {\n\t\tP gen = mGen; // keep the gen from being destroyed out from under pull().\n\t\tif (gen->done()) {\n\t\t\tgen->end();\n\t\t} else {\n\t\t\tgen->pull(th);\n\t\t}\n\t\t// mGen should be NULL at this point because one of the following should have been called: fulfill, link, end.\n\t}\n}\n\nint64_t List::length(Thread& th)\n{\n\tif (!isFinite())\n\t\tindefiniteOp(\"size\", \"\");\n\t\n\tList* list = this;\n\t\n\tint64_t sum = 0;\n\twhile (list) {\n\t\tlist->force(th);\n\t\t\n\t\tsum += list->mArray->size();\n\t\tlist = list->nextp();\n\t}\n\t\n\treturn sum;\n}\n\nArray::~Array()\n{\n\tif (isV()) {\n\t\tdelete [] vv;\n\t} else {\n\t\tfree(p);\n\t}\n}\n\nvoid Array::alloc(int64_t inCap)\n{\n\tif (mCap >= inCap) return;\n\tmCap = inCap;\n\tif (isV()) {\n\t\tV* oldv = vv;\n\t\tvv = new V[mCap];\n\t\tfor (int64_t i = 0; i < size(); ++i) \n\t\t\tvv[i] = oldv[i];\n\t\tdelete [] oldv;\n\t} else {\n\t\tp = realloc(p, mCap * elemSize());\n\t}\n}\n\nvoid Array::add(Arg inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = inItem;\n\telse zz[mSize++] = inItem.asFloat();\n}\n\nvoid Array::addAll(Array* a)\n{\n\tif (!a->mSize)\n\t\treturn;\n\t\t\n\tint64_t newSize = mSize + a->size();\n\tif (newSize > mCap)\n\t\talloc(NEXTPOWEROFTWO(newSize));\n\t\n\tif (isV()) {\n\t\tif (a->isV()) {\n\t\t\tV* x = vv + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t} else {\n\t\t\tV* x = vv + size();\n\t\t\tZ* y = a->zz;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i];\n\t\t}\n\t} else {\n\t\tif (a->isV()) {\n\t\t\tZ* x = zz + size();\n\t\t\tV* y = a->vv;\n\t\t\tfor (int64_t i = 0; i < a->size(); ++i) x[i] = y[i].asFloat();\n\t\t} else {\n\t\t\tmemcpy(zz + mSize, a->zz, a->mSize * sizeof(Z));\n\t\t}\n\t}\n\tmSize = newSize;\n}\n\nvoid Array::addz(Z inItem)\n{\n\tif (mSize >= mCap)\n\t\talloc(2 * mCap);\n\tif (isV()) vv[mSize++] = V(inItem);\n\telse zz[mSize++] = inItem;\n}\n\nvoid Array::put(int64_t inIndex, Arg inItem)\n{\n\tif (isV()) vv[inIndex] = inItem;\n\telse zz[inIndex] = inItem.asFloat();\n}\n\nvoid Array::putz(int64_t inIndex, Z inItem)\n{\n\tif (isV()) vv[inIndex] = V(inItem);\n\telse zz[inIndex] = inItem;\n}\n\nIn::In()\n\t: mList(nullptr), mOffset(0), mConstant(0.), mIsConstant(true)\n{\n}\n\nVIn::VIn()\n{\n\tset(0.);\n}\n\nVIn::VIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nZIn::ZIn()\n{\n\tset(0.);\n}\n\nZIn::ZIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nBothIn::BothIn()\n{\n\tset(0.);\n}\n\nBothIn::BothIn(Arg inValue)\n{\n\tset(inValue);\n}\n\nvoid VIn::set(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid VIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid BothIn::set(Arg inValue)\n{\n\tif (inValue.isList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setv(Arg inValue)\n{\n\tif (inValue.isVList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nvoid BothIn::setConstant(Arg inValue)\n{\n\tmList = nullptr;\n\tmConstant = inValue;\n\tmIsConstant = true;\n}\n\n\nvoid ZIn::set(Arg inValue)\n{\n\tif (inValue.isZList()) {\n\t\tmList = (List*)inValue.o();\n\t\tmOffset = 0;\n\t\tmIsConstant = false;\n\t} else {\n\t\tmList = nullptr;\n\t\tmConstant = inValue;\n\t\tmIsConstant = true;\n\t}\n}\n\nbool VIn::operator()(Thread& th, int& ioNum, int& outStride, V*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant;\n\t\treturn false;\n\t}\n\t\n\tif (mList) {\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n int num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->v() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n }\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant;\n\tmDone = true;\n\treturn true;\n}\n\nbool ZIn::operator()(Thread& th, int& ioNum, int& outStride, Z*& outBuffer)\n{\n\tif (mIsConstant) {\n\t\toutStride = 0;\n\t\toutBuffer = &mConstant.f;\n\t\treturn false;\n\t}\n\tif (mList) {\n\t\tif (mOnce) {\n\t\t\tmOnce = false;\n\t\t}\n while (1) {\n mList->force(th);\n assert(mList->mArray);\n\t\t\tint num = (int)(mList->mArray->size() - mOffset);\n if (num) {\n ioNum = std::min(ioNum, num);\n outBuffer = mList->mArray->z() + mOffset;\n outStride = 1;\n return false;\n } else if (mList->next()) {\n mList = mList->next();\n } else break;\n }\n\t}\n\tmConstant = 0.;\n\toutStride = 0;\n\toutBuffer = &mConstant.f;\n ioNum = 0;\n\tmDone = true;\n\treturn true;\n}\n\nvoid dumpList(List const* list)\n{\n\tfor (int i = 0; list; ++i, list = list->nextp()) {\n\t\tprintf(\" List %d %p mGen %p\\n\", i, list, list->mGen());\n\t\tprintf(\" List %d %p mNext %p\\n\", i, list, list->nextp());\n\t\tprintf(\" List %d %p mArray %p %d\\n\", i, list, list->mArray(), (int)(list->mArray() ? list->mArray->size() : 0));\n\t}\n}\n\nbool VIn::link(Thread& th, List* inList)\n{\n\tif (!mList) return false;\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tV* out = inList->fulfill_link(n, mList->next());\n\t\t\t\tV* in = mList->mArray->v() + mOffset;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = in[i];\n\t\t\t\t}\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nbool ZIn::link(Thread& th, List* inList)\n{\t\n\tif (!mList) return false;\n\n\twhile (1) {\n\t\tmList->force(th);\n\t\tassert(mList->mArray);\n\t\tif (mOffset) {\n\t\t\tint n = (int)(mList->mArray->size() - mOffset);\n\t\t\tif (n) {\n\t\t\t\tZ* out = inList->fulfillz_link(n, mList->next());\n\t\t\t\tZ* in = mList->mArray->z() + mOffset;\n\t\t\t\tmemcpy(out, in, n * sizeof(Z));\n\n\t\t\t\tmList = nullptr;\n\t\t\t\tmDone = true;\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tmList = mList->next();\n\t\t\t}\n\t\t} else {\n\t\t\tinList->link(th, mList());\n\t\t\tmList = nullptr;\n\t\t\tmDone = true;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n\nvoid In::advance(int inNum)\n{\n\tif (mList) {\n\t\tmOffset += inNum;\n\t\tif (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n\t\t\tmOffset = 0;\n\t\t}\n\t}\n}\n\nbool VIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool ZIn::peek(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.f;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n mList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tz = mList->mArray->z()[mOffset];\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::one(Thread& th, V& v)\n{\n if (mIsConstant) {\n\t\tv = mConstant;\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tv = mList->mArray->v()[mOffset++];\n\t\t\telse\n\t\t\t\tv = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onez(Thread& th, Z& z)\n{\n if (mIsConstant) {\n\t\tz = mConstant.asFloat();\n\t\treturn false;\n }\n while (mList) {\n if (mOffset == 0) {\n mList->force(th);\n\t\t}\n if (mOffset == mList->mArray->size()) {\n\t\t\tmList = mList->next();\n mOffset = 0;\n } else {\n\t\t\tif (mList->isV())\n\t\t\t\tz = mList->mArray->v()[mOffset++].asFloat();\n\t\t\telse\n\t\t\t\tz = mList->mArray->z()[mOffset++];\n\t\t\t\t\n\t\t\tif (mOffset == mList->mArray->size()) {\n\t\t\t\tmList = mList->next();\n\t\t\t\tmOffset = 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n }\n\tmDone = true;\n return true;\n}\n\nbool BothIn::onei(Thread& th, int64_t& i)\n{\n\tZ z = 0.;\n\tbool result = onez(th, z);\n\ti = (int64_t)floor(z);\n\treturn result;\n}\n\nbool ZIn::bench(Thread& th, int& ioNum)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, Z* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nbool ZIn::fill(Thread& th, int& ioNum, float* outBuffer, int outStride)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tfor (int i = 0, k = 0; i < framesToFill; ++i)\t{\n\t\t\t\toutBuffer[k] = 0.;\n\t\t\t\tk += outStride;\n\t\t\t}\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0, j = 0, k = 0; i < n; ++i)\t{\n\t\t\toutBuffer[k] = a[j];\n\t\t\tj += astride;\n\t\t\tk += outStride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n * outStride;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nvoid ZIn::hop(Thread& th, int framesToAdvance)\n{\n\tP list = mList;\n\tint offset = mOffset;\n\twhile (list && framesToAdvance) {\n\t\tlist->force(th);\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tif (avail >= framesToAdvance) {\n\t\t\toffset += framesToAdvance;\n\t\t\tmList = list;\n\t\t\tmOffset = offset;\n\t\t\treturn;\n\t\t}\n\t\tframesToAdvance -= avail;\n\t\toffset = 0;\n\t\tlist = list->next();\n\t\tif (!list) {\n\t\t\tmList = nullptr;\n\t\t\tmOffset = 0;\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nbool ZIn::fillSegment(Thread& th, int inNum, Z* outBuffer)\n{\n\tint framesToFill = inNum;\n\tif (mIsConstant) {\n\t\tZ z = mConstant.f;\n\t\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\treturn false;\n\t}\n\n\tP list = mList;\n\tint offset = mOffset;\n\tZ* out = outBuffer;\n\twhile (list) {\n\t\tlist->force(th);\n\t\tassert(list->mArray);\n\t\t\n\t\tint avail = (int)(list->mArray->size() - offset);\n\t\tint numToFill = std::min(framesToFill, avail);\n\n\t\t// copy\n\t\tZ* in = list->mArray->z() + offset;\n\t\tmemcpy(out, in, numToFill * sizeof(Z));\n\t\tout += numToFill;\n\t\tframesToFill -= numToFill;\n\t\t\n\t\tif (framesToFill == 0)\n\t\t\treturn false;\n\t\t\n\t\tlist = list->next();\n\t\toffset = 0;\n\t}\n\t\n\tZ z = mConstant.f;\n\tfor (int i = 0; i < framesToFill; ++i) outBuffer[i] = z;\n\t\n\tmDone = true;\n\treturn true;\n}\n\n\nbool ZIn::mix(Thread& th, int& ioNum, Z* outBuffer)\n{\n\tint framesToFill = ioNum;\n\tint framesFilled = 0;\n\twhile (framesToFill) {\n\t\tint n = framesToFill;\n\t\tint astride;\n\t\tZ* a;\n\t\tif (operator()(th, n, astride, a)) {\n\t\t\tioNum = framesFilled;\n\t\t\treturn true;\n\t\t}\n\t\tfor (int i = 0; i < n; ++i)\t{\n\t\t\toutBuffer[i] += *a;\n\t\t\ta += astride;\n\t\t}\n\t\tframesToFill -= n;\n\t\tframesFilled += n;\n\t\tadvance(n);\n\t\toutBuffer += n;\n\t}\n\tioNum = framesFilled;\n\treturn false;\n}\n\nclass Comma : public Gen\n{\n\tVIn _a;\n\tV key;\npublic:\n\tComma(Thread& th, Arg a, Arg inKey) : Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {} \n\t\n\tvirtual const char* TypeName() const override { return \"Comma\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\tout[i] = a->comma(th, key);\n\t\t\t\t\ta += astride;\n\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\nclass Dot : public Gen\n{\n\tVIn _a;\n\tV key;\n\tV defaultValue;\npublic:\n\tDot(Thread& th, Arg a, Arg inKey, Arg inDefaultValue)\n\t\t\t\t\t: Gen(th, itemTypeV, a.isFinite()), _a(a), key(inKey) {}\n\t\n\tvirtual const char* TypeName() const override { return \"Dot\"; }\n\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (_a(th, n,astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\t\tV v = defaultValue;\n\t\t\t\t\t\ta->dot(th, key, v);\n\t\t\t\t\t\tout[i] = v;\n\t\t\t\t\t\ta += astride;\n\t\t\t\t\t}\n\t\t\t\t_a.advance(n);\n\t\t\t}\n\t\t\tframesToFill -= n;\n\t\t\tout += n;\n\t\t}\n\t\tproduce(framesToFill);\n\t\t\n\t}\n\t\n};\n\n\nV List::comma(Thread& th, Arg key)\n{\n\treturn new List(new Comma(th, this, key));\n}\n\nbool List::dot(Thread& th, Arg key, V& ioValue)\n{\n\tioValue = new List(new Dot(th, this, key, ioValue));\n\treturn true;\n}\n\nbool List::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isList()) return false;\n\tList* that = (List*)v.o();\n\tif (!isFinite())\n\t\tindefiniteOp(\"\", \"equals : a\");\n\tif (!that->isFinite())\n\t\tindefiniteOp(\"\", \"equals : b\");\n\t\n\tif (elemType != that->elemType) return false;\n\t\n\tif (isVList()) {\n\t\tVIn _a(this);\n\t\tVIn _b(that);\n\t\t\n\t\tV *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = kDefaultVBlockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n \n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (!a->Equals(th, *b)) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t\t\n\t} else {\n\t\tZIn _a(this);\n\t\tZIn _b(that);\n\t\t\n\t\tZ *a, *b;\n\t\tint astride, bstride;\n\n\t\twhile(1) {\n\t\t\tint n = th.rate.blockSize;\n\t\t\tbool aend = _a(th, n,astride, a);\n\t\t\tbool bend = _b(th, n,bstride, b);\n\t\t\tif (aend != bend) return false;\n\t\t\tif (aend && bend) return true;\n\t\t\t\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tif (*a != *b) return false;\n\t\t\t\ta += astride;\n\t\t\t\tb += bstride;\n\t\t\t}\n\t\t\t\n\t\t\t_a.advance(n);\n\t\t\t_b.advance(n);\n\t\t}\t\n\t}\n\n}\n\nList::List(int inItemType) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, 0))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\nList::List(int inItemType, int64_t inCap) // construct nil\n\t: mNext(nullptr), mGen(nullptr), mArray(new Array(inItemType, inCap))\n{\n\telemType = inItemType;\n\tsetFinite(true);\n}\n\n\n\nList::List(P const& inGen) \n\t: mNext(nullptr), mGen(inGen), mArray(0)\n{\n\telemType = inGen->elemType;\n\tsetFinite(inGen->isFinite());\n\tinGen->setOut(this);\n}\n\nList::List(P const& inArray) \n\t: mNext(nullptr), mGen(nullptr), mArray(inArray)\n{\n\telemType = inArray->elemType;\n\tsetFinite(true);\n}\n\nList::List(P const& inArray, P const& inNext) \n\t: mNext(inNext), mGen(0), mArray(inArray)\n{\n\tassert(!mNext || mArray->elemType == mNext->elemType);\n\telemType = inArray->elemType;\n\tsetFinite(!mNext || mNext->isFinite());\n}\n\nList::~List()\n{\n\t// free as much tail as possible at once in order to prevent stack overflow.\n\tP list = mNext;\n\tmNext = nullptr;\n\twhile (list) {\n\t\tif (list->getRefcount() > 1) break;\n\t\tP next = list->mNext;\n\t\tlist->mNext = nullptr;\n\t\tlist = next;\n\t}\n}\n\nint64_t List::fillz(Thread& th, int64_t n, Z* z)\n{\n\tint64_t k = 0;\n\tP list = this;\n\twhile(list && k < n) {\n\t\tlist->force(th);\n\t\t\n\t\tint64_t m = std::min((n-k), list->mArray->size());\n\t\tfor (int64_t i = 0; i < m; ++i) {\n\t\t\tz[k++] = list->mArray->_atz(i);\n\t\t}\n\t\tlist = list->mNext;\n\t}\n\treturn k;\n}\n\n\nList* List::pack(Thread& th)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packz(Thread& th)\n{\n force(th);\n\tif (isPacked() && isZ())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(itemTypeZ, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::pack(Thread& th, int limit)\n{\n force(th);\n\tif (isPacked())\n\t\treturn this;\n\t\t\n\tint cap = 0;\n\tP list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcap += list->mArray->size();\t\n\t\t\t\t\n\t\tif (cap > limit) return nullptr;\n\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, cap);\n\t\n\tlist = this;\n\twhile(list) {\n\t\ta->addAll(list->mArray());\n\t\tlist = list->mNext;\n\t}\n\t\n\treturn new List(a);\n}\n\nList* List::packSome(Thread& th, int64_t& limit)\n{\n force(th);\n\tif (isPacked()) {\n\t\tlimit = std::min(limit, length(th));\n\t\treturn this;\n\t}\n\t\t\n\tP list = this;\n\tint64_t count = 0;\n\twhile(list && count < limit) {\n\t\tlist->force(th);\n\t\t\t\n\t\tcount += list->mArray->size();\t\n\t\t\t\t\t\t\n\t\tlist = list->mNext;\n\t}\n\n\tP a = new Array(elemType, count);\n\t\n\tlist = this;\n\tcount = 0;\n\twhile(list && count < limit) {\n\t\ta->addAll(list->mArray());\n\t\tcount += list->mArray->size();\t\n\t\tlist = list->mNext;\n\t}\n\tlimit = std::min(limit, count);\n\t\n\treturn new List(a);\n}\n\nvoid List::forceAll(Thread& th)\n{\n\tList* list = this;\n\twhile(list) {\n\t\tlist->force(th);\n\t\tlist = list->nextp();\n\t}\n}\n\nV V::msgSend(Thread& th, Arg receiver)\n{\n\tif (!o) {\n\t\treturn *this;\n\t} else {\n\t\treturn o->msgSend(th, receiver);\n\t}\n}\n\nV Prim::msgSend(Thread& th, Arg receiver)\n{\n\tSaveStack ss(th, Takes());\n\tth.push(receiver);\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\nV Fun::msgSend(Thread& th, Arg receiver)\n{\n\tth.push(receiver);\n\tSaveStack ss(th, NumArgs());\n\tapply(th);\n\tif (th.stackDepth() >= 1) {\n\t\treturn th.pop();\n\t} else {\n\t\treturn V(0.);\n\t}\n}\n\t\nTableMap::TableMap(size_t inSize)\n\t: mSize(inSize)\n{\n\tif (inSize == 0) {\n\t\tmMask = 0;\n\t\tmIndices = nullptr;\n\t\tmKeys = nullptr;\n\t} else {\n\t\tsize_t n = 2*NEXTPOWEROFTWO((int64_t)mSize);\n\t\tmMask = n-1;\n\t\tmIndices = new size_t[n]();\n\t\tmKeys = new V[mSize];\n\t}\n}\n\nTableMap::TableMap(Arg inKey)\n\t: mSize(1)\n{\n\tmMask = 1;\n\tmIndices = new size_t[2]();\n\tmKeys = new V[mSize];\n\t\n\tmKeys[0] = inKey;\n\tmIndices[inKey.Hash() & 1] = 1;\n}\n\n\nTableMap::~TableMap()\n{\n\tdelete [] mKeys;\n\tdelete [] mIndices;\n}\n\nbool TableMap::getIndex(Arg inKey, int64_t inKeyHash, size_t& outIndex)\n{\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\tV* keys = mKeys;\n\twhile(1) {\n\t\tsize_t index = indices[i];\n\t\tif (index == 0)\n\t\t\treturn false;\n\t\tsize_t index2 = index - 1;\n\t\tif (inKey.Identical(keys[index2])) {\n\t\t\toutIndex = index2;\n\t\t\treturn true;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nvoid TableMap::put(size_t inIndex, Arg inKey, int64_t inKeyHash)\n{\n\tmKeys[inIndex] = inKey;\n\t\n\tsize_t mask = mMask;\n\tsize_t i = inKeyHash & mask;\n\tsize_t* indices = mIndices;\n\t\n\twhile(1) {\n\t\tif (indices[i] == 0) {\n\t\t\tindices[i] = inIndex + 1;\n\t\t\treturn;\n\t\t}\n\t\ti = (i + 1) & mask;\n\t}\t\t\n}\n\nTable::Table(P const& inMap)\n\t: mMap(inMap), mValues(new V[mMap->mSize])\n{\n}\n\nTable::~Table()\n{\n\tdelete [] mValues;\n}\n\nbool Table::Equals(Thread& th, Arg v)\n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isTable()) return false;\n\tif (this == v.o()) return true;\n\tTable* that = (Table*)v.o();\n\tsize_t size = mMap->mSize;\n\tif (size != that->mMap->mSize)\n\t\treturn false;\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tV key = mMap->mKeys[i];\n\t\tV thatValue;\n\t\tif (!that->getWithHash(th, key, key.Hash(), thatValue))\n\t\t\treturn false;\n\t\tif (!mValues[i].Equals(th, thatValue))\n\t\t\treturn false;\n\t}\n return true;\n}\n\nbool Table::getWithHash(Thread& th, Arg key, int64_t hash, V& value) const\n{\n\tsize_t index;\n\tif (!mMap->getIndex(key, hash, index))\n\t\treturn false;\n\tvalue = mValues[index];\n\treturn true;\n}\n\nvoid Table::put(size_t inIndex, Arg inValue)\n{\n\tmValues[inIndex] = inValue;\n}\n\nvoid Table::print(Thread& th, std::string& out, int depth)\n{\n\tfor (size_t i = 0; i < mMap->mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmMap->mKeys[i].print(th, out, depth+1);\n\t\tzprintf(out, \" \");\n\t\tmValues[i].print(th, out, depth+1);\n\t}\n}\n\nvoid TableMap::print(Thread& th, std::string& out, int depth)\n{\n\tzprintf(out, \"{\");\n\tfor (size_t i = 0; i < mSize; ++i) {\n\t\tif (i == 0) zprintf(out, \":\");\n\t\telse zprintf(out, \" :\");\n\t\tmKeys[i].print(th, out, depth+1);\n\t}\n\tzprintf(out, \"}\");\n}\n\n\nstatic P chase_z(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\twhile (list && n > 0) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tif (asize > n) {\n\t\t\tint64_t remain = asize - n;\n\t\t\tArray* a2 = new Array(list->elemType, remain);\n\t\t\ta2->setSize(remain);\n\n\t\t\tmemcpy(a2->z(), a->z() + n, remain * a->elemSize());\n\n\t\t\treturn new List(a2, list->next());\n\t\t}\n\t\tn -= asize;\n\t\tlist = list->next();\n\t}\n\t\n\tif (!list) {\n\t\tlist = vm._nilz;\n\t}\n\t\n\treturn list;\n}\n\nstatic P chase_v(Thread& th, P list, int64_t n)\n{\n\tif (n <= 0) return list;\n\t\n\tif (!list->isFinite()) {\n\t\tindefiniteOp(\"chase : list\", \"\");\n\t}\n\t\n\tint64_t length = list->length(th);\n\t\n\tP result = new List(itemTypeV, length);\n\tP array = result->mArray;\n\tV* out = array->v();\n\t\n\tint64_t i = 0;\n\t\n\twhile (list) {\n\t\tlist->force(th);\n\n\t\tArray* a = list->mArray();\n\t\tint64_t asize = a->size();\n\t\tV* in = a->v();\n\t\t\n\t\tfor (int64_t j = 0; j < asize; ++j, ++i) {\n\t\t\tout[i] = in[j].chase(th, n);\n\t\t}\n\n\t\tlist = list->next();\n\t}\n\t\n\treturn list;\n}\n\nV List::chase(Thread& th, int64_t n)\n{\n\tif (isVList()) {\n\t\treturn chase_v(th, this, n);\n\t} else {\n\t\treturn chase_z(th, this, n);\n\t}\n}\n\nP Form::chaseForm(Thread& th, int64_t n)\n{\n\tP nextForm = mNextForm() ? mNextForm->chaseForm(th, n) : nullptr;\n\treturn new Form(mTable->chaseTable(th, n), nextForm);\n}\n\nP
Table::chaseTable(Thread& th, int64_t n)\n{\n\tP
result = new Table(mMap);\n\t\n\tsize_t size = mMap->mSize;\n\n\tfor (size_t i = 0; i < size; ++i) {\n\t\tresult->mValues[i] = mValues[i].chase(th, n);\n\t}\n\t\n\treturn result;\n}\n\n\n\nvoid Plug::setPlug(Arg inV)\n{\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid Plug::setPlug(const VIn& inVIn, int inChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inVIn;\n\t}\n}\n\nvoid Plug::getPlug(VIn& outVIn, int& outChangeCount)\n{\n\tSpinLocker lock(mSpinLock);\n\toutVIn = in;\n\toutChangeCount = mChangeCount;\n}\n\n\nvoid ZPlug::setPlug(Arg inV) {\n\tSpinLocker lock(mSpinLock);\n\tin.set(inV);\n\t++mChangeCount;\n}\n\nvoid ZPlug::setPlug(const ZIn& inZIn, int inChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\tif (inChangeCount == mChangeCount) {\n\t\tin = inZIn;\n\t}\n}\n\nvoid ZPlug::getPlug(ZIn& outZIn, int& outChangeCount) {\n\tSpinLocker lock(mSpinLock);\n\toutZIn = in;\n\toutChangeCount = mChangeCount;\n}\n"], ["/sapf/src/SoundFiles.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"SoundFiles.hpp\"\n#include \n\nextern char gSessionTime[256];\n\n\nclass SFReaderOutputChannel;\n\nclass SFReader : public Object\n{\n\tExtAudioFileRef mXAF;\n\tint64_t mFramesRemaining;\n\tSFReaderOutputChannel* mOutputs;\n\tint mNumChannels;\n\tAudioBufferList* mABL;\n\tbool mFinished = false;\n\t\npublic:\n\t\n\tSFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration);\n\t\n\t~SFReader();\n\n\tvirtual const char* TypeName() const override { return \"SFReader\"; }\n\n\tP createOutputs(Thread& th);\n\t\n\tbool pull(Thread& th);\n\tvoid fulfillOutputs(int blockSize);\n\tvoid produceOutputs(int shrinkBy);\n};\n\nclass SFReaderOutputChannel : public Gen\n{\n\tfriend class SFReader;\n\tP mSFReader;\n\tSFReaderOutputChannel* mNextOutput = nullptr;\n\tZ* mDummy = nullptr;\n\t\npublic:\t\n\tSFReaderOutputChannel(Thread& th, SFReader* inSFReader)\n : Gen(th, itemTypeZ, true), mSFReader(inSFReader)\n\t{\n\t}\n\t\n\t~SFReaderOutputChannel()\n\t{\n\t\tif (mDummy) free(mDummy);\n\t}\n\t\n\tvirtual void norefs() override\n\t{\n\t\tmOut = nullptr; \n\t\tmSFReader = nullptr;\n\t}\n\t\t\n\tvirtual const char* TypeName() const override { return \"SFReaderOutputChannel\"; }\n\t\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tif (mSFReader->pull(th)) {\n\t\t\tend();\n\t\t}\n\t}\n\t\n};\n\nSFReader::SFReader(ExtAudioFileRef inXAF, int inNumChannels, int64_t inDuration)\n\t: mXAF(inXAF), mNumChannels(inNumChannels), mFramesRemaining(inDuration), mABL(nullptr)\n{\n\tmABL = (AudioBufferList*)calloc(1, sizeof(AudioBufferList) + (mNumChannels - 1) * sizeof(AudioBuffer));\n}\n\nSFReader::~SFReader()\n{\n\tExtAudioFileDispose(mXAF); free(mABL);\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tSFReaderOutputChannel* next = output->mNextOutput;\n\t\tdelete output;\n\t\toutput = next;\n\t} while (output);\n}\n\nvoid SFReader::fulfillOutputs(int blockSize)\n{\n\tmABL->mNumberBuffers = mNumChannels;\n\tSFReaderOutputChannel* output = mOutputs;\n\tsize_t bufSize = blockSize * sizeof(Z);\n\tfor (int i = 0; output; ++i, output = output->mNextOutput){\n\t\tZ* out;\n\t\tif (output->mOut)\n\t\t\tout = output->mOut->fulfillz(blockSize);\n\t\telse {\n\t\t\tif (!output->mDummy)\n\t\t\t\toutput->mDummy = (Z*)calloc(output->mBlockSize, sizeof(Z));\n\n\t\t\tout = output->mDummy;\n\t\t}\n\t\t\t\n\t\tmABL->mBuffers[i].mNumberChannels = 1;\n\t\tmABL->mBuffers[i].mData = out;\n\t\tmABL->mBuffers[i].mDataByteSize = (UInt32)bufSize;\n\t\tmemset(out, 0, bufSize);\n\t};\n}\n\nvoid SFReader::produceOutputs(int shrinkBy)\n{\n\tSFReaderOutputChannel* output = mOutputs;\n\tdo {\n\t\tif (output->mOut)\n\t\t\toutput->produce(shrinkBy);\n\t\toutput = output->mNextOutput;\n\t} while (output);\n}\n\nP SFReader::createOutputs(Thread& th)\n{\n\tP s = new List(itemTypeV, mNumChannels);\n\t\n\t// fill s->mArray with ola's output channels.\n SFReaderOutputChannel* last = nullptr;\n\tP a = s->mArray;\n\tfor (int i = 0; i < mNumChannels; ++i) {\n SFReaderOutputChannel* c = new SFReaderOutputChannel(th, this);\n if (last) last->mNextOutput = c;\n else mOutputs = c;\n last = c;\n\t\ta->add(new List(c));\n\t}\n\t\n\treturn s;\n}\n\nbool SFReader::pull(Thread& th)\n{\n\tif (mFramesRemaining == 0) \n\t\tmFinished = true;\n\n\tif (mFinished) \n\t\treturn true;\n\t\n\tSFReaderOutputChannel* output = mOutputs;\n\tint blockSize = output->mBlockSize;\n\tif (mFramesRemaining > 0)\n\t\tblockSize = (int)std::min(mFramesRemaining, (int64_t)blockSize);\n\t\n\tfulfillOutputs(blockSize);\n\t\n\t// read file here.\n\tUInt32 framesRead = blockSize;\n\tOSStatus err = ExtAudioFileRead(mXAF, &framesRead, mABL);\n\t\n\tif (err || framesRead == 0) {\n\t\tmFinished = true;\n\t}\n\t\n\tproduceOutputs(blockSize - framesRead);\n\tif (mFramesRemaining > 0) mFramesRemaining -= blockSize;\n\t\n\treturn mFinished; \n}\n\nvoid sfread(Thread& th, Arg filename, int64_t offset, int64_t frames)\n{\n\tconst char* path = ((String*)filename.o())->s;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path\\n\");\n\t\treturn;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileOpenURL(url, &xaf);\n\n\tcfpathReleaser.release();\n\turlReleaser.release();\n\t\n\tif (err) {\n\t\tpost(\"failed to open file %d\\n\", (int)err);\n\t\treturn;\n\t}\n\n\tAudioStreamBasicDescription fileFormat;\n\t\n\tUInt32 propSize = sizeof(fileFormat);\n\terr = ExtAudioFileGetProperty(xaf, kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);\n\t\n\tint numChannels = fileFormat.mChannelsPerFrame;\n\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved,\n\t\tstatic_cast(sizeof(double)),\n\t\t1,\n\t\tstatic_cast(sizeof(double)),\n\t\tstatic_cast(numChannels),\n\t\t64,\n\t\t0\n\t};\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\terr = ExtAudioFileSeek(xaf, offset);\n\tif (err) {\n\t\tpost(\"seek failed %d\\n\", (int)err);\n\t\tExtAudioFileDispose(xaf);\n\t\treturn;\n\t}\n\t\n\tSFReader* sfr = new SFReader(xaf, numChannels, -1);\n\t\n\tth.push(sfr->createOutputs(th));\n}\n\nExtAudioFileRef sfcreate(Thread& th, const char* path, int numChannels, double fileSampleRate, bool interleaved)\n{\n\tif (fileSampleRate == 0.)\n\t\tfileSampleRate = th.rate.sampleRate;\n\n\tCFStringRef cfpath = CFStringCreateWithFileSystemRepresentation(0, path);\n\tif (!cfpath) {\n\t\tpost(\"failed to create path '%s'\\n\", path);\n\t\treturn nullptr;\n\t}\n\tCFReleaser cfpathReleaser(cfpath);\n\t\n\tCFURLRef url = CFURLCreateWithFileSystemPath(0, cfpath, kCFURLPOSIXPathStyle, false);\n\tif (!url) {\n\t\tpost(\"failed to create url\\n\");\n\t\treturn nullptr;\n\t}\n\tCFReleaser urlReleaser(url);\n\t\n\tAudioStreamBasicDescription fileFormat = {\n\t\tfileSampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * numChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\n\tint interleavedChannels = interleaved ? numChannels : 1;\n\tUInt32 interleavedBit = interleaved ? 0 : kAudioFormatFlagIsNonInterleaved;\n\t\n\tAudioStreamBasicDescription clientFormat = {\n\t\tth.rate.sampleRate,\n\t\tkAudioFormatLinearPCM,\n\t\tkAudioFormatFlagsNativeFloatPacked | interleavedBit,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\t1,\n\t\tstatic_cast(sizeof(float) * interleavedChannels),\n\t\tstatic_cast(numChannels),\n\t\t32,\n\t\t0\n\t};\n\t\t\n\tExtAudioFileRef xaf;\n\tOSStatus err = ExtAudioFileCreateWithURL(url, kAudioFileWAVEType, &fileFormat, nullptr, kAudioFileFlags_EraseFile, &xaf);\n\t\n\tif (err) {\n\t\tpost(\"failed to create file '%s'. err: %d\\n\", path, (int)err);\n\t\treturn nullptr;\n\t}\n\t\n\terr = ExtAudioFileSetProperty(xaf, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat);\n\tif (err) {\n\t\tpost(\"failed to set client data format\\n\");\n\t\tExtAudioFileDispose(xaf);\n\t\treturn nullptr;\n\t}\n\t\n\treturn xaf;\n}\n\nstd::atomic gFileCount = 0;\n\nvoid makeRecordingPath(Arg filename, char* path, int len)\n{\n\tif (filename.isString()) {\n\t\tconst char* recDir = getenv(\"SAPF_RECORDINGS\");\n\t\tif (!recDir || strlen(recDir)==0) recDir = \"/tmp\";\n\t\tsnprintf(path, len, \"%s/%s.wav\", recDir, ((String*)filename.o())->s);\n\t} else {\n\t\tint32_t count = ++gFileCount;\n\t\tsnprintf(path, len, \"/tmp/sapf-%s-%04d.wav\", gSessionTime, count);\n\t}\n}\n\nvoid sfwrite(Thread& th, V& v, Arg filename, bool openIt)\n{\n\tstd::vector in;\n\t\n\tint numChannels = 0;\n\t\t\n\tif (v.isZList()) {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of frames\", \"\");\n\t\tnumChannels = 1;\n\t\tin.push_back(ZIn(v));\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\">sf : s - indefinite number of channels\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th);\n\t\tArray* a = s->mArray();\n\t\tnumChannels = (int)a->size();\n\n\t\tif (numChannels > kMaxSFChannels)\n\t\t\tthrow errOutOfRange;\n\t\t\n\t\tbool allIndefinite = true;\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tV va = a->at(i);\n\t\t\tif (va.isFinite()) allIndefinite = false;\n\t\t\tin.push_back(ZIn(va));\n\t\t\tva.o = nullptr;\n\t\t}\n\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t\t\n\t\tif (allIndefinite) indefiniteOp(\">sf : s - all channels have indefinite number of frames\", \"\");\n\t}\n\tv.o = nullptr;\n\n\tchar path[1024];\n\t\n\tmakeRecordingPath(filename, path, 1024);\n\t\n\tExtAudioFileRef xaf = sfcreate(th, path, numChannels, 0., true);\n\tif (!xaf) return;\n\t\n\tstd::valarray buf(0., numChannels * kBufSize);\n\tAudioBufferList abl;\n\tabl.mNumberBuffers = 1;\n\tabl.mBuffers[0].mNumberChannels = numChannels;\n\tabl.mBuffers[0].mData = &buf[0];\n\tabl.mBuffers[0].mDataByteSize = kBufSize * sizeof(float);\n\t\n\tint64_t framesPulled = 0;\n\tint64_t framesWritten = 0;\n\tbool done = false;\n\twhile (!done) {\n\t\tint minn = kBufSize;\n\t\tmemset(&buf[0], 0, kBufSize * numChannels);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tint n = kBufSize;\n\t\t\tbool imdone = in[i].fill(th, n, &buf[0]+i, numChannels);\n\t\t\tframesPulled += n;\n\t\t\tif (imdone) done = true;\n\t\t\tminn = std::min(n, minn);\n\t\t}\n\n\t\tabl.mBuffers[0].mDataByteSize = minn * sizeof(float);\n\t\tOSStatus err = ExtAudioFileWrite(xaf, minn, &abl);\n\t\tif (err) {\n\t\t\tpost(\"ExtAudioFileWrite failed %d\\n\", (int)err);\n\t\t\tbreak;\n\t\t}\n\n\t\tframesWritten += minn;\n\t}\n\t\n\tpost(\"wrote file '%s' %d channels %g secs\\n\", path, numChannels, framesWritten * th.rate.invSampleRate);\n\t\n\tExtAudioFileDispose(xaf);\n\t\n\tif (openIt) {\n\t\tchar cmd[1100];\n\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path);\n\t\tsystem(cmd);\n\t}\n}\n"], ["/sapf/src/MultichannelExpansion.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MultichannelExpansion.hpp\"\n#include \"clz.hpp\"\n#include \n#include \n\n// multi channel mapping is a special case of auto mapping where the mask is all z's.\n\nclass MultichannelMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tVIn args[kMaxArgs];\npublic:\n\t\n\tMultichannelMapper(Thread& th, bool inFinite, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\targs[i].set(inArgs[i]);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"MultichannelMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\ntemplate \nvoid mcx_(Thread& th, Prim* prim)\n{\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV& fun = prim->v;\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool hasVList = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tif (args[k].isVList()) {\n\t\t\thasVList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t}\n\t}\n\t\n\tif (hasVList) {\n\t\tList* s = new List(new MultichannelMapper(th, isFinite, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tfun.apply(th);\n\t}\n\n}\n\n\nconst char* kAaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";\nconst size_t kAaaLength = strlen(kAaa);\n\nconst char* kZzz = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\";\nconst size_t kZzzLength = strlen(kZzz);\n\nconst char* Prim::GetAutoMapMask() const\n{\n\t//return NoEachOps() || mNumArgs == 0 ? nullptr : kAaa + kAaaLength - mNumArgs;\n\treturn nullptr;\n}\n\nclass MultichannelMapPrim : public Prim\n{\npublic:\n\tMultichannelMapPrim(PrimFun _primFun, Arg _v, int n, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return kZzz + kZzzLength - mTakes; }\n\t\n};\n\nPrim* mcx(int n, Arg f, const char* name, const char* help)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = mcx_< 1>; break;\n\t\tcase 2 : pf = mcx_< 2>; break;\n\t\tcase 3 : pf = mcx_< 3>; break;\n\t\tcase 4 : pf = mcx_< 4>; break;\n\t\tcase 5 : pf = mcx_< 5>; break;\n\t\tcase 6 : pf = mcx_< 6>; break;\n\t\tcase 7 : pf = mcx_< 7>; break;\n\t\tcase 8 : pf = mcx_< 8>; break;\n\t\tcase 9 : pf = mcx_< 9>; break;\n\t\tcase 10 : pf = mcx_<10>; break;\n\t\tcase 11 : pf = mcx_<11>; break;\n\t\tcase 12 : pf = mcx_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new MultichannelMapPrim(pf, f, n, name, help);\n}\n\nclass AutoMapPrim : public Prim\n{\npublic:\n\tconst char* mask;\n\tAutoMapPrim(PrimFun _primFun, Arg _v, int n, const char* inMask, const char* inName, const char* inHelp) \n\t\t: Prim(_primFun, _v, n, 1, inName, inHelp), mask(inMask)\n\t{\n\t}\n\t\n\tvirtual const char* GetAutoMapMask() const { return mask; }\n\t\n};\n\nclass AutoMapper : public Gen\n{\n\tV fun;\n\tint numArgs;\n\tBothIn args[kMaxArgs];\npublic:\n\t\n\tAutoMapper(Thread& th, bool inFinite, const char* inMask, int n, V* inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), fun(inFun), numArgs(n)\n\t{\n\t\tfor (int i = 0; i < numArgs; ++i) {\n\t\t\tswitch (inMask[i]) {\n\t\t\t\tcase 'a' :\n\t\t\t\t\targs[i].setConstant(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'z' : // auto map over V lists, but not Z lists.\n\t\t\t\t\targs[i].setv(inArgs[i]);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", inMask[i]);\n\t\t\t\tcase 'k' :\n\t\t\t\t\targs[i].set(inArgs[i]);\n\t\t\t\t\t\n\t\t\t}\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"AutoMapper\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tSaveStack ss(th);\n\t\t\tfor (int j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tth.push(v);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tfun.apply(th);\n\t\t\t} catch (...) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\tthrow;\n\t\t\t}\n\t\t\tout[i] = th.pop();\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n/*\n\ta - as is. argument is not automapped.\n\tz - argument is expected to be a signal or scalar, streams are auto mapped.\n\tk - argument is expected to be a scalar, signals and streams are automapped.\n*/\n\ntemplate \nvoid automap_(Thread& th, Prim* prim)\n{\n\n\tconst char* mask = ((AutoMapPrim*)prim)->mask;\n\n\tif (th.stackDepth() < N)\n\t\tthrow errStackUnderflow;\n\t\t\n\tV* args = &th.top() - (N - 1);\n\t\n\tbool canMap = false;\n\tbool isFinite = false;\n\tfor (int k = 0; k < N; ++k) {\n\t\tswitch (mask[k]) {\n\t\t\tcase 'a' :\n\t\t\t\tbreak;\n\t\t\tcase 'z' :\n\t\t\t\tif (args[k].isVList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault :\n\t\t\t\tpost(\"unrecognized AutoMap char '%c'\\n\", mask[k]);\n\t\t\t\tthrow errFailed;\n\t\t\t\tbreak;\n\t\t\tcase 'k' :\n\t\t\t\tif (args[k].isList()) {\n\t\t\t\t\tcanMap = true;\n\t\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\t\tisFinite = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tif (canMap) {\n\t\tList* s = new List(new AutoMapper(th, isFinite, mask, N, args, prim));\n\t\tth.popn(N);\n\t\tth.push(s);\n\t} else {\n\t\tprim->v.apply(th);\n\t}\n\n}\n\nPrim* automap(const char* mask, int n, Arg f, const char* inName, const char* inHelp)\n{\n\tPrimFun pf = nullptr;\n\tswitch (n) {\n\t\tcase 1 : pf = automap_< 1>; break;\n\t\tcase 2 : pf = automap_< 2>; break;\n\t\tcase 3 : pf = automap_< 3>; break;\n\t\tcase 4 : pf = automap_< 4>; break;\n\t\tcase 5 : pf = automap_< 5>; break;\n\t\tcase 6 : pf = automap_< 6>; break;\n\t\tcase 7 : pf = automap_< 7>; break;\n\t\tcase 8 : pf = automap_< 8>; break;\n\t\tcase 9 : pf = automap_< 9>; break;\n\t\tcase 10 : pf = automap_<10>; break;\n\t\tcase 11 : pf = automap_<11>; break;\n\t\tcase 12 : pf = automap_<12>; break;\n\t\tdefault : throw errFailed;\n\t}\n\t\t\n\treturn new AutoMapPrim(pf, f, n, mask, inName, inHelp);\n}\n\n\n\n\n\nclass EachMapper : public Gen\n{\n\tconst int level;\n\tconst int numLevels;\n\tV fun;\n\tArgInfo args;\npublic:\n\t\n\tEachMapper(Thread& th, bool inFinite, int inLevel, int inNumLevels, const ArgInfo& inArgs, Arg inFun)\n\t\t: Gen(th, itemTypeV, inFinite), level(inLevel), numLevels(inNumLevels), args(inArgs), fun(inFun)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"EachMapper\"; }\n\t\n\tvoid pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\tif (level == 0) {\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tSaveStack ss(th);\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, v)) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tth.push(v);\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tfun.apply(th);\n\t\t\t\t} catch (...) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\tthrow;\n\t\t\t\t}\n\t\t\t\tout[i] = th.pop();\n\t\t\t\t\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t} else {\n\t\t\tArgInfo subargs;\n\t\t\tsubargs.numArgs = args.numArgs;\n\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\tsubargs.arg[j].mask = args.arg[j].mask;\n\t\t\t}\n\t\t\t\n\t\t\tint bit = 1 << (numLevels - level);\n\t\t\t\n\t\t\tbool mmIsFinite = true;\n\t\t\t\t\t\t\n\t\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\t\tV argv[kMaxArgs];\n\t\t\t\tbool allConstant = true;\n\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\tV v;\n\t\t\t\t\tif (args.arg[j].in.one(th, argv[j])) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (argv[j].isList() && (args.arg[j].mask & bit))\n\t\t\t\t\t\tallConstant = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (allConstant) {\n\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tth.push(argv[j]);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfun.apply(th);\n\t\t\t\t\t} catch (...) {\n\t\t\t\t\t\tsetDone();\n\t\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\t\tthrow;\n\t\t\t\t\t}\n\t\t\t\t\tout[i] = th.pop();\n\t\t\t\t} else {\n\t\t\t\t\tfor (int j = 0; j < args.numArgs; ++j) {\n\t\t\t\t\t\tV v = argv[j];\n\t\t\t\t\t\tif (args.arg[j].mask & bit) {\n\t\t\t\t\t\t\tif (v.isList() && !v.isFinite())\n\t\t\t\t\t\t\t\tmmIsFinite = false;\n\t\t\t\t\t\t\tsubargs.arg[j].in.set(v);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tsubargs.arg[j].in.setConstant(v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\tout[i] = new List(new EachMapper(th, mmIsFinite, level - 1, numLevels, subargs, fun));\n\t\t\t\t}\n\t\t\t\t--framesToFill;\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\t\n};\n\nList* handleEachOps(Thread& th, int numArgs, Arg fun)\n{\n\tArgInfo args;\n\tV argv[kMaxArgs];\n\t\n\targs.numArgs = numArgs;\n\tint32_t maxMask = 0;\n\n\tbool mmIsFinite = true;\n\n\tfor (int i = numArgs-1; i >= 0; --i) {\n\t\tV v = th.pop();\n\t\targv[i] = v;\n\t\tif (v.isEachOp()) {\n\t\t\t\n\t\t\tEachOp* adv = (EachOp*)v.o();\n\t\t\targs.arg[i].mask = adv->mask;\n\t\t\tmaxMask |= adv->mask;\n\t\t\tif (adv->mask & 1) {\n\t\t\t\tif (!adv->v.isFinite()) \n\t\t\t\t\tmmIsFinite = false;\n\t\t\t\targs.arg[i].in.set(adv->v);\n\t\t\t} else {\n\t\t\t\targs.arg[i].in.setConstant(adv->v);\n\t\t\t}\n\t\t} else {\n\t\t\targs.arg[i].in.setConstant(v);\n\t\t\targs.arg[i].mask = 0;\n\t\t}\n\t}\n\tif (maxMask > 1 && maxMask != NEXTPOWEROFTWO(maxMask) - 1) {\n\t\tpost(\"there are empty levels of iteration. mask: %x\\n\", maxMask);\n\t\tthrow errFailed;\n\t}\n\t\n\tint numLevels = maxMask <= 1 ? 1 : LOG2CEIL(maxMask);\n\treturn new List(new EachMapper(th, mmIsFinite, numLevels-1, numLevels, args, fun));\n}\n\n\nclass Flop : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlop(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flop\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nclass Flops : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlops(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tVIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flops\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeV, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->add(v);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Flopz : public Gen\n{\n\tsize_t numArgs;\n\tstd::vector args;\npublic:\n\t\n\tFlopz(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Flopz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tP s = new List(itemTypeZ, numArgs);\n\t\t\tP a = s->mArray;\n\t\t\tfor (size_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta->addz(z);\n\t\t\t}\n\t\t\tout[i] = s;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass FlopsNth : public Gen\n{\n\tVIn _in;\n\tsize_t _nth;\npublic:\n\t\n\tFlopsNth(Thread& th, size_t nth, Arg in)\n\t\t: Gen(th, itemTypeV, false), _nth(nth), _in(in)\n\t{\n\t}\n\t\n\tconst char* TypeName() const override { return \"FlopsNth\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (_in.one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (v.isVList()) {\n\t\t\t\tif (!v.isFinite()) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tP u = (List*)v.o();\n\t\t\t\tu = u->pack(th);\n\t\t\t\tP b = u->mArray;\n\t\t\t\t\n\t\t\t\tout[i] = u->wrapAt(_nth);\n\t\t\t} else {\n\t\t\t\tout[i] = v;\n\t\t\t}\n\t\t\t\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid flop_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\nvoid flops_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flops : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flops(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tth.push(s);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flops : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flops : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flops : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopsNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nvoid flop1_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popVList(\"flop1 : list\");\n\t\t\n\tif (s->isFinite()) {\n\t\n\t\ts = s->pack(th);\n\t\t\n\t\tV* args = s->mArray->v();\n\t\tsize_t N = s->mArray->size();\n\t\t\n\t\tbool hasList = false;\n\t\tbool isFinite = false;\n\t\tbool allZ = true;\n\t\tfor (size_t k = 0; k < N; ++k) {\n\t\t\tif (args[k].isList()) {\n\t\t\t\thasList = true;\n\t\t\t\tif (args[k].isFinite()) \n\t\t\t\t\tisFinite = true;\n\t\t\t\tif (!args[k].isZList())\n\t\t\t\t\tallZ = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (hasList) {\n\t\t\tif (allZ) {\n\t\t\t\tList* result = new List(new Flopz(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t} else {\n\t\t\t\tList* result = new List(new Flop(th, isFinite, N, args));\n\t\t\t\tth.push(result);\n\t\t\t}\n\t\t} else {\n\t\t\tList* result = new List(itemTypeV, 1);\n\t\t\tresult->add(s);\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tVIn in(s);\n\t\tV first;\n\t\tif (in.one(th, first)) {\n\t\t\tpost(\"flop1 : can't flop an empty list.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\tif (!first.isList()) {\n\t\t\twrongType(\"flop1 : first item in list\", \"List\", first);\n\t\t}\n\t\tif (!first.isFinite()) {\n\t\t\tpost(\"flop1 : can't flop an infinite list of infinite lists.\");\n\t\t\tthrow errFailed;\n\t\t}\n\t\t\n\t\tsize_t n = first.length(th);\n\t\t\n\t\tList* result = new List(itemTypeV, n);\n\t\tfor (size_t i = 0; i < n; ++i) {\n\t\t\tresult->add(new List(new FlopNth(th, i, s)));\n\t\t}\n\t\tth.push(result);\n\t}\n\n}\n\n\nclass Lace : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLace(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), argPos(0)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lace\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tV v;\n\t\t\tif (args[argPos].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Lacez : public Gen\n{\n\tsize_t numArgs;\n\tsize_t argPos;\n\tstd::vector args;\npublic:\n\t\n\tLacez(Thread& th, bool inFinite, size_t n, V* inArgs)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), argPos(0)\n\t{\n\t\tpost(\"Lacez\\n\");\n\t\targs.reserve(numArgs);\n\t\tfor (size_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Lacez\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tZ z;\n\t\t\tif (args[argPos].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t\tif (++argPos >= numArgs) argPos = 0;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nvoid lace_(Thread& th, Prim* prim)\n{\n\n\tP s = th.popList(\"lace : list\");\n\tif (!s->isVList())\n\t\twrongType(\"lace : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"lace : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Lacez(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Lace(th, isFinite, N, args));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\nclass Sel : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSel(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sel\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tV v;\n\t\t\t\tif (args[j].one(th, v)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = v;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Selz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSelz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Selz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tfor (int64_t j = 0; j < numArgs; ++j) {\n\t\t\t\tZ z;\n\t\t\t\tif (args[j].onez(th, z)) {\n\t\t\t\t\tsetDone();\n\t\t\t\t\tproduce(framesToFill);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (j == k) {\n\t\t\t\t\tout[i] = z;\n\t\t\t\t\t--framesToFill;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sell : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSell(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeV, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tBothIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sell\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tV v;\n\t\t\tif (args[k].one(th, v)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = v;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nclass Sellz : public Gen\n{\n\tint64_t numArgs;\n\tstd::vector args;\n\tBothIn sel;\npublic:\n\t\n\tSellz(Thread& th, bool inFinite, int64_t n, V* inArgs, Arg inSel)\n\t\t: Gen(th, itemTypeZ, inFinite), numArgs(n), sel(inSel)\n\t{\n\t\targs.reserve(numArgs);\n\t\tfor (int64_t i = 0; i < numArgs; ++i) {\n\t\t\tZIn in;\n\t\t\tin.set(inArgs[i]);\n\t\t\targs.push_back(in);\n\t\t}\n\t}\n\t\n\tconst char* TypeName() const override { return \"Sellz\"; }\n\n\tvirtual void pull(Thread& th) override\n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\t\n\t\tfor (int i = 0; i < mBlockSize; ++i) {\n\t\t\tint64_t k;\n\t\t\tif (sel.onei(th, k)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tk = sc_imod(k, numArgs);\n\t\t\tZ z;\n\t\t\tif (args[k].onez(th, z)) {\n\t\t\t\tsetDone();\n\t\t\t\tproduce(framesToFill);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout[i] = z;\n\t\t\t--framesToFill;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nvoid sel_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sel : indices\");\n\n\tP s = th.popList(\"sel : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sel : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sel : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Selz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sel(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\nvoid sell_(Thread& th, Prim* prim)\n{\n\tP indices = th.popList(\"sell : indices\");\n\n\tP s = th.popList(\"sell : list\");\n\tif (!s->isVList())\n\t\twrongType(\"sell : list\", \"VList\", s);\n\t\t\n\tif (!s->isFinite())\n\t\tindefiniteOp(\"sell : list\", \"\");\n\t\n\ts = s->pack(th);\n\t\n\tV* args = s->mArray->v();\n\tsize_t N = s->mArray->size();\n\t\n\tbool hasList = false;\n\tbool isFinite = false;\n\tbool allZ = true;\n\tfor (size_t k = 0; k < N; ++k) {\n\t\tif (args[k].isList()) {\n\t\t\thasList = true;\n\t\t\tif (args[k].isFinite()) \n\t\t\t\tisFinite = true;\n\t\t\tif (!args[k].isZList())\n\t\t\t\tallZ = false;\n\t\t}\n\t}\n\t\n\tif (hasList) {\n\t\tif (allZ) {\n\t\t\tList* result = new List(new Sellz(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t} else {\n\t\t\tList* result = new List(new Sell(th, isFinite, N, args, indices));\n\t\t\tth.push(result);\n\t\t}\n\t} else {\n\t\tth.push(s);\n\t}\n\n}\n\n\n\n\n\n\n\n"], ["/sapf/libmanta/Manta.h", "class Manta {\n public:\n Manta(void) {\n for(int i = 0; i < 53; ++i)\n {\n LastInReport[i] = 0;\n MaxSensorValues[i] = AverageMaxSensorValues[i];\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = 0xFF;\n }\n for(unsigned int i = 0; i < sizeof(CurrentOutReport); ++i)\n {\n CurrentOutReport[i] = 0;\n }\n for(unsigned int i = 0; i < sizeof(VelocityWaiting) / sizeof(VelocityWaiting[0]); ++i)\n {\n VelocityWaiting[i] = false;\n }\n}\n virtual void SetPadLED(LEDState state, int ledID) {\n int row = ledID / 8;\n int column = ledID % 8;\n\n if(ledID < 0 || ledID > 47)\n {\n throw std::invalid_argument(\"Invalid Pad Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= (1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= (1 << column);\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n break;\n case Off:\n CurrentOutReport[AmberIndex + row] &= ~(1 << column);\n CurrentOutReport[RedIndex + row] &= ~(1 << column);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) {\n if(row < 0 || row > 5)\n {\n throw std::invalid_argument(\"Invalid Row Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDRow(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", row, mask);\n MantaClient::DebugPrint(\"ByteReverse(0x%X) = 0x%X\", 0xA0, byteReverse(0xA0));\n switch(state)\n {\n case Amber:\n CurrentOutReport[AmberIndex + row] |= byteReverse(mask);\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n break;\n case Red:\n CurrentOutReport[RedIndex + row] |= byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n case Off:\n CurrentOutReport[RedIndex + row] &= ~byteReverse(mask);\n CurrentOutReport[AmberIndex + row] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) {\n if(column < 0 || column > 7)\n {\n throw std::invalid_argument(\"Invalid Column Index\");\n }\n\n MantaClient::DebugPrint(\"Called SetPadLEDColumn(%s, %d, %X)\",\n state == Off ? \"Off\" : state == Amber ? \"Amber\" : \"Red\", column, mask);\n switch(state)\n {\n case Amber:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[AmberIndex + i] |= (0x01 << column);\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Red:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] |= (0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n case Off:\n for(int i = 0; i < 6; ++i)\n {\n if((mask >> i) & 0x01)\n {\n CurrentOutReport[RedIndex + i] &= ~(0x01 << column);\n CurrentOutReport[AmberIndex + i] &= ~(0x01 << column);\n }\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) {\n switch(state)\n {\n case Amber:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Red:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] |= byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case Off:\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[RedIndex + i] &= ~byteReverse(mask[i]);\n CurrentOutReport[AmberIndex + i] &= ~byteReverse(mask[i]);\n }\n break;\n case All:\n // when setting both colors we use two frames at once\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n uint8_t amberMask = mask[i];\n uint8_t redMask = mask[i+sizeof(LEDFrame)];\n // turn off any amber LEDs if there's a red LED in that position\n amberMask &= ~redMask;\n CurrentOutReport[RedIndex + i] = byteReverse(redMask);\n CurrentOutReport[AmberIndex + i] = byteReverse(amberMask);\n }\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) {\n if(id < 0 || id > 1)\n {\n throw std::invalid_argument(\"Invalid Slider Index\");\n }\n switch(state)\n {\n case Amber:\n CurrentOutReport[SliderIndex + id] |= byteReverse(mask);\n break;\n case Red:\n /* no Red slider LEDs, do nothing */\n break;\n case Off:\n CurrentOutReport[SliderIndex + id] &= ~byteReverse(mask);\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetButtonLED(LEDState state, int id) {\n if(id < 0 || id > 3)\n {\n throw std::invalid_argument(\"Invalid Button Index\");\n }\n\n switch(state)\n {\n case Amber:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n break;\n case Red:\n CurrentOutReport[ButtonIndex] |= (0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n case Off:\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id + 4));\n CurrentOutReport[ButtonIndex] &= ~(0x01 << (id));\n break;\n default:\n throw std::invalid_argument(\"Invalid state\");\n }\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ResendLEDState(void) {\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearPadAndButtonLEDs(void) {\n for(unsigned int i = 0; i < sizeof(LEDFrame); ++i)\n {\n CurrentOutReport[AmberIndex + i] = 0;\n CurrentOutReport[RedIndex + i] = 0;\n }\n\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void ClearButtonLEDs(void) {\n CurrentOutReport[ButtonIndex] = 0;\n\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void Recalibrate(void) {\n if(! IsConnected())\n {\n throw MantaNotConnectedException(this);\n }\n\n /* make sure these messages get queued so that they\n * don't just cancel each other out */\n CurrentOutReport[ConfigIndex] |= 0x40;\n WriteFrame(CurrentOutReport, true);\n CurrentOutReport[ConfigIndex] &= ~0x40;\n WriteFrame(CurrentOutReport, true);\n}\n virtual void SetLEDControl(LEDControlType control, bool state) {\n uint8_t flag;\n\n switch(control)\n {\n case PadAndButton:\n flag = 0x01;\n break;\n case Slider:\n flag = 0x02;\n break;\n case Button:\n flag = 0x20;\n break;\n default:\n throw std::invalid_argument(\"Invalid Control Type\");\n }\n\n if(state)\n CurrentOutReport[ConfigIndex] |= flag;\n else\n CurrentOutReport[ConfigIndex] &= ~flag;\n if(IsConnected())\n {\n /* if we're disabling LEDControl, we want to make sure that this\n * message gets queued so that any pending LED messages get sent\n * down before we disable LEDs */\n WriteFrame(CurrentOutReport, !state);\n }\n}\n virtual void SetTurboMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x04;\n else\n CurrentOutReport[ConfigIndex] &= ~0x04;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetRawMode(bool Enabled) {\n if(Enabled)\n CurrentOutReport[ConfigIndex] |= 0x08;\n else\n CurrentOutReport[ConfigIndex] &= ~0x08;\n if(IsConnected())\n {\n WriteFrame(CurrentOutReport, false);\n }\n}\n virtual void SetMaxSensorValues(int *values) {\n for(int i = 0; i < 53; ++i)\n {\n MaxSensorValues[i] = values[i];\n }\n}\n private:\n virtual void FrameReceived(int8_t *frame) {\nbool hadEvent = false;\n uint8_t *uframe = (uint8_t *)frame;\n for(int i = 1; i < 53; ++i)\n {\n uframe[i] = ScaleSensorValue(frame[i] + 128, i);\n }\n /* apply the offset to the slider bytes without scaling them */\n for(int i = 53; i < 57; ++i)\n {\n uframe[i] = frame[i] + 128;\n }\n //printf(\"\\n\");\n FrameEvent(uframe);\n /* input frames have one reportID byte at the beginning */\n for(int i = 1; i < 53; ++i)\n {\n /*\n * overall pad logic:\n * if there's a velocity waiting to be calculated, send a note-on\n * if this is the first zero value, send a note-off\n * if the pad changed, send a padValue\n */\n int padIndex = i - 1;\n /* track whether this pad just went high for a single sample,\n * so we don't trigger a simultaneous note-on and note-off */\n bool singleSample = false;\n\n /* check to see if there's a previous sample waiting to have\n * the velocity algorithm run */\n if(VelocityWaiting[i])\n {\n if(uframe[i] == 0)\n {\n // we were waiting for a 2nd sample for velocity but we got zero.\n singleSample = true;\n }\n else\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48,\n CalculateVelocity(LastInReport[i], uframe[i]));\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n VelocityWaiting[i] = false;\n }\n\n\n if(uframe[i] != LastInReport[i])\n {\n if(padIndex < 48) {\n PadEvent(padIndex / 8, padIndex % 8, padIndex, uframe[i]);\n\t\t\t hadEvent = true;\n } else {\n ButtonEvent(padIndex - 48, uframe[i]);\n\t\t\t hadEvent = true;\n\t\t}\n\n /* check to see if this is a release */\n if(0 == uframe[i] && !singleSample)\n {\n if(padIndex < 48) {\n PadVelocityEvent(padIndex / 8, padIndex % 8, padIndex, 0);\n\t\t\t hadEvent = true;\n } else {\n ButtonVelocityEvent(padIndex - 48, 0);\n\t\t\t hadEvent = true;\n\t\t\t}\n }\n /* check to see if this is the first nonzero sample */\n else if(0 == LastInReport[i])\n {\n VelocityWaiting[i] = true;\n }\n }\n LastInReport[i] = uframe[i];\n }\n if(uframe[53] != LastInReport[53] || uframe[54] != LastInReport[54])\n {\n\t //printf(\"slider 0 %3d %3d\\n\", (int)uframe[53], uframe[54]);\n\t int value = (uframe[53]) | ((uframe[54]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n if(uframe[55] != LastInReport[55] || uframe[56] != LastInReport[56])\n {\n\t //printf(\"slider 1 %3d %3d\\n\", (int)uframe[55], uframe[56]);\n\t int value = (uframe[55]) | ((uframe[56]) << 8 );\n\t //if (value != 65535) {\n \t SliderEvent(0, value);\n\t\t\t hadEvent = true;\n\t //}\n }\n for(int i = 53; i < 57; ++i)\n {\n LastInReport[i] = uframe[i];\n }\n\t\n if (hadEvent) printf(\"---\\n\");\n}\n int ScaleSensorValue(int rawValue, int index) {\n float div = (float)rawValue / MaxSensorValues[index];\n return (int)((div * 210) + 0.5);\n}\n static uint8_t byteReverse(uint8_t inByte) {\n // Algorithm from Bit Twiddling Hacks\n uint8_t outByte = inByte; // first get LSB of inByte\n int s = 7; // extra shift needed at end\n\n for (inByte >>= 1; inByte; inByte >>= 1)\n {\n outByte <<= 1;\n outByte |= inByte & 1;\n s--;\n }\n outByte <<= s; // shift when inByte's highest bits are zero\n return outByte;\n}\n static int CalculateVelocity(int firstValue, int secondValue) {\n float LOG1, LOG2;\n float MAX;\n float MIN;\n float RELATIVE1, RELATIVE2;\n float LOG_RELATIVE1, LOG_RELATIVE2;\n float SUM_RAW;\n float LOG_SUM_RAW;\n float LOG_SUM_RELATIVE;\n float UP1;\n float VELOCITY = 0;\n int VELint = 0;\n\n\n // now do the velocity calculation\n LOG1 = log(1.0 + (float)LastValue);\n LOG2 = log(1.0 + (float)CurrentValue);\n\n MIN = LastValue;\n if (CurrentValue < MIN)\n {\n MIN = CurrentValue;\n }\n MAX = LastValue;\n if (CurrentValue > MAX)\n {\n MAX = CurrentValue;\n }\n RELATIVE1 = LastValue/MAX;\n RELATIVE2 = CurrentValue/MAX;\n LOG_RELATIVE1 = log(1.0 + RELATIVE1);\n LOG_RELATIVE2 = log(1.0 + RELATIVE2);\n SUM_RAW = LastValue+CurrentValue;\n LOG_SUM_RAW = log(1.0 + SUM_RAW);\n LOG_SUM_RELATIVE = log(1.0 + SUM_RAW/MAX);\n UP1 = 0;\n if (CurrentValue>LastValue) { UP1 = 1; }\n VELOCITY =\n -14.997037 +\n LastValue * 0.009361 +\n MIN * -0.014234 +\n LOG1 * 1.099763 +\n RELATIVE2 * -9.588311 +\n LOG_RELATIVE1 *-27.595303 +\n LOG_RELATIVE2 * -8.803761 +\n LOG_SUM_RELATIVE * 44.013138 +\n UP1 * 0.221622;\n //Then trim value to [0.4] range:\n if (VELOCITY < 0.)\n {\n VELOCITY = 0.;\n }\n if (VELOCITY > 4.)\n {\n VELOCITY = 4.;\n }\n //get it to 0. to 1. range\n VELOCITY = VELOCITY / 4.;\n // curve it exponentially\n VELOCITY = VELOCITY * VELOCITY;\n //get it to 0-126 range\n VELOCITY = VELOCITY * 126;\n //get it to 1-127 range\n VELOCITY = VELOCITY+ 1;\n //round to ints\n VELint = (int)VELOCITY;\n return VELint;\n}\n static const int AmberIndex = 0;\n static const int RedIndex = 10;\n static const int SliderIndex = 7;\n static const int ButtonIndex = 6;\n static const int ConfigIndex = 9;\n static const int AverageMaxSensorValues[53];\n int MaxSensorValues[53];\n uint8_t LastInReport[InPacketLen];\n uint8_t CurrentOutReport[OutPacketLen];\n bool VelocityWaiting[53];\n bool CentroidEnabled;\n bool MaximumEnabled;\n bool PadFrameEnabled;\n};"], ["/sapf/src/Play.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Play.hpp\"\n#include \n#include \n#include \n\n#include \"SoundFiles.hpp\"\n\npthread_mutex_t gPlayerMutex = PTHREAD_MUTEX_INITIALIZER;\n\nconst int kMaxChannels = 32;\n\nstruct AUPlayer* gAllPlayers = nullptr;\n\n\n\nstruct AUPlayer\n{\n\tAUPlayer(Thread& inThread, int inNumChannels, ExtAudioFileRef inXAFRef = nullptr)\n\t\t: th(inThread), count(0), done(false), prev(nullptr), next(gAllPlayers), outputUnit(nullptr), numChannels(inNumChannels), xaf(inXAFRef)\n\t{ \n\t\tgAllPlayers = this; \n\t\tif (next) next->prev = this; \n\t}\n\t\n\t~AUPlayer() {\n\t\tif (next) next->prev = prev;\n\n\t\tif (prev) prev->next = next;\n\t\telse gAllPlayers = next;\n\t\t\n\t\tif (xaf) {\n\t\t\tExtAudioFileDispose(xaf);\n\t\t\tchar cmd[1100];\n\t\t\tsnprintf(cmd, 1100, \"open \\\"%s\\\"\", path.c_str());\n\t\t\tsystem(cmd);\n\t\t}\n\t}\n\t\n\tThread th;\n\tint count;\n\tbool done;\n\tAUPlayer* prev;\n\tAUPlayer* next;\n\tAudioComponentInstance outputUnit;\n\tint numChannels;\n\tZIn in[kMaxChannels];\n\tExtAudioFileRef xaf = nullptr;\n\tstd::string path;\n\t\n};\n\nstatic void stopPlayer(AUPlayer* player)\n{\n\tAudioComponentInstance outputUnit = player->outputUnit;\n\tplayer->outputUnit = nullptr;\n\tif (outputUnit) {\n\t\n\t\tOSStatus err = AudioOutputUnitStop(outputUnit);\n\t\tif (err) post(\"AudioOutputUnitStop err %d\\n\", (int)err);\n\t\terr = AudioComponentInstanceDispose(outputUnit);\n\t\tif (err) post(\"AudioComponentInstanceDispose outputUnit err %d\\n\", (int)err);\n\t\t\n\t}\n\tdelete player;\n}\n\nvoid stopPlaying()\n{\n\tLocker lock(&gPlayerMutex);\n\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nvoid stopPlayingIfDone()\n{\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer* player = gAllPlayers;\n\twhile (player) {\n\t\tAUPlayer* next = player->next;\n\t\tif (player->done)\n\t\t\tstopPlayer(player);\n\t\tplayer = next;\n\t}\n}\n\nstatic void* stopDonePlayers(void* x)\n{\n\twhile(1) {\n\t\tsleep(1);\n\t\tstopPlayingIfDone();\n\t}\n\treturn nullptr;\n}\n\nbool gWatchdogRunning = false;\npthread_t watchdog;\n\nstatic bool fillBufferList(AUPlayer* player, int inNumberFrames, AudioBufferList* ioData)\n{\n\tif (player->done) {\nzeroAll:\n\t\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\t\tmemset((float*)ioData->mBuffers[i].mData, 0, inNumberFrames * sizeof(float));\n\t\t}\n\t\treturn true;\n\t}\n\tZIn* in = player->in;\n\tbool done = true;\n\tfor (int i = 0; i < (int)ioData->mNumberBuffers; ++i) {\n\t\tint n = inNumberFrames;\n\t\tif (i >= player->numChannels) {\n\t\t\tmemset(ioData->mBuffers[i].mData, 0, ioData->mBuffers[i].mDataByteSize);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfloat* buf = (float*)ioData->mBuffers[i].mData;\n\t\t\t\tbool imdone = in[i].fill(player->th, n, buf, 1);\n\t\t\t\tif (n < inNumberFrames) {\n\t\t\t\t\tmemset((float*)ioData->mBuffers[i].mData + n, 0, (inNumberFrames - n) * sizeof(float));\n\t\t\t\t}\n\t\t\t\tdone = done && imdone;\n\t\t\t} catch (int err) {\n\t\t\t\tif (err <= -1000 && err > -1000 - kNumErrors) {\n\t\t\t\t\tpost(\"\\nerror: %s\\n\", errString[-1000 - err]);\n\t\t\t\t} else {\n\t\t\t\t\tpost(\"\\nerror: %d\\n\", err);\n\t\t\t\t}\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (std::bad_alloc& xerr) {\n\t\t\t\tpost(\"\\nnot enough memory\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t} catch (...) {\n\t\t\t\tpost(\"\\nunknown error\\n\");\n\t\t\t\tpost(\"exception in real time. stopping player.\\n\");\n\t\t\t\tdone = true;\n\t\t\t\tgoto zeroAll;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn done;\n}\n\nstatic void recordPlayer(AUPlayer* player, int inNumberFrames, AudioBufferList const* inData)\n{\n\tif (!player->xaf) return;\n\t\t\n\tOSStatus err = ExtAudioFileWriteAsync(player->xaf, inNumberFrames, inData); // initialize async.\n\tif (err) printf(\"ExtAudioFileWriteAsync err %d\\n\", (int)err);\n}\n\nstatic OSStatus inputCallback(\tvoid *\t\t\t\t\t\t\tinRefCon,\n\t\t\t\t\t\tAudioUnitRenderActionFlags *\tioActionFlags,\n\t\t\t\t\t\tconst AudioTimeStamp *\t\t\tinTimeStamp,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinBusNumber,\n\t\t\t\t\t\tUInt32\t\t\t\t\t\t\tinNumberFrames,\n\t\t\t\t\t\tAudioBufferList *\t\t\t\tioData)\n{\n\t\n\tAUPlayer* player = (AUPlayer*)inRefCon;\n\t\t\n\tbool done = fillBufferList(player, inNumberFrames, ioData);\n\trecordPlayer(player, inNumberFrames, ioData);\n\n\tif (done) {\n\t\tplayer->done = true;\n\t}\n\treturn noErr;\n}\n\n\nstatic AudioComponentInstance openAU(UInt32 inType, UInt32 inSubtype, UInt32 inManuf)\n{\n AudioComponentDescription desc;\n desc.componentType = inType;\n desc.componentSubType = inSubtype;\n desc.componentManufacturer = inManuf;\n desc.componentFlags = 0;\n desc.componentFlagsMask = 0;\n\n AudioComponent comp = AudioComponentFindNext(nullptr, &desc);\n\tif (!comp) {\n\t\treturn nullptr;\n\t}\n\n AudioComponentInstance au = nullptr;\n AudioComponentInstanceNew(comp, &au);\n\t\n\treturn au;\n}\n\nstatic OSStatus createGraph(AUPlayer* player)\n{\n OSStatus err = noErr;\n\tAudioComponentInstance outputUnit = openAU('auou', 'def ', 'appl');\n\tif (!outputUnit) {\n\t\tpost(\"open output unit failed\\n\");\n\t\treturn 'fail';\n\t}\n\t\n\tplayer->outputUnit = outputUnit;\n\t\n\tUInt32 flags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;\n\tAudioStreamBasicDescription fmt = { vm.ar.sampleRate, kAudioFormatLinearPCM, flags, 4, 1, 4, (UInt32)player->numChannels, 32, 0 };\n\t\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &fmt, sizeof(fmt));\n\tif (err) {\n\t\tpost(\"set outputUnit client format failed\\n\");\n\t\treturn err;\n\t}\n\t\n\tAURenderCallbackStruct cbs;\n\t\t\n\tcbs.inputProc = inputCallback;\n\tcbs.inputProcRefCon = player;\n\t\n\terr = AudioUnitSetProperty(outputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &cbs, sizeof(cbs));\n\tif (err) {\n\t\tpost(\"set render callback failed\\n\");\n\t\treturn err;\n\t}\n\t\n\terr = AudioUnitInitialize(outputUnit);\n\tif (err) {\n\t\tpost(\"initialize output unit failed\\n\");\n\t\treturn err;\n\t}\n\t\n\terr = AudioOutputUnitStart(outputUnit);\n\tif (err) {\n\t\tpost(\"start output unit failed\\n\");\n\t\treturn err;\n\t}\n\t\n\tpost(\"start output unit OK\\n\");\n\t\n\treturn noErr;\n}\n\nvoid playWithAudioUnit(Thread& th, V& v)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\t\n\tif (v.isZList()) {\n\t\tplayer = new AUPlayer(th, 1);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint asize = (int)a->size();\n\t\t\n\t\tplayer = new AUPlayer(th, asize);\n\t\tfor (int i = 0; i < asize; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n \n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n\nvoid recordWithAudioUnit(Thread& th, V& v, Arg filename)\n{\n\tif (!v.isList()) wrongType(\"play : s\", \"List\", v);\n\n\tLocker lock(&gPlayerMutex);\n\t\n\tAUPlayer *player;\n\n\tchar path[1024];\n\tExtAudioFileRef xaf = nullptr;\n\t\n\tif (v.isZList()) {\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, 1, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\n\t\tplayer = new AUPlayer(th, 1, xaf);\n\t\tplayer->in[0].set(v);\n\t\tplayer->numChannels = 1;\n\t} else {\n\t\tif (!v.isFinite()) indefiniteOp(\"play : s\", \"\");\n\t\tP s = (List*)v.o();\n\t\ts = s->pack(th, kMaxChannels);\n\t\tif (!s()) {\n\t\t\tpost(\"Too many channels. Max is %d.\\n\", kMaxChannels);\n\t\t\treturn;\n\t\t}\n\t\tArray* a = s->mArray();\n\t\t\n\t\tint numChannels = (int)a->size();\n\n\t\tmakeRecordingPath(filename, path, 1024);\n\t\txaf = sfcreate(th, path, numChannels, 0., false);\n\t\tif (!xaf) {\n\t\t\tprintf(\"couldn't create recording file \\\"%s\\\"\\n\", path);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tplayer = new AUPlayer(th, numChannels, xaf);\n\t\tfor (int i = 0; i < numChannels; ++i) {\n\t\t\tplayer->in[i].set(a->at(i));\n\t\t}\n\t\ts = nullptr;\n\t\ta = nullptr;\n\t}\n\tv.o = nullptr; // try to prevent leak.\n\n\tplayer->path = path;\n\n\t{\n\t\tOSStatus err = ExtAudioFileWriteAsync(xaf, 0, nullptr); // initialize async.\n\t\tif (err) printf(\"init ExtAudioFileWriteAsync err %d\\n\", (int)err);\n }\n\t\n std::atomic_thread_fence(std::memory_order_seq_cst);\n\t\t\n\tif (!gWatchdogRunning) {\n\t\tpthread_create(&watchdog, nullptr, stopDonePlayers, nullptr);\n\t\tgWatchdogRunning = true;\n\t}\n\n\t{\n\t\tOSStatus err = noErr;\n\t\terr = createGraph(player);\n\t\tif (err) {\n\t\t\tpost(\"play failed: %d '%4.4s'\\n\", (int)err, (char*)&err);\n\t\t\tthrow errFailed;\n\t\t}\n\t}\n}\n\n"], ["/sapf/src/main.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \n#include \n#include \n#include \n#include \"primes.hpp\"\n#include \n#include \n#include \n#include \"Manta.h\"\n\nclass MyManta : public Manta\n{\n\tvirtual void PadEvent(int row, int column, int id, int value) {\n\t\tprintf(\"pad %d %d %d %d\\n\", row, column, id, value);\n\t}\n\tvirtual void SliderEvent(int id, int value) {\n\t\tprintf(\"slider %d %d\\n\", id, value);\n\t}\n\tvirtual void ButtonEvent(int id, int value) {\n\t\tprintf(\"button %d %d\\n\", id, value);\n\t}\n\tvirtual void PadVelocityEvent(int row, int column, int id, int velocity) {\n\t\tprintf(\"pad vel %d %d %d %d\\n\", row, column, id, velocity);\n\n\t}\n\tvirtual void ButtonVelocityEvent(int id, int velocity) {\n\t\tprintf(\"button vel %d %d\\n\", id, velocity);\n\t}\n\tvirtual void FrameEvent(uint8_t *frame) {}\n\tvirtual void DebugPrint(const char *fmt, ...) {}\n};\n\nManta* manta();\nManta* manta()\n{\n\tstatic MyManta* sManta = new MyManta();\n\treturn sManta;\n}\n\n/* issue:\n\n[These comments are very old and I have not checked if they are still relevant.]\n\nTableData alloc should use new\n\nbugs:\n\nitd should have a tail time. currently the ugen stops as soon as its input, cutting off the delayed signal.\n\n+ should not stop until both inputs stop?\nother additive binops: - avg2 sumsq\n\nno, use a operator \n\n---\n\nadsrg (gate a d s r --> out) envelope generator with gate. \nadsr (dur a d s r --> out) envelope generator with duration. \nevgg - (gate levels times curves suspt --> out) envelope generator with gate. suspt is the index of the sustain level. \nevg - (dur levels times curves suspt --> out) envelope generator with duration. suspt is the index of the sustain level.\n\nblip (freq phase nharm --> out) band limited impulse oscillator.\ndsf1 (freq phase nharm lharm hmul --> out) sum of sines oscillator.\n\nformant (freq formfreq bwfreq --> out) formant oscillator\n\nsvf (in freq rq --> [lp hp bp bs]) state variable filter.\nmoogf (in freq rq --> out) moog ladder low pass filter.\n\n*/\n\nextern void AddCoreOps();\nextern void AddMathOps();\nextern void AddStreamOps();\nextern void AddLFOps();\nextern void AddUGenOps();\nextern void AddSetOps();\nextern void AddRandomOps();\nextern void AddMidiOps();\n\nconst char* gVersionString = \"0.1.21\";\n\nstatic void usage()\n{\n\tfprintf(stdout, \"sapf [-r sample-rate][-p prelude-file]\\n\");\n\tfprintf(stdout, \"\\n\");\n\tfprintf(stdout, \"sapf [-h]\\n\");\n\tfprintf(stdout, \" print this help\\n\");\n\tfprintf(stdout, \"\\n\");\t\n}\n\nint main (int argc, const char * argv[]) \n{\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"A tool for the expression of sound as pure form.\\n\");\t\n\tpost(\"------------------------------------------------\\n\");\t\n\tpost(\"--- version %s\\n\", gVersionString);\n\t\n\tfor (int i = 1; i < argc;) {\n\t\tint c = argv[i][0];\n\t\tif (c == '-') {\n\t\t\tc = argv[i][1];\n\t\t\tswitch (c) {\n\t\t\t\tcase 'r' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected sample rate after -r\\n\"); return 1; }\n\t\t\t\t\t\t\n\t\t\t\t\tdouble sr = atof(argv[i+1]);\n\t\t\t\t\tif (sr < 1000. || sr > 768000.) { post(\"sample rate out of range.\\n\"); return 1; }\n\t\t\t\t\tvm.setSampleRate(sr);\n\t\t\t\t\tpost(\"sample rate set to %g\\n\", vm.ar.sampleRate);\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'p' : {\n\t\t\t\t\tif (argc <= i+1) { post(\"expected prelude file name after -p\\n\"); return 1; }\n\t\t\t\t\tvm.prelude_file = argv[i+1];\n\t\t\t\t\ti += 2;\n\t\t\t\t} break;\n\t\t\t\tcase 'h' : {\n\t\t\t\t\tusage();\n\t\t\t\t\texit(0);\n\t\t\t\t} break;\n\t\t\t\tdefault: \n\t\t\t\t\tpost(\"unrecognized option -%c\\n\", c);\n\t\t\t}\n\t\t} else {\n\t\t\tpost(\"expected option, got \\\"%s\\\"\\n\", argv[i]);\n\t\t\t++i;\n\t\t}\n\t}\n\t\n\t\n\tvm.addBifHelp(\"Argument Automapping legend:\");\n\tvm.addBifHelp(\" a - as is. argument is not automapped.\");\n\tvm.addBifHelp(\" z - argument is expected to be a signal or scalar, streams are auto mapped.\");\n\tvm.addBifHelp(\" k - argument is expected to be a scalar, signals and streams are automapped.\");\n\tvm.addBifHelp(\"\");\n\t\n\tAddCoreOps();\n\tAddMathOps();\n\tAddStreamOps();\n AddRandomOps();\n\tAddUGenOps();\n\tAddMidiOps();\n AddSetOps();\n\t\n\t\n\tvm.log_file = getenv(\"SAPF_LOG\");\n\tif (!vm.log_file) {\n\t\tconst char* home_dir = getenv(\"HOME\");\n\t\tchar logfilename[PATH_MAX];\n\t\tsnprintf(logfilename, PATH_MAX, \"%s/sapf-log.txt\", home_dir);\n\t\tvm.log_file = strdup(logfilename);\n\t}\n\t\n\t__block Thread th;\n\n\tauto m = manta();\n\ttry {\n\t\tm->Connect();\n\t} catch(...) {\n\t}\n\tprintf(\"Manta %s connected.\\n\", m->IsConnected() ? \"is\" : \"IS NOT\");\n\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\t/*** see at bottom for better way ***/\n\t\twhile(true) {\n\t\t\ttry {\n\t\t\t\tMantaUSB::HandleEvents();\n\t\t\t\tusleep(5000);\n\t\t\t} catch(...) {\n\t\t\t\tsleep(1);\n\t\t\t}\n\t\t}\n\t});\n\t\n\tif (!vm.prelude_file) {\n\t\tvm.prelude_file = getenv(\"SAPF_PRELUDE\");\n\t}\n\tif (vm.prelude_file) {\n\t\tloadFile(th, vm.prelude_file);\n\t}\n\t\n\tdispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n\t\tth.repl(stdin, vm.log_file);\n\t\texit(0);\n\t});\n\t\n\tCFRunLoopRun();\n\t\n\treturn 0;\n}\n\n"], ["/sapf/src/SetOps.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"VM.hpp\"\n#include \"clz.hpp\"\n\nstruct SetPair\n{\n\tV mValue;\n\tint mIndex;\n};\n\nclass Set : public Object\n{\n\tint mSize;\n\tint mCap;\n\tint* mIndices;\n\tSetPair* mPairs;\n\t\n\tvoid grow(Thread& th);\n\tvoid alloc(int cap);\n \n\tSet(const Set& that) {}\npublic:\n\t\n\tSet(int capacity) { alloc(capacity); }\n Set(Thread& th, P list) { alloc(32); putAll(th, list); }\n \n\tvirtual ~Set();\n\t\n\tvirtual const char* TypeName() const override { return \"Set\"; }\n \n\tvirtual bool isSet() const override { return true; }\n\tvirtual bool Equals(Thread& th, Arg v) override;\n\t\n\tint size() { return mSize; }\n\t\n\tbool has(Thread& th, V& value);\n int indexOf(Thread& th, V& value);\n\t\n\tvoid put(Thread& th, V& inValue, int inIndex);\n \n void putAll(Thread& th, P& list);\n\t\n\tvirtual V at(int64_t i) override { return mPairs[i].mValue; }\n \n P asVList(Thread& th);\n P asZList(Thread& th);\n};\n\n\nbool Set::Equals(Thread& th, Arg v) \n{\n\tif (v.Identical(this)) return true;\n\tif (!v.isSet()) return false;\n\tif (this == v.o()) return true;\n\tSet* that = (Set*)v.o();\n\tif (mSize != that->size()) return false;\n \n\tfor (int64_t i = 0; i < mSize; ++i) {\n\t\tV& value = mPairs[i].mValue;\n\t\tV u;\n\t\tif (!that->has(th, value)) return false;\n\t}\n \n\treturn true;\n}\n\nbool Set::has(Thread& th, V& value) \n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn false;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn true;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn false;\n}\n\nint Set::indexOf(Thread& th, V& value)\n{\t\n\tint hash = value.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n\t\n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\treturn -1;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (value.Equals(th, testVal)) {\n\t\t\treturn pairs[index2].mIndex;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\t\n\t\n\treturn -1;\n}\n\n\nSet::~Set()\n{\n\tdelete [] mPairs;\n\tfree(mIndices);\n}\n\nvoid Set::alloc(int cap)\n{\n\tcap = NEXTPOWEROFTWO(cap);\n\tmPairs = new SetPair[cap];\n\tmIndices = (int*)calloc(2 * cap, sizeof(int));\n\tmCap = cap;\n\tmSize = 0;\n}\n\nvoid Set::grow(Thread& th)\n{\n\tfree(mIndices);\n \n\tSetPair* oldPairs = mPairs;\n\tint oldSize = mSize;\n \n\talloc(mCap * 2);\n\t\n\tfor (int i = 0; i < oldSize; ++i) {\n\t\tSetPair& pair = oldPairs[i];\n\t\tput(th, pair.mValue, pair.mIndex);\n\t}\n\t\n\tdelete [] oldPairs;\n}\n\nvoid Set::put(Thread& th, V& inValue, int inIndex)\n{\n\tif (mSize == mCap) {\n\t\tgrow(th);\n\t}\n \n\tint hash = inValue.Hash();\n\tint mask = mCap * 2 - 1;\n\tint index = hash & mask;\n\tint* indices = mIndices;\n\tSetPair* pairs = mPairs;\n \n\twhile(1) {\n\t\tint index2 = indices[index]-1;\n\t\tif (index2 == -1) {\n\t\t\tindex2 = mSize++;\n\t\t\tindices[index] = index2+1;\n\t\t\tpairs[index2].mValue = inValue;\n\t\t\tpairs[index2].mIndex = inIndex;\n\t\t\treturn;\n\t\t}\n\t\tV& testVal = pairs[index2].mValue;\n\t\tif (inValue.Equals(th, testVal)) {\n\t\t\treturn;\n\t\t}\n\t\tindex = (index + 1) & mask;\n\t}\n}\n\nvoid Set::putAll(Thread& th, P& in)\n{\n // caller must ensure that in is finite.\n int64_t insize = in->length(th);\n in = in->pack(th);\n for (int i = 0; i < insize; ++i) {\n V val = in->at(i);\n put(th, val, i);\n }\n}\n\n\nP Set::asVList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeV, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nP Set::asZList(Thread& th)\n{\n int64_t outsize = size();\n \n P out = new List(itemTypeZ, outsize);\n \n for (int i = 0; i < outsize; ++i) {\n out->add(at(i));\n }\n \n return out;\n}\n\nstatic P nub(Thread& th, P in)\n{\n P set = new Set(th, in);\n \n return set->asVList(th);\n}\n\n\nstatic P set_or(Thread& th, P a, P b)\n{\n P set = new Set(32);\n\n set->putAll(th, a);\n set->putAll(th, b);\n return a->isZ() && b->isZ() ? set->asZList(th) : set->asVList(th);\n}\n\nstatic P set_and(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_minus(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic P set_xor(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n P out = new List(a->isZ() && b->isZ() ? itemTypeZ : itemTypeV, 32);\n \n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) out->add(v);\n }\n for (int64_t i = 0; i < setB->size(); ++i) {\n V v = setB->at(i);\n if (!setA->has(th, v)) out->add(v);\n }\n \n return out;\n}\n\nstatic bool subset(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n for (int64_t i = 0; i < setA->size(); ++i) {\n V v = setA->at(i);\n if (!setB->has(th, v)) return false;\n }\n\t\n\treturn true;\n}\n\nstatic bool set_equals(Thread& th, P a, P b)\n{\n P setA = new Set(th, a);\n P setB = new Set(th, b);\n\n\treturn setA->Equals(th, setB);\n}\n\n/* \n \n list minus values from set.\n \n \n \n\n \n \n \n*/\n\n\nstatic void nub_(Thread& th, Prim* prim)\n{\n P a = th.popList(\"nub : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"nub : a\", \"\");\n \n th.push(nub(th, a));\n}\n\nstatic void set_or_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"|| : b\");\n if (!b->isFinite())\n indefiniteOp(\"|| : b\", \"\");\n \n P a = th.popList(\"|| : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"|| : a\", \"\");\n \n th.push(set_or(th, a, b));\n}\n\nstatic void set_and_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"&& : b\");\n if (!b->isFinite())\n indefiniteOp(\"&& : b\", \"\");\n \n P a = th.popList(\"&& : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"&& : a\", \"\");\n \n th.push(set_and(th, a, b));\n}\n\n\nstatic void set_xor_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_xor : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_xor : b\", \"\");\n \n P a = th.popList(\"set_xor : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_xor : a\", \"\");\n \n th.push(set_xor(th, a, b));\n}\n\nstatic void set_minus_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_minus : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_minus : b\", \"\");\n \n P a = th.popList(\"set_minus : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_minus : a\", \"\");\n \n th.push(set_minus(th, a, b));\n}\n\nstatic void subset_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"subset : b\");\n if (!b->isFinite())\n indefiniteOp(\"subset : b\", \"\");\n \n P a = th.popList(\"subset : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"subset : a\", \"\");\n \n th.pushBool(subset(th, a, b));\n}\n\n\nstatic void set_equals_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"set_equals : b\");\n if (!b->isFinite())\n indefiniteOp(\"set_equals : b\", \"\");\n \n P a = th.popList(\"set_equals : a\");\n \n if (!a->isFinite())\n indefiniteOp(\"set_equals : a\", \"\");\n \n th.push(set_equals(th, a, b));\n}\n\nstruct FindV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tFindV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->indexOf(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct FindZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tFindZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeZ, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"FindZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->indexOf(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\n\nstruct SetHasV : Gen\n{\n\tP mSet;\n\tVIn items;\n\t\n\tSetHasV(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasV\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tV* out = mOut->fulfill(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tV *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tout[i] = mSet->has(th, *a);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstruct SetHasZ : Gen\n{\n\tP mSet;\n\tZIn items;\n\t\n\tSetHasZ(Thread& th, Arg inItems, P const& inSet)\n\t\t: Gen(th, itemTypeV, inItems.isFinite()), mSet(inSet), items(inItems) {}\n\t\t\n\tconst char* TypeName() const override { return \"SetHasZ\"; }\n\t\n\tvirtual void pull(Thread& th) override \n\t{\n\t\tint framesToFill = mBlockSize;\n\t\tZ* out = mOut->fulfillz(framesToFill);\n\t\twhile (framesToFill) {\n\t\t\tint n = framesToFill;\n\t\t\tint astride;\n\t\t\tZ *a;\n\t\t\tif (items(th, n, astride, a)) {\n\t\t\t\tsetDone();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tV va = *a;\n\t\t\t\tout[i] = mSet->has(th, va);\n\t\t\t\ta += astride;\n\t\t\t}\n\t\t\titems.advance(n);\n\t\t\tframesToFill -= n;\n\t\t}\n\t\tproduce(framesToFill);\n\t}\n};\n\nstatic V findBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new FindZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new FindV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->indexOf(th, a);\n\t}\n\treturn result;\n}\n\nstatic void find_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"find : list\");\n if (!b->isFinite())\n indefiniteOp(\"find : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(findBase(th, a, setB));\n}\n\nstatic V hasBase(Thread& th, V& a, P const& inSet)\n{\n\tV result;\n\tif (a.isList()) {\n\t\tif (a.isZList()) {\n\t\t\tresult = new List(new SetHasZ(th, a, inSet));\n\t\t} else {\n\t\t\tresult = new List(new SetHasV(th, a, inSet));\n\t\t}\n\t} else {\n\t\tresult = inSet->has(th, a);\n\t}\n\treturn result;\n}\n\nstatic void sethas_(Thread& th, Prim* prim)\n{\n P b = th.popList(\"Shas : list\");\n if (!b->isFinite())\n indefiniteOp(\"Shas : list\", \"\");\n\n\tV a = th.pop();\n\n P setB = new Set(th, b);\n\t\n\tth.push(hasBase(th, a, setB));\n}\n\n#pragma mark ADD STREAM OPS\n\n#define DEF(NAME, N, HELP) \tvm.def(#NAME, N, NAME##_, HELP);\n#define DEFMCX(NAME, N, HELP) \tvm.defmcx(#NAME, N, NAME##_, HELP);\n#define DEFAM(NAME, MASK, HELP) \tvm.defautomap(#NAME, #MASK, NAME##_, HELP);\n\nvoid AddSetOps();\nvoid AddSetOps()\n{\n\tvm.addBifHelp(\"\\n*** set operations ***\");\n vm.def(\"S\", 1, 1, nub_, \"(list --> set) removes all duplicates from a finite list.\");\n vm.def(\"S|\", 2, 1, set_or_, \"(listA listB --> set) returns the set union of the elements of lists A and B.\");\n vm.def(\"S&\", 2, 1, set_and_, \"(listA listB --> set) returns the set intersection of the elements of lists A and B.\");\n vm.def(\"Sx\", 2, 1, set_xor_, \"(listA listB --> set) returns the set of the elements which occur in list A or B, but not both.\");\n vm.def(\"S-\", 2, 1, set_minus_, \"(listA listB --> set) returns the set of the elements of listA which do not occur in listB.\");\n vm.def(\"S=\", 2, 1, set_equals_, \"(listA listB --> set) returns 1 if the set of elements in listA is equal to the set of elements in listB.\");\n vm.def(\"subset?\", 2, 1, subset_, \"(listA listB --> set) returns 1 if the set of elements of listA is a subset of the set of elements of listB. else 0.\");\n vm.def(\"find\", 2, 1, find_, \"(item(s) list --> set) returns index of item in finite list, or -1 if not in list.\");\n vm.def(\"Shas\", 2, 1, sethas_, \"(item(s) list --> set) returns 1 if finite list contains item(s), else 0.\");\n}\n\n\n\n\n\n\n"], ["/sapf/src/MathFuns.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"MathFuns.hpp\"\n#include \"VM.hpp\"\n\ndouble gSineTable[kSineTableSize+1];\ndouble gDBAmpTable[kDBAmpTableSize+2];\ndouble gDecayTable[kDecayTableSize+1];\ndouble gFirstOrderCoeffTable[kFirstOrderCoeffTableSize+1];\n\n\ninline double freqToTableF(double freq)\n{\n\treturn std::clamp(3. * log2(freq * .05), 0., 28.999);\n}\n\nZ gFreqToTable[20001];\n\nstatic void initFreqToTable()\n{\n\tfor (int freq = 0; freq < 20001; ++freq) {\n\t\tgFreqToTable[freq] = freqToTableF(freq);\n\t}\n}\n\ninline double freqToTable(double freq)\n{\n\tdouble findex = std::clamp(freq, 0., 20000.);\n\tdouble iindex = floor(findex);\n\treturn lut(gFreqToTable, (int)iindex, findex - iindex);\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\nvoid fillSineTable()\n{\n\tfor (int i = 0; i < kSineTableSize; ++i) {\n\t\tgSineTable[i] = sin(gSineTableOmega * i);\n\t}\n\tgSineTable[kSineTableSize] = gSineTable[0];\n}\n\nvoid fillDBAmpTable()\n{\n\tfor (int i = 0; i < kDBAmpTableSize+2; ++i) {\n\t\tdouble dbgain = i * kInvDBAmpScale - kDBAmpOffset;\n\t\tdouble amp = pow(10., .05 * dbgain);\n\t\tgDBAmpTable[i] = amp;\n\t}\n}\n\nvoid fillDecayTable()\n{\n\tfor (int i = 0; i < kDecayTableSize+1; ++i) {\n\t\tgDecayTable[i] = exp(log001 * i * .001);\n\t}\t\n}\n\nvoid fillFirstOrderCoeffTable()\n{\n\tdouble k = M_PI * kInvFirstOrderCoeffTableSize;\n\tfor (int i = 0; i < kFirstOrderCoeffTableSize+1; ++i) {\n\t\tdouble x = k * i;\n\t\tZ b = 2. - cos(x);\n\t\tgFirstOrderCoeffTable[i] = b - sqrt(b*b - 1.);\n\t}\t\n}\n\n\n"], ["/sapf/src/Opcode.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Opcode.hpp\"\n#include \"clz.hpp\"\n\nconst char* opcode_name[kNumOpcodes] = \n{\n\t\"BAD OPCODE\",\n\t\"opNone\",\n\t\"opPushImmediate\",\n\t\"opPushLocalVar\",\n\t\"opPushFunVar\",\n\t\"opPushWorkspaceVar\",\n\t\n\t\"opPushFun\",\n\n\t\"opCallImmediate\",\n\t\"opCallLocalVar\",\n\t\"opCallFunVar\",\n\t\"opCallWorkspaceVar\",\n\n\t\"opDot\",\n\t\"opComma\",\n\t\"opBindLocal\",\n\t\"opBindLocalFromList\",\n\t\"opBindWorkspaceVar\",\n\t\"opBindWorkspaceVarFromList\",\n\t\n\t\"opParens\",\n\t\"opNewVList\",\n\t\"opNewZList\",\n\t\"opNewForm\",\n\t\"opInherit\",\n\t\"opEach\",\n\t\"opReturn\"\n};\n\n\nstatic void printOpcode(Thread& th, Opcode* c)\n{\n\tV& v = c->v;\n\tpost(\"%p %s \", c, opcode_name[c->op]);\n\tswitch (c->op) {\n\t\tcase opPushImmediate :\n\t\tcase opPushWorkspaceVar :\n\t\tcase opPushFun : \n\t\tcase opCallImmediate :\n\t\tcase opCallWorkspaceVar :\n\t\tcase opDot :\n\t\tcase opComma :\n\t\tcase opInherit :\n\t\tcase opNewForm :\n\t\tcase opBindWorkspaceVar :\n\t\tcase opBindWorkspaceVarFromList :\n\t\tcase opParens :\n\t\tcase opNewVList : \n\t\tcase opNewZList : \n\t\t\tv.printShort(th);\n\t\t\tbreak;\n\t\t\t\n\t\tcase opPushLocalVar :\n\t\tcase opPushFunVar :\n\t\tcase opCallLocalVar :\n\t\tcase opCallFunVar :\n\t\tcase opBindLocal :\n\t\tcase opBindLocalFromList :\n\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\tbreak;\n\t\tcase opEach :\n\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\tbreak;\n\t\t\n\t\tcase opNone :\n\t\tcase opReturn : \n\t\t\tbreak;\n\t\t\n\t\tdefault :\n\t\t\tpost(\"BAD OPCODE\\n\");\n\t}\n\tpost(\"\\n\");\n}\n\nvoid Thread::run(Opcode* opc)\n{\n\tThread& th = *this;\n\ttry {\n\t\tfor (;;++opc) {\n\n\t\t\tV& v = opc->v;\n\n\t\t\tif (vm.traceon) {\n\t\t\t\tpost(\"stack : \"); th.printStack(); post(\"\\n\");\n\t\t\t\tprintOpcode(th, opc);\n\t\t\t}\n\n\t\t\tswitch (opc->op) {\n\t\t\t\tcase opNone :\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushImmediate :\n\t\t\t\t\tpush(v);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushLocalVar :\n\t\t\t\t\tpush(getLocal(v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFunVar :\n\t\t\t\t\tpush(fun->mVars[v.i]);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushWorkspaceVar :\n\t\t\t\t\tpush(fun->Workspace()->mustGet(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opPushFun : {\n\t\t\t\t\t\tpush(new Fun(th, (FunDef*)v.o()));\n\t\t\t\t\t} break;\n\t\t\t\t\t\n\t\t\t\tcase opCallImmediate :\n\t\t\t\t\tv.apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallLocalVar :\n\t\t\t\t\tgetLocal(v.i).apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallFunVar :\n\t\t\t\t\tfun->mVars[v.i].apply(th);\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opCallWorkspaceVar :\n\t\t\t\t\tfun->Workspace()->mustGet(th, v).apply(th);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase opDot : {\n\t\t\t\t\tV ioValue;\n\t\t\t\t\tif (!pop().dot(th, v, ioValue))\n\t\t\t\t\t\tnotFound(v);\n\t\t\t\t\tpush(ioValue);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase opComma :\n\t\t\t\t\tpush(pop().comma(th, v));\n\t\t\t\t\tbreak;\n\t\t\t\t\t\n\t\t\t\tcase opBindLocal :\n\t\t\t\t\tgetLocal(v.i) = pop();\n\t\t\t\t\tbreak;\n\t\t\t\tcase opBindWorkspaceVar : {\n V value = pop();\n if (value.isList() && !value.isFinite()) {\n post(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n } else if (value.isFun()) {\n\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n } break;\n \n\t\t\t\tcase opBindLocalFromList :\n\t\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\t\t{\n\t\t\t\t\tV list = pop();\n\t\t\t\t\tBothIn in(list);\n\t\t\t\t\twhile (1) {\n\t\t\t\t\t\tif (opc->op == opNone) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tV value;\n\t\t\t\t\t\t\tif (in.one(th, value)) {\n\t\t\t\t\t\t\t\tpost(\"not enough items in list for = [..]\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (opc->op == opBindLocalFromList) {\n\t\t\t\t\t\t\t\tgetLocal(opc->v.i) = value;\n\t\t\t\t\t\t\t} else if (opc->op == opBindWorkspaceVarFromList) {\n\t\t\t\t\t\t\t\tv = opc->v;\n\t\t\t\t\t\t\t\tif (value.isList() && !value.isFinite()) {\n\t\t\t\t\t\t\t\t\tpost(\"WARNING: binding a possibly infinite list at the top level can leak unbounded memory!\\n\");\n\t\t\t\t\t\t\t\t} else if (value.isFun()) {\n\t\t\t\t\t\t\t\t\tconst char* mask = value.GetAutoMapMask();\n\t\t\t\t\t\t\t\t\tconst char* help = value.OneLineHelp();\n\t\t\t\t\t\t\t\t\tif (mask || help) {\n\t\t\t\t\t\t\t\t\t\tchar* name = ((String*)v.o())->s;\n\t\t\t\t\t\t\t\t\t\tvm.addUdfHelp(name, mask, help);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfun->Workspace() = fun->Workspace()->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t\tth.mWorkspace = th.mWorkspace->putImpure(v, value); // workspace mutation\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++opc;\n\t\t\t\t\t}\n\t\t\t\t} break;\n\t\t\t\tcase opParens : {\n\t\t\t\t\t\tParenStack ss(th);\n\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewVList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newVList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewZList : {\n\t\t\t\t\t\tV x;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t len = stackDepth();\n\t\t\t\t\t\t\tvm.newZList->apply_n(th, len);\n\t\t\t\t\t\t\tx = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(x);\n\t\t\t\t\t} break;\n\t\t\t\tcase opInherit : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tif (depth < 1) {\n\t\t\t\t\t\t\t\tresult = vm._ee;\n\t\t\t\t\t\t\t} else if (depth > 1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvm.inherit->apply_n(th, 1);\n\t\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opNewForm : {\n\t\t\t\t\t\tV result;\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSaveStack ss(th);\n\t\t\t\t\t\t\trun(((Code*)v.o())->getOps());\n\t\t\t\t\t\t\tsize_t depth = stackDepth();\n\t\t\t\t\t\t\tTableMap* tmap = (TableMap*)th.top().o();\n\t\t\t\t\t\t\tsize_t numArgs = tmap->mSize;\n\t\t\t\t\t\t\tif (depth == numArgs+1) {\n\t\t\t\t\t\t\t\t// no inheritance, must insert zero for parent.\n\t\t\t\t\t\t\t\tth.tuck(numArgs+1, V(0.));\n\t\t\t\t\t\t\t} else if (depth < numArgs+1) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"fewer arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errStackUnderflow;\n\t\t\t\t\t\t\t} else if (depth > numArgs+2) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"more arguments than keys for form.\\n\");\n\t\t\t\t\t\t\t\tthrow errFailed;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvm.newForm->apply_n(th, numArgs+2);\n\t\t\t\t\t\t\tresult = th.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tth.push(result);\n\t\t\t\t\t} break;\n\t\t\t\tcase opEach :\n\t\t\t\t\tpush(new EachOp(pop(), (int)v.i));\n\t\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\tcase opReturn : return;\n\t\t\t\t\n\t\t\t\tdefault :\n\t\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t\t\t\tthrow errInternalError;\n\t\t\t}\n\t\t}\n\t} catch (...) {\n\t\tpost(\"backtrace: %s \", opcode_name[opc->op]);\n\t\topc->v.printShort(th);\n\t\tpost(\"\\n\");\n\t\tthrow;\n\t}\n}\n\nCode::~Code() { }\n\nvoid Code::shrinkToFit()\n{\n\tstd::vector(ops.begin(), ops.end()).swap(ops);\n}\n\nvoid Code::add(int _op, Arg v)\n{\n\tops.push_back(Opcode(_op, v));\n}\n\nvoid Code::add(int _op, double f)\n{\n\tadd(_op, V(f));\n}\n\nvoid Code::addAll(const P &that)\n{\n\tfor (Opcode& op : that->ops) {\n\t\tops.push_back(op);\n\t}\n}\n\nvoid Code::decompile(Thread& th, std::string& out)\n{\n\tfor (Opcode& c : ops) {\n\t\tV& v = c.v;\n\t\tswitch (c.op) {\n\t\t\tcase opPushImmediate : {\n\t\t\t\tstd::string s;\n\t\t\t\tv.printShort(th, s);\n\t\t\t\tout += s;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase opPushWorkspaceVar :\n\t\t\tcase opPushFun : \n\t\t\tcase opCallImmediate :\n\t\t\tcase opCallWorkspaceVar :\n\t\t\tcase opDot :\n\t\t\tcase opComma :\n\t\t\tcase opInherit :\n\t\t\tcase opNewForm :\n\t\t\tcase opBindWorkspaceVar :\n\t\t\tcase opBindWorkspaceVarFromList :\n\t\t\tcase opParens :\n\t\t\tcase opNewVList : \n\t\t\tcase opNewZList : \n\t\t\t\tv.printShort(th);\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\tcase opPushLocalVar :\n\t\t\tcase opPushFunVar :\n\t\t\tcase opCallLocalVar :\n\t\t\tcase opCallFunVar :\n\t\t\tcase opBindLocal :\n\t\t\tcase opBindLocalFromList :\n\t\t\t\tpost(\"%lld\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\tcase opEach :\n\t\t\t\tpost(\"%llx\", (int64_t)v.i);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase opNone :\n\t\t\tcase opReturn : \n\t\t\t\tbreak;\n\t\t\t\n\t\t\tdefault :\n\t\t\t\tpost(\"BAD OPCODE\\n\");\n\t\t}\n\t}\n}\n\n"], ["/sapf/libmanta/MantaUSB.h", "class MantaUSB {\n public:\n MantaUSB(void) {\n mantaList.push_back(this);\n MantaIndex = int(mantaList.size());\n\n DebugPrint(\"%s-%d: Manta %d initialized\", __FILE__, __LINE__, MantaIndex);\n}\n virtual ~MantaUSB(void) {\n Disconnect();\n mantaList.remove(this);\n if(mantaList.empty())\n {\n hid_exit();\n }\n}\n void WriteFrame(uint8_t *frame, bool forceQueued) {\n if(NULL == DeviceHandle)\n {\n throw(MantaNotConnectedException(this));\n }\n MantaTxQueueEntry *queuedMessage = GetQueuedTxMessage();\n if(queuedMessage && !forceQueued)\n {\n /* replace the queued packet payload with the new one */\n for(int i = 0; i < OutPacketLen; ++i)\n {\n /* the first byte of the report is the report ID (0x00) */\n queuedMessage->OutFrame[i+1] = frame[i];\n }\n DebugPrint(\"%s-%d: (WriteFrame) Queued Transfer overwritten on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n else\n {\n /* no transfer in progress, queue up a new one */\n MantaTxQueueEntry *newMessage = new MantaTxQueueEntry;\n newMessage->OutFrame[0] = 0;\n newMessage->TargetManta = this;\n /* the first byte of the report is the report ID (0x00) */\n memcpy(newMessage->OutFrame + 1, frame, OutPacketLen);\n txQueue.push_back(newMessage);\n DebugPrint(\"%s-%d: (WriteFrame) Transfer Queued on Manta %d\",\n __FILE__, __LINE__, GetSerialNumber());\n }\n}\n bool IsConnected(void) {\n return DeviceHandle != NULL;\n}\n void Connect(int connectionSerial = 0) {\n#define SERIAL_STRING_SIZE 32\n wchar_t serialString[SERIAL_STRING_SIZE];\n\n if(IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Attempting to Connect to Manta %d...\",\n __FILE__, __LINE__, connectionSerial);\n if(connectionSerial)\n {\n swprintf(serialString, SERIAL_STRING_SIZE, L\"%d\", connectionSerial);\n DeviceHandle = hid_open(VendorID, ProductID, serialString);\n }\n else\n {\n DeviceHandle = hid_open(VendorID, ProductID, NULL);\n }\n if(NULL == DeviceHandle)\n throw(MantaNotFoundException());\n hid_get_serial_number_string(DeviceHandle, serialString, SERIAL_STRING_SIZE);\n SerialNumber = int(wcstol(serialString, NULL, 10));\n int rc = hid_set_nonblocking(DeviceHandle, 1);\n printf(\"hid_set_nonblocking %d\\n\", rc);\n printf(\"SerialNumber %d\\n\", SerialNumber);\n}\n void Disconnect() {\n if(! IsConnected())\n {\n return;\n }\n\n DebugPrint(\"%s-%d: Manta %d Disconnecting...\", __FILE__, __LINE__, GetSerialNumber());\n hid_close(DeviceHandle);\n DeviceHandle = NULL;\n}\n int GetSerialNumber(void) {\n return SerialNumber;\n}\n int GetHardwareVersion(void) {\n return (SerialNumber < 70) ? 1 : 2;\n}\n bool MessageQueued(void) {\n return GetQueuedTxMessage() != NULL;\n}\n static void HandleEvents(void) {\n list::iterator i = mantaList.begin();\n /* read from each manta and trigger any events */\n while(mantaList.end() != i)\n {\n MantaUSB *current = *i;\n if(current->IsConnected())\n {\n int bytesRead;\n int8_t inFrame[InPacketLen];\n\n bytesRead = hid_read(current->DeviceHandle,\n reinterpret_cast(inFrame), InPacketLen);\n if(bytesRead < 0)\n {\n current->DebugPrint(\"%s-%d: Read error on Manta %d\",\n __FILE__, __LINE__, current->GetSerialNumber());\n throw(MantaCommunicationException(current));\n }\n else if(bytesRead)\n {\n current->FrameReceived(inFrame);\n }\n }\n ++i;\n }\n\n /* pop one item off the transmit queue and send down to its target */\n if(! txQueue.empty())\n {\n int bytesWritten;\n MantaTxQueueEntry *txMessage = txQueue.front();\n txQueue.pop_front();\n bytesWritten = hid_write(txMessage->TargetManta->DeviceHandle,\n txMessage->OutFrame, OutPacketLen + 1);\n txMessage->TargetManta->DebugPrint(\"%s-%d: Frame Written to Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n for(int j = 0; j < 16; j += 8)\n {\n uint8_t *frame = txMessage->OutFrame + 1;\n txMessage->TargetManta->DebugPrint(\"\\t\\t%x %x %x %x %x %x %x %x\",\n frame[j], frame[j+1], frame[j+2], frame[j+3], frame[j+4],\n frame[j+5], frame[j+6], frame[j+7]);\n }\n delete txMessage;\n if(bytesWritten < 0)\n {\n txMessage->TargetManta->DebugPrint(\"%s-%d: Write error on Manta %d\",\n __FILE__, __LINE__, txMessage->TargetManta->GetSerialNumber());\n throw(MantaCommunicationException(txMessage->TargetManta));\n }\n }\n}\n protected:\n virtual void FrameReceived(int8_t *frame) = 0;\n static const int OutPacketLen = 16;\n static const int InPacketLen = 64;\n int SerialNumber;\n int MantaIndex;\n private:\n struct MantaTxQueueEntry\n {\n MantaUSB *TargetManta;\n uint8_t OutFrame[17];\n };\n MantaTxQueueEntry *GetQueuedTxMessage();\n static const int Interface = 0;\n static const int EndpointIn = 0x81;\n static const int EndpointOut = 0x02;\n static const int Timeout = 5000;\n static const int VendorID = 0x2424;\n static const int ProductID = 0x2424;\n hid_device *DeviceHandle;\n static list mantaList;\n static list txQueue;\n};"], ["/sapf/src/symbol.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"symbol.hpp\"\n#include \"VM.hpp\"\n#include \"Hash.hpp\"\n#include \n#include \n\nconst int kSymbolTableSize = 4096;\nconst int kSymbolTableMask = kSymbolTableSize - 1;\n\t\n// global atomic symbol table\nvolatile std::atomic sSymbolTable[kSymbolTableSize];\n\n\n\nstatic String* SymbolTable_lookup(String* list, const char* name, int32_t hash)\n{\n\twhile (list) {\n\t\tif (list->hash == hash && strcmp(list->s, name) == 0)\n\t\t\treturn list;\n\t\tlist = list->nextSymbol;\n\t}\n\treturn nullptr;\n}\n\nstatic String* SymbolTable_lookup(const char* name, int hash)\n{\n\treturn SymbolTable_lookup(sSymbolTable[hash & kSymbolTableMask].load(), name, hash);\n}\n\nstatic String* SymbolTable_lookup(const char* name)\n{\n\tuintptr_t hash = Hash(name);\n\treturn SymbolTable_lookup(name, (int)hash);\n}\n\nP getsym(const char* name)\n{\n\t// thread safe\n\n\tint32_t hash = Hash(name);\n int32_t binIndex = hash & kSymbolTableMask;\n\tvolatile std::atomic* bin = &sSymbolTable[binIndex];\n\twhile (1) {\n // get the head of the list.\n\t\tString* head = bin->load();\n // search the list for the symbol\n\t\tString* existingSymbol = head;\n\t\twhile (existingSymbol) {\n\t\t\tif (existingSymbol->hash == hash && strcmp(existingSymbol->s, name) == 0) {\n\t\t\t\treturn existingSymbol;\n\t\t\t}\n\t\t\texistingSymbol = existingSymbol->nextSymbol;\n\t\t}\n\t\tString* newSymbol = new String(name, hash, head);\n\t\tif (bin->compare_exchange_weak(head, newSymbol)) {\n\t\t\tnewSymbol->retain(); \n\t\t\treturn newSymbol;\n\t\t}\n delete newSymbol;\n\t}\t\n}\n"], ["/sapf/libmanta/extern/hidapi/hidapi/hidapi.h", "/*******************************************************\n HIDAPI - Multi-Platform library for\n communication with HID devices.\n\n Alan Ott\n Signal 11 Software\n\n 8/22/2009\n\n Copyright 2009, All Rights Reserved.\n\n At the discretion of the user of this library,\n this software may be licensed under the terms of the\n GNU Public License v3, a BSD-Style license, or the\n original HIDAPI license as outlined in the LICENSE.txt,\n LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt\n files located at the root of the source distribution.\n These files may also be found in the public source\n code repository located at:\n http://github.com/signal11/hidapi .\n********************************************************/\n\n/** @file\n * @defgroup API hidapi API\n */\n\n#ifndef HIDAPI_H__\n#define HIDAPI_H__\n\n#include \n\n#ifdef _WIN32\n #define HID_API_EXPORT __declspec(dllexport)\n #define HID_API_CALL\n#else\n #define HID_API_EXPORT /**< API export macro */\n #define HID_API_CALL /**< API call macro */\n#endif\n\n#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\t\tstruct hid_device_;\n\t\ttypedef struct hid_device_ hid_device; /**< opaque hidapi structure */\n\n\t\t/** hidapi info structure */\n\t\tstruct hid_device_info {\n\t\t\t/** Platform-specific device path */\n\t\t\tchar *path;\n\t\t\t/** Device Vendor ID */\n\t\t\tunsigned short vendor_id;\n\t\t\t/** Device Product ID */\n\t\t\tunsigned short product_id;\n\t\t\t/** Serial Number */\n\t\t\twchar_t *serial_number;\n\t\t\t/** Device Release Number in binary-coded decimal,\n\t\t\t also known as Device Version Number */\n\t\t\tunsigned short release_number;\n\t\t\t/** Manufacturer String */\n\t\t\twchar_t *manufacturer_string;\n\t\t\t/** Product string */\n\t\t\twchar_t *product_string;\n\t\t\t/** Usage Page for this Device/Interface\n\t\t\t (Windows/Mac only). */\n\t\t\tunsigned short usage_page;\n\t\t\t/** Usage for this Device/Interface\n\t\t\t (Windows/Mac only).*/\n\t\t\tunsigned short usage;\n\t\t\t/** The USB interface which this logical device\n\t\t\t represents. Valid on both Linux implementations\n\t\t\t in all cases, and valid on the Windows implementation\n\t\t\t only if the device contains more than one interface. */\n\t\t\tint interface_number;\n\n\t\t\t/** Pointer to the next device */\n\t\t\tstruct hid_device_info *next;\n\t\t};\n\n\n\t\t/** @brief Initialize the HIDAPI library.\n\n\t\t\tThis function initializes the HIDAPI library. Calling it is not\n\t\t\tstrictly necessary, as it will be called automatically by\n\t\t\thid_enumerate() and any of the hid_open_*() functions if it is\n\t\t\tneeded. This function should be called at the beginning of\n\t\t\texecution however, if there is a chance of HIDAPI handles\n\t\t\tbeing opened by different threads simultaneously.\n\t\t\t\n\t\t\t@ingroup API\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_init(void);\n\n\t\t/** @brief Finalize the HIDAPI library.\n\n\t\t\tThis function frees all of the static data associated with\n\t\t\tHIDAPI. It should be called at the end of execution to avoid\n\t\t\tmemory leaks.\n\n\t\t\t@ingroup API\n\n\t\t @returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_exit(void);\n\n\t\t/** @brief Enumerate the HID Devices.\n\n\t\t\tThis function returns a linked list of all the HID devices\n\t\t\tattached to the system which match vendor_id and product_id.\n\t\t\tIf @p vendor_id and @p product_id are both set to 0, then\n\t\t\tall HID devices will be returned.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the types of device\n\t\t\t\tto open.\n\t\t\t@param product_id The Product ID (PID) of the types of\n\t\t\t\tdevice to open.\n\n\t\t @returns\n\t\t \tThis function returns a pointer to a linked list of type\n\t\t \tstruct #hid_device, containing information about the HID devices\n\t\t \tattached to the system, or NULL in the case of failure. Free\n\t\t \tthis linked list by calling hid_free_enumeration().\n\t\t*/\n\t\tstruct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);\n\n\t\t/** @brief Free an enumeration Linked List\n\n\t\t This function frees a linked list created by hid_enumerate().\n\n\t\t\t@ingroup API\n\t\t @param devs Pointer to a list of struct_device returned from\n\t\t \t hid_enumerate().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);\n\n\t\t/** @brief Open a HID device using a Vendor ID (VID), Product ID\n\t\t\t(PID) and optionally a serial number.\n\n\t\t\tIf @p serial_number is NULL, the first device with the\n\t\t\tspecified VID and PID is opened.\n\n\t\t\t@ingroup API\n\t\t\t@param vendor_id The Vendor ID (VID) of the device to open.\n\t\t\t@param product_id The Product ID (PID) of the device to open.\n\t\t\t@param serial_number The Serial Number of the device to open\n\t\t\t\t (Optionally NULL).\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);\n\n\t\t/** @brief Open a HID device by its path name.\n\n\t\t\tThe path name be determined by calling hid_enumerate(), or a\n\t\t\tplatform-specific path name can be used (eg: /dev/hidraw0 on\n\t\t\tLinux).\n\n\t\t\t@ingroup API\n\t\t @param path The path name of the device to open\n\n\t\t\t@returns\n\t\t\t\tThis function returns a pointer to a #hid_device object on\n\t\t\t\tsuccess or NULL on failure.\n\t\t*/\n\t\tHID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);\n\n\t\t/** @brief Write an Output report to a HID device.\n\n\t\t\tThe first byte of @p data[] must contain the Report ID. For\n\t\t\tdevices which only support a single report, this must be set\n\t\t\tto 0x0. The remaining bytes contain the report data. Since\n\t\t\tthe Report ID is mandatory, calls to hid_write() will always\n\t\t\tcontain one more byte than the report contains. For example,\n\t\t\tif a hid report is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_write(), the Report ID (or 0x0, for devices with a\n\t\t\tsingle report), followed by the report data (16 bytes). In\n\t\t\tthis example, the length passed in would be 17.\n\n\t\t\thid_write() will send the data on the first OUT endpoint, if\n\t\t\tone exists. If it does not, it will send the data through\n\t\t\tthe Control Endpoint (Endpoint 0).\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Read an Input report from a HID device with timeout.\n\n\t\t\tInput reports are returned\n\t\t\tto the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\t\t\t@param milliseconds timeout in milliseconds or -1 for blocking wait.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);\n\n\t\t/** @brief Read an Input report from a HID device.\n\n\t\t\tInput reports are returned\n\t\t to the host through the INTERRUPT IN endpoint. The first byte will\n\t\t\tcontain the Report number if the device uses numbered reports.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into.\n\t\t\t@param length The number of bytes to read. For devices with\n\t\t\t\tmultiple reports, make sure to read an extra byte for\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Set the device handle to be non-blocking.\n\n\t\t\tIn non-blocking mode calls to hid_read() will return\n\t\t\timmediately with a value of 0 if there is no data to be\n\t\t\tread. In blocking mode, hid_read() will wait (block) until\n\t\t\tthere is data to read before returning.\n\n\t\t\tNonblocking can be turned on and off at any time.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param nonblock enable or not the nonblocking reads\n\t\t\t - 1 to enable nonblocking\n\t\t\t - 0 to disable nonblocking.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);\n\n\t\t/** @brief Send a Feature report to the device.\n\n\t\t\tFeature reports are sent over the Control endpoint as a\n\t\t\tSet_Report transfer. The first byte of @p data[] must\n\t\t\tcontain the Report ID. For devices which only support a\n\t\t\tsingle report, this must be set to 0x0. The remaining bytes\n\t\t\tcontain the report data. Since the Report ID is mandatory,\n\t\t\tcalls to hid_send_feature_report() will always contain one\n\t\t\tmore byte than the report contains. For example, if a hid\n\t\t\treport is 16 bytes long, 17 bytes must be passed to\n\t\t\thid_send_feature_report(): the Report ID (or 0x0, for\n\t\t\tdevices which do not use numbered reports), followed by the\n\t\t\treport data (16 bytes). In this example, the length passed\n\t\t\tin would be 17.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data The data to send, including the report number as\n\t\t\t\tthe first byte.\n\t\t\t@param length The length in bytes of the data to send, including\n\t\t\t\tthe report number.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the actual number of bytes written and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);\n\n\t\t/** @brief Get a feature report from a HID device.\n\n\t\t\tMake sure to set the first byte of @p data[] to the Report\n\t\t\tID of the report to be read. Make sure to allow space for\n\t\t\tthis extra byte in @p data[].\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param data A buffer to put the read data into, including\n\t\t\t\tthe Report ID. Set the first byte of @p data[] to the\n\t\t\t\tReport ID of the report to be read.\n\t\t\t@param length The number of bytes to read, including an\n\t\t\t\textra byte for the report ID. The buffer can be longer\n\t\t\t\tthan the actual report.\n\n\t\t\t@returns\n\t\t\t\tThis function returns the number of bytes read and\n\t\t\t\t-1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);\n\n\t\t/** @brief Close a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t*/\n\t\tvoid HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);\n\n\t\t/** @brief Get The Manufacturer String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Product String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get The Serial Number String from a HID device.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string from a HID device, based on its string index.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\t\t\t@param string_index The index of the string to get.\n\t\t\t@param string A wide string buffer to put the data into.\n\t\t\t@param maxlen The length of the buffer in multiples of wchar_t.\n\n\t\t\t@returns\n\t\t\t\tThis function returns 0 on success and -1 on error.\n\t\t*/\n\t\tint HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);\n\n\t\t/** @brief Get a string describing the last error which occurred.\n\n\t\t\t@ingroup API\n\t\t\t@param device A device handle returned from hid_open().\n\n\t\t\t@returns\n\t\t\t\tThis function returns a string containing the last error\n\t\t\t\twhich occurred or NULL if none has occurred.\n\t\t*/\n\t\tHID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"], ["/sapf/src/primes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"primes.hpp\"\n#include \"ErrorCodes.hpp\"\n#include \n\n// Within a cycle of 30, there are only 8 numbers that are not multiples of 2, 3 or 5.\n// We pack these 8 into a one byte bit map.\n\nconst int gLowPrimes[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimeOffsets[8] = {1, 7, 11, 13, 17, 19, 23, 29};\nconst int gPrimesShift[30] = \n{\n\t-1, 0, -1, -1, -1, -1, -1, 1, -1, -1, \n\t-1, 2, -1, 3, -1, -1, -1, 4, -1, 5, \n\t-1, -1, -1, 6, -1, -1, -1, -1, -1, 7 \n};\n\t\nconst uint32_t gLowPrimesMask = 0x208a28ac;\n\n//const int kPrimeUpperLimit = kPrimesMaskSize * 30;\nuint8_t gPrimesMask[kPrimesMaskSize] = {\n\t0xdf, 0xef, 0x7e, 0xb6, 0xdb, 0x3d, 0xf9, 0xd5, 0x4f, 0x1e, 0xf3, 0xea, 0xa6, 0xed, 0x9e, 0xe6, \n\t0x0c, 0xd3, 0xd3, 0x3b, 0xdd, 0x59, 0xa5, 0x6a, 0x67, 0x92, 0xbd, 0x78, 0x1e, 0xa6, 0x56, 0x56, \n\t0xe3, 0xad, 0x2d, 0xde, 0x2a, 0x4c, 0x55, 0xd9, 0xa3, 0xf0, 0x9f, 0x03, 0x54, 0xa1, 0xf8, 0x2e, \n\t0xfd, 0x44, 0xe9, 0x66, 0xf6, 0x13, 0x3a, 0xb8, 0x4c, 0x2b, 0x3a, 0x45, 0x11, 0xbf, 0x54, 0x8c, \n\t0xc1, 0x7a, 0xb3, 0xc8, 0xbc, 0x8c, 0x4f, 0x21, 0x58, 0x71, 0x71, 0x9b, 0xc1, 0x17, 0xef, 0x54, \n\t0x96, 0x1a, 0x08, 0xe5, 0x83, 0x8c, 0x46, 0x72, 0xfb, 0xae, 0x65, 0x92, 0x8f, 0x58, 0x87, 0xd2, \n\t0x92, 0xd8, 0x81, 0x65, 0x26, 0xe3, 0xa0, 0x11, 0x38, 0xc7, 0x26, 0x3c, 0x81, 0xeb, 0x99, 0x8d, \n\t0x51, 0x88, 0x3e, 0x24, 0xf3, 0x33, 0x4d, 0x5a, 0x8b, 0x1c, 0xa7, 0x2a, 0xb4, 0x58, 0x4c, 0x4e, \n\t0x26, 0xf6, 0x19, 0x82, 0xdc, 0x83, 0xc3, 0x2c, 0xf1, 0x38, 0x02, 0xb5, 0xcd, 0xcd, 0x02, 0xb2, \n\t0x4a, 0x94, 0x0c, 0x57, 0x4c, 0x7a, 0x30, 0x43, 0x0b, 0xf1, 0xcb, 0x44, 0x6c, 0x24, 0xf8, 0x19, \n\t0x01, 0x95, 0xa8, 0x5c, 0x73, 0xea, 0x8d, 0x24, 0x96, 0x2b, 0x50, 0xa6, 0x22, 0x1e, 0xc4, 0xd1, \n\t0x48, 0x06, 0xd4, 0x3a, 0x2f, 0x74, 0x9c, 0x07, 0x6a, 0x05, 0x88, 0xbf, 0x68, 0x15, 0x2e, 0x60, \n\t0x55, 0xe3, 0xb7, 0x51, 0x98, 0x08, 0x14, 0x86, 0x5a, 0xaa, 0x45, 0x4d, 0x49, 0x70, 0x27, 0xd2, \n\t0x93, 0xd5, 0xca, 0xab, 0x02, 0x83, 0x61, 0x05, 0x24, 0xce, 0x87, 0x22, 0xc2, 0xa9, 0xad, 0x18, \n\t0x8c, 0x4d, 0x78, 0xd1, 0x89, 0x16, 0xb0, 0x57, 0xc7, 0x62, 0xa2, 0xc0, 0x34, 0x24, 0x52, 0xae, \n\t0x5a, 0x40, 0x32, 0x8d, 0x21, 0x08, 0x43, 0x34, 0xb6, 0xd2, 0xb6, 0xd9, 0x19, 0xe1, 0x60, 0x67, \n\t0x1a, 0x39, 0x60, 0xd0, 0x44, 0x7a, 0x94, 0x9a, 0x09, 0x88, 0x83, 0xa8, 0x74, 0x55, 0x10, 0x27, \n\t0xa1, 0x5d, 0x68, 0x1e, 0x23, 0xc8, 0x32, 0xe0, 0x19, 0x03, 0x44, 0x73, 0x48, 0xb1, 0x38, 0xc3, \n\t0xe6, 0x2a, 0x57, 0x61, 0x98, 0xb5, 0x1c, 0x0a, 0x68, 0xc5, 0x81, 0x8f, 0xac, 0x02, 0x29, 0x1a, \n\t0x47, 0xe3, 0x94, 0x11, 0x4e, 0x64, 0x2e, 0x14, 0xcb, 0x3d, 0xdc, 0x14, 0xc5, 0x06, 0x10, 0xe9, \n\t0x29, 0xb1, 0x82, 0xe9, 0x30, 0x47, 0xe3, 0x34, 0x19, 0xc3, 0x25, 0x0a, 0x30, 0x30, 0xb4, 0x6c, \n\t0xc1, 0xe5, 0x46, 0x44, 0xd8, 0x8e, 0x4c, 0x5d, 0x22, 0x24, 0x70, 0x78, 0x92, 0x89, 0x81, 0x82, \n\t0x56, 0x26, 0x1b, 0x86, 0xe9, 0x08, 0xa5, 0x00, 0xd3, 0xc3, 0x29, 0xb0, 0xc2, 0x4a, 0x10, 0xb2, \n\t0x59, 0x38, 0xa1, 0x1d, 0x42, 0x60, 0xc7, 0x22, 0x27, 0x8c, 0xc8, 0x44, 0x1a, 0xc6, 0x8b, 0x82, \n\t0x81, 0x1a, 0x46, 0x10, 0xa6, 0x31, 0x09, 0xf0, 0x54, 0x2f, 0x18, 0xd2, 0xd8, 0xa9, 0x15, 0x06, \n\t0x2e, 0x0c, 0xf6, 0xc0, 0x0e, 0x50, 0x91, 0xcd, 0x26, 0xc1, 0x18, 0x38, 0x65, 0x19, 0xc3, 0x56, \n\t0x93, 0x8b, 0x2a, 0x2d, 0xd6, 0x84, 0x4a, 0x61, 0x0a, 0xa5, 0x2c, 0x09, 0xe0, 0x76, 0xc4, 0x6a, \n\t0x3c, 0xd8, 0x08, 0xe8, 0x14, 0x66, 0x1b, 0xb0, 0xa4, 0x02, 0x63, 0x36, 0x10, 0x31, 0x07, 0xd5, \n\t0x92, 0x48, 0x42, 0x12, 0xc3, 0x8a, 0xa0, 0x9f, 0x2d, 0x74, 0xa4, 0x82, 0x85, 0x78, 0x5c, 0x0d, \n\t0x18, 0xb0, 0x61, 0x14, 0x1d, 0x02, 0xe8, 0x18, 0x12, 0xc1, 0x01, 0x49, 0x1c, 0x83, 0x30, 0x67, \n\t0x33, 0xa1, 0x88, 0xd8, 0x0f, 0x0c, 0xf4, 0x98, 0x88, 0x58, 0xd7, 0x66, 0x42, 0x47, 0xb1, 0x16, \n\t0xa8, 0x96, 0x08, 0x18, 0x41, 0x59, 0x15, 0xb5, 0x44, 0x2a, 0x52, 0xe1, 0xb3, 0xaa, 0xa1, 0x59, \n\t0x45, 0x62, 0x55, 0x18, 0x11, 0xa5, 0x0c, 0xa3, 0x3c, 0x67, 0x00, 0xbe, 0x54, 0xd6, 0x0a, 0x20, \n\t0x36, 0x6b, 0x82, 0x0c, 0x15, 0x08, 0x7e, 0x56, 0x91, 0x01, 0x78, 0xd0, 0x61, 0x0a, 0x84, 0xa8, \n\t0x2c, 0x01, 0x57, 0x0e, 0x56, 0xa0, 0x50, 0x0b, 0x98, 0x8c, 0x47, 0x6c, 0x20, 0x63, 0x10, 0xc4, \n\t0x09, 0xe4, 0x0c, 0x57, 0x88, 0x0b, 0x75, 0x0b, 0xc2, 0x52, 0x82, 0xc2, 0x39, 0x24, 0x02, 0x2c, \n\t0x56, 0x25, 0x7a, 0x31, 0x29, 0xd6, 0xa3, 0x20, 0xe1, 0xb1, 0x18, 0xb0, 0x0c, 0x8a, 0x32, 0xc1, \n\t0x11, 0x32, 0x09, 0xc5, 0xad, 0x30, 0x37, 0x08, 0xbc, 0x91, 0x82, 0xcf, 0x20, 0x25, 0x6b, 0x9c, \n\t0x30, 0x8f, 0x44, 0x26, 0x46, 0x6a, 0x07, 0x49, 0x8e, 0x09, 0x58, 0x10, 0x02, 0x25, 0xc5, 0xc4, \n\t0x42, 0x5a, 0x80, 0xa0, 0x80, 0x3c, 0x90, 0x28, 0x64, 0x14, 0xe1, 0x03, 0x84, 0x51, 0x0c, 0x2e, \n\t0xa3, 0x8a, 0xa4, 0x08, 0xc0, 0x47, 0x7e, 0xd3, 0x2b, 0x03, 0xcd, 0x54, 0x2a, 0x00, 0x04, 0xb3, \n\t0x92, 0x6c, 0x42, 0x29, 0x4c, 0x83, 0xc1, 0x92, 0xcc, 0x1c, 0x2d, 0x46, 0x21, 0xdb, 0x38, 0x59, \n\t0x84, 0x8c, 0x24, 0x12, 0x58, 0xbb, 0xe0, 0x06, 0x0d, 0x70, 0x30, 0xc9, 0x09, 0x28, 0x91, 0x41, \n\t0x44, 0x32, 0xf9, 0x8c, 0x30, 0x80, 0xc2, 0x72, 0xa4, 0x62, 0x0c, 0x7d, 0x81, 0x83, 0x14, 0xe1, \n\t0xaa, 0x0e, 0x15, 0x82, 0x0a, 0x78, 0x14, 0x70, 0x97, 0x08, 0x10, 0x6f, 0x2e, 0xf0, 0xb2, 0x1d, \n\t0x30, 0x49, 0x44, 0x32, 0x53, 0x62, 0x86, 0x65, 0x45, 0x84, 0x0a, 0x11, 0x4b, 0x36, 0xd9, 0x8c, \n\t0x69, 0x3a, 0x61, 0x80, 0x90, 0x7c, 0x19, 0xc0, 0x30, 0x95, 0x40, 0x8b, 0x0c, 0x05, 0x2d, 0x0e, \n\t0xc0, 0x71, 0xa1, 0xb4, 0x96, 0x85, 0x1a, 0x16, 0xc0, 0x15, 0x14, 0x51, 0x4c, 0x48, 0xb7, 0x79, \n\t0x95, 0x10, 0x89, 0x8a, 0x2e, 0x02, 0xa1, 0x1c, 0xd5, 0x90, 0x81, 0x10, 0x91, 0x08, 0x22, 0xb4, \n\t0x1e, 0xe9, 0x78, 0xc0, 0x33, 0x20, 0x5c, 0x8b, 0xc4, 0x0e, 0xe2, 0xaa, 0x23, 0x10, 0x47, 0xe3, \n\t0x28, 0x55, 0x7b, 0x19, 0xa1, 0x51, 0xa8, 0x06, 0x04, 0x90, 0x82, 0x2c, 0xd1, 0x61, 0x60, 0xa1, \n\t0x52, 0x06, 0x41, 0x44, 0x81, 0x54, 0x23, 0x88, 0x18, 0xa9, 0x04, 0x27, 0x22, 0x72, 0x48, 0xb6, \n\t0x40, 0x1c, 0x42, 0x12, 0x17, 0xca, 0x29, 0xa0, 0x5a, 0x01, 0x3c, 0xe1, 0x52, 0x84, 0x89, 0xda, \n\t0x01, 0x40, 0x06, 0xf1, 0x2c, 0x69, 0xd2, 0x48, 0x42, 0x63, 0xc1, 0x21, 0x34, 0x8a, 0xc8, 0x6c, \n\t0x21, 0x71, 0x26, 0x09, 0x88, 0x2e, 0x44, 0xd5, 0x28, 0x92, 0x1d, 0x98, 0x86, 0x12, 0xd1, 0x52, \n\t0xa3, 0xa0, 0x46, 0x20, 0x46, 0x14, 0x50, 0x83, 0xdc, 0xdd, 0x83, 0x50, 0x44, 0xa9, 0x8c, 0x4d, \n\t0x14, 0x2e, 0x54, 0x14, 0x89, 0x1b, 0x39, 0x42, 0x80, 0x14, 0x81, 0x29, 0x8f, 0x80, 0x02, 0x03, \n\t0x32, 0x96, 0x82, 0x83, 0xb0, 0x05, 0x0c, 0x14, 0x51, 0x88, 0x07, 0xf8, 0xd9, 0xec, 0x1a, 0x06, \n\t0x48, 0x31, 0x5c, 0x43, 0x86, 0x06, 0x23, 0xb3, 0x09, 0x44, 0x0c, 0xa5, 0x00, 0xf0, 0xb2, 0x80, \n\t0x01, 0xca, 0xe1, 0x42, 0xc2, 0x18, 0xb6, 0x2c, 0x9b, 0xc7, 0x2e, 0x52, 0x29, 0x2c, 0x61, 0x1a, \n\t0x8a, 0x26, 0x24, 0x8b, 0x84, 0x80, 0x5e, 0x60, 0x02, 0xc1, 0x53, 0x2a, 0x35, 0x45, 0x21, 0x52, \n\t0xd1, 0x42, 0xb8, 0xc5, 0x4a, 0x48, 0x04, 0x16, 0x70, 0x23, 0x61, 0xc1, 0x09, 0x50, 0xc4, 0x81, \n\t0x88, 0x18, 0xd9, 0x01, 0x16, 0x22, 0x28, 0x8c, 0x90, 0x84, 0xeb, 0x38, 0x24, 0x53, 0x09, 0xa9, \n\t0x41, 0x6a, 0x14, 0x82, 0x09, 0x86, 0x30, 0x9c, 0xa2, 0x38, 0x42, 0x00, 0x2b, 0x95, 0x5a, 0x02, \n\t0x4a, 0xc1, 0xa2, 0xad, 0x45, 0x04, 0x27, 0x54, 0xc0, 0x28, 0xa9, 0x05, 0x8c, 0x2e, 0x6e, 0x60, \n\t0xf3, 0x16, 0x90, 0x1b, 0x82, 0x1e, 0x00, 0x80, 0x26, 0x1c, 0x1d, 0x4a, 0x14, 0xc2, 0x1a, 0x22, \n\t0x3c, 0x85, 0xc1, 0x10, 0xb0, 0x48, 0x11, 0x00, 0x4a, 0xc5, 0x30, 0xf4, 0xaa, 0x30, 0x8c, 0xc8, \n\t0x49, 0x18, 0x07, 0xf0, 0x1c, 0xe9, 0x07, 0xcd, 0x0c, 0x22, 0x1b, 0x1c, 0xec, 0xc2, 0x45, 0x0a, \n\t0x50, 0x3a, 0x20, 0xe4, 0x0e, 0x6c, 0x20, 0x82, 0xc3, 0x91, 0xd9, 0xc8, 0x62, 0x4c, 0xd1, 0x80, \n\t0x85, 0x65, 0x09, 0x02, 0x30, 0x95, 0xf9, 0x10, 0x69, 0x02, 0xa6, 0x4a, 0x64, 0xc2, 0xb6, 0xf9, \n\t0x16, 0x20, 0x48, 0xa1, 0x73, 0x94, 0x31, 0x54, 0x61, 0x44, 0x07, 0x03, 0x82, 0x2c, 0x06, 0x00, \n\t0x38, 0x33, 0x09, 0x1c, 0xc1, 0x4b, 0xce, 0x12, 0x35, 0x41, 0xa4, 0x90, 0x99, 0x2d, 0x2a, 0xc0, \n\t0x59, 0x84, 0xd1, 0x4a, 0xa4, 0x72, 0x04, 0x22, 0x3c, 0x54, 0xc2, 0xa0, 0x0c, 0x01, 0x18, 0xac, \n\t0xac, 0x96, 0xe4, 0x04, 0x04, 0x03, 0x93, 0x05, 0x9b, 0x48, 0x44, 0x63, 0x32, 0x01, 0x31, 0x5f, \n\t0x60, 0x5c, 0x02, 0x00, 0x03, 0x80, 0xd1, 0x04, 0x2e, 0x34, 0xa9, 0x30, 0x49, 0xc4, 0xca, 0x1e, \n\t0x02, 0x4b, 0x32, 0x14, 0x05, 0x86, 0x22, 0xc5, 0xc2, 0x2a, 0x4c, 0xc8, 0x00, 0x08, 0xf3, 0x18, \n\t0x38, 0x65, 0x99, 0x82, 0x4a, 0x54, 0x63, 0xa1, 0x94, 0x8f, 0x44, 0x12, 0x93, 0xe9, 0x19, 0x28, \n\t0xca, 0xa1, 0x06, 0x12, 0x8a, 0x20, 0xa5, 0x51, 0x48, 0x18, 0x70, 0x31, 0xae, 0x90, 0x08, 0x43, \n\t0x68, 0x97, 0x32, 0xaf, 0x91, 0xc8, 0x0a, 0x2c, 0x02, 0x02, 0x8c, 0x0c, 0x51, 0xa5, 0x12, 0x00, \n\t0x1b, 0x1e, 0x81, 0x8a, 0x08, 0x28, 0x60, 0xd2, 0x86, 0x34, 0x44, 0x63, 0x76, 0x04, 0x43, 0x00, \n\t0xf1, 0x01, 0x04, 0x40, 0x36, 0xc8, 0xa1, 0x8c, 0xc3, 0xce, 0x32, 0x42, 0x09, 0x29, 0x55, 0x44, \n\t0x4e, 0x28, 0x43, 0x60, 0x1c, 0xa0, 0xda, 0x28, 0x0e, 0xa5, 0xf2, 0x05, 0x40, 0x59, 0x8c, 0x4e, \n\t0xa2, 0x60, 0x05, 0xe0, 0x05, 0xc5, 0x04, 0x62, 0x81, 0x26, 0xa8, 0x8a, 0xa4, 0x24, 0xb4, 0xd3, \n\t0x1a, 0x81, 0x42, 0xe4, 0x60, 0x34, 0x08, 0x2a, 0x39, 0xcc, 0x62, 0x08, 0x47, 0xd0, 0x00, 0x40, \n\t0x07, 0x02, 0x78, 0x20, 0xd9, 0xa2, 0x89, 0x50, 0x23, 0x32, 0x00, 0xb8, 0x80, 0x64, 0x11, 0xe9, \n\t0x74, 0x62, 0x0a, 0xaa, 0x44, 0x08, 0x8b, 0x16, 0x06, 0x18, 0x2d, 0xf1, 0x4c, 0x4f, 0x2a, 0x21, \n\t0x40, 0x15, 0xb4, 0x0c, 0x48, 0x22, 0xd1, 0xe1, 0x80, 0xd8, 0x17, 0xa7, 0x14, 0xa0, 0x82, 0x15, \n\t0x64, 0xc0, 0x89, 0x5a, 0x11, 0xbb, 0x8c, 0x78, 0x08, 0xcd, 0x04, 0x24, 0xa2, 0x9b, 0x9c, 0x10, \n\t0xcc, 0x42, 0xa3, 0x28, 0x3b, 0x58, 0x5f, 0xa6, 0x40, 0x90, 0x23, 0x04, 0x2c, 0xd2, 0xae, 0x52, \n\t0x51, 0x1a, 0xa4, 0x69, 0x80, 0xc1, 0x4a, 0xa3, 0xc8, 0x90, 0x19, 0x48, 0x42, 0x24, 0x22, 0x43, \n\t0x02, 0x45, 0xc1, 0x05, 0x00, 0x74, 0x11, 0x15, 0x94, 0x10, 0x0c, 0x38, 0x73, 0x8a, 0x25, 0x04, \n\t0x07, 0x28, 0x7e, 0x01, 0x40, 0x82, 0x41, 0x48, 0x6d, 0x16, 0x36, 0x29, 0x31, 0xe5, 0x81, 0xa4, \n\t0x1c, 0x81, 0xfa, 0x09, 0x00, 0x14, 0x2d, 0x10, 0x60, 0x40, 0x97, 0xdc, 0x88, 0x02, 0x4e, 0x17, \n\t0x98, 0x85, 0x44, 0x9c, 0xa2, 0x60, 0x91, 0x8a, 0x92, 0x68, 0x19, 0x0a, 0x40, 0x51, 0x80, 0x37, \n\t0x84, 0x15, 0x40, 0x62, 0x64, 0xb2, 0x0e, 0x91, 0x48, 0x2a, 0x00, 0x55, 0x48, 0x99, 0xb0, 0x08, \n\t0x85, 0x1a, 0x13, 0x10, 0x9b, 0x00, 0x5e, 0xc9, 0x50, 0x00, 0xe8, 0xa4, 0x00, 0x83, 0x45, 0x6c, \n\t0x40, 0x0b, 0x9d, 0xa0, 0x02, 0x2d, 0x34, 0x92, 0x01, 0x21, 0x81, 0x17, 0xa3, 0x46, 0xa0, 0x8a, \n\t0x85, 0xe8, 0x88, 0x47, 0x18, 0x96, 0x01, 0xb6, 0x41, 0x93, 0x84, 0x08, 0x02, 0x18, 0x02, 0x35, \n\t0x50, 0xe4, 0x3a, 0x81, 0x10, 0x11, 0xa1, 0xda, 0x82, 0x4c, 0x34, 0x32, 0x85, 0x00, 0x57, 0x4b, \n\t0x28, 0xa5, 0xa8, 0x38, 0x84, 0x1d, 0x0e, 0x30, 0xb3, 0x50, 0x22, 0x41, 0xc3, 0xc6, 0x06, 0xd0, \n\t0x20, 0x28, 0xa1, 0x05, 0x8a, 0x1a, 0x84, 0x22, 0x85, 0x0c, 0x46, 0x44, 0x72, 0x90, 0xc8, 0x17, \n\t0xd8, 0x41, 0x61, 0x64, 0x30, 0x39, 0x00, 0x0c, 0x97, 0xa3, 0x0e, 0xb2, 0x29, 0x02, 0x50, 0x88, \n\t0xa9, 0x5c, 0x22, 0xc1, 0x8e, 0x90, 0xc3, 0x47, 0x40, 0x31, 0x12, 0x2c, 0x38, 0x8c, 0x63, 0x64, \n\t0x86, 0xc0, 0xb3, 0x00, 0x4a, 0x2a, 0x38, 0x11, 0x91, 0x13, 0x38, 0x47, 0x49, 0x14, 0x81, 0x73, \n\t0x02, 0x2c, 0x4c, 0x8e, 0x52, 0xe5, 0xd1, 0x10, 0x10, 0x07, 0x4c, 0x06, 0x65, 0x61, 0x1a, 0x54, \n\t0x84, 0x01, 0x4a, 0xe2, 0x01, 0x2f, 0x10, 0x06, 0x09, 0x42, 0x44, 0x9a, 0x00, 0xa9, 0x52, 0x8c, \n\t0x28, 0x94, 0x61, 0x01, 0x99, 0x05, 0x20, 0x1c, 0x23, 0x78, 0xa2, 0x51, 0x18, 0x82, 0x3c, 0x41, \n\t0xd0, 0xb7, 0xc4, 0x43, 0x87, 0x44, 0xc6, 0x0a, 0x93, 0x68, 0xc1, 0x81, 0x30, 0x52, 0xb2, 0xa8, \n\t0xc1, 0x8a, 0x24, 0x1c, 0x21, 0x03, 0x33, 0x41, 0x14, 0x4a, 0x2e, 0x41, 0xe2, 0x82, 0x45, 0x01, \n\t0xac, 0x06, 0x40, 0x18, 0x20, 0x95, 0x4c, 0x67, 0x20, 0x26, 0x50, 0x94, 0x55, 0x92, 0x08, 0x1a, \n\t0x82, 0xe1, 0x8c, 0x10, 0x5b, 0x61, 0x02, 0x86, 0x72, 0x99, 0x30, 0x8d, 0x06, 0x2c, 0xb0, 0xa1, \n\t0x18, 0x28, 0x06, 0x27, 0x46, 0x20, 0x18, 0x82, 0x21, 0x9c, 0xeb, 0x18, 0xc4, 0x30, 0x81, 0x58, \n\t0xc1, 0x84, 0x06, 0x37, 0x9a, 0x24, 0x50, 0x0d, 0xa2, 0x40, 0x05, 0x29, 0x19, 0x09, 0x02, 0x84, \n\t0x52, 0x64, 0x11, 0x17, 0xec, 0xd1, 0x20, 0x78, 0x86, 0x63, 0x0e, 0xd1, 0x11, 0x2a, 0x60, 0x03, \n\t0xd1, 0x22, 0x60, 0x84, 0x06, 0x32, 0xa4, 0x68, 0x24, 0x81, 0xc7, 0xc0, 0x12, 0x42, 0x01, 0xbb, \n\t0xa8, 0x00, 0x41, 0x7c, 0x41, 0x21, 0x81, 0x91, 0x10, 0x85, 0x14, 0xa0, 0xa8, 0x2d, 0x5c, 0x15, \n\t0x47, 0x40, 0xd0, 0xfa, 0x2a, 0x84, 0x0e, 0x8f, 0x10, 0xd2, 0x80, 0x09, 0xd4, 0x49, 0x21, 0x26, \n\t0x32, 0xb0, 0x38, 0x20, 0x41, 0xa0, 0x4a, 0x11, 0x4b, 0xba, 0xac, 0x4e, 0x20, 0x34, 0x61, 0x60, \n\t0x15, 0x0d, 0x13, 0x6a, 0x70, 0x43, 0x42, 0x9c, 0x2d, 0x55, 0xe8, 0x00, 0x96, 0x98, 0x92, 0xe4, \n\t0xc8, 0x4c, 0x0c, 0xa5, 0x19, 0x81, 0x31, 0xca, 0x42, 0x02, 0x12, 0x4a, 0x30, 0x30, 0x51, 0x01, \n\t0x66, 0xa2, 0xe2, 0x16, 0x41, 0xcf, 0xa0, 0x2a, 0x84, 0x51, 0x18, 0x18, 0x41, 0xc6, 0x56, 0xa0, \n\t0x21, 0x8e, 0xe1, 0x96, 0x0b, 0x04, 0x60, 0x11, 0xb8, 0x4c, 0x93, 0x0d, 0x06, 0x04, 0x2a, 0x2a, \n\t0x4c, 0x04, 0x86, 0x2a, 0x51, 0x51, 0x31, 0x00, 0x01, 0x80, 0x76, 0x51, 0x98, 0x94, 0x2d, 0xcc, \n\t0x4a, 0x6a, 0xa4, 0x42, 0xb2, 0x69, 0x48, 0x01, 0x40, 0xb5, 0xd2, 0x32, 0x5c, 0x0e, 0x62, 0x20, \n\t0x16, 0x01, 0x37, 0xe4, 0xc1, 0xc2, 0x58, 0x24, 0x23, 0x08, 0x88, 0x02, 0x24, 0x14, 0x85, 0x98, \n\t0x06, 0xd0, 0x1d, 0xaa, 0x34, 0x80, 0x0a, 0x34, 0x61, 0x10, 0x4b, 0x48, 0x42, 0xc2, 0x02, 0x98, \n\t0x94, 0x00, 0x20, 0x57, 0xb3, 0xa1, 0x88, 0x1a, 0xce, 0x08, 0x05, 0xa0, 0xb0, 0x79, 0x4a, 0x01, \n\t0x14, 0x46, 0x03, 0x24, 0x24, 0x8d, 0x00, 0x44, 0x41, 0x41, 0x03, 0x6c, 0x8a, 0xc1, 0x02, 0xc1, \n\t0x59, 0x26, 0xd8, 0x41, 0x68, 0x56, 0x53, 0x43, 0x2a, 0x14, 0x04, 0x28, 0x0a, 0x25, 0x20, 0x8a, \n\t0x94, 0x47, 0x83, 0x1a, 0x85, 0xa0, 0x0f, 0x84, 0xd5, 0x08, 0x40, 0x70, 0x19, 0x06, 0x08, 0x51, \n\t0x80, 0x5a, 0x16, 0xa8, 0x08, 0x55, 0xd2, 0x28, 0x18, 0x41, 0x49, 0x09, 0x85, 0x02, 0x65, 0x50, \n\t0xb4, 0x80, 0x3d, 0x80, 0x81, 0x2a, 0x4a, 0x86, 0x80, 0x30, 0x01, 0x03, 0x86, 0x1c, 0x53, 0x93, \n\t0xa3, 0x61, 0x58, 0x2a, 0x54, 0x21, 0xb2, 0x97, 0xb0, 0x86, 0xab, 0x52, 0x44, 0xe9, 0x88, 0x59, \n\t0x00, 0x8b, 0x20, 0x10, 0xd2, 0x18, 0x18, 0x85, 0x08, 0x1c, 0x31, 0x50, 0x03, 0x64, 0x8c, 0x0a, \n\t0x40, 0x61, 0xc0, 0x0c, 0xa8, 0x08, 0x40, 0x32, 0x65, 0x0b, 0x9c, 0x88, 0x02, 0x42, 0x4c, 0x14, \n\t0x60, 0x34, 0x85, 0x13, 0x21, 0x50, 0x71, 0x48, 0xa1, 0xe5, 0x14, 0x6e, 0x48, 0x20, 0x32, 0x8a, \n\t0x18, 0x18, 0x45, 0x6a, 0x32, 0x20, 0x82, 0x71, 0x8b, 0xa3, 0x62, 0x16, 0x92, 0xbb, 0x01, 0x91, \n\t0x20, 0x76, 0x11, 0x21, 0x34, 0x54, 0x4c, 0x80, 0x16, 0xc6, 0x38, 0x10, 0xe4, 0x04, 0x84, 0x00, \n\t0x41, 0x01, 0x9a, 0x59, 0x48, 0x84, 0x1a, 0xa4, 0x68, 0x89, 0x51, 0x91, 0x48, 0x40, 0x46, 0xa9, \n\t0x09, 0x94, 0x04, 0x4d, 0x2a, 0x60, 0xb9, 0x18, 0x08, 0xc9, 0xc6, 0x40, 0xa4, 0x99, 0x34, 0x3c, \n\t0x11, 0x8d, 0x10, 0xe0, 0x20, 0xa4, 0x75, 0x0a, 0xe6, 0x44, 0x93, 0xb2, 0x94, 0x04, 0x81, 0xa0, \n\t0x48, 0x75, 0x2a, 0xa3, 0x48, 0x42, 0x05, 0x6e, 0x96, 0x0a, 0x08, 0x29, 0x91, 0x0c, 0x14, 0x05, \n\t0xf0, 0x22, 0x84, 0x01, 0x21, 0x04, 0xa1, 0x00, 0x3a, 0xd8, 0x15, 0x65, 0x10, 0x11, 0xc1, 0xa0, \n\t0x98, 0x8c, 0x2a, 0x16, 0xc1, 0x01, 0x88, 0xf5, 0x12, 0x42, 0x40, 0xa5, 0x01, 0x0b, 0xa0, 0xc2, \n\t0x09, 0x5c, 0xc4, 0x72, 0x00, 0x18, 0x06, 0xe4, 0x0c, 0x26, 0x5a, 0x3d, 0x80, 0x10, 0x40, 0x40, \n\t0x40, 0x11, 0x23, 0x30, 0x9c, 0x80, 0x74, 0x32, 0x82, 0x84, 0x85, 0x00, 0xaf, 0x20, 0x95, 0x20, \n\t0x8f, 0x51, 0x8e, 0xc3, 0x26, 0x84, 0x62, 0x03, 0xc1, 0x09, 0xa8, 0x34, 0x34, 0x83, 0x22, 0xcc, \n\t0x90, 0x23, 0x1a, 0x82, 0x22, 0x88, 0x48, 0x40, 0x6c, 0x32, 0xc5, 0x91, 0xa3, 0x35, 0x89, 0xa0, \n\t0x24, 0xa0, 0x58, 0x07, 0x21, 0x98, 0x0e, 0x0a, 0xf2, 0x6b, 0xb0, 0xac, 0x4a, 0x6c, 0x08, 0x92, \n\t0x29, 0x18, 0x40, 0x42, 0xc1, 0x2e, 0x04, 0x91, 0x30, 0xd1, 0x94, 0xa3, 0x42, 0x43, 0xd9, 0x20, \n\t0x59, 0x98, 0x2d, 0x20, 0x74, 0x00, 0x3d, 0x8c, 0x13, 0x0a, 0x46, 0x62, 0x00, 0x05, 0x34, 0x59, \n\t0x40, 0x26, 0x02, 0x58, 0x38, 0xad, 0x94, 0x2a, 0x18, 0x10, 0x0a, 0xa0, 0x69, 0x47, 0xe3, 0x18, \n\t0xe2, 0x70, 0x8c, 0x04, 0x54, 0x01, 0x24, 0x00, 0x8a, 0x10, 0x29, 0x06, 0xad, 0x02, 0x46, 0x28, \n\t0x0b, 0xd0, 0x50, 0xc5, 0x72, 0x50, 0xc1, 0xa9, 0x14, 0x14, 0x09, 0x60, 0xb0, 0x52, 0x12, 0x60, \n\t0x45, 0x20, 0x16, 0x06, 0xc3, 0x01, 0xa9, 0x93, 0xae, 0x04, 0x82, 0x1a, 0x0b, 0x58, 0x0e, 0x2c, \n\t0x64, 0x84, 0x30, 0x07, 0x55, 0x92, 0x09, 0x08, 0x90, 0xba, 0x91, 0x25, 0x02, 0x47, 0x66, 0x56, \n\t0x68, 0x21, 0x00, 0x9c, 0x06, 0x60, 0x20, 0x88, 0x34, 0x89, 0x9b, 0x88, 0x22, 0xc2, 0x52, 0x92, \n\t0x1d, 0x14, 0x80, 0x40, 0xd5, 0x19, 0x0b, 0xb4, 0xc4, 0xe0, 0x38, 0x45, 0x50, 0x1b, 0x44, 0x88, \n\t0x08, 0x08, 0x07, 0xe2, 0x0f, 0x24, 0x80, 0x65, 0x28, 0x72, 0x00, 0x0a, 0xe9, 0xc1, 0x08, 0x48, \n\t0xb0, 0x42, 0x0c, 0x41, 0x55, 0x26, 0x0e, 0x21, 0x1a, 0x84, 0xd1, 0x10, 0x42, 0x18, 0x07, 0xa1, \n\t0x13, 0x4c, 0xd0, 0xc0, 0x0c, 0x44, 0x2a, 0x83, 0x44, 0x01, 0x46, 0x06, 0x45, 0xf0, 0xbc, 0x04, \n\t0x8a, 0xa6, 0x0a, 0x30, 0x11, 0xb4, 0x61, 0xc3, 0x6b, 0x06, 0x07, 0x23, 0xb4, 0x6c, 0x19, 0x49, \n\t0x46, 0xa0, 0x18, 0x28, 0x60, 0x84, 0x8a, 0x12, 0xa5, 0x20, 0x04, 0x31, 0xda, 0x4c, 0x60, 0x21, \n\t0x0a, 0x17, 0x14, 0x02, 0x04, 0x32, 0x90, 0x92, 0x83, 0x89, 0x4b, 0x42, 0x68, 0x00, 0x53, 0x11, \n\t0x80, 0xd7, 0x88, 0x18, 0x72, 0xa1, 0x04, 0xb0, 0x00, 0x64, 0x08, 0x42, 0xc1, 0x2e, 0x54, 0x81, \n\t0x85, 0x68, 0xa4, 0x98, 0x92, 0x38, 0x59, 0x04, 0x44, 0x00, 0xa3, 0xa1, 0x64, 0x0f, 0x22, 0x3e, \n\t0x00, 0x90, 0x02, 0xdd, 0x1c, 0x8b, 0x1c, 0x60, 0xd0, 0x32, 0x84, 0x04, 0x03, 0x06, 0x74, 0x1a, \n\t0x31, 0x2d, 0xc9, 0x82, 0x22, 0xc3, 0x10, 0x82, 0x30, 0x8c, 0x41, 0x12, 0x12, 0x60, 0x35, 0x94, \n\t0x1f, 0x09, 0x32, 0xf1, 0xa8, 0x8c, 0x08, 0x90, 0x6b, 0x48, 0x20, 0x79, 0x3d, 0x54, 0x86, 0x04, \n\t0x4a, 0x71, 0xc8, 0x00, 0xcc, 0x02, 0xe9, 0x0c, 0x24, 0x21, 0x0a, 0x80, 0x52, 0xee, 0x00, 0xa4, \n\t0x32, 0x96, 0x1c, 0x92, 0x64, 0x20, 0x82, 0x8a, 0x88, 0xa1, 0x4b, 0x0e, 0x78, 0x35, 0x51, 0x00, \n\t0xa0, 0x49, 0x69, 0x72, 0x07, 0x23, 0x14, 0xa0, 0x45, 0x0a, 0x04, 0xd0, 0xd9, 0x82, 0xa1, 0x07, \n\t0xe5, 0x08, 0x03, 0x20, 0x3c, 0x70, 0xd4, 0x0c, 0x12, 0xc0, 0x49, 0x20, 0x08, 0xd1, 0x08, 0x62, \n\t0x63, 0x11, 0x02, 0x10, 0x98, 0x4f, 0x72, 0x20, 0x81, 0x11, 0xa8, 0x53, 0xab, 0x14, 0x02, 0x10, \n\t0x8e, 0x94, 0x86, 0x49, 0x20, 0x31, 0x02, 0x19, 0x41, 0x48, 0x62, 0x44, 0xc5, 0x80, 0x18, 0x14, \n\t0xd0, 0x83, 0x00, 0x57, 0x88, 0x25, 0xad, 0x42, 0x80, 0x3a, 0x30, 0x90, 0x15, 0xd5, 0x1a, 0xe1, \n\t0x4c, 0x24, 0x20, 0x80, 0xe1, 0x08, 0xc7, 0x14, 0x05, 0x8a, 0x11, 0xb0, 0x01, 0x28, 0x10, 0x33, \n\t0x21, 0x93, 0x04, 0xcf, 0x44, 0x22, 0xc0, 0xc9, 0x9a, 0x00, 0x4a, 0x0c, 0x2c, 0x01, 0xb1, 0x8e, \n\t0x10, 0x58, 0x21, 0x14, 0x96, 0x63, 0x34, 0x44, 0x43, 0x04, 0x44, 0xb0, 0x5b, 0x80, 0x28, 0x0c, \n\t0x00, 0x24, 0x33, 0x80, 0x0a, 0x1c, 0x0b, 0x65, 0x26, 0xe0, 0x2a, 0x1e, 0x09, 0x9d, 0xa5, 0x48, \n\t0x44, 0x13, 0x25, 0x2c, 0xc4, 0x22, 0x30, 0x00, 0x62, 0xa4, 0x48, 0x46, 0x40, 0x50, 0x27, 0x00, \n\t0xb8, 0xa4, 0x44, 0x0c, 0x26, 0x44, 0x98, 0x89, 0x81, 0x03, 0x0d, 0x1c, 0xc6, 0x58, 0x82, 0x40, \n\t0x18, 0x4b, 0x40, 0x85, 0x8b, 0x3b, 0x38, 0xc8, 0x2d, 0x64, 0x87, 0x61, 0x11, 0x58, 0x41, 0x88, \n\t0x16, 0x14, 0x89, 0x19, 0x9d, 0x10, 0xa0, 0x08, 0x22, 0x80, 0x02, 0x44, 0x86, 0x81, 0x04, 0x33, \n\t0x80, 0x10, 0x19, 0xc0, 0xc1, 0x48, 0x10, 0x80, 0x31, 0x40, 0x1f, 0x01, 0x24, 0x03, 0xe1, 0x3f, \n\t0x48, 0x4b, 0x8a, 0x10, 0x21, 0xd8, 0x06, 0x95, 0x19, 0x6b, 0x42, 0x80, 0x68, 0x16, 0x64, 0x48, \n\t0x22, 0x40, 0xd5, 0x18, 0xa9, 0x10, 0xc5, 0x0b, 0x1c, 0x74, 0x51, 0xb8, 0x25, 0x00, 0xc0, 0x62, \n\t0xa2, 0xa9, 0x10, 0xb4, 0x8a, 0x60, 0x2a, 0x77, 0xc1, 0x8e, 0x10, 0x83, 0x48, 0x76, 0x92, 0x42, \n\t0x25, 0x08, 0xc0, 0x2c, 0x1e, 0x30, 0x60, 0x21, 0x79, 0x02, 0x88, 0x30, 0x95, 0x30, 0x2a, 0x84, \n\t0x00, 0x4a, 0x4c, 0x43, 0x10, 0x17, 0x11, 0x94, 0xa2, 0x08, 0x80, 0x31, 0xb4, 0x6d, 0xc8, 0x80, \n\t0x6a, 0x40, 0x2b, 0x04, 0x70, 0x1b, 0x49, 0x78, 0xc0, 0x88, 0x04, 0x5c, 0x01, 0x25, 0x40, 0x44, \n\t0x41, 0x18, 0x05, 0x4f, 0x06, 0x0a, 0x20, 0x61, 0x37, 0xd0, 0x40, 0x05, 0x0a, 0x26, 0x48, 0xb8, \n\t0x88, 0x5b, 0x21, 0x10, 0x43, 0xda, 0x9e, 0x29, 0x81, 0xa3, 0x18, 0x00, 0x33, 0x09, 0x98, 0x93, \n\t0xcd, 0x52, 0x42, 0xa3, 0x25, 0x85, 0x1e, 0x28, 0x14, 0x35, 0x50, 0x01, 0xd0, 0xd0, 0x4a, 0x2c, \n\t0xa1, 0x22, 0xa0, 0x5d, 0x1c, 0xe2, 0x02, 0x54, 0x90, 0x02, 0x88, 0x5f, 0x28, 0x78, 0x04, 0x83, \n\t0x02, 0x40, 0x8c, 0x20, 0x0c, 0x82, 0x11, 0x04, 0x71, 0x4d, 0x26, 0x66, 0x32, 0x88, 0x8a, 0xa0, \n\t0x07, 0x8c, 0x00, 0xa3, 0x40, 0x09, 0x31, 0xc7, 0x81, 0x30, 0xd4, 0x43, 0x0a, 0x88, 0x9d, 0x49, \n\t0x4a, 0x81, 0x01, 0x8a, 0x18, 0x02, 0x67, 0x64, 0x36, 0x88, 0x18, 0x88, 0x05, 0xe8, 0x14, 0x40, \n\t0x79, 0x07, 0x49, 0x90, 0xc9, 0x2c, 0xd6, 0x02, 0x93, 0x80, 0x48, 0xa9, 0x0c, 0x67, 0x10, 0xa6, \n\t0x24, 0x51, 0x66, 0x04, 0x00, 0x5b, 0x13, 0xc8, 0xcd, 0x00, 0x62, 0x05, 0x2b, 0x32, 0x31, 0x19, \n\t0xc8, 0x20, 0x02, 0x90, 0x92, 0x21, 0x4d, 0xe0, 0x64, 0xc0, 0x43, 0x10, 0x84, 0x44, 0xa7, 0x1a, \n\t0x12, 0x18, 0x34, 0x01, 0x08, 0x07, 0x0a, 0xb4, 0xaa, 0x32, 0x1c, 0x16, 0x40, 0x06, 0xc1, 0xa8, \n\t0x1e, 0x21, 0x40, 0x41, 0x12, 0xb4, 0x13, 0x08, 0x85, 0x40, 0x0c, 0x02, 0xf0, 0x13, 0x28, 0x69, \n\t0x80, 0x45, 0x70, 0x75, 0x70, 0x80, 0x41, 0x02, 0x21, 0x00, 0x33, 0x88, 0xbc, 0x65, 0x80, 0x46, \n\t0x54, 0x82, 0x03, 0x13, 0x04, 0xc1, 0x08, 0x20, 0x50, 0x03, 0x23, 0x30, 0x1e, 0x82, 0x32, 0xa6, \n\t0xc8, 0x2a, 0x91, 0x48, 0x4c, 0x10, 0x94, 0xc1, 0x20, 0x9c, 0x03, 0x28, 0x34, 0x90, 0x70, 0xba, \n\t0xb1, 0x4a, 0xc4, 0x58, 0x44, 0xe0, 0xa8, 0xbc, 0x40, 0x05, 0x48, 0x35, 0x22, 0x10, 0x30, 0x16, \n\t0x27, 0x24, 0x20, 0x12, 0x38, 0x64, 0x07, 0x46, 0x08, 0xa3, 0xf0, 0x09, 0x14, 0x8a, 0xea, 0x20, \n\t0x07, 0xc3, 0x00, 0x85, 0x89, 0xc0, 0x22, 0xc0, 0x20, 0x8c, 0x68, 0x0a, 0x02, 0x26, 0x43, 0x48, \n\t0x8e, 0x4c, 0x03, 0xa2, 0x48, 0x75, 0xb2, 0x00, 0x61, 0x81, 0x60, 0x68, 0x40, 0x83, 0x90, 0xc5, \n\t0x50, 0x00, 0x50, 0x56, 0x02, 0xa3, 0x14, 0x44, 0x24, 0x3e, 0xa4, 0x49, 0x3a, 0x01, 0xd0, 0x0b, \n\t0x48, 0x63, 0x8a, 0xa4, 0x20, 0xd2, 0x4c, 0x1e, 0x44, 0x61, 0x11, 0x49, 0x44, 0x61, 0x36, 0x84, \n\t0x12, 0x38, 0xe8, 0x04, 0xa6, 0x50, 0x92, 0x69, 0x89, 0x35, 0x1c, 0xa1, 0x04, 0x75, 0x62, 0x2d, \n\t0xc0, 0x91, 0x82, 0x02, 0x32, 0x18, 0x05, 0x71, 0xc8, 0x66, 0x50, 0x06, 0x58, 0x3a, 0x04, 0x00, \n\t0x2c, 0x18, 0x21, 0x21, 0x07, 0x8c, 0x41, 0x42, 0x14, 0xc0, 0xb0, 0x2e, 0x08, 0x01, 0x0b, 0x10, \n\t0x03, 0x80, 0x91, 0x88, 0x02, 0xae, 0x0c, 0x14, 0x09, 0x84, 0x60, 0x5b, 0xc1, 0x40, 0x23, 0x63, \n\t0x08, 0x80, 0x10, 0x0d, 0x0e, 0x82, 0xc8, 0x00, 0xb9, 0xdd, 0x44, 0x2a, 0x30, 0x6a, 0x30, 0x69, \n\t0x10, 0x6c, 0x00, 0x93, 0x19, 0x82, 0xcc, 0x10, 0x80, 0x2c, 0x41, 0xd2, 0x85, 0x18, 0x88, 0x24, \n\t0x4e, 0xd7, 0x88, 0xa9, 0x0c, 0x86, 0xa1, 0x04, 0x43, 0x2a, 0x91, 0x60, 0x03, 0x04, 0x12, 0x50, \n\t0x50, 0x20, 0xb1, 0xcc, 0x02, 0x60, 0x87, 0xab, 0x16, 0x90, 0x10, 0xe4, 0x72, 0x51, 0x00, 0x2b, \n\t0x60, 0x4a, 0x05, 0x0a, 0x35, 0x00, 0x22, 0x40, 0x89, 0x8a, 0x48, 0x56, 0xc2, 0x0c, 0x00, 0xc2, \n\t0x2c, 0x40, 0x34, 0x3a, 0x08, 0x39, 0x9b, 0x85, 0x5a, 0x14, 0x53, 0x0d, 0x10, 0x01, 0x0f, 0x00, \n\t0x81, 0x93, 0x2e, 0x69, 0x94, 0x2e, 0x1c, 0x41, 0xc0, 0x17, 0x18, 0x91, 0x8e, 0x08, 0x44, 0x98, \n\t0xa3, 0x61, 0x02, 0x44, 0x26, 0x42, 0xe1, 0x80, 0x88, 0x16, 0x02, 0x00, 0x64, 0x0a, 0x30, 0x00, \n\t0x08, 0xe1, 0x04, 0x03, 0xd1, 0x38, 0x14, 0x19, 0x01, 0x72, 0x52, 0x51, 0x18, 0x05, 0x85, 0x4e, \n\t0x06, 0xa1, 0x30, 0x26, 0x84, 0x4e, 0x4b, 0x42, 0x71, 0x01, 0x98, 0x30, 0x44, 0x21, 0x0e, 0x70, \n\t0x62, 0x19, 0x11, 0x00, 0x2b, 0x10, 0x30, 0x22, 0x25, 0x6c, 0x14, 0xc0, 0x5e, 0xd2, 0xb8, 0x07, \n\t0x45, 0x90, 0x48, 0x50, 0xc5, 0xa3, 0x81, 0x85, 0x40, 0x22, 0x4a, 0x05, 0x9a, 0x16, 0x48, 0x8d, \n\t0x05, 0x32, 0x16, 0xe2, 0xa2, 0x21, 0x4c, 0x00, 0x06, 0x05, 0x60, 0xa2, 0xbd, 0x48, 0xcb, 0x50, \n\t0x04, 0x02, 0x8a, 0xe4, 0x08, 0xa0, 0x00, 0x41, 0x00, 0x19, 0x65, 0x05, 0x8d, 0x20, 0x00, 0x20, \n\t0x87, 0x30, 0x0d, 0x4a, 0x7a, 0xd3, 0x28, 0x07, 0x04, 0x84, 0x61, 0x14, 0xd0, 0x81, 0x88, 0xa1, \n\t0xde, 0x86, 0x22, 0x80, 0x69, 0x00, 0xa9, 0xc3, 0x00, 0x06, 0x33, 0xc8, 0x01, 0x51, 0x16, 0x08, \n\t0x20, 0x66, 0x10, 0x9e, 0xc4, 0x00, 0xc6, 0x44, 0xc6, 0x02, 0x02, 0x0d, 0xd1, 0x25, 0x74, 0xd2, \n\t0x41, 0x28, 0xe0, 0x18, 0x82, 0x04, 0x34, 0x52, 0xa5, 0x48, 0x84, 0x4a, 0x76, 0xa1, 0x0b, 0xb6, \n\t0x0c, 0x50, 0x20, 0x20, 0x04, 0x03, 0x88, 0xdc, 0x0c, 0x41, 0x0a, 0x06, 0x00, 0x31, 0x91, 0x02, \n\t0x89, 0x10, 0xe4, 0x23, 0x91, 0x10, 0x9f, 0x45, 0x6c, 0x54, 0xf9, 0x9f, 0x60, 0x0a, 0x80, 0x02, \n\t0x30, 0x71, 0x0d, 0x10, 0x42, 0x82, 0x46, 0x30, 0x12, 0x04, 0x0c, 0x12, 0x08, 0x70, 0xa1, 0x71, \n\t0xa2, 0x50, 0x00, 0xe4, 0x44, 0xd2, 0x28, 0x09, 0x0d, 0xda, 0x40, 0x40, 0x16, 0x78, 0x26, 0xa0, \n\t0x86, 0xa4, 0x08, 0x14, 0x90, 0x00, 0xd1, 0x0a, 0x00, 0x0a, 0xc3, 0x19, 0xac, 0xa5, 0x41, 0xc0, \n\t0x66, 0xb1, 0x50, 0x22, 0x28, 0x09, 0x04, 0x0a, 0xc6, 0x01, 0x96, 0x20, 0x5a, 0x4c, 0x08, 0x45, \n\t0xa2, 0x20, 0xac, 0x57, 0x0c, 0x20, 0x24, 0xa0, 0x81, 0x48, 0x50, 0x85, 0x4e, 0x14, 0x8a, 0x08, \n\t0x50, 0xd5, 0x4f, 0x46, 0xe3, 0x79, 0x0d, 0x0c, 0x88, 0x83, 0x10, 0x03, 0xa0, 0x0b, 0x85, 0x92, \n\t0x05, 0x60, 0xe2, 0x08, 0x20, 0x25, 0x15, 0x44, 0x1a, 0x45, 0x11, 0xbc, 0x80, 0x08, 0x80, 0x50, \n\t0x34, 0x22, 0x15, 0x80, 0x8b, 0x8a, 0x10, 0x41, 0x79, 0xa8, 0x64, 0x50, 0x4e, 0x04, 0xa4, 0x0a, \n\t0x18, 0xcc, 0x88, 0xa5, 0x04, 0xa2, 0x41, 0x8d, 0x40, 0x56, 0x00, 0x70, 0xa3, 0x41, 0x03, 0x30, \n\t0x88, 0x2c, 0x2c, 0x07, 0xcb, 0x92, 0xc1, 0x05, 0xae, 0x14, 0x82, 0xb8, 0x01, 0x58, 0x07, 0x09, \n\t0x10, 0xc2, 0x21, 0x2c, 0xf0, 0x18, 0x02, 0x40, 0x64, 0xa2, 0x29, 0x58, 0x41, 0x80, 0x28, 0xc4, \n\t0x88, 0x09, 0x64, 0x87, 0x82, 0x16, 0x90, 0x21, 0x09, 0x09, 0x5f, 0x06, 0x50, 0x00, 0xd0, 0x92, \n\t0xb8, 0x83, 0x81, 0x68, 0x01, 0x5a, 0x10, 0x3c, 0x05, 0x60, 0x20, 0xb0, 0x10, 0x80, 0x48, 0x88, \n\t0x2b, 0x04, 0x53, 0x38, 0xb3, 0x41, 0x92, 0x4c, 0x62, 0xa6, 0x21, 0x05, 0x2c, 0x48, 0x4d, 0x14, \n\t0x34, 0x32, 0x0b, 0x01, 0x1a, 0xa9, 0x48, 0x02, 0xca, 0x20, 0x21, 0x44, 0x47, 0x06, 0x40, 0x40, \n\t0x81, 0xd4, 0x12, 0x62, 0x14, 0x95, 0x61, 0xb1, 0x98, 0x00, 0x6b, 0x46, 0xa3, 0xb2, 0x1e, 0x10, \n\t0xd6, 0x21, 0x1c, 0x01, 0x88, 0x94, 0x25, 0x80, 0x80, 0x46, 0x61, 0xcb, 0xb3, 0x40, 0x84, 0x8b, \n\t0x50, 0x43, 0xd1, 0x34, 0x31, 0x1d, 0x04, 0x12, 0x15, 0x40, 0x30, 0x00, 0x48, 0xc2, 0x20, 0x95, \n\t0x19, 0x18, 0xf5, 0x8d, 0x84, 0x10, 0x31, 0x0a, 0xbc, 0x04, 0xd9, 0x20, 0x1c, 0x42, 0xf0, 0x01, \n\t0x68, 0x94, 0x2e, 0x0a, 0x86, 0xb0, 0x01, 0x4c, 0x40, 0x21, 0x4c, 0x91, 0x80, 0xaa, 0x34, 0x06, \n\t0xa4, 0x58, 0x01, 0x13, 0xa1, 0x50, 0x41, 0x43, 0x20, 0xc4, 0xa2, 0xa0, 0x20, 0x46, 0x04, 0x38, \n\t0x96, 0xaa, 0x82, 0x6c, 0x12, 0x0e, 0x4c, 0x21, 0x43, 0x13, 0x94, 0x1e, 0x02, 0x46, 0x66, 0x48, \n\t0x10, 0x44, 0x45, 0xe8, 0x06, 0x01, 0x10, 0x12, 0xcc, 0x0a, 0xcd, 0x08, 0x31, 0x10, 0x2f, 0xf0, \n\t0x19, 0x00, 0x70, 0x22, 0x63, 0x88, 0x0c, 0x13, 0x04, 0x48, 0xe0, 0x68, 0x86, 0xa8, 0xcf, 0x60, \n\t0x50, 0x00, 0xb2, 0x00, 0x81, 0x47, 0x22, 0x48, 0x40, 0x3b, 0x25, 0x40, 0x96, 0x45, 0x24, 0x62, \n\t0xa1, 0x08, 0x99, 0xc2, 0x44, 0x04, 0x32, 0x22, 0x01, 0x14, 0x96, 0xa5, 0x58, 0x16, 0x4b, 0x90, \n\t0x49, 0x01, 0x08, 0x32, 0x74, 0x61, 0x00, 0x6d, 0x17, 0x22, 0x12, 0x46, 0x41, 0x20, 0x79, 0x11, \n\t0x01, 0x56, 0xa6, 0x00, 0x02, 0x49, 0x46, 0x2f, 0x02, 0x07, 0x08, 0x0d, 0x45, 0x40, 0xc9, 0x68, \n\t0x07, 0x01, 0x98, 0x34, 0x00, 0x48, 0x28, 0x83, 0x00, 0x1c, 0x81, 0x41, 0xc8, 0x50, 0x20, 0x32, \n\t0x34, 0x95, 0x07, 0x45, 0x48, 0x60, 0x08, 0x0a, 0x54, 0x82, 0x24, 0x60, 0x37, 0xd0, 0xaa, 0xc5, \n\t0xd3, 0x42, 0x04, 0x32, 0xaa, 0x1a, 0x40, 0x05, 0xc1, 0x10, 0x44, 0x0a, 0x80, 0x2c, 0xd0, 0x88, \n\t0x4c, 0x31, 0x42, 0x06, 0x95, 0x07, 0xe2, 0x0c, 0x23, 0xdb, 0xa0, 0x81, 0x09, 0x64, 0x24, 0xf0, \n\t0x4a, 0x10, 0x30, 0x03, 0xc0, 0x1c, 0xc6, 0x40, 0x88, 0xa5, 0x5d, 0x45, 0x22, 0xc1, 0xc2, 0x03, \n\t0x20, 0x9a, 0x2c, 0x40, 0x76, 0x08, 0x14, 0x21, 0x8c, 0xe0, 0x26, 0xb4, 0xf2, 0x08, 0x74, 0x82, \n\t0x0d, 0x04, 0x90, 0x98, 0x2a, 0x48, 0x00, 0x09, 0x50, 0x31, 0xc2, 0x06, 0x08, 0x43, 0xe3, 0x22, \n\t0x14, 0x02, 0x89, 0x45, 0xc4, 0x23, 0x18, 0xd0, 0xb8, 0xa0, 0x89, 0x92, 0x2a, 0x58, 0x51, 0xa0, \n\t0x80, 0xed, 0x03, 0x2b, 0x20, 0x80, 0x18, 0x96, 0x8c, 0x08, 0x00, 0x02, 0x62, 0x83, 0x09, 0x61, \n\t0x01, 0x8d, 0x28, 0x04, 0x48, 0x85, 0x11, 0x58, 0x07, 0x50, 0x05, 0x08, 0x37, 0xb0, 0x96, 0x40, \n\t0x04, 0x05, 0x93, 0x01, 0x11, 0x0f, 0xa9, 0x74, 0x02, 0xb0, 0x04, 0xac, 0xd0, 0xa3, 0x00, 0x21, \n\t0xb0, 0x04, 0x68, 0x10, 0x63, 0x20, 0x60, 0x53, 0x98, 0x88, 0x11, 0x47, 0x28, 0x31, 0x20, 0x24, \n\t0x79, 0x03, 0x20, 0x66, 0x13, 0xa3, 0x36, 0xa1, 0x0f, 0x00, 0x42, 0x74, 0x50, 0x84, 0x70, 0x87, \n\t0x40, 0x28, 0x61, 0xd2, 0x06, 0x98, 0x18, 0x09, 0x44, 0x75, 0x88, 0x93, 0x81, 0x46, 0x82, 0x06, \n\t0xc4, 0x20, 0x8c, 0x44, 0x02, 0x8c, 0x62, 0x94, 0x4b, 0x80, 0x04, 0x0d, 0x49, 0x18, 0x80, 0x80, \n\t0x98, 0x29, 0xc0, 0x2a, 0x76, 0x80, 0x40, 0x15, 0xd1, 0x42, 0x2a, 0x0e, 0xd0, 0xe9, 0x81, 0x11, \n\t0x0a, 0x84, 0x58, 0x00, 0x00, 0x9f, 0x80, 0x80, 0x8e, 0x02, 0x45, 0x90, 0x10, 0x30, 0x53, 0x82, \n\t0x0e, 0x06, 0xa0, 0xb2, 0xa8, 0x90, 0x84, 0x04, 0x41, 0x99, 0x05, 0x11, 0x0f, 0xa1, 0x70, 0x82, \n\t0x29, 0x8e, 0xbc, 0x10, 0x41, 0x20, 0xe5, 0x5b, 0x32, 0x05, 0x86, 0x47, 0x02, 0x23, 0x20, 0x25, \n\t0xd0, 0x8c, 0x02, 0x30, 0x40, 0x4a, 0x32, 0x28, 0xc1, 0x40, 0x62, 0x52, 0x12, 0x19, 0xa8, 0x5a, \n\t0xc5, 0x78, 0x26, 0x4a, 0x0d, 0x65, 0x97, 0x08, 0x1c, 0x81, 0x03, 0x8c, 0xd1, 0x8c, 0x02, 0x0c, \n\t0xa4, 0xe1, 0x02, 0xc0, 0xc9, 0x2e, 0x20, 0x00, 0x32, 0x30, 0x59, 0x50, 0xa7, 0x20, 0xc1, 0x40, \n\t0x84, 0xe9, 0xd8, 0x08, 0x5a, 0x50, 0x91, 0x10, 0x50, 0x1a, 0xc8, 0x28, 0x80, 0x4a, 0x0a, 0x14, \n\t0x09, 0x86, 0x70, 0x80, 0x51, 0x13, 0xc8, 0x02, 0xc4, 0x34, 0x54, 0x60, 0x8a, 0x95, 0x80, 0x07, \n\t0x28, 0x64, 0x22, 0x8c, 0x1c, 0x8a, 0x25, 0x18, 0x03, 0xe2, 0x97, 0x90, 0x16, 0x61, 0x00, 0x26, \n\t0x08, 0x38, 0x24, 0xc1, 0xe8, 0x50, 0x82, 0x12, 0x00, 0x09, 0x90, 0x84, 0x4c, 0x80, 0x92, 0x01, \n\t0x04, 0x0a, 0x6f, 0x68, 0x34, 0x9a, 0xa8, 0x30, 0x58, 0x05, 0x12, 0x84, 0xa3, 0x02, 0x0c, 0xd1, \n\t0xa4, 0x2a, 0x10, 0x09, 0x03, 0x45, 0x15, 0x61, 0x30, 0xa7, 0x00, 0x98, 0x01, 0x44, 0x88, 0x16, \n\t0x13, 0x93, 0x28, 0x11, 0xc6, 0x44, 0x04, 0x77, 0x68, 0x18, 0x00, 0x8b, 0x03, 0x4a, 0xb3, 0x60, \n\t0x2e, 0x90, 0x85, 0x29, 0x42, 0x36, 0x38, 0x9c, 0xa0, 0x00, 0x2a, 0x40, 0x04, 0x2b, 0x14, 0x05, \n\t0x86, 0xa1, 0x4c, 0xd1, 0x0a, 0x27, 0xc0, 0x04, 0x4a, 0x60, 0x04, 0xb1, 0xa1, 0x04, 0x10, 0xe9, \n\t0x62, 0xb6, 0xb2, 0x04, 0x74, 0x48, 0x61, 0x4c, 0x01, 0x12, 0x87, 0x05, 0x91, 0xa4, 0x16, 0x30, \n\t0x09, 0xb4, 0x68, 0x54, 0x03, 0x04, 0x82, 0x02, 0x22, 0x45, 0x54, 0x88, 0x00, 0x81, 0xda, 0x8a, \n\t0xb5, 0x00, 0x42, 0x30, 0x41, 0x30, 0xb1, 0x04, 0x06, 0x0e, 0x1a, 0xa0, 0xe8, 0x09, 0x00, 0x48, \n\t0x40, 0x0e, 0x86, 0x10, 0x02, 0xe0, 0x0e, 0x07, 0x60, 0x10, 0x10, 0x29, 0x08, 0xd3, 0xec, 0x12, \n\t0x71, 0x88, 0x22, 0x8c, 0x92, 0xa4, 0x08, 0x20, 0x53, 0x0f, 0xc0, 0x81, 0x00, 0x0a, 0x87, 0x08, \n\t0x03, 0x0d, 0x08, 0x20, 0x7c, 0x40, 0x08, 0x2b, 0xa1, 0x46, 0x24, 0x60, 0x70, 0x22, 0x85, 0x11, \n\t0x81, 0xc1, 0x6a, 0x84, 0x80, 0x06, 0xa4, 0x14, 0xcb, 0x04, 0xa2, 0x02, 0xb8, 0x10, 0x05, 0x4b, \n\t0x30, 0x55, 0x28, 0x84, 0xc4, 0x00, 0x42, 0x2a, 0xc0, 0xc2, 0x18, 0x80, 0x04, 0x25, 0x4a, 0x65, \n\t0x13, 0x1d, 0x39, 0x90, 0x0c, 0x58, 0x84, 0xc3, 0x0c, 0x38, 0x83, 0xe2, 0x00, 0x21, 0x0a, 0x8c, \n\t0x38, 0x86, 0x4d, 0x74, 0xc2, 0x10, 0x04, 0x09, 0x4b, 0xa1, 0x40, 0xb4, 0x0a, 0xa2, 0x2c, 0x52, \n\t0x22, 0x10, 0xc0, 0x63, 0x08, 0xc1, 0x82, 0x82, 0x0e, 0x21, 0x28, 0x12, 0x94, 0xd8, 0x02, 0x0c, \n\t0x46, 0x09, 0x3a, 0x84, 0x11, 0xc8, 0x12, 0x30, 0x89, 0x90, 0x35, 0x48, 0xe8, 0x24, 0x55, 0x10, \n\t0xa7, 0x80, 0x03, 0x43, 0x02, 0x17, 0x09, 0x9a, 0x10, 0x8d, 0x28, 0x62, 0xe4, 0x2a, 0x11, 0x68, \n\t0x04, 0x20, 0x22, 0x10, 0x42, 0x01, 0xcc, 0x04, 0x88, 0x1e, 0xc1, 0x83, 0x28, 0x20, 0x0c, 0x24, \n\t0x14, 0x63, 0xa1, 0x90, 0x09, 0x19, 0x23, 0x28, 0x20, 0x2a, 0x38, 0x0c, 0x1d, 0x42, 0x4c, 0x90, \n\t0xc0, 0x0b, 0x41, 0x8f, 0x06, 0x14, 0x55, 0xb8, 0x92, 0x2d, 0xc8, 0x49, 0x42, 0xa0, 0x23, 0x92, \n\t0x48, 0x05, 0xc7, 0x74, 0x84, 0x80, 0x8b, 0x4d, 0x8d, 0x40, 0x38, 0x00, 0x20, 0x9c, 0xa1, 0x06, \n\t0x09, 0x32, 0x54, 0xa8, 0x85, 0x88, 0x41, 0x05, 0x44, 0xd3, 0x13, 0x04, 0x21, 0xd8, 0x8f, 0x02, \n\t0x90, 0xc1, 0x08, 0x78, 0x54, 0x26, 0x40, 0x50, 0x4a, 0x24, 0x39, 0x16, 0xa0, 0x00, 0x12, 0x41, \n\t0xb0, 0x14, 0x50, 0x82, 0x6c, 0xa3, 0x80, 0xa3, 0x71, 0x82, 0x03, 0x04, 0x04, 0xd9, 0x21, 0x09, \n\t0x5e, 0xa8, 0x08, 0x70, 0x82, 0x15, 0x68, 0x04, 0x8b, 0x52, 0x63, 0x29, 0x3a, 0x54, 0x51, 0x4b, \n\t0x62, 0x80, 0x99, 0x18, 0x34, 0x44, 0x2e, 0x30, 0x30, 0x40, 0xb2, 0x41, 0x4e, 0x44, 0x10, 0xc0, \n\t0xca, 0xa4, 0x10, 0x1a, 0x01, 0x40, 0x66, 0xf2, 0x8c, 0x01, 0x84, 0x2c, 0x18, 0x30, 0xaa, 0x11, \n\t0x05, 0xd0, 0x40, 0x52, 0xa1, 0x79, 0x83, 0xb0, 0x80, 0x2b, 0x64, 0x01, 0x80, 0x9e, 0x50, 0x18, \n\t0x01, 0x04, 0x00, 0xa2, 0x17, 0x28, 0xca, 0x24, 0x30, 0xd3, 0x22, 0xa2, 0x6d, 0x50, 0x20, 0x46, \n\t0x24, 0x80, 0x84, 0xe8, 0x0a, 0x00, 0x02, 0x01, 0x33, 0x8c, 0x74, 0x00, 0x07, 0x42, 0xd6, 0x13, \n\t0x11, 0x38, 0x0c, 0x8c, 0x18, 0x32, 0x49, 0x29, 0x61, 0x82, 0x8a, 0x20, 0x50, 0x41, 0x08, 0xac, \n\t0xc1, 0x41, 0x30, 0x25, 0x58, 0x8a, 0xb0, 0x42, 0x24, 0x5c, 0x02, 0x5a, 0x00, 0xc5, 0x12, 0x82, \n\t0x1c, 0x20, 0x42, 0x07, 0xad, 0x04, 0x21, 0x64, 0x52, 0x00, 0x9f, 0x48, 0x48, 0x09, 0x24, 0x31, \n\t0xa2, 0xa9, 0x14, 0x58, 0xe1, 0x72, 0x15, 0x58, 0x26, 0x89, 0x0d, 0x0e, 0x04, 0x00, 0x00, 0x26, \n\t0x84, 0x85, 0xa0, 0x26, 0x03, 0x00, 0x32, 0xb9, 0x00, 0xa2, 0x50, 0x05, 0x80, 0x11, 0x10, 0x0e, \n\t0x85, 0x00, 0x62, 0x61, 0x85, 0x74, 0x99, 0x8a, 0x00, 0x31, 0x4a, 0x01, 0x90, 0x09, 0x0c, 0x26, \n\t0xd0, 0x90, 0x07, 0xc1, 0x50, 0x41, 0x26, 0xb6, 0xd9, 0x3c, 0x19, 0x83, 0x09, 0x08, 0x71, 0x10, \n\t0x2a, 0x68, 0x88, 0x25, 0x00, 0xb2, 0xb0, 0x00, 0xc4, 0x82, 0xc1, 0x48, 0x07, 0x92, 0x16, 0x0c, \n\t0x01, 0xe4, 0x22, 0x02, 0x03, 0x88, 0x0c, 0x81, 0x24, 0x4e, 0x24, 0x48, 0x20, 0x75, 0x41, 0xa2, \n\t0x28, 0x80, 0x90, 0x12, 0x59, 0x15, 0x47, 0x52, 0x80, 0x00, 0xb1, 0x15, 0x09, 0xc0, 0x18, 0x81, \n\t0x18, 0x21, 0x44, 0x58, 0x80, 0x28, 0xc2, 0x00, 0xb6, 0xac, 0x58, 0x00, 0x50, 0x24, 0x32, 0x81, \n\t0x18, 0x15, 0x6a, 0x64, 0x84, 0xc9, 0x21, 0xd0, 0x01, 0x4e, 0x16, 0x31, 0xe8, 0x2e, 0xc1, 0x98, \n\t0x81, 0x04, 0x03, 0x30, 0xa4, 0x8c, 0xc0, 0x0f, 0x02, 0xe1, 0x08, 0x13, 0x49, 0x00, 0xe0, 0x40, \n\t0x52, 0xd2, 0x08, 0x09, 0x8c, 0x02, 0x44, 0x60, 0x89, 0xb3, 0x29, 0x93, 0x89, 0x1c, 0x24, 0x9a, \n\t0x04, 0x71, 0x18, 0x08, 0x30, 0x91, 0xc2, 0x2a, 0x51, 0x40, 0xa6, 0x02, 0x04, 0x19, 0x18, 0xc1, \n\t0xc8, 0x41, 0x12, 0x06, 0xc0, 0x05, 0x18, 0x47, 0x6c, 0x24, 0x91, 0x21, 0x08, 0x90, 0x4d, 0x6d, \n\t0x10, 0x24, 0xe0, 0x01, 0x0d, 0x92, 0x8b, 0x16, 0xc0, 0x20, 0xa1, 0x40, 0x00, 0x80, 0x24, 0xd4, \n\t0x72, 0x00, 0x88, 0x80, 0xc1, 0x20, 0x43, 0x28, 0x3a, 0x58, 0x42, 0xc5, 0x24, 0x54, 0x69, 0xa6, \n\t0x81, 0x06, 0xac, 0x2a, 0x24, 0x13, 0x12, 0x8c, 0x8a, 0x03, 0x0c, 0x80, 0x32, 0x86, 0xc5, 0x44, \n\t0xa8, 0x00, 0x30, 0x13, 0x19, 0xc8, 0x43, 0x80, 0x1e, 0x10, 0x08, 0x0b, 0x44, 0x5b, 0xc4, 0x10, \n\t0x60, 0x09, 0x25, 0x24, 0xd4, 0x45, 0x24, 0x02, 0xc0, 0x1f, 0x89, 0x14, 0x61, 0x18, 0x30, 0x48, \n\t0x25, 0xac, 0x91, 0xa4, 0x04, 0x51, 0x13, 0xa8, 0x39, 0x14, 0x48, 0x04, 0x20, 0x23, 0x1e, 0x48, \n\t0x0a, 0x83, 0x08, 0x86, 0x20, 0x35, 0x00, 0x09, 0x01, 0x48, 0x90, 0x01, 0xb6, 0xe0, 0x08, 0x08, \n\t0x44, 0x41, 0x61, 0x02, 0x50, 0x1c, 0x29, 0x62, 0x03, 0xd0, 0xaa, 0x00, 0x59, 0xad, 0x30, 0x15, \n\t0x40, 0x0a, 0xfc, 0x81, 0x80, 0x20, 0x63, 0x10, 0x1a, 0x01, 0x15, 0x41, 0x40, 0x47, 0x08, 0x21, \n\t0x00, 0x96, 0x28, 0x22, 0x92, 0x88, 0x8e, 0x80, 0x0b, 0xe8, 0x22, 0x10, 0x11, 0x00, 0x04, 0x07, \n\t0xee, 0x46, 0xb2, 0x48, 0x88, 0x01, 0x8c, 0x42, 0x7c, 0x07, 0xa0, 0x84, 0xd0, 0x82, 0xce, 0x06, \n\t0x97, 0x3a, 0xa0, 0x18, 0x43, 0x81, 0x34, 0x80, 0xa3, 0x01, 0x44, 0xca, 0x2e, 0x44, 0x01, 0x51, \n\t0x00, 0x18, 0x5d, 0x41, 0x0a, 0x84, 0x90, 0x34, 0x24, 0x00, 0xcc, 0x26, 0x03, 0x08, 0x11, 0xc8, \n\t0x0a, 0xc6, 0x20, 0x42, 0x01, 0x18, 0x11, 0xca, 0x46, 0x40, 0x51, 0x00, 0x21, 0x88, 0x0b, 0x25, \n\t0x58, 0x21, 0x80, 0x91, 0x09, 0x18, 0xc2, 0x54, 0x24, 0x41, 0x00, 0xc4, 0xd0, 0x09, 0x0a, 0x10, \n\t0xb9, 0x80, 0xb8, 0x18, 0x21, 0x24, 0x86, 0x30, 0xac, 0x40, 0xd0, 0x63, 0x64, 0xa0, 0x10, 0x10, \n\t0x69, 0x41, 0x41, 0x42, 0x11, 0xaa, 0x16, 0x8d, 0x40, 0x8c, 0x2a, 0x50, 0x8b, 0x80, 0xe1, 0x58, \n\t0x03, 0x46, 0x24, 0x52, 0x84, 0x45, 0x04, 0xa2, 0x52, 0xe6, 0x98, 0x28, 0x10, 0xcf, 0x69, 0x08, \n\t0x14, 0x48, 0x2a, 0x30, 0x83, 0xc0, 0x50, 0x83, 0x20, 0x07, 0xa4, 0x1b, 0x64, 0x52, 0x43, 0x23, \n\t0x14, 0x18, 0x01, 0xc2, 0x78, 0x30, 0x09, 0x04, 0xbc, 0x40, 0x40, 0x4c, 0xc1, 0x90, 0x04, 0x40, \n\t0x0c, 0xa2, 0x70, 0x05, 0xa2, 0x29, 0x09, 0x90, 0xc6, 0x2c, 0xd2, 0x08, 0x0e, 0x68, 0x19, 0xc4, \n\t0x26, 0xd0, 0x12, 0x00, 0x24, 0x87, 0xa0, 0x18, 0x10, 0x9a, 0x85, 0x78, 0x88, 0x60, 0x52, 0x45, \n\t0x43, 0x20, 0xdd, 0x01, 0x20, 0x32, 0x44, 0xc9, 0x9a, 0xc8, 0x4a, 0x83, 0x06, 0x25, 0x10, 0x83, \n\t0xe0, 0x56, 0x00, 0x08, 0x60, 0x2b, 0x8c, 0x28, 0x94, 0x00, 0x26, 0xd0, 0xb1, 0x80, 0x58, 0x9c, \n\t0x00, 0x32, 0x00, 0x80, 0x01, 0x48, 0x07, 0xe4, 0x44, 0x20, 0x22, 0xa6, 0x99, 0x8a, 0x0c, 0x78, \n\t0x90, 0x22, 0x15, 0x94, 0x4a, 0x80, 0x46, 0x32, 0x30, 0x37, 0x05, 0xd1, 0x22, 0x10, 0x04, 0x71, \n\t0xa4, 0x84, 0x13, 0x82, 0x50, 0x44, 0x32, 0x07, 0x50, 0x80, 0x89, 0x18, 0xe3, 0x28, 0x08, 0x91, \n\t0x5c, 0x20, 0x24, 0x24, 0x42, 0x93, 0x89, 0x80, 0x49, 0x20, 0xb4, 0x41, 0x20, 0x01, 0x00, 0x84, \n\t0x00, 0x13, 0x29, 0x8a, 0x04, 0x4c, 0x41, 0x4a, 0xc4, 0x60, 0x08, 0x08, 0x04, 0x8d, 0x48, 0xa6, \n\t0x18, 0x38, 0x0c, 0x84, 0xca, 0x08, 0xa3, 0xb0, 0x8c, 0x0c, 0x0e, 0x4f, 0x34, 0xc0, 0xc0, 0x21, \n\t0x55, 0x53, 0x04, 0x60, 0x76, 0x9a, 0x28, 0x39, 0x81, 0x83, 0x3a, 0x95, 0x43, 0xb4, 0x21, 0x05, \n\t0x82, 0x0c, 0x54, 0xb0, 0xb3, 0x80, 0x02, 0x62, 0x5c, 0x04, 0x2a, 0x2e, 0x08, 0x00, 0x65, 0x06, \n\t0x50, 0x80, 0x8b, 0x90, 0x08, 0x61, 0x12, 0x60, 0x20, 0x0f, 0x50, 0x0b, 0xc1, 0x08, 0x20, 0x41, \n\t0x10, 0x30, 0x01, 0x60, 0x0c, 0x16, 0x89, 0x01, 0x78, 0x9a, 0x68, 0x22, 0x04, 0x31, 0x30, 0x4c, \n\t0x12, 0x85, 0x18, 0x42, 0xb1, 0x81, 0x14, 0x8a, 0x05, 0x58, 0x82, 0x83, 0x34, 0x09, 0x83, 0x07, \n\t0x6e, 0x63, 0x00, 0x1d, 0x00, 0x18, 0xc4, 0x3a, 0xc1, 0x98, 0x3a, 0x2d, 0x41, 0x02, 0x64, 0x15, \n\t0xa8, 0x26, 0x08, 0x0b, 0x68, 0x48, 0x24, 0x03, 0x16, 0x94, 0x4c, 0x86, 0x46, 0x65, 0x82, 0x8a, \n\t0xc8, 0x4d, 0x48, 0x34, 0x71, 0x30, 0x2a, 0x20, 0xd4, 0x8b, 0x00, 0xf0, 0x8a, 0x9e, 0xa4, 0x43, \n\t0x48, 0x1c, 0x02, 0x10, 0x84, 0x01, 0xc5, 0x63, 0x34, 0x16, 0x13, 0x25, 0xc1, 0x10, 0x48, 0x54, \n\t0xc1, 0xc3, 0x00, 0xd0, 0x10, 0x22, 0x04, 0x84, 0xc1, 0x38, 0x01, 0x02, 0x09, 0x02, 0xa0, 0x00, \n\t0x8c, 0x24, 0x0c, 0x03, 0x08, 0x11, 0xc8, 0x2d, 0x48, 0x58, 0x0e, 0x00, 0x04, 0xb2, 0x84, 0x30, \n\t0x80, 0x49, 0x62, 0x00, 0xb8, 0x20, 0x30, 0x08, 0xa7, 0x74, 0x32, 0x08, 0x02, 0x8c, 0xc9, 0x46, \n\t0x12, 0x91, 0x31, 0x33, 0xa0, 0xc7, 0x85, 0x32, 0x24, 0x68, 0x84, 0x90, 0xc0, 0x09, 0x30, 0x50, \n\t0x49, 0x8e, 0xa8, 0x90, 0x84, 0x6a, 0x92, 0x39, 0x14, 0x0d, 0x10, 0xa8, 0x48, 0x21, 0x13, 0x2a, \n\t0x74, 0x98, 0x84, 0x40, 0x96, 0x82, 0x81, 0x00, 0x11, 0x44, 0x00, 0x62, 0xa8, 0xb3, 0x28, 0xd9, \n\t0x02, 0x30, 0xc5, 0xf2, 0x19, 0x80, 0x57, 0x04, 0x02, 0x41, 0x73, 0x00, 0x0c, 0x90, 0x28, 0x00, \n\t0x07, 0x32, 0xa8, 0x2c, 0x58, 0x64, 0x42, 0x03, 0x43, 0x18, 0xb4, 0x04, 0x85, 0x2c, 0x21, 0x19, \n\t0x21, 0x80, 0x02, 0x43, 0x32, 0x54, 0xc0, 0x16, 0x30, 0x8e, 0x21, 0x4a, 0x55, 0x08, 0x02, 0xc0, \n\t0x8b, 0x20, 0x4c, 0x80, 0x32, 0x38, 0x14, 0xd4, 0xa3, 0x40, 0x63, 0xd3, 0x00, 0x49, 0x10, 0xe4, \n\t0x18, 0xe0, 0x01, 0x81, 0x04, 0x52, 0x81, 0x6e, 0x33, 0x28, 0x04, 0x05, 0xce, 0x46, 0x72, 0x82, \n\t0xc2, 0x8d, 0x60, 0x58, 0x0a, 0x36, 0x51, 0x6a, 0x26, 0x04, 0xda, 0x80, 0x0e, 0x06, 0xb1, 0x2a, \n\t0x89, 0x15, 0x08, 0x30, 0x83, 0x10, 0xa1, 0x01, 0x00, 0x84, 0x1c, 0xa1, 0x70, 0xa4, 0x34, 0x4a, \n\t0x4e, 0x28, 0x00, 0xa1, 0x2b, 0x10, 0x90, 0x00, 0x28, 0xc2, 0x70, 0x05, 0xf9, 0x41, 0x67, 0x74, \n\t0x02, 0x18, 0x08, 0xb0, 0xd4, 0x8a, 0x4a, 0xc1, 0x03, 0x0a, 0x91, 0x08, 0x02, 0x3c, 0x25, 0x22, \n\t0x05, 0x44, 0x50, 0x40, 0x08, 0x55, 0x32, 0x07, 0x49, 0x02, 0x27, 0x00, 0x00, 0x02, 0x9a, 0xa4, \n\t0x02, 0x80, 0x44, 0x65, 0x4b, 0xa4, 0x20, 0x13, 0x8b, 0x48, 0x81, 0x0a, 0x88, 0xc0, 0x44, 0x08, \n\t0x56, 0xa7, 0x40, 0x22, 0x05, 0x4e, 0x2e, 0x04, 0xd1, 0x19, 0x88, 0x34, 0x0c, 0x03, 0x00, 0xa2, \n\t0x21, 0x22, 0xa8, 0x1c, 0x01, 0x06, 0x72, 0x91, 0x15, 0x39, 0xd8, 0x8c, 0x2a, 0x22, 0xc8, 0x38, \n\t0x48, 0x05, 0x47, 0x48, 0x12, 0x30, 0x0a, 0x2c, 0x16, 0x89, 0x30, 0xd3, 0x02, 0x06, 0x09, 0x18, \n\t0x24, 0x22, 0x04, 0x02, 0x28, 0x45, 0x46, 0x25, 0x32, 0xc6, 0x00, 0x00, 0x01, 0xc2, 0x0a, 0x78, \n\t0x51, 0xa8, 0x32, 0xa0, 0x03, 0xe8, 0x58, 0xc6, 0x0a, 0x84, 0x65, 0x01, 0x80, 0x10, 0xd4, 0x12, \n\t0xa1, 0x60, 0x0e, 0x89, 0x00, 0x96, 0x01, 0x31, 0x80, 0x09, 0x00, 0x08, 0xf4, 0x0b, 0xb3, 0x1c, \n\t0x8d, 0x20, 0x14, 0x90, 0xe3, 0x12, 0x30, 0x48, 0x0d, 0x1e, 0x04, 0x60, 0x21, 0x88, 0x82, 0x8a, \n\t0x5a, 0x00, 0x4b, 0x89, 0x44, 0x0e, 0xe0, 0x64, 0x01, 0x72, 0x1c, 0x58, 0x11, 0x04, 0x0c, 0x30, \n\t0xa0, 0x1a, 0x1d, 0x9d, 0x03, 0x12, 0x02, 0xd0, 0x12, 0x25, 0x43, 0x2a, 0x3a, 0x50, 0x21, 0x35, \n\t0x69, 0x44, 0x43, 0x08, 0xc0, 0x4a, 0x2c, 0x01, 0x18, 0x41, 0x04, 0x12, 0xd2, 0x0b, 0x48, 0xc7, \n\t0x40, 0x0a, 0xa4, 0x18, 0x9e, 0x80, 0x88, 0x40, 0x18, 0x55, 0xe1, 0x0c, 0x94, 0x5d, 0x01, 0x70, \n\t0x83, 0x48, 0x12, 0x90, 0x59, 0x29, 0x24, 0x22, 0x0a, 0x20, 0x38, 0x80, 0x08, 0x08, 0x03, 0x08, \n\t0x09, 0x64, 0x10, 0x43, 0x20, 0x85, 0x00, 0x2a, 0x1d, 0xda, 0x20, 0x06, 0xe0, 0x22, 0x3c, 0x24, \n\t0x43, 0x40, 0x26, 0xc0, 0x78, 0x94, 0x08, 0x17, 0x0e, 0x58, 0x20, 0x29, 0x07, 0xa4, 0xcc, 0x80, \n\t0x54, 0x42, 0xa2, 0x18, 0x91, 0x01, 0xc4, 0x00, 0x80, 0x10, 0x23, 0x7c, 0x05, 0x87, 0x02, 0xc0, \n\t0x58, 0xaa, 0x01, 0x1e, 0x0b, 0x68, 0x41, 0x03, 0x83, 0xa0, 0x57, 0x01, 0x10, 0x34, 0x19, 0x14, \n\t0x80, 0x02, 0xa0, 0x28, 0x82, 0x61, 0x2c, 0x61, 0x42, 0x40, 0x0e, 0xa3, 0x92, 0x84, 0x81, 0x10, \n\t0x43, 0x2c, 0x94, 0x02, 0x04, 0xcc, 0x48, 0x60, 0x2a, 0x51, 0x92, 0x01, 0x18, 0x49, 0xe6, 0x38, \n\t0x81, 0xa3, 0x2d, 0x60, 0x44, 0x20, 0x10, 0x21, 0x71, 0xb0, 0x04, 0x07, 0xaa, 0x0c, 0xc4, 0x2a, \n\t0x18, 0x14, 0x00, 0x8e, 0x54, 0xf2, 0x01, 0x18, 0x19, 0x48, 0x23, 0x22, 0xc0, 0x18, 0x0c, 0x35, \n\t0x06, 0x49, 0x32, 0x10, 0x63, 0x32, 0xac, 0x44, 0x60, 0x08, 0xe1, 0x48, 0x96, 0x88, 0x84, 0x08, \n\t0x24, 0x00, 0xfb, 0x25, 0x80, 0x81, 0xce, 0x16, 0x02, 0xb9, 0x00, 0xc1, 0x00, 0x0c, 0x44, 0x06, \n\t0x10, 0x83, 0x40, 0x51, 0xc2, 0x60, 0x23, 0x1a, 0xb8, 0x41, 0x80, 0x42, 0x0c, 0x11, 0xe2, 0x12, \n\t0xa4, 0x0d, 0x8a, 0x2e, 0x41, 0x98, 0x20, 0x0d, 0x14, 0xe0, 0x6a, 0x41, 0x10, 0x10, 0xc1, 0x54, \n\t0x05, 0x16, 0x42, 0x18, 0x28, 0x55, 0x0d, 0x03, 0x0a, 0x43, 0x40, 0x00, 0xe0, 0x96, 0x80, 0x10, \n\t0xa1, 0x48, 0x01, 0xa4, 0x12, 0x40, 0x34, 0xe5, 0x30, 0x00, 0x39, 0x06, 0x23, 0x08, 0x94, 0x21, \n\t0x19, 0xc8, 0x41, 0x06, 0x14, 0x82, 0x82, 0x80, 0x4c, 0x90, 0x41, 0x3c, 0x03, 0x12, 0xa6, 0xc4, \n\t0x40, 0x4b, 0x24, 0x44, 0x32, 0x97, 0x7c, 0x02, 0x64, 0x66, 0x52, 0x29, 0x06, 0x85, 0x1c, 0xa2, \n\t0x34, 0x00, 0x18, 0x21, 0x09, 0x90, 0x21, 0x62, 0x06, 0xcb, 0x00, 0x01, 0x45, 0xa0, 0x20, 0x12, \n\t0x41, 0x33, 0x94, 0x08, 0x62, 0x1e, 0x82, 0x50, 0x84, 0xb0, 0x10, 0x8d, 0x50, 0x23, 0x8b, 0x14, \n\t0x00, 0x10, 0x04, 0x48, 0x70, 0x8b, 0x80, 0x88, 0x8f, 0x4d, 0x5c, 0xb0, 0xa1, 0x01, 0x00, 0x84, \n\t0xa8, 0x04, 0x12, 0xf9, 0x00, 0x08, 0x00, 0x8f, 0x30, 0x41, 0x62, 0x90, 0x05, 0x8a, 0xa3, 0x6a, \n\t0x90, 0x02, 0x14, 0x58, 0x4d, 0x00, 0x40, 0x04, 0x80, 0xa5, 0xc1, 0x17, 0x02, 0x76, 0x04, 0x83, \n\t0x07, 0x50, 0x98, 0x49, 0x04, 0x22, 0x90, 0x88, 0x01, 0x5d, 0x04, 0x30, 0x11, 0x58, 0x11, 0x68, \n\t0x80, 0x4c, 0x28, 0x51, 0x61, 0x15, 0x11, 0x4d, 0x42, 0x02, 0x92, 0x22, 0x02, 0x34, 0x5e, 0x49, \n\t0x5a, 0xa2, 0xe2, 0x80, 0x98, 0x0a, 0x0f, 0x40, 0x04, 0x60, 0x08, 0x50, 0x12, 0x60, 0x40, 0x90, \n\t0x1b, 0x8d, 0xd4, 0x86, 0x0e, 0x40, 0x40, 0x70, 0x2b, 0x99, 0xc9, 0x65, 0x00, 0x87, 0x88, 0x2e, \n\t0x10, 0xd3, 0x84, 0x42, 0x01, 0x58, 0x98, 0x05, 0x80, 0x00, 0x20, 0x60, 0xd8, 0x03, 0x80, 0x92, \n\t0xcb, 0x0c, 0x40, 0x98, 0x06, 0x29, 0x40, 0x23, 0x20, 0x36, 0x90, 0x91, 0x50, 0x83, 0x0d, 0x16, \n\t0x24, 0x48, 0xaa, 0x95, 0x0f, 0xc7, 0x60, 0xa0, 0x48, 0x2d, 0xa0, 0x41, 0x28, 0x30, 0x45, 0x82, \n\t0x02, 0x40, 0x55, 0x0e, 0x2e, 0x90, 0x52, 0x20, 0xa5, 0x03, 0x20, 0x5a, 0x41, 0x71, 0xa1, 0x18, \n\t0x90, 0x8e, 0x40, 0xf1, 0xe0, 0xad, 0x40, 0x90, 0x21, 0x06, 0x52, 0x32, 0xa4, 0x20, 0x90, 0x02, \n\t0x0a, 0x90, 0x11, 0x0e, 0x0c, 0x1c, 0xa4, 0x40, 0x21, 0x40, 0x90, 0xa8, 0x4c, 0x8b, 0x3a, 0x20, \n\t0x53, 0x3a, 0x45, 0x01, 0xa5, 0x14, 0x82, 0xc8, 0xb8, 0x11, 0x8c, 0xa2, 0x10, 0x33, 0x08, 0x86, \n\t0xe4, 0x11, 0x07, 0x02, 0xb2, 0x28, 0x1b, 0x24, 0x43, 0x04, 0x66, 0x66, 0x62, 0x8e, 0x60, 0x53, \n\t0x8a, 0x70, 0x90, 0x01, 0x1d, 0x11, 0x14, 0x27, 0x58, 0x10, 0x80, 0x21, 0x89, 0x04, 0xe0, 0x24, \n\t0x44, 0xc0, 0x99, 0x98, 0x00, 0xcf, 0x08, 0x03, 0x10, 0xa0, 0x5d, 0x18, 0x20, 0x0c, 0xd2, 0xb8, \n\t0x15, 0x44, 0xc3, 0xa8, 0x60, 0x40, 0x50, 0x91, 0xc0, 0x03, 0x88, 0x4c, 0x82, 0x60, 0x0e, 0x0d, \n\t0x19, 0x03, 0x26, 0x15, 0x80, 0xba, 0x01, 0xce, 0xa0, 0x10, 0xa0, 0x10, 0x84, 0x50, 0x05, 0x43, \n\t0x38, 0x62, 0x00, 0x19, 0x00, 0x88, 0x08, 0x64, 0x52, 0x23, 0x14, 0x00, 0xc6, 0x0a, 0x50, 0x84, \n\t0x0b, 0x01, 0x00, 0x10, 0x05, 0x52, 0x71, 0xd1, 0x0a, 0x80, 0x94, 0xe0, 0x08, 0x22, 0x83, 0xac, \n\t0x40, 0xc9, 0x2a, 0x4a, 0x34, 0xa2, 0xa2, 0x41, 0x13, 0x80, 0x14, 0x05, 0xc8, 0x18, 0xa0, 0x4c, \n\t0xa6, 0x00, 0x40, 0x13, 0x01, 0x24, 0x54, 0x22, 0x14, 0xa1, 0x78, 0x98, 0x38, 0x4d, 0x29, 0x06, \n\t0x60, 0x43, 0x22, 0x2c, 0x8a, 0x40, 0x22, 0x00, 0x49, 0x25, 0xc0, 0xd4, 0x8c, 0x32, 0x85, 0x81, \n\t0x18, 0x24, 0x5b, 0x04, 0x68, 0x61, 0x39, 0x16, 0x61, 0x42, 0x41, 0x60, 0x10, 0x0a, 0x00, 0x44, \n\t0x12, 0x40, 0x4c, 0x61, 0x03, 0xa0, 0xc4, 0x90, 0x22, 0x2c, 0xe4, 0x10, 0x98, 0x45, 0x1a, 0x05, \n\t0x48, 0x02, 0x02, 0x28, 0x74, 0x40, 0x42, 0x06, 0x06, 0x4a, 0x0b, 0xa8, 0x94, 0x28, 0x0c, 0x40, \n\t0x02, 0x05, 0xd9, 0x8a, 0xc2, 0x00, 0x43, 0x60, 0x20, 0xb0, 0x10, 0x2c, 0x06, 0x05, 0x01, 0x89, \n\t0x08, 0x8c, 0x03, 0x12, 0x74, 0x21, 0x88, 0x44, 0x87, 0x47, 0x20, 0x25, 0x82, 0x35, 0x10, 0x0a, \n\t0x0d, 0x0a, 0x22, 0x01, 0x07, 0xd0, 0x80, 0xe3, 0x44, 0x04, 0xf0, 0x38, 0x3d, 0x92, 0xa5, 0x50, \n\t0xa0, 0x30, 0x80, 0x39, 0x80, 0x40, 0x14, 0x17, 0xd2, 0x02, 0x45, 0xc0, 0xa0, 0x00, 0x34, 0x18, \n\t0xa0, 0x41, 0x04, 0x82, 0x1e, 0x16, 0x2b, 0x04, 0x41, 0x8a, 0x80, 0x02, 0x00, 0x50, 0x25, 0x71, \n\t0xd2, 0x21, 0x60, 0x87, 0x81, 0x24, 0x39, 0x15, 0x06, 0x74, 0x22, 0x41, 0xa2, 0xe8, 0x42, 0x02, \n\t0x08, 0xc3, 0x71, 0x31, 0xc5, 0x44, 0x8b, 0x48, 0x20, 0x02, 0x0a, 0x04, 0x46, 0x0d, 0x40, 0x95, \n\t0x30, 0x18, 0x19, 0x44, 0x6a, 0x02, 0x92, 0xaa, 0x30, 0xf0, 0x10, 0x87, 0x1e, 0xb2, 0xa8, 0x06, \n\t0x25, 0x14, 0xcf, 0x74, 0xe0, 0x01, 0x0a, 0x00, 0x08, 0xc7, 0x22, 0x10, 0x08, 0x20, 0x15, 0x0a, \n\t0x67, 0x64, 0x05, 0x82, 0x01, 0x8c, 0xca, 0xa8, 0x40, 0x00, 0x58, 0xa3, 0x04, 0x12, 0x69, 0x06, \n\t0x84, 0xb9, 0x9e, 0x2c, 0x40, 0x00, 0x04, 0xa2, 0x5b, 0x01, 0x80, 0x0c, 0xae, 0x2a, 0x05, 0x41, \n\t0x13, 0x00, 0xc0, 0x0d, 0x50, 0x95, 0x22, 0xb0, 0x10, 0x43, 0x0c, 0x38, 0x03, 0xfa, 0x12, 0x08, \n\t0x52, 0x86, 0x40, 0x84, 0x00, 0x1d, 0xb0, 0xc6, 0x8c, 0x0a, 0x70, 0x92, 0x0d, 0x38, 0x00, 0x82, \n\t0x60, 0xd4, 0x32, 0xa3, 0x88, 0x10, 0x04, 0x28, 0x51, 0x18, 0x10, 0x29, 0x98, 0x20, 0x50, 0x04, \n\t0xc0, 0x2e, 0x88, 0x51, 0x0a, 0x28, 0x55, 0x32, 0xb1, 0x90, 0x0d, 0x62, 0x60, 0x04, 0x00, 0xb6, \n\t0xdc, 0x58, 0xc9, 0x34, 0x14, 0x41, 0xa8, 0xc1, 0x44, 0x82, 0x38, 0x90, 0x00, 0x19, 0x90, 0x11, \n\t0x01, 0x3a, 0x04, 0xc0, 0x2f, 0x00, 0x88, 0x21, 0x28, 0x20, 0x51, 0x93, 0x01, 0x89, 0x61, 0x14, \n\t0x26, 0x29, 0x15, 0xe4, 0x12, 0x64, 0x00, 0xc1, 0x28, 0x0b, 0x45, 0x02, 0xa8, 0x44, 0x63, 0x80, \n\t0x8a, 0x94, 0x8a, 0x04, 0x42, 0x04, 0x28, 0x95, 0x25, 0x86, 0x42, 0x40, 0x02, 0xb3, 0xa0, 0xc8, \n\t0x1e, 0x00, 0x1e, 0x51, 0xb0, 0x02, 0x7c, 0x4c, 0x00, 0x06, 0x86, 0xe8, 0x38, 0x80, 0x0c, 0xad, \n\t0x02, 0xc4, 0x02, 0x89, 0xb1, 0x81, 0xa4, 0x20, 0x21, 0x20, 0x2d, 0xd1, 0x54, 0x02, 0x08, 0x62, \n\t0x68, 0x81, 0xa8, 0x11, 0x05, 0x42, 0x50, 0x10, 0x92, 0x91, 0x50, 0x4c, 0x18, 0x04, 0x71, 0x04, \n\t0x24, 0xd5, 0x2a, 0x14, 0x00, 0x89, 0xaa, 0x78, 0x08, 0x04, 0x5c, 0x50, 0x00, 0x04, 0x11, 0x08, \n\t0x64, 0x0c, 0xd1, 0x92, 0x91, 0x0c, 0x13, 0x61, 0x00, 0x40, 0xd3, 0x22, 0xc1, 0x8e, 0x86, 0x1c, \n\t0x34, 0xd9, 0x31, 0x4c, 0xc1, 0xa2, 0x08, 0x80, 0x02, 0x82, 0x60, 0x08, 0x00, 0x06, 0x62, 0x48, \n\t0x20, 0x11, 0x4a, 0x26, 0x00, 0x71, 0x49, 0x14, 0x84, 0x07, 0xc7, 0x40, 0xa0, 0x43, 0xa7, 0x80, \n\t0x8f, 0x20, 0x56, 0x35, 0x12, 0x10, 0x50, 0x1c, 0x43, 0x38, 0x20, 0xab, 0x1c, 0xcd, 0xc0, 0xc1, \n\t0x08, 0x12, 0x00, 0x09, 0xd8, 0x18, 0xa5, 0x58, 0x72, 0x43, 0x20, 0x41, 0x41, 0xe8, 0x48, 0xa0, \n\t0x90, 0xa2, 0x70, 0xc1, 0x45, 0x36, 0x00, 0x69, 0x93, 0xec, 0x87, 0x28, 0x36, 0x00, 0x0a, 0xb0, \n\t0x8c, 0x41, 0x02, 0x62, 0x26, 0x53, 0x2a, 0x80, 0x48, 0x2b, 0x42, 0xc5, 0x91, 0x99, 0x78, 0x00, \n\t0x61, 0x26, 0x14, 0x20, 0x1d, 0x10, 0x01, 0x4a, 0x48, 0xa0, 0x08, 0x2f, 0x90, 0x8a, 0x4c, 0x04, \n\t0xe0, 0xa1, 0x82, 0x31, 0x45, 0x22, 0x30, 0x04, 0x20, 0x10, 0x08, 0x81, 0xe3, 0x50, 0xb1, 0x22, \n\t0xa0, 0x4c, 0x8c, 0x49, 0x60, 0x66, 0xa1, 0x0e, 0x09, 0x11, 0xa4, 0x00, 0x80, 0xa0, 0x9c, 0x21, \n\t0x43, 0x61, 0x18, 0x03, 0x58, 0x80, 0xc1, 0xc5, 0x22, 0x08, 0x31, 0x12, 0x80, 0x00, 0x18, 0x08, \n\t0x1a, 0x85, 0xc3, 0x34, 0x90, 0x48, 0x20, 0x06, 0x13, 0x49, 0x28, 0xa1, 0x01, 0x0d, 0x02, 0x65, \n\t0x50, 0x15, 0x95, 0x10, 0x0c, 0x02, 0x04, 0x80, 0x09, 0x18, 0x8c, 0x49, 0x04, 0x25, 0x91, 0x18, \n\t0x38, 0x1b, 0x01, 0x72, 0x02, 0x90, 0x20, 0x80, 0x03, 0xa4, 0x06, 0xc1, 0x78, 0x08, 0x98, 0x10, \n\t0x00, 0x10, 0x85, 0x01, 0x8f, 0x81, 0x48, 0x82, 0x08, 0xc2, 0x08, 0xa5, 0x14, 0x5f, 0x83, 0x20, \n\t0x55, 0x70, 0x0d, 0x41, 0x00, 0x04, 0x5e, 0x20, 0xb1, 0x03, 0xb1, 0x88, 0xc0, 0x48, 0x40, 0xcb, \n\t0x20, 0xe5, 0x41, 0xc6, 0x40, 0x12, 0x91, 0xb3, 0x78, 0x40, 0x23, 0x24, 0x03, 0x20, 0x87, 0x04, \n\t0x0d, 0x88, 0x30, 0x90, 0x20, 0x10, 0x80, 0x03, 0x68, 0x68, 0xc6, 0x10, 0x15, 0x01, 0xcc, 0x20, \n\t0x08, 0x06, 0x78, 0x0c, 0x20, 0x94, 0x85, 0x02, 0x91, 0x10, 0x06, 0xc8, 0x12, 0x86, 0x48, 0x02, \n\t0xb0, 0x04, 0x04, 0x1a, 0xe8, 0x00, 0x96, 0x82, 0x20, 0x35, 0x98, 0x82, 0x48, 0x80, 0x10, 0x29, \n\t0x84, 0xcb, 0x22, 0x6c, 0x50, 0x00, 0xb0, 0x9d, 0x02, 0x02, 0x4c, 0x24, 0x48, 0x8e, 0x01, 0x50, \n\t0xcf, 0x40, 0x42, 0x10, 0x1b, 0x29, 0x09, 0x29, 0x24, 0x00, 0x10, 0x82, 0x00, 0x42, 0x05, 0x22, \n\t0x01, 0xc8, 0x15, 0x98, 0x18, 0x05, 0x04, 0x34, 0x0a, 0x85, 0x80, 0x1e, 0xa6, 0x34, 0x80, 0xe9, \n\t0x00, 0x75, 0x05, 0xcb, 0x12, 0x03, 0x51, 0x25, 0x6c, 0x10, 0x8a, 0x44, 0x87, 0xa0, 0x11, 0x08, \n\t0x01, 0xa2, 0x42, 0xc5, 0x38, 0x22, 0x24, 0x81, 0xc6, 0x70, 0x82, 0xe1, 0x10, 0x04, 0x1a, 0x88, \n\t0x14, 0x20, 0x12, 0x26, 0x04, 0x5c, 0x49, 0x12, 0x60, 0x12, 0x38, 0xd0, 0x05, 0x81, 0x20, 0x67, \n\t0x92, 0x12, 0x49, 0x01, 0xa1, 0x0c, 0x43, 0x60, 0x18, 0xc4, 0xc3, 0x08, 0x60, 0x52, 0x82, 0x16, \n\t0xbc, 0x88, 0x64, 0x24, 0x61, 0xd0, 0x00, 0x70, 0x19, 0x20, 0x74, 0x24, 0x00, 0x19, 0xc0, 0xc4, \n\t0x02, 0x04, 0xb1, 0x42, 0x85, 0x10, 0x94, 0x6a, 0x28, 0x10, 0x21, 0xa9, 0xcc, 0x08, 0xc8, 0x02, \n\t0x42, 0x92, 0xb5, 0x08, 0x12, 0x81, 0x0a, 0x82, 0xe0, 0x05, 0x49, 0x5b, 0x0c, 0x0c, 0x24, 0xc9, \n\t0x20, 0x1c, 0x8a, 0x83, 0x0e, 0x60, 0x99, 0x06, 0x91, 0x00, 0x4d, 0x56, 0x10, 0x5b, 0x98, 0x25, \n\t0xc9, 0x89, 0x00, 0xb0, 0x48, 0xa1, 0x10, 0x0d, 0x06, 0x42, 0xc6, 0x80, 0x20, 0x10, 0xc3, 0x28, \n\t0x74, 0x62, 0xa1, 0x09, 0x01, 0x44, 0xe6, 0x22, 0x26, 0x88, 0x11, 0xa8, 0xd2, 0x00, 0x58, 0x02, \n\t0x19, 0x00, 0xa1, 0x04, 0x01, 0x18, 0xa5, 0x91, 0x16, 0xd0, 0xd0, 0x60, 0x00, 0x05, 0x08, 0x02, \n\t0x0d, 0x1d, 0xe4, 0x02, 0xd6, 0x08, 0x3a, 0x48, 0x19, 0x0c, 0x3c, 0x00, 0x20, 0xa3, 0xa0, 0x54, \n\t0x21, 0x14, 0x41, 0x88, 0x28, 0x49, 0x00, 0x86, 0x24, 0x33, 0x82, 0x30, 0x58, 0x01, 0x4f, 0x28, \n\t0x93, 0x69, 0x29, 0x54, 0x45, 0x82, 0x50, 0xc3, 0x8a, 0x38, 0x30, 0x46, 0x45, 0x2a, 0x14, 0x08, \n\t0x8e, 0x99, 0x06, 0x60, 0x02, 0x10, 0xe8, 0x00, 0x19, 0x82, 0x21, 0x5c, 0x20, 0x00, 0xa7, 0x24, \n\t0x86, 0x00, 0x28, 0x36, 0x02, 0x1c, 0xc4, 0x0b, 0x0c, 0x0e, 0xb4, 0x08, 0x0d, 0x64, 0xd4, 0xc4, \n\t0x00, 0x81, 0x09, 0xb1, 0x01, 0x41, 0x2e, 0x14, 0x20, 0x08, 0x82, 0x0d, 0x51, 0xca, 0x0a, 0x07, \n\t0x23, 0xb0, 0x28, 0x05, 0x09, 0x20, 0x60, 0x90, 0x99, 0x90, 0x82, 0x0e, 0x0e, 0xc1, 0x70, 0x24, \n\t0x60, 0xcb, 0xc3, 0x00, 0xa0, 0xea, 0x17, 0x24, 0x14, 0x04, 0x70, 0x22, 0x00, 0x01, 0x48, 0xc1, \n\t0xa4, 0x20, 0x24, 0x70, 0x28, 0x8d, 0xc4, 0x44, 0x00, 0xa1, 0x51, 0x20, 0x7d, 0x88, 0x01, 0x1c, \n\t0xa3, 0xa0, 0x85, 0x8c, 0x50, 0xa8, 0x44, 0x60, 0x02, 0x3c, 0x44, 0x55, 0xa3, 0x30, 0x06, 0xb3, \n\t0x0c, 0x44, 0x12, 0xac, 0x0a, 0x14, 0x21, 0x03, 0x15, 0x59, 0x20, 0x58, 0xa0, 0x9a, 0x94, 0x11, \n\t0x08, 0x63, 0x62, 0xe0, 0x42, 0x23, 0xb5, 0xce, 0x00, 0x00, 0x15, 0x10, 0x82, 0xa0, 0x1a, 0x4e, \n\t0x00, 0x23, 0x63, 0x18, 0x10, 0x94, 0x04, 0x52, 0x82, 0xbb, 0x08, 0x70, 0xc6, 0x41, 0x68, 0x02, \n\t0x90, 0x14, 0x08, 0x93, 0x88, 0x10, 0x51, 0x78, 0x05, 0x44, 0x18, 0x8e, 0x50, 0xd6, 0x43, 0x84, \n\t0x08, 0x8a, 0x80, 0x00, 0xc0, 0x22, 0x14, 0x40, 0x04, 0xc0, 0x48, 0x05, 0xa0, 0x01, 0x08, 0x40, \n\t0x80, 0x40, 0x40, 0xcb, 0x94, 0x0d, 0xd2, 0x8a, 0x46, 0x86, 0x80, 0x80, 0xb9, 0x48, 0x40, 0x74, \n\t0x95, 0x10, 0xa8, 0x34, 0x8f, 0x0d, 0x0e, 0x16, 0x08, 0x2a, 0x50, 0x90, 0x0b, 0x5a, 0xc5, 0x6a, \n\t0x14, 0x80, 0x8d, 0x48, 0x02, 0x03, 0x02, 0x81, 0x21, 0x4c, 0x86, 0x5a, 0x82, 0x83, 0x09, 0x99, \n\t0x02, 0x20, 0x04, 0x60, 0x6b, 0x89, 0x48, 0x08, 0x6a, 0x68, 0x84, 0x40, 0xa5, 0xc4, 0x0a, 0x81, \n\t0x40, 0x21, 0x28, 0x16, 0x04, 0x02, 0x61, 0x16, 0x94, 0x00, 0x3a, 0x80, 0xd6, 0x2c, 0x22, 0x64, \n\t0x48, 0x80, 0x08, 0xc1, 0x40, 0x38, 0x00, 0x80, 0x18, 0x08, 0x10, 0xc1, 0x34, 0x03, 0xda, 0x82, \n\t0x44, 0x03, 0x4b, 0x0a, 0x74, 0x38, 0x85, 0x41, 0x42, 0xc5, 0x32, 0x65, 0x40, 0x26, 0xb4, 0x90, \n\t0x21, 0x6a, 0x94, 0x0b, 0x09, 0x20, 0x14, 0x21, 0x72, 0x80, 0x82, 0x25, 0x20, 0x80, 0x2a, 0x0a, \n\t0x12, 0x81, 0x81, 0x10, 0x02, 0x08, 0x18, 0x62, 0x80, 0x88, 0x55, 0x58, 0x09, 0x0e, 0xe2, 0x22, \n\t0x31, 0x61, 0x53, 0x62, 0x68, 0x54, 0x12, 0x9b, 0xc0, 0x9d, 0x82, 0x2e, 0x00, 0x88, 0x20, 0x45, \n\t0xc0, 0x40, 0x72, 0x62, 0x0b, 0x04, 0x31, 0x18, 0xe6, 0x22, 0x60, 0x48, 0x1a, 0x40, 0x80, 0xa7, \n\t0x12, 0x72, 0x10, 0x9d, 0x80, 0x8d, 0x82, 0x08, 0x66, 0xc2, 0xb4, 0x24, 0x00, 0x20, 0x54, 0x90, \n\t0x28, 0x0c, 0x08, 0x81, 0xe9, 0x10, 0x04, 0xb3, 0x28, 0x60, 0x05, 0x22, 0x0c, 0x10, 0x81, 0x09, \n\t0x01, 0x98, 0x0c, 0x24, 0x12, 0x41, 0x02, 0x88, 0xc2, 0x42, 0x04, 0x95, 0x80, 0xa1, 0x48, 0x1b, \n\t0x85, 0x0c, 0x85, 0x03, 0x9a, 0x88, 0x8e, 0x20, 0x04, 0x04, 0x91, 0x10, 0x31, 0x1e, 0x01, 0x40, \n\t0x03, 0x10, 0xbe, 0x48, 0x04, 0x0a, 0x74, 0x60, 0x01, 0x03, 0xf4, 0x46, 0x46, 0x10, 0x41, 0x09, \n\t0x8a, 0xb0, 0x43, 0x88, 0x58, 0xd1, 0x20, 0x26, 0x94, 0xc4, 0x04, 0x5e, 0x83, 0x18, 0x1b, 0x59, \n\t0x88, 0xc2, 0x10, 0x02, 0x11, 0x30, 0xa0, 0x56, 0xa5, 0x08, 0x00, 0x20, 0x0c, 0xf4, 0x0a, 0xad, \n\t0x00, 0x14, 0x20, 0x21, 0x80, 0x13, 0x25, 0x2c, 0x80, 0x12, 0x13, 0x50, 0x88, 0x67, 0x12, 0x15, \n\t0x4a, 0x04, 0x0d, 0xc9, 0x06, 0x02, 0x10, 0xd8, 0x10, 0xcc, 0x0b, 0x02, 0x24, 0x04, 0x02, 0xa4, \n\t0x75, 0x04, 0x28, 0x00, 0xa2, 0x40, 0x90, 0x3c, 0x44, 0xc3, 0x00, 0xe2, 0x61, 0x83, 0x20, 0x06, \n\t0x03, 0x58, 0x50, 0x09, 0x31, 0x80, 0xce, 0x08, 0x04, 0xa5, 0x98, 0x1c, 0x89, 0x95, 0x04, 0x02, \n\t0x30, 0x00, 0x28, 0x05, 0x05, 0xc1, 0x52, 0xa0, 0x10, 0x2e, 0x19, 0x80, 0x28, 0x50, 0x56, 0x21, \n\t0x0f, 0x08, 0x52, 0x21, 0x46, 0x26, 0x08, 0x02, 0x14, 0x10, 0x80, 0x5c, 0x10, 0x82, 0xa1, 0xc0, \n\t0xd5, 0x0e, 0x50, 0x10, 0x43, 0x05, 0x48, 0x95, 0x21, 0x26, 0x41, 0xa0, 0x20, 0x2d, 0x4c, 0x42, \n\t0x02, 0xc3, 0x03, 0x99, 0xc8, 0x03, 0x0c, 0x22, 0x40, 0x50, 0x26, 0x90, 0x02, 0x81, 0x08, 0x42, \n\t0x2b, 0xa5, 0x00, 0x46, 0x65, 0x22, 0x72, 0x4a, 0x08, 0x80, 0x98, 0xc5, 0x0a, 0x80, 0xc9, 0x19, \n\t0x54, 0x94, 0x05, 0x16, 0x02, 0xc0, 0x82, 0x01, 0x88, 0xc3, 0x38, 0xa1, 0x51, 0x1d, 0x08, 0x8a, \n\t0xc1, 0x44, 0x45, 0x3a, 0xb0, 0x00, 0x05, 0xc0, 0x28, 0x41, 0xe9, 0x04, 0x09, 0x50, 0x08, 0x02, \n\t0x30, 0x28, 0x86, 0x21, 0x8b, 0x00, 0x02, 0xe4, 0xaa, 0x0e, 0xb1, 0x00, 0xe5, 0x20, 0xa1, 0x11, \n\t0x1b, 0x11, 0x80, 0x0c, 0x2a, 0xd5, 0x40, 0x02, 0x35, 0x1d, 0x40, 0x38, 0x00, 0x61, 0x1a, 0x24, \n\t0x49, 0x0c, 0x1c, 0x27, 0xd0, 0x01, 0x00, 0xc0, 0xa3, 0x12, 0x14, 0x2a, 0x15, 0x4d, 0x01, 0x01, \n\t0x06, 0xc2, 0x38, 0x2e, 0xec, 0x94, 0xc2, 0x50, 0x00, 0x21, 0x24, 0x1d, 0x40, 0xac, 0x04, 0x15, \n\t0x30, 0xb0, 0x01, 0x81, 0x00, 0x62, 0x40, 0x43, 0x3f, 0x25, 0x80, 0x02, 0x06, 0x31, 0x18, 0xb4, \n\t0x54, 0x1a, 0xcb, 0x10, 0x22, 0x00, 0x02, 0x6c, 0x10, 0x6a, 0x72, 0x20, 0x83, 0x13, 0x44, 0x88, \n\t0xcd, 0x2c, 0xa1, 0x19, 0x0f, 0x95, 0x54, 0x8d, 0x3a, 0x37, 0xc0, 0xb3, 0x08, 0x55, 0x61, 0x50, \n\t0xd2, 0x8b, 0x84, 0x01, 0x48, 0xc0, 0x28, 0x04, 0x48, 0x08, 0xa1, 0x06, 0x42, 0x46, 0x03, 0x40, \n\t0x00, 0x40, 0x80, 0x20, 0x50, 0xb3, 0x13, 0x08, 0x50, 0x50, 0x04, 0x08, 0x64, 0x32, 0x2f, 0x7c, \n\t0x0c, 0x41, 0x62, 0x13, 0xe0, 0x38, 0xa8, 0xd1, 0x20, 0x10, 0x05, 0xf2, 0xa4, 0x15, 0x03, 0x01, \n\t0x52, 0x05, 0x7a, 0xa8, 0x05, 0x09, 0xc0, 0x62, 0xc4, 0x10, 0x0a, 0x45, 0x08, 0x69, 0x24, 0x61, \n\t0x01, 0x00, 0x81, 0x16, 0x88, 0x0a, 0x14, 0x81, 0x83, 0x0c, 0x02, 0x4d, 0x1a, 0x84, 0xaa, 0x81, \n\t0x91, 0xc6, 0x0a, 0x24, 0x10, 0x51, 0x0d, 0x88, 0x90, 0x4e, 0x5a, 0x21, 0xc1, 0xa2, 0xa4, 0x90, \n\t0x0c, 0x34, 0x44, 0x21, 0x80, 0x48, 0x43, 0x0b, 0x48, 0x43, 0x92, 0x90, 0x30, 0xc0, 0x06, 0x14, \n\t0x45, 0xb9, 0x00, 0x08, 0x1b, 0x88, 0x20, 0x44, 0xa9, 0x11, 0x60, 0x0c, 0x8a, 0x30, 0x03, 0x48, \n\t0x28, 0x88, 0x11, 0x86, 0x64, 0x23, 0x8a, 0x22, 0x30, 0xc1, 0xa1, 0x28, 0x40, 0x00, 0x05, 0xe4, \n\t0x0d, 0x86, 0x3a, 0x22, 0x62, 0xaf, 0x8c, 0x56, 0x60, 0x10, 0x10, 0xb8, 0x18, 0x41, 0x04, 0x24, \n\t0x48, 0x30, 0x82, 0x15, 0x70, 0x00, 0x88, 0x42, 0x53, 0x20, 0xad, 0x81, 0x98, 0x4b, 0x50, 0x86, \n\t0x02, 0x0b, 0x40, 0x88, 0x2d, 0x4c, 0xa0, 0x02, 0x00, 0x08, 0x42, 0x40, 0x16, 0x84, 0x00, 0x99, \n\t0x4c, 0x00, 0xa2, 0x22, 0x40, 0x52, 0x14, 0x10, 0x84, 0xa9, 0x0c, 0x26, 0x92, 0x08, 0x24, 0x49, \n\t0x8e, 0x42, 0x93, 0x49, 0x8a, 0x54, 0x04, 0x88, 0x06, 0x40, 0x08, 0x1d, 0x21, 0x90, 0x00, 0x60, \n\t0x21, 0x02, 0x94, 0x98, 0x89, 0x04, 0x1a, 0x94, 0x5b, 0x87, 0x20, 0x44, 0x47, 0x48, 0x90, 0x2a, \n\t0x18, 0x80, 0xd1, 0x43, 0x14, 0x02, 0x29, 0xa0, 0x8c, 0x10, 0xe1, 0x60, 0xf0, 0x81, 0x09, 0xc5, \n\t0xc0, 0x2d, 0x08, 0x95, 0x82, 0xa4, 0x04, 0x4a, 0x40, 0x12, 0x00, 0x11, 0xaf, 0xc1, 0x94, 0x26, \n\t0x3e, 0x60, 0x41, 0x10, 0x41, 0x87, 0xa0, 0x16, 0x42, 0x60, 0x9a, 0x8c, 0x04, 0xe0, 0x14, 0x62, \n\t0x12, 0x18, 0xf4, 0xc0, 0x02, 0x0c, 0x10, 0x21, 0x98, 0x01, 0xde, 0x82, 0x08, 0xb3, 0x60, 0x11, \n\t0x18, 0x01, 0x49, 0x32, 0x00, 0xd0, 0x0a, 0x58, 0x91, 0x29, 0x26, 0x04, 0x48, 0x00, 0x35, 0x00, \n\t0xc8, 0x08, 0x31, 0x32, 0x0e, 0x70, 0x0a, 0x46, 0x00, 0x17, 0x70, 0x88, 0x90, 0xc0, 0x8b, 0x00, \n\t0x04, 0x28, 0x22, 0x45, 0x11, 0x64, 0x38, 0x10, 0xb1, 0x1a, 0xa4, 0x00, 0x24, 0x4a, 0x50, 0x08, \n\t0x82, 0xa0, 0x0f, 0xc0, 0x0e, 0x85, 0x9b, 0x04, 0x31, 0x11, 0x4c, 0x02, 0xf4, 0xc2, 0x90, 0xc5, \n\t0x03, 0x02, 0x04, 0xc3, 0x10, 0x08, 0xa0, 0x57, 0xc0, 0x42, 0x05, 0x80, 0x00, 0x94, 0x42, 0x00, \n\t0x52, 0x45, 0x81, 0x01, 0x09, 0x1d, 0x4b, 0x2a, 0xa6, 0xa0, 0x30, 0x04, 0x95, 0x00, 0x0a, 0x52, \n\t0x08, 0x28, 0x24, 0x12, 0x65, 0x14, 0x24, 0x70, 0xa4, 0x00, 0x98, 0xe2, 0x68, 0x10, 0x0a, 0x33, \n\t0x41, 0x80, 0x01, 0x44, 0x90, 0x0a, 0x36, 0xc1, 0x5b, 0x22, 0x40, 0x71, 0x23, 0xa4, 0x01, 0x14, \n\t0x8a, 0x64, 0x62, 0xab, 0x9a, 0x10, 0x48, 0xc8, 0x04, 0x10, 0xc1, 0x82, 0x11, 0xca, 0xc1, 0x14, \n\t0x96, 0x58, 0x04, 0xe0, 0x01, 0x00, 0x20, 0xa6, 0x8b, 0x81, 0x1c, 0xcf, 0x08, 0x30, 0x12, 0x53, \n\t0x1b, 0xb8, 0x12, 0x0a, 0x5c, 0x22, 0x61, 0x25, 0xc0, 0x84, 0x0f, 0x42, 0x12, 0x00, 0xa4, 0x09, \n\t0x94, 0x0e, 0x20, 0xd0, 0x71, 0x22, 0x04, 0x0b, 0x00, 0x60, 0xa3, 0x10, 0x00, 0x75, 0x5b, 0x00, \n\t0x70, 0x90, 0x50, 0x86, 0x24, 0x1e, 0x80, 0x18, 0x35, 0x02, 0x81, 0x38, 0xc7, 0x60, 0x4c, 0x06, \n\t0x00, 0x92, 0x08, 0x00, 0x20, 0x50, 0x01, 0x42, 0x30, 0x25, 0x44, 0x6c, 0x34, 0x34, 0x20, 0x12, \n\t0x04, 0xc1, 0xc1, 0x1a, 0x83, 0x09, 0x20, 0x90, 0x86, 0x40, 0x08, 0x35, 0x48, 0x94, 0xe1, 0x09, \n\t0x05, 0x5e, 0x34, 0x08, 0x01, 0x91, 0x12, 0xca, 0x10, 0xd2, 0x30, 0x23, 0x45, 0x0e, 0x48, 0x34, \n\t0x24, 0xc3, 0xbf, 0x50, 0xd8, 0x2c, 0x02, 0x31, 0x12, 0x90, 0x20, 0x42, 0x21, 0x24, 0xc5, 0x21, \n\t0x85, 0x24, 0x14, 0x04, 0x3c, 0x11, 0x08, 0x10, 0x00, 0x09, 0x6b, 0x10, 0xc6, 0xb8, 0x80, 0x8c, \n\t0x0d, 0x0b, 0x32, 0x85, 0x5a, 0x01, 0x98, 0x01, 0x01, 0x00, 0x62, 0x70, 0xa6, 0xc0, 0x4c, 0x40, \n\t0x20, 0x40, 0x81, 0x00, 0x28, 0x80, 0x04, 0x08, 0x30, 0x19, 0x15, 0xb8, 0xda, 0x28, 0x5c, 0x80, \n\t0xe1, 0x08, 0x41, 0x52, 0x45, 0x4c, 0x23, 0x09, 0x81, 0x08, 0x00, 0x02, 0x40, 0x63, 0x00, 0x32, \n\t0xd0, 0x12, 0xa6, 0x2a, 0x81, 0x38, 0xa3, 0x15, 0x54, 0x03, 0x58, 0x00, 0x22, 0x00, 0x0d, 0x90, \n\t0x82, 0x10, 0x21, 0x80, 0x25, 0x01, 0x11, 0xc0, 0x44, 0x81, 0x5b, 0x02, 0xc4, 0x00, 0x02, 0x42, \n\t0x60, 0x91, 0x20, 0x10, 0x80, 0xe5, 0x10, 0x13, 0x48, 0x1a, 0xa0, 0xc1, 0x48, 0x0a, 0x14, 0x29, \n\t0xb0, 0x24, 0x0b, 0x00, 0x70, 0xe1, 0x02, 0x0c, 0x51, 0x40, 0xca, 0x0c, 0x02, 0x8a, 0x11, 0xa8, \n\t0x87, 0xad, 0x18, 0xe0, 0xb1, 0x85, 0x65, 0x08, 0x6c, 0x48, 0xa3, 0xc0, 0x24, 0x11, 0x8a, 0xc8, \n\t0x22, 0x04, 0x88, 0x98, 0x18, 0x50, 0x22, 0x00, 0x56, 0x61, 0x21, 0x00, 0xde, 0x84, 0x02, 0x10, \n\t0x53, 0x22, 0xdd, 0x13, 0x08, 0x2a, 0x06, 0xc1, 0xa4, 0xc8, 0x00, 0x00, 0x12, 0xa6, 0xc8, 0xa0, \n\t0x1c, 0x8c, 0x22, 0x2e, 0x02, 0x18, 0x1f, 0xf0, 0x03, 0x07, 0x02, 0x03, 0x09, 0x33, 0xa4, 0x10, \n\t0x08, 0x60, 0xd1, 0x0a, 0x0e, 0x90, 0x5c, 0x40, 0x70, 0xa4, 0x02, 0x18, 0xd1, 0x00, 0xa3, 0x1e, \n\t0x80, 0x70, 0x02, 0xc5, 0x84, 0xe2, 0x00, 0x20, 0x30, 0x91, 0x05, 0x43, 0x81, 0x04, 0x62, 0x98, \n\t0x92, 0x41, 0x00, 0x64, 0x02, 0x13, 0xa2, 0x0d, 0x40, 0x13, 0x0c, 0x40, 0x25, 0x42, 0xa4, 0x40, \n\t0x19, 0x09, 0x10, 0xa1, 0x6b, 0x10, 0x25, 0x19, 0x04, 0x06, 0xd4, 0xc8, 0x13, 0x28, 0x42, 0x23, \n\t0x26, 0x22, 0x20, 0x09, 0xe0, 0x08, 0x04, 0x00, 0xd5, 0xc2, 0x30, 0x38, 0x54, 0x01, 0x2e, 0x00, \n\t0xa1, 0x14, 0x80, 0x08, 0xc5, 0x4a, 0x10, 0x40, 0x00, 0x60, 0xc6, 0x24, 0x06, 0xd1, 0x20, 0x0a, \n\t0x09, 0x06, 0x0c, 0x28, 0x00, 0x11, 0xa8, 0xc9, 0xc8, 0x02, 0x08, 0x86, 0xb2, 0x21, 0x19, 0x87, \n\t0x62, 0x3c, 0x56, 0x40, 0x0b, 0x24, 0x94, 0xa0, 0x28, 0x44, 0x00, 0x80, 0xb4, 0x08, 0x08, 0x04, \n\t0x47, 0xeb, 0x24, 0xa0, 0x50, 0x64, 0x70, 0xa0, 0x13, 0xb8, 0xc0, 0x01, 0x29, 0x08, 0x90, 0x21, \n\t0x92, 0x54, 0xc1, 0x08, 0x0a, 0x02, 0xe3, 0x21, 0x00, 0x18, 0x44, 0x06, 0x05, 0x00, 0x08, 0x68, \n\t0x10, 0xa4, 0x12, 0x20, 0x5b, 0x3d, 0x2c, 0xd0, 0x45, 0x08, 0x13, 0x03, 0x89, 0x90, 0x82, 0x40, \n\t0x44, 0xd1, 0xe1, 0x22, 0x00, 0xca, 0x02, 0x00, 0x06, 0xb8, 0xb8, 0x00, 0x8f, 0x07, 0x10, 0xc4, \n\t0x58, 0xa8, 0x65, 0x0e, 0x86, 0x4e, 0x00, 0x80, 0x25, 0x81, 0x1d, 0x60, 0x20, 0x63, 0x42, 0x08, \n\t0x25, 0x04, 0x40, 0x56, 0x20, 0x10, 0x80, 0x14, 0x0b, 0x21, 0x32, 0xc3, 0x48, 0x00, 0x24, 0xdb, \n\t0x84, 0x40, 0x91, 0x02, 0x82, 0x98, 0x41, 0x09, 0x64, 0x06, 0x41, 0x86, 0x41, 0xc5, 0x08, 0x2a, \n\t0x00, 0xb8, 0x11, 0x4d, 0x12, 0x41, 0x18, 0xe2, 0x60, 0xa0, 0x11, 0x04, 0x0a, 0x08, 0x80, 0xe0, \n\t0x14, 0x05, 0x91, 0x8f, 0x48, 0x30, 0x82, 0x31, 0x54, 0x01, 0x02, 0x50, 0x00, 0x28, 0x33, 0x68, \n\t0x90, 0x0a, 0x12, 0x24, 0x43, 0x20, 0x04, 0x03, 0x63, 0x70, 0x61, 0x31, 0x10, 0x3c, 0x44, 0x23, \n\t0x30, 0x40, 0x0a, 0x08, 0x8d, 0x45, 0x29, 0x14, 0x10, 0x40, 0x06, 0xc5, 0x40, 0x85, 0x4a, 0x52, \n\t0x08, 0x88, 0xa0, 0x90, 0x09, 0x0e, 0xe4, 0x02, 0x82, 0x71, 0x19, 0x02, 0x42, 0x26, 0x08, 0x3d, \n\t0x01, 0x90, 0x6c, 0x40, 0x31, 0x4b, 0x81, 0xe9, 0x86, 0xa2, 0x0c, 0x94, 0x62, 0x80, 0x41, 0x1b, \n\t0x42, 0x22, 0xc3, 0x00, 0x18, 0x29, 0x0e, 0x24, 0x1e, 0x02, 0x88, 0x8c, 0x0c, 0xc1, 0x28, 0x62, \n\t0x71, 0x01, 0x01, 0x70, 0x85, 0xc2, 0x62, 0x41, 0x01, 0x2e, 0x60, 0x08, 0x0d, 0x12, 0x56, 0xca, \n\t0x80, 0xbc, 0x00, 0x08, 0x00, 0x44, 0x08, 0x8e, 0x41, 0x03, 0xc4, 0x32, 0x22, 0x00, 0x80, 0x94, \n\t0x88, 0x40, 0x50, 0x00, 0xd9, 0x9b, 0x20, 0x42, 0x04, 0x44, 0x90, 0x22, 0x05, 0x5c, 0x43, 0xc4, \n\t0x14, 0xa1, 0xab, 0xae, 0x60, 0x88, 0x83, 0x60, 0x03, 0x02, 0x02, 0x10, 0xd9, 0x4a, 0x06, 0xb7, \n\t0x20, 0x05, 0x68, 0x1c, 0xa0, 0x0e, 0x55, 0x38, 0x38, 0xe0, 0x49, 0x86, 0x10, 0x41, 0x92, 0x20, \n\t0x21, 0x12, 0x83, 0x40, 0x62, 0xa9, 0x38, 0x25, 0x10, 0xcc, 0x40, 0x54, 0xc0, 0x20, 0x0c, 0x84, \n\t0x4a, 0x0c, 0xe3, 0x30, 0x26, 0x55, 0xc6, 0x01, 0x22, 0x44, 0x09, 0x82, 0xa8, 0x54, 0x25, 0x0a, \n\t0x31, 0x62, 0x1e, 0xd8, 0x84, 0x01, 0x6e, 0x82, 0x40, 0x2d, 0x19, 0x00, 0xa0, 0x54, 0x10, 0x11, \n\t0xa0, 0xcc, 0x02, 0x6f, 0x24, 0xf4, 0x02, 0x09, 0x09, 0x59, 0xc5, 0x40, 0x00, 0x30, 0xac, 0x45, \n\t0x08, 0xa1, 0x56, 0x00, 0x52, 0x02, 0x81, 0xc4, 0x24, 0x40, 0x01, 0xa9, 0x32, 0x8c, 0x80, 0x6a, \n\t0x00, 0x81, 0xb1, 0x92, 0x90, 0x15, 0xca, 0x44, 0x63, 0x41, 0x32, 0x00, 0x48, 0x81, 0x1c, 0xa2, \n\t0x08, 0x81, 0x34, 0x1a, 0xcb, 0x28, 0x74, 0x00, 0xa1, 0x0c, 0x90, 0x4c, 0x24, 0xc2, 0x31, 0x01, \n\t0xc8, 0xdb, 0x04, 0x30, 0x14, 0xb1, 0x08, 0x04, 0x05, 0xc4, 0x0a, 0xd0, 0x20, 0x2e, 0x21, 0x0e, \n\t0x41, 0x20, 0x00, 0x50, 0x89, 0x0c, 0x89, 0x20, 0x20, 0x40, 0x12, 0x05, 0x44, 0x93, 0x66, 0x00, \n\t0xc0, 0x80, 0x08, 0xcc, 0x5b, 0x20, 0x08, 0x44, 0x12, 0x82, 0xb5, 0x13, 0x61, 0x12, 0x84, 0x41, \n\t0x04, 0x49, 0x00, 0x09, 0x64, 0x82, 0x03, 0x22, 0xf8, 0x04, 0xa0, 0x2e, 0x83, 0x60, 0x31, 0x15, \n\t0x52, 0x08, 0x08, 0xa5, 0x63, 0x1c, 0x80, 0x06, 0x09, 0x18, 0xa6, 0x49, 0x8c, 0x21, 0x8b, 0xc0, \n\t0x02, 0x16, 0x50, 0x14, 0xa0, 0x11, 0x09, 0x1c, 0x82, 0x80, 0x03, 0x90, 0x80, 0xc3, 0x00, 0x07, \n\t0x33, 0x80, 0x14, 0xc0, 0x0b, 0x48, 0x41, 0x08, 0x8e, 0x10, 0xc8, 0x62, 0x24, 0x07, 0xd0, 0x16, \n\t0x01, 0x42, 0x08, 0x18, 0x75, 0x03, 0x25, 0xe1, 0x01, 0xc3, 0x04, 0x86, 0x20, 0x92, 0x54, 0x01, \n\t0x80, 0x44, 0x42, 0xd8, 0x0a, 0x10, 0x80, 0x6c, 0x28, 0x23, 0x41, 0x22, 0x50, 0x08, 0x00, 0x38, \n\t0x37, 0xc0, 0x00, 0x28, 0x1e, 0x0c, 0x3a, 0x00, 0x19, 0x03, 0x30, 0x11, 0x00, 0x54, 0x04, 0xc2, \n\t0x19, 0xcc, 0x14, 0x01, 0x04, 0xf0, 0x63, 0x8d, 0x2c, 0x0c, 0x69, 0x44, 0x56, 0x02, 0x21, 0x80, \n\t0x12, 0x4c, 0x2c, 0x71, 0x08, 0x38, 0x2c, 0x52, 0xc2, 0x20, 0x80, 0x51, 0x90, 0x80, 0x0f, 0xa6, \n\t0x28, 0x14, 0x00, 0x83, 0x70, 0x4e, 0x00, 0x26, 0x24, 0x8a, 0x16, 0x4d, 0x41, 0xa3, 0x00, 0x00, \n\t0x03, 0x12, 0x68, 0xc7, 0xca, 0x30, 0xa4, 0x20, 0x97, 0x41, 0x0a, 0x80, 0x60, 0xe0, 0x22, 0x8d, \n\t0xa4, 0x5f, 0x04, 0x60, 0x02, 0x9a, 0x82, 0x89, 0xc0, 0x6a, 0x1e, 0x20, 0xa0, 0x34, 0x80, 0x43, \n\t0x44, 0x02, 0x43, 0xc2, 0x20, 0x75, 0x18, 0x05, 0x40, 0x66, 0x10, 0x35, 0x50, 0x02, 0x81, 0x40, \n\t0x52, 0x18, 0x28, 0x0c, 0x92, 0x42, 0x2a, 0x02, 0x80, 0x29, 0x08, 0x96, 0x04, 0x08, 0x20, 0x99, \n\t0x30, 0x91, 0x15, 0x09, 0x36, 0xa6, 0xe0, 0x18, 0x09, 0x14, 0x0f, 0x60, 0x81, 0x40, 0x21, 0x14, \n\t0xcc, 0x02, 0x22, 0x13, 0x08, 0x1c, 0x51, 0x92, 0xc0, 0x08, 0x62, 0x69, 0x8c, 0x04, 0x07, 0x61, \n\t0x48, 0x44, 0xa8, 0x88, 0xc1, 0x03, 0x01, 0x56, 0x00, 0x99, 0x0c, 0x75, 0x02, 0xa8, 0x4a, 0x31, \n\t0xd0, 0x21, 0x99, 0x10, 0x07, 0x44, 0x25, 0x42, 0x33, 0x40, 0x80, 0xa4, 0x22, 0x02, 0xba, 0x00, \n\t0x5c, 0x4c, 0x81, 0x24, 0xc3, 0xc0, 0x09, 0x20, 0x0a, 0xae, 0x06, 0x44, 0x41, 0x95, 0x0d, 0xdc, \n\t0x02, 0x26, 0x02, 0x42, 0x0c, 0xf0, 0x19, 0x43, 0x00, 0x10, 0x18, 0x12, 0xc4, 0xc5, 0x61, 0x22, \n\t0xb5, 0x69, 0x32, 0x10, 0x98, 0x44, 0x52, 0x40, 0x08, 0xb0, 0x24, 0x81, 0x44, 0x74, 0x45, 0xd0, \n\t0x01, 0x89, 0x4b, 0x41, 0x2c, 0x36, 0x20, 0x20, 0x04, 0x96, 0x26, 0x18, 0x72, 0xa2, 0x08, 0x45, \n\t0x82, 0xa0, 0x40, 0x63, 0x03, 0x26, 0xd1, 0x89, 0xaa, 0x24, 0x14, 0x92, 0x15, 0x20, 0xc0, 0x27, \n\t0x70, 0x52, 0x00, 0xb4, 0x21, 0x40, 0x86, 0x16, 0x50, 0x89, 0x91, 0x59, 0x0c, 0x2b, 0x6c, 0x20, \n\t0xe0, 0x30, 0x70, 0x4c, 0xa2, 0x00, 0x32, 0x11, 0x21, 0x54, 0x40, 0x29, 0x0c, 0x84, 0x11, 0xb2, \n\t0xd0, 0x08, 0x84, 0x02, 0x01, 0x69, 0x15, 0x20, 0x99, 0x09, 0x00, 0x12, 0x53, 0x18, 0x21, 0x40, \n\t0x28, 0x6a, 0x94, 0x02, 0x20, 0xed, 0x85, 0x46, 0x4a, 0xc2, 0x30, 0x80, 0x00, 0x8a, 0x43, 0x34, \n\t0x11, 0x21, 0x30, 0x49, 0x83, 0x20, 0x6e, 0x06, 0x20, 0x05, 0x30, 0x41, 0x65, 0x30, 0xd3, 0x98, \n\t0x81, 0x80, 0x41, 0x88, 0x3a, 0x05, 0x80, 0xa2, 0x01, 0xd0, 0x62, 0x60, 0x00, 0x69, 0xa2, 0xcc, \n\t0x51, 0x8e, 0x20, 0x80, 0x10, 0x92, 0x0d, 0x02, 0xa0, 0x14, 0x85, 0x21, 0x29, 0xf0, 0x10, 0x08, \n\t0x5a, 0x41, 0x23, 0x00, 0x14, 0xc8, 0x41, 0x00, 0xc0, 0xa1, 0x0f, 0x28, 0x0c, 0x0e, 0x30, 0x90, \n\t0x90, 0x35, 0x08, 0x07, 0x80, 0x16, 0x80, 0x82, 0x8e, 0x10, 0x80, 0x60, 0x58, 0x14, 0x10, 0x04, \n\t0x41, 0x8a, 0xc6, 0x44, 0x85, 0xa0, 0x8b, 0x04, 0xc0, 0xa1, 0x04, 0x01, 0x8b, 0xb6, 0x61, 0x54, \n\t0x2a, 0x10, 0x70, 0x30, 0x16, 0x89, 0x12, 0x48, 0x4a, 0xa5, 0x81, 0x82, 0x61, 0x01, 0x65, 0x70, \n\t0xa7, 0x43, 0x89, 0x09, 0x40, 0x48, 0x34, 0xb1, 0x21, 0x04, 0xb4, 0xc8, 0x80, 0x00, 0x85, 0x6a, \n\t0x12, 0x18, 0x0e, 0x04, 0x12, 0x46, 0x50, 0x9d, 0x28, 0x8e, 0x0e, 0x0a, 0x20, 0xd1, 0x05, 0x61, \n\t0x03, 0x2a, 0x08, 0x50, 0x98, 0x29, 0xfc, 0x84, 0x88, 0x00, 0x03, 0x80, 0x08, 0x8c, 0x00, 0x00, \n\t0x26, 0x22, 0x0a, 0xb0, 0x1c, 0x99, 0x43, 0x70, 0x54, 0x03, 0x06, 0x28, 0x00, 0x04, 0x78, 0x41, \n\t0x88, 0x07, 0xc8, 0x57, 0x80, 0x24, 0x00, 0x0a, 0x88, 0xc8, 0x01, 0x46, 0x22, 0x36, 0x1b, 0x00, \n\t0xb4, 0x49, 0xe8, 0x2c, 0x23, 0x38, 0x8d, 0xa0, 0x10, 0x8b, 0x10, 0x31, 0x82, 0xb0, 0xb8, 0x8c, \n\t0x25, 0x50, 0x44, 0x62, 0x10, 0x50, 0x1d, 0xc8, 0x34, 0x00, 0x03, 0x08, 0x28, 0x54, 0x09, 0x4e, \n\t0xc2, 0x11, 0xa5, 0x00, 0x04, 0x2c, 0x08, 0xa0, 0x81, 0x39, 0x11, 0x82, 0x04, 0x08, 0x36, 0x88, \n\t0x32, 0x40, 0x87, 0x05, 0x04, 0x81, 0x10, 0x28, 0x2c, 0x45, 0x08, 0x12, 0x35, 0x48, 0x32, 0xb9, \n\t0x46, 0x02, 0x50, 0x21, 0x01, 0x8c, 0x88, 0x08, 0x03, 0x56, 0xb2, 0x50, 0x1b, 0xd4, 0x00, 0xa9, \n\t0x0c, 0x00, 0x58, 0x24, 0x00, 0x97, 0xc2, 0x30, 0x56, 0x03, 0x0a, 0xac, 0x10, 0x60, 0x72, 0x03, \n\t0x31, 0x8c, 0x91, 0xc0, 0x60, 0x2e, 0x20, 0x80, 0x00, 0xd0, 0x10, 0x46, 0x4c, 0xe1, 0x8a, 0x85, \n\t0x10, 0x0e, 0x8c, 0x38, 0x92, 0x12, 0x08, 0x40, 0x42, 0x46, 0x08, 0x21, 0x10, 0x2b, 0x09, 0x1a, \n\t0xa5, 0x50, 0x94, 0xb8, 0x30, 0x24, 0x08, 0x06, 0x20, 0x65, 0x7a, 0xb0, 0x68, 0x00, 0x09, 0x1c, \n\t0x81, 0x88, 0x06, 0x21, 0x0c, 0xc4, 0x32, 0x51, 0x52, 0xb0, 0x81, 0x88, 0x84, 0x18, 0x90, 0x61, \n\t0x9d, 0x01, 0x49, 0xc2, 0x02, 0x00, 0xc0, 0x14, 0x14, 0x9f, 0x60, 0x00, 0x74, 0x00, 0x0b, 0x01, \n\t0x90, 0x84, 0x28, 0x22, 0x09, 0x10, 0x41, 0x43, 0x44, 0x06, 0x70, 0xe0, 0x25, 0x04, 0x1e, 0x24, \n\t0x04, 0x92, 0x50, 0x88, 0x99, 0x40, 0x27, 0x42, 0x82, 0xaa, 0x83, 0x5c, 0xc2, 0x40, 0x24, 0x40, \n\t0x11, 0x2a, 0xc5, 0x11, 0xa2, 0x4e, 0x04, 0x10, 0x01, 0xc4, 0x84, 0x88, 0x02, 0xc5, 0x22, 0x28, \n\t0x50, 0x10, 0xab, 0x00, 0x11, 0x81, 0x82, 0x8c, 0x88, 0x4a, 0x3c, 0x02, 0x50, 0x0e, 0x34, 0x01, \n\t0x88, 0x50, 0x15, 0x29, 0x16, 0x2c, 0x5b, 0x00, 0x08, 0x91, 0x03, 0x04, 0x48, 0x8e, 0x64, 0x16, \n\t0x26, 0x5a, 0x21, 0x0d, 0x50, 0x81, 0x44, 0x21, 0x08, 0x03, 0x0c, 0x94, 0xe0, 0x18, 0x90, 0x22, \n\t0x92, 0x84, 0x40, 0xc9, 0x64, 0xa0, 0x18, 0x04, 0x70, 0x49, 0x82, 0x18, 0x02, 0x19, 0x80, 0x80, \n\t0x85, 0x20, 0x6c, 0x41, 0x0b, 0x21, 0x9d, 0x4e, 0x00, 0x12, 0x40, 0x09, 0x8a, 0x10, 0x08, 0x64, \n\t0x74, 0x44, 0xd3, 0x08, 0x69, 0xc6, 0x08, 0x02, 0x76, 0x68, 0x38, 0x50, 0x91, 0x85, 0x00, 0xd1, \n\t0x42, 0xa5, 0x20, 0x15, 0x04, 0x08, 0x20, 0x79, 0x00, 0x71, 0x45, 0xe2, 0x34, 0x10, 0x11, 0x18, \n\t0x30, 0x94, 0x0e, 0x40, 0x30, 0x2a, 0x25, 0x15, 0x04, 0x25, 0x44, 0x10, 0xc2, 0x0f, 0x9d, 0x80, \n\t0x62, 0x20, 0x52, 0x00, 0x00, 0x20, 0xc6, 0x47, 0x5a, 0x14, 0xb9, 0x9a, 0x8c, 0x83, 0x28, 0x4e, \n\t0x21, 0x19, 0x02, 0x44, 0xd8, 0x81, 0x00, 0xa0, 0x18, 0x12, 0x51, 0x19, 0x09, 0x20, 0x13, 0x88, \n\t0x10, 0x20, 0xc0, 0x40, 0x20, 0x06, 0x19, 0x33, 0x45, 0x02, 0x89, 0x52, 0x20, 0x42, 0x05, 0x88, \n\t0x40, 0x08, 0x10, 0x04, 0x92, 0x10, 0x28, 0x19, 0xe3, 0x2c, 0x10, 0x82, 0x25, 0x20, 0x97, 0x41, \n\t0x10, 0x02, 0x88, 0x00, 0x11, 0x96, 0xce, 0x40, 0x37, 0x80, 0x08, 0x05, 0x02, 0x43, 0x02, 0x31, \n\t0x20, 0x9b, 0x20, 0x0e, 0x06, 0x20, 0x84, 0x78, 0x85, 0xc8, 0x06, 0x8a, 0x08, 0x10, 0x72, 0x25, \n\t0xa0, 0x90, 0xea, 0x3e, 0x82, 0x20, 0x12, 0x71, 0x18, 0x40, 0x04, 0x24, 0x89, 0x0a, 0x60, 0x4b, \n\t0xcd, 0x12, 0x00, 0x40, 0x98, 0x11, 0x15, 0x41, 0x22, 0x52, 0x2a, 0x23, 0x14, 0x81, 0x28, 0x1c, \n\t0x40, 0x23, 0x89, 0x00, 0x11, 0x6e, 0x48, 0x00, 0xb2, 0x1d, 0x14, 0x44, 0x80, 0x56, 0xc1, 0x11, \n\t0x8c, 0x20, 0x9e, 0xac, 0x40, 0x81, 0x31, 0x11, 0x14, 0x8a, 0xc0, 0x02, 0xd0, 0x28, 0x03, 0x08, \n\t0x06, 0x64, 0x44, 0xc3, 0xa1, 0x80, 0x20, 0x84, 0x80, 0x10, 0x45, 0x03, 0x10, 0xc9, 0xc2, 0x20, \n\t0x4a, 0x83, 0x78, 0x1a, 0xc0, 0x0d, 0x49, 0x00, 0x24, 0x90, 0x99, 0xe1, 0x05, 0xa6, 0x14, 0x82, \n\t0x10, 0x80, 0x91, 0xd9, 0x01, 0x00, 0x47, 0x68, 0x09, 0x10, 0x86, 0x08, 0x08, 0x14, 0x40, 0x9f, \n\t0x70, 0xd5, 0x6b, 0x0c, 0x14, 0x4a, 0x01, 0xd0, 0x40, 0x60, 0x02, 0x40, 0x10, 0x22, 0xa5, 0x08, \n\t0x4d, 0x20, 0xe0, 0x00, 0x97, 0x41, 0x4a, 0x8a, 0x06, 0xf1, 0x10, 0x35, 0x14, 0x82, 0x20, 0x68, \n\t0x00, 0x09, 0x34, 0x60, 0x01, 0x86, 0x00, 0x20, 0x40, 0x04, 0xcd, 0x02, 0x43, 0x06, 0x87, 0x03, \n\t0x9a, 0xa8, 0x14, 0xae, 0x62, 0x44, 0x0b, 0x88, 0x34, 0x42, 0x42, 0x20, 0x42, 0x60, 0x81, 0x14, \n\t0xc3, 0x83, 0x10, 0x53, 0x80, 0x11, 0x28, 0x95, 0x64, 0x3c, 0xe6, 0x8b, 0x00, 0x81, 0xd8, 0x81, \n\t0x14, 0xa2, 0x33, 0x20, 0x85, 0x44, 0x40, 0x00, 0x21, 0x1a, 0x09, 0x68, 0x0c, 0x40, 0x40, 0xf5, \n\t0x81, 0x80, 0x0d, 0x5b, 0x26, 0x2a, 0x03, 0x32, 0x22, 0x21, 0x00, 0x05, 0x0a, 0x80, 0xe0, 0x28, \n\t0x8c, 0x86, 0x24, 0x04, 0x01, 0x92, 0x91, 0x2c, 0x44, 0x81, 0x40, 0x26, 0x60, 0xb4, 0x7c, 0x15, \n\t0x49, 0x50, 0x02, 0x80, 0x08, 0x85, 0x86, 0xab, 0x10, 0x42, 0x40, 0x82, 0x94, 0x5d, 0x0f, 0x02, \n\t0x10, 0x6a, 0x19, 0x90, 0x0a, 0x05, 0x20, 0x24, 0xaa, 0x00, 0xd1, 0x04, 0x28, 0x74, 0x22, 0x80, \n\t0x11, 0x60, 0x81, 0xa9, 0x44, 0x00, 0x9b, 0x06, 0x04, 0x00, 0x49, 0x54, 0xe2, 0xf3, 0x09, 0x00, \n\t0xcb, 0xa2, 0x40, 0xa2, 0x08, 0x10, 0x18, 0x90, 0x22, 0x28, 0x50, 0xa9, 0x27, 0x04, 0xd8, 0xae, \n\t0x18, 0x41, 0xe0, 0x00, 0x70, 0x06, 0x82, 0x20, 0xc1, 0x90, 0x02, 0x09, 0x00, 0x06, 0x06, 0xc4, \n\t0xdb, 0x00, 0x08, 0x81, 0x0c, 0x0a, 0x26, 0x50, 0x82, 0xa4, 0x17, 0xc6, 0x28, 0x40, 0x21, 0x27, \n\t0x00, 0x43, 0x2d, 0x44, 0xd7, 0x31, 0x02, 0x09, 0x83, 0x00, 0x2a, 0xb0, 0x70, 0x05, 0x9c, 0x41, \n\t0x47, 0x12, 0xa2, 0x50, 0x22, 0x44, 0x90, 0x00, 0x48, 0x03, 0x11, 0x8e, 0xc9, 0x50, 0x21, 0x66, \n\t0x10, 0xa8, 0x81, 0x04, 0x11, 0xc1, 0x62, 0x91, 0x49, 0x00, 0x44, 0x91, 0x22, 0x0e, 0x24, 0x8a, \n\t0x36, 0xe1, 0x0d, 0x61, 0x6c, 0x44, 0x28, 0xa0, 0x94, 0x18, 0x04, 0x04, 0x81, 0x19, 0x01, 0x38, \n\t0x47, 0x42, 0x30, 0xa4, 0x41, 0x04, 0x05, 0x9a, 0x84, 0x50, 0x32, 0x29, 0x0c, 0x10, 0x08, 0x08, \n\t0x66, 0x21, 0x20, 0x85, 0xc8, 0x8c, 0x04, 0x06, 0x12, 0x40, 0x35, 0x19, 0x96, 0x04, 0x12, 0x52, \n\t0xd2, 0x08, 0xb0, 0x14, 0xa7, 0x40, 0x00, 0x53, 0x1f, 0x08, 0x03, 0xe1, 0x28, 0x81, 0x00, 0x3e, \n\t0x01, 0xdb, 0x42, 0x5c, 0x05, 0x61, 0xad, 0x00, 0xc0, 0x0c, 0x14, 0x20, 0x18, 0x93, 0x0c, 0x52, \n\t0x89, 0x24, 0xe0, 0x82, 0x0e, 0x04, 0x40, 0x6d, 0x32, 0xb6, 0x4a, 0xaa, 0x91, 0x00, 0x41, 0x04, \n\t0x00, 0x01, 0x12, 0x65, 0x8c, 0x00, 0x12, 0x51, 0x88, 0xbb, 0xa4, 0x0c, 0x21, 0x48, 0xa1, 0x10, \n\t0x0e, 0x48, 0x8a, 0x24, 0x54, 0x02, 0x61, 0x38, 0x31, 0x00, 0x88, 0x00, 0x42, 0xc9, 0x0e, 0x0c, \n\t0x82, 0x40, 0x0c, 0x22, 0x51, 0x04, 0x90, 0x00, 0x6c, 0x22, 0x24, 0x88, 0x9c, 0x04, 0x04, 0x42, \n\t0x40, 0x01, 0x23, 0x01, 0x88, 0x05, 0x20, 0x0a, 0x70, 0xa2, 0xa6, 0x00, 0x11, 0x68, 0x38, 0x24, \n\t0xa0, 0x30, 0xa1, 0x41, 0x4d, 0x20, 0xf0, 0x90, 0x00, 0x15, 0x40, 0xc0, 0x02, 0xe4, 0x59, 0x2c, \n\t0xe0, 0xd7, 0x08, 0x3a, 0x90, 0x8b, 0xaa, 0x20, 0x08, 0x08, 0x00, 0xd2, 0x02, 0x04, 0xe1, 0xc0, \n\t0x00, 0x38, 0x04, 0xe9, 0x08, 0xb8, 0x47, 0x86, 0x40, 0x00, 0x32, 0x23, 0x99, 0x00, 0x05, 0x0c, \n\t0x57, 0x10, 0x30, 0x55, 0x59, 0x8a, 0x48, 0x84, 0x90, 0x33, 0x3c, 0x04, 0xc1, 0x6a, 0x12, 0xc1, \n\t0x00, 0x85, 0x5a, 0x06, 0x30, 0x44, 0x98, 0x34, 0x19, 0x18, 0x22, 0x32, 0x24, 0x70, 0x24, 0xa0, \n\t0x0c, 0x23, 0x44, 0x51, 0x00, 0x29, 0x51, 0x43, 0x00, 0x10, 0x21, 0x10, 0x21, 0x00, 0x14, 0x42, \n\t0x62, 0x84, 0x01, 0x00, 0x38, 0x1b, 0x68, 0x10, 0x73, 0x52, 0x02, 0x00, 0x11, 0x21, 0x06, 0x90, \n\t0x01, 0x05, 0x60, 0x04, 0x62, 0x00, 0x00, 0x80, 0xa0, 0x41, 0x1e, 0xcc, 0x00, 0x03, 0xf0, 0xb8, \n\t0x4c, 0x08, 0x20, 0x0c, 0x01, 0x20, 0x08, 0x7c, 0x06, 0x24, 0x40, 0x93, 0x4b, 0x80, 0x45, 0xc7, \n\t0x84, 0x46, 0x25, 0x11, 0x00, 0xd0, 0x89, 0x02, 0x18, 0xc2, 0xf0, 0x02, 0x08, 0x1c, 0xac, 0x42, \n\t0xd4, 0x48, 0x10, 0xac, 0xc4, 0x02, 0x1a, 0x11, 0x49, 0x19, 0x00, 0xcd, 0xc0, 0x5a, 0x47, 0xa2, \n\t0xa9, 0x08, 0x00, 0x01, 0x24, 0x21, 0x60, 0x10, 0x40, 0x52, 0xec, 0x00, 0x04, 0x00, 0x19, 0x50, \n\t0x11, 0x8d, 0x1a, 0x30, 0x9a, 0x03, 0x80, 0x80, 0xc7, 0x20, 0x03, 0x90, 0x03, 0x98, 0x88, 0x2f, \n\t0x0e, 0x34, 0x08, 0x15, 0x68, 0xd5, 0x26, 0x24, 0x80, 0x50, 0x81, 0x04, 0x57, 0xa0, 0x60, 0x01, \n\t0x31, 0x15, 0xb4, 0x92, 0x00, 0x06, 0xe0, 0x40, 0x30, 0x01, 0x59, 0x48, 0x04, 0x86, 0x49, 0x99, \n\t0xc0, 0x08, 0x4b, 0x26, 0x81, 0x48, 0x0e, 0x44, 0x14, 0x43, 0x22, 0x26, 0x82, 0x2e, 0x00, 0x81, \n\t0x40, 0x68, 0xa1, 0x51, 0x84, 0x58, 0x86, 0xc0, 0x20, 0xa2, 0x92, 0x28, 0x44, 0x84, 0x03, 0x5c, \n\t0x50, 0x90, 0x02, 0x6c, 0x04, 0xaf, 0x70, 0x16, 0x32, 0x06, 0x91, 0x81, 0xa8, 0x00, 0xb0, 0x28, \n\t0x23, 0x30, 0x01, 0x40, 0x60, 0x81, 0x08, 0xa9, 0x41, 0x10, 0x0a, 0x2a, 0x74, 0x29, 0x97, 0xa0, \n\t0x52, 0x8a, 0x1c, 0x40, 0xa2, 0x38, 0x9c, 0x10, 0x07, 0x02, 0xc0, 0x02, 0x01, 0x50, 0x4e, 0x0b, \n\t0x00, 0x06, 0x21, 0xad, 0x24, 0x53, 0x44, 0x4a, 0x96, 0x8b, 0x20, 0x10, 0x9c, 0x40, 0x24, 0xa3, \n\t0x89, 0x19, 0x70, 0x01, 0x22, 0x14, 0x10, 0x98, 0x00, 0x21, 0x95, 0x09, 0x4a, 0x91, 0x49, 0x22, \n\t0xc5, 0x04, 0x27, 0x60, 0x65, 0xe2, 0x20, 0x80, 0x02, 0x00, 0x24, 0x22, 0xaa, 0x96, 0x64, 0x84, \n\t0x02, 0x4e, 0xc0, 0x0a, 0x18, 0xe0, 0x80, 0x04, 0x58, 0x04, 0x51, 0x25, 0x81, 0x98, 0x40, 0x0e, \n\t0x20, 0x90, 0x0a, 0xc8, 0x0d, 0x08, 0x42, 0x21, 0x81, 0x12, 0x00, 0xca, 0x00, 0x36, 0x82, 0x58, \n\t0x20, 0x15, 0x01, 0xca, 0x48, 0x21, 0x41, 0x01, 0xb0, 0x00, 0x20, 0x06, 0x80, 0x18, 0x04, 0x00, \n\t0x92, 0x09, 0x28, 0x24, 0x01, 0x0c, 0x74, 0x05, 0x42, 0x18, 0x90, 0x61, 0x2b, 0x09, 0x16, 0x45, \n\t0x44, 0xa2, 0xc0, 0x1a, 0x14, 0x01, 0x00, 0x00, 0x40, 0x22, 0x9d, 0x45, 0x4b, 0x84, 0x12, 0x05, \n\t0xea, 0x04, 0xcc, 0x0a, 0x08, 0x20, 0x40, 0x09, 0x02, 0x6c, 0x83, 0x80, 0x00, 0x00, 0x30, 0x90, \n\t0x99, 0x00, 0x4d, 0x30, 0x41, 0x9a, 0x03, 0x65, 0xc5, 0x29, 0x38, 0x10, 0x50, 0x24, 0x61, 0x80, \n\t0x44, 0x02, 0xd2, 0xc0, 0x80, 0x20, 0x02, 0x20, 0x02, 0x54, 0x63, 0x10, 0xb0, 0x15, 0x85, 0x48, \n\t0xa2, 0x03, 0x10, 0x95, 0xd0, 0x00, 0x08, 0xc1, 0xe3, 0x0c, 0x40, 0x16, 0x66, 0x40, 0x45, 0x11, \n\t0x89, 0x00, 0x00, 0x8e, 0x42, 0x93, 0xb0, 0x28, 0x69, 0xd0, 0xe2, 0x22, 0x07, 0x11, 0x0c, 0x2c, \n\t0x98, 0x80, 0x48, 0x04, 0x10, 0x14, 0xdd, 0x8e, 0x01, 0x08, 0x07, 0xe2, 0x8e, 0x08, 0x00, 0x6a, \n\t0x30, 0x11, 0x40, 0x03, 0x40, 0x85, 0x26, 0x08, 0x06, 0x18, 0x0a, 0x40, 0x82, 0x01, 0x28, 0x50, \n\t0x29, 0xa3, 0xa0, 0xc3, 0x68, 0x54, 0xa2, 0x98, 0x88, 0x20, 0x00, 0x2e, 0x46, 0x26, 0xa0, 0x00, \n\t0x1c, 0x41, 0x04, 0x14, 0x02, 0x42, 0x80, 0x89, 0x1e, 0xa9, 0x44, 0xc5, 0x92, 0xb0, 0x80, 0xca, \n\t0xa0, 0x08, 0x76, 0xb0, 0xa8, 0x40, 0xcf, 0x83, 0x2a, 0xc0, 0x58, 0x3e, 0x0c, 0x04, 0x84, 0x0e, \n\t0x51, 0xc0, 0x13, 0x81, 0x59, 0xe8, 0x40, 0x42, 0x19, 0x0a, 0x38, 0x40, 0xc6, 0x22, 0x40, 0x11, \n\t0x80, 0x41, 0x01, 0x66, 0x2e, 0xa1, 0x08, 0x31, 0x50, 0x0a, 0x89, 0x00, 0x07, 0x40, 0x13, 0x00, \n\t0x41, 0x28, 0x02, 0xc0, 0x0b, 0x85, 0x11, 0xd8, 0x28, 0x2e, 0x82, 0xa2, 0x24, 0xb0, 0x50, 0x67, \n\t0x56, 0x80, 0x03, 0x8f, 0x28, 0x00, 0x05, 0x24, 0x81, 0xc0, 0x12, 0x4c, 0x82, 0x04, 0x0a, 0x16, \n\t0xb0, 0x8a, 0x51, 0x00, 0x80, 0x14, 0x41, 0x53, 0x0e, 0x29, 0x4a, 0x08, 0x14, 0x14, 0x22, 0xa5, \n\t0x24, 0x46, 0x41, 0x02, 0x01, 0x40, 0x84, 0x64, 0x04, 0xc4, 0x04, 0x92, 0x99, 0x08, 0xa8, 0x89, \n\t0x2a, 0x10, 0x40, 0x21, 0x14, 0xa0, 0x18, 0xc8, 0x48, 0xa4, 0x49, 0xa1, 0x00, 0x47, 0x41, 0x28, \n\t0x86, 0x88, 0x0e, 0x80, 0x48, 0xa1, 0x64, 0x12, 0x72, 0x28, 0x40, 0x53, 0x48, 0x52, 0xb2, 0x02, \n\t0x00, 0xd8, 0x90, 0x48, 0x20, 0x36, 0xc2, 0x25, 0x80, 0x09, 0x25, 0x2c, 0x12, 0x88, 0x98, 0x69, \n\t0x1c, 0x04, 0x12, 0x14, 0xe2, 0x90, 0x68, 0x06, 0x88, 0x38, 0x00, 0x23, 0x01, 0x90, 0x15, 0xa0, \n\t0x1e, 0x04, 0x31, 0xa6, 0x71, 0x40, 0x0a, 0x50, 0xd4, 0x41, 0x08, 0x08, 0x0a, 0x04, 0x2c, 0x15, \n\t0x00, 0x8a, 0x40, 0x10, 0x8a, 0x70, 0xb0, 0x81, 0x22, 0x14, 0x0b, 0x25, 0x12, 0x15, 0x0a, 0x00, \n\t0x30, 0x81, 0xcc, 0x08, 0x30, 0x61, 0x18, 0xdc, 0xc4, 0x60, 0x14, 0x83, 0x78, 0xa1, 0x00, 0x82, \n\t0x83, 0x08, 0x52, 0xb0, 0x06, 0x0c, 0x02, 0x29, 0x00, 0x14, 0x2a, 0x90, 0x0d, 0x11, 0x64, 0x42, \n\t0x02, 0x40, 0x21, 0x80, 0x45, 0x06, 0x08, 0x04, 0x4b, 0x04, 0x30, 0x50, 0x40, 0x26, 0x64, 0xe2, \n\t0x04, 0xc5, 0x0c, 0xc8, 0x30, 0xc6, 0x02, 0x0b, 0x18, 0x4f, 0x80, 0x28, 0x84, 0x20, 0x29, 0x85, \n\t0x8e, 0x0b, 0x58, 0x24, 0x80, 0x01, 0x14, 0x55, 0x04, 0x02, 0xc1, 0xb0, 0x80, 0xc0, 0x80, 0x8b, \n\t0x42, 0x82, 0x59, 0x34, 0x4c, 0xc0, 0xc0, 0x12, 0x53, 0x39, 0x20, 0x84, 0x0a, 0xc5, 0x18, 0x91, \n\t0x20, 0xa3, 0x50, 0x48, 0x43, 0x4a, 0x10, 0x3a, 0xb2, 0x11, 0x89, 0x42, 0x18, 0x10, 0xe0, 0x93, \n\t0x40, 0x02, 0xa6, 0x64, 0x04, 0x08, 0x87, 0x18, 0xc3, 0x00, 0x16, 0x07, 0x20, 0x2a, 0x04, 0x09, \n\t0x44, 0x22, 0xa2, 0x83, 0xb0, 0x29, 0xc1, 0x40, 0x20, 0xa3, 0x01, 0x07, 0x81, 0x5c, 0x42, 0x00, \n\t0x45, 0x21, 0x83, 0xac, 0x13, 0x25, 0x0e, 0x80, 0x80, 0x01, 0x49, 0x14, 0x8b, 0x10, 0x16, 0x62, \n\t0x10, 0x14, 0x82, 0x07, 0x48, 0xb0, 0xe9, 0x09, 0x80, 0x9a, 0x88, 0x70, 0xe0, 0xc0, 0x0d, 0x8d, \n\t0x03, 0x84, 0x04, 0xd1, 0x20, 0x82, 0x25, 0x07, 0x62, 0x68, 0x11, 0x10, 0x20, 0x20, 0x01, 0x06, \n\t0x14, 0x40, 0x72, 0x12, 0x11, 0xd4, 0x20, 0x10, 0x65, 0x72, 0x10, 0xc8, 0x04, 0x8a, 0x04, 0x04, \n\t0x0a, 0x98, 0x08, 0xc8, 0x20, 0x04, 0x12, 0x48, 0x85, 0x70, 0x10, 0xc3, 0x08, 0x25, 0x80, 0x18, \n\t0x00, 0x1c, 0x40, 0x1e, 0x20, 0x00, 0x13, 0xa1, 0x43, 0xe0, 0x1e, 0x04, 0xc3, 0x18, 0xc4, 0x00, \n\t0x69, 0x44, 0x00, 0x20, 0xaf, 0xa0, 0x04, 0x0a, 0x00, 0x01, 0x43, 0x3c, 0x11, 0x10, 0x66, 0x48, \n\t0x82, 0x20, 0x0f, 0x1c, 0x0c, 0x44, 0x38, 0x13, 0xa8, 0x14, 0x24, 0x8f, 0x80, 0x06, 0x60, 0x72, \n\t0x00, 0x90, 0x84, 0x01, 0x12, 0x61, 0x50, 0x2e, 0xbc, 0x04, 0x24, 0x64, 0x90, 0x48, 0x28, 0x49, \n\t0x83, 0xa0, 0x10, 0x54, 0x19, 0x1b, 0xa5, 0x01, 0x08, 0x52, 0xf6, 0x00, 0x07, 0xac, 0x09, 0x40, \n\t0x24, 0x42, 0xd8, 0x8a, 0xd1, 0x99, 0x88, 0x6e, 0x90, 0x08, 0x04, 0x00, 0x50, 0x0c, 0x18, 0x73, \n\t0x09, 0x85, 0x24, 0x84, 0x6a, 0x00, 0xc0, 0x83, 0xa1, 0x85, 0x5a, 0x40, 0x42, 0x64, 0x82, 0x30, \n\t0x31, 0x48, 0x05, 0x14, 0xd1, 0x7a, 0x00, 0x0d, 0x10, 0x20, 0x42, 0x20, 0xc0, 0x26, 0x84, 0x0c, \n\t0xc3, 0x1c, 0x20, 0x51, 0x10, 0xa9, 0x19, 0x21, 0x14, 0x22, 0x41, 0xa8, 0x90, 0x0d, 0xe9, 0x10, \n\t0x64, 0x29, 0xbd, 0x31, 0xc4, 0x46, 0x28, 0x40, 0x0a, 0x9a, 0x88, 0xc4, 0x20, 0x28, 0x21, 0xc2, \n\t0x80, 0x40, 0x86, 0x03, 0x38, 0x96, 0x83, 0x08, 0x39, 0xd0, 0x0c, 0x1a, 0x81, 0x78, 0x2a, 0x51, \n\t0x06, 0xc7, 0x00, 0x13, 0x91, 0x05, 0x01, 0x59, 0x4c, 0x00, 0xc1, 0x02, 0x86, 0x15, 0x5f, 0x84, \n\t0x22, 0x56, 0x62, 0xa3, 0x84, 0x10, 0x00, 0x7a, 0x01, 0xa1, 0x11, 0x91, 0x92, 0xa0, 0x48, 0x20, \n\t0x28, 0x98, 0x10, 0x45, 0xa4, 0x04, 0x81, 0x02, 0x3a, 0x88, 0x01, 0x08, 0x24, 0xc3, 0x20, 0x34, \n\t0x84, 0x5c, 0x40, 0x20, 0xf6, 0x22, 0x10, 0xbc, 0x02, 0x21, 0x02, 0x44, 0x38, 0x0b, 0x98, 0x82, \n\t0x60, 0x2e, 0x96, 0x88, 0x05, 0x44, 0x45, 0xca, 0x0c, 0x00, 0x0a, 0x82, 0xe9, 0x00, 0x61, 0x58, \n\t0x00, 0x11, 0x15, 0x10, 0x13, 0x21, 0x26, 0x02, 0x08, 0x80, 0x41, 0x96, 0x04, 0x28, 0x01, 0x81, \n\t0x0d, 0x21, 0x99, 0x00, 0x42, 0x71, 0x82, 0xa2, 0xc0, 0x45, 0x60, 0x38, 0x40, 0xd2, 0x80, 0x80, \n\t0x58, 0x43, 0x06, 0xe1, 0x13, 0x22, 0xe8, 0x08, 0x00, 0x00, 0x40, 0x00, 0x1d, 0x20, 0x5b, 0x44, \n\t0x42, 0x12, 0x4b, 0x28, 0x10, 0x0c, 0x0c, 0x54, 0xc2, 0xc0, 0x0e, 0x10, 0xc7, 0x00, 0x70, 0xa0, \n\t0x60, 0x30, 0x3c, 0x82, 0x03, 0x48, 0x40, 0x12, 0x2c, 0x7c, 0x80, 0x86, 0x20, 0x02, 0x12, 0x21, \n\t0x49, 0x01, 0xe9, 0x68, 0x12, 0xb8, 0x28, 0x04, 0xd0, 0x82, 0x54, 0x42, 0x89, 0x9b, 0x40, 0x52, \n\t0x84, 0x1e, 0x21, 0xe0, 0x22, 0x85, 0x15, 0x80, 0x4c, 0x84, 0x81, 0x04, 0xc0, 0x09, 0x0a, 0x42, \n\t0x46, 0x81, 0x22, 0x40, 0x89, 0x26, 0x16, 0x94, 0x49, 0x11, 0x94, 0x41, 0x0f, 0x00, 0x40, 0xa0, \n\t0x2d, 0x28, 0x40, 0x2d, 0x18, 0x11, 0x1b, 0x19, 0x18, 0x92, 0x81, 0x26, 0x26, 0x0b, 0x00, 0x0c, \n\t0x91, 0x0c, 0x46, 0xe0, 0x20, 0x0c, 0x31, 0x8a, 0x08, 0x14, 0x90, 0x12, 0x3a, 0x11, 0x53, 0x25, \n\t0x00, 0x85, 0x22, 0x11, 0x05, 0x40, 0x80, 0x20, 0x96, 0x40, 0x83, 0x41, 0x8d, 0x28, 0x00, 0x40, \n\t0xe2, 0x04, 0x08, 0xc6, 0x08, 0x10, 0xa2, 0x98, 0x12, 0x29, 0x00, 0x29, 0x24, 0x54, 0x80, 0x82, \n\t0x25, 0x03, 0x45, 0x16, 0x00, 0x18, 0x90, 0x30, 0x11, 0x0a, 0x30, 0x84, 0x21, 0x06, 0x08, 0x0c, \n\t0x60, 0x22, 0x14, 0xc2, 0x82, 0x38, 0x54, 0xc0, 0x6a, 0x84, 0x11, 0x3c, 0x00, 0x10, 0x8c, 0x48, \n\t0x82, 0x8a, 0x8d, 0x65, 0x88, 0x40, 0x00, 0x42, 0x33, 0x25, 0x5c, 0x09, 0x01, 0x00, 0x03, 0x20, \n\t0x3f, 0x50, 0x0a, 0xe6, 0x04, 0x40, 0x38, 0x00, 0x0d, 0xd0, 0x8e, 0x50, 0x40, 0x61, 0x04, 0x20, \n\t0x4c, 0x83, 0x24, 0x26, 0x28, 0x06, 0xc0, 0x00, 0x88, 0x04, 0x72, 0x12, 0x19, 0x81, 0x84, 0x43, \n\t0x26, 0x10, 0x18, 0x90, 0x21, 0x93, 0x04, 0x08, 0xa3, 0x89, 0x27, 0x04, 0x84, 0x68, 0x00, 0x93, \n\t0x43, 0x81, 0x71, 0x84, 0x0c, 0x10, 0xb4, 0xe0, 0x21, 0xc1, 0x52, 0x2e, 0x02, 0x10, 0x00, 0x00, \n\t0xc1, 0x08, 0x00, 0x68, 0x80, 0xd2, 0x01, 0x00, 0x00, 0xa5, 0x0e, 0x85, 0x32, 0x8c, 0x01, 0x40, \n\t0x82, 0x20, 0x95, 0x8b, 0x92, 0x40, 0x1c, 0x08, 0x54, 0x30, 0x40, 0x36, 0x34, 0x09, 0x82, 0x06, \n\t0x84, 0xf2, 0xac, 0x84, 0x18, 0x21, 0x32, 0xd0, 0x41, 0x11, 0xb0, 0x82, 0x43, 0x12, 0x50, 0x08, \n\t0x0a, 0x80, 0x0b, 0x02, 0x50, 0x06, 0x60, 0xa6, 0x04, 0x51, 0x08, 0x02, 0x84, 0x1b, 0x91, 0x79, \n\t0x01, 0x8c, 0x44, 0x30, 0xa2, 0x00, 0x20, 0x16, 0x82, 0x48, 0x10, 0x00, 0x21, 0x09, 0x08, 0x22, \n\t0x08, 0x20, 0x62, 0x30, 0x99, 0x89, 0x4a, 0x26, 0x07, 0xb2, 0x0a, 0x01, 0x02, 0xc4, 0x2c, 0x03, \n\t0xd0, 0x22, 0xc4, 0x94, 0x80, 0x5a, 0x14, 0xc0, 0x15, 0x49, 0x86, 0x28, 0x0a, 0xa2, 0x43, 0x24, \n\t0x24, 0x14, 0x01, 0x16, 0x60, 0xd0, 0x2b, 0x45, 0x09, 0x04, 0x16, 0xa1, 0x48, 0x1e, 0xa4, 0x14, \n\t0xc0, 0x48, 0x00, 0x42, 0x8b, 0x90, 0xcd, 0x40, 0x68, 0xc2, 0x02, 0x91, 0x00, 0x4c, 0xc8, 0x24, \n\t0x12, 0x4b, 0x28, 0x21, 0x04, 0x48, 0x12, 0x10, 0x82, 0x87, 0x01, 0x9a, 0xa1, 0x14, 0x60, 0x41, \n\t0x8b, 0xd0, 0x08, 0xa8, 0x22, 0x20, 0x02, 0x8c, 0x69, 0x88, 0x06, 0x58, 0x05, 0xa3, 0x27, 0x48, \n\t0x15, 0xaa, 0x20, 0x40, 0x50, 0x30, 0x2c, 0x0c, 0x08, 0x6c, 0x82, 0x21, 0x8a, 0x29, 0x58, 0x0d, \n\t0x40, 0x91, 0xd3, 0x00, 0x05, 0x02, 0x2e, 0x24, 0x11, 0x11, 0xb5, 0xc0, 0x94, 0x08, 0x02, 0x60, \n\t0x20, 0x08, 0x88, 0x0f, 0x25, 0x46, 0xc4, 0x42, 0x12, 0x18, 0x41, 0x2d, 0x10, 0x04, 0x12, 0x25, \n\t0x20, 0xc1, 0xe0, 0x44, 0x30, 0xd0, 0x2a, 0x1c, 0x06, 0x62, 0x38, 0x73, 0x81, 0xa0, 0x4c, 0x01, \n\t0x08, 0x60, 0x16, 0x02, 0x95, 0x3c, 0x51, 0xa1, 0x58, 0x12, 0x71, 0x2d, 0x60, 0x98, 0x08, 0x68, \n\t0x00, 0x12, 0x01, 0x50, 0x54, 0x00, 0x02, 0x87, 0xa9, 0x32, 0x19, 0x00, 0x82, 0x00, 0x41, 0x02, \n\t0xa1, 0x00, 0x0d, 0xe0, 0x10, 0x82, 0x50, 0x88, 0x75, 0x8c, 0x8c, 0x42, 0x16, 0x48, 0x19, 0x28, \n\t0x00, 0x08, 0x00, 0x94, 0x08, 0x11, 0x00, 0x1b, 0x83, 0x12, 0x20, 0x08, 0x2c, 0x2c, 0xc2, 0x60, \n\t0x10, 0x82, 0xb8, 0x02, 0x09, 0x04, 0x04, 0x38, 0x61, 0x51, 0x36, 0x04, 0x82, 0xe0, 0x06, 0xa1, \n\t0x0a, 0x8c, 0x11, 0xc3, 0x42, 0x0c, 0x17, 0x42, 0x84, 0x28, 0x03, 0x86, 0x4c, 0x70, 0x3b, 0x15, \n\t0xf8, 0xc8, 0x40, 0x10, 0xe1, 0xc8, 0xa0, 0x14, 0x41, 0x24, 0x64, 0x92, 0x41, 0x2b, 0x31, 0x09, \n\t0x41, 0x0c, 0x80, 0x40, 0x80, 0x85, 0x10, 0x82, 0x22, 0x52, 0xc8, 0x12, 0x38, 0x46, 0x65, 0x16, \n\t0x26, 0x20, 0x98, 0x61, 0x00, 0x29, 0x04, 0x94, 0xab, 0x28, 0x09, 0x00, 0x23, 0x02, 0xf0, 0x02, \n\t0x84, 0xe0, 0x0a, 0x05, 0x40, 0x20, 0xf0, 0x3b, 0x8c, 0x18, 0x4f, 0x44, 0xc0, 0x08, 0x2c, 0x20, \n\t0x42, 0x20, 0x00, 0x01, 0x02, 0xa9, 0x41, 0x03, 0x00, 0x52, 0x20, 0x72, 0x02, 0x80, 0xc2, 0x0a, \n\t0x64, 0x47, 0x92, 0x04, 0x49, 0x14, 0x03, 0x74, 0x80, 0x10, 0x83, 0x8c, 0x09, 0x29, 0x0e, 0x50, \n\t0x29, 0x04, 0x81, 0x1f, 0x49, 0x08, 0x85, 0xc0, 0x8c, 0x00, 0xd5, 0x41, 0x32, 0x46, 0xe1, 0x82, \n\t0x20, 0x90, 0xa6, 0x22, 0x80, 0xa8, 0x08, 0xf5, 0x43, 0x05, 0x18, 0x22, 0x41, 0x04, 0xc0, 0x00, \n\t0x0e, 0x1c, 0x12, 0xa0, 0x84, 0x44, 0xd9, 0x2c, 0x2a, 0xc7, 0x20, 0x2b, 0x04, 0x1b, 0x00, 0x3e, \n\t0x10, 0x00, 0x14, 0xc5, 0x05, 0x84, 0x04, 0x55, 0x22, 0x04, 0x08, 0xd1, 0xa8, 0x5a, 0x41, 0x12, \n\t0x9e, 0xf4, 0x08, 0x04, 0x50, 0x05, 0x48, 0x90, 0x0d, 0x07, 0x40, 0x08, 0x74, 0x28, 0x80, 0x81, \n\t0x16, 0x08, 0x0a, 0x80, 0x08, 0x0c, 0x04, 0xc9, 0x41, 0x7a, 0x65, 0x43, 0x82, 0x21, 0x92, 0x61, \n\t0x04, 0x94, 0xc1, 0x08, 0x00, 0x54, 0x01, 0x54, 0xa2, 0xe1, 0x01, 0x3c, 0x80, 0xa0, 0x04, 0x12, \n\t0xa2, 0x98, 0x80, 0x49, 0x4c, 0x62, 0x26, 0x02, 0x04, 0x28, 0x48, 0xa4, 0x04, 0x91, 0x4a, 0xa8, \n\t0x49, 0x11, 0x80, 0x00, 0x30, 0x69, 0x06, 0xf4, 0x93, 0x01, 0x08, 0x03, 0x11, 0x00, 0x51, 0x40, \n\t0x40, 0x12, 0x20, 0xd1, 0xba, 0x8d, 0x06, 0x40, 0x28, 0xe4, 0x10, 0x86, 0x85, 0xc8, 0x42, 0x02, \n\t0xc1, 0x20, 0x00, 0x90, 0x5b, 0x01, 0x14, 0x10, 0x20, 0x07, 0xe0, 0x81, 0x0a, 0x02, 0xb6, 0x39, \n\t0x19, 0x80, 0x10, 0x29, 0x48, 0x43, 0x2b, 0x0b, 0xc0, 0x84, 0x64, 0x34, 0xb6, 0x42, 0x14, 0x80, \n\t0x48, 0x26, 0x2e, 0xd1, 0x00, 0x33, 0x14, 0x11, 0x20, 0x02, 0x52, 0x82, 0xa9, 0x45, 0x08, 0xaa, \n\t0x18, 0x00, 0x21, 0x91, 0x9d, 0x12, 0x80, 0x4c, 0xa6, 0xd2, 0x90, 0x40, 0x19, 0x0f, 0x40, 0x64, \n\t0x01, 0x10, 0x68, 0x04, 0x45, 0x20, 0xb2, 0x18, 0x06, 0x20, 0x94, 0x8a, 0x30, 0x90, 0x03, 0xb4, \n\t0x2c, 0x83, 0x69, 0x20, 0x14, 0x50, 0x90, 0x30, 0x09, 0x43, 0x30, 0x80, 0x12, 0x18, 0xc1, 0x95, \n\t0x62, 0x40, 0x52, 0x70, 0x0c, 0x8c, 0x84, 0x89, 0x08, 0xc4, 0x00, 0x09, 0x04, 0x09, 0x00, 0x60, \n\t0xc5, 0x30, 0xa7, 0x60, 0x81, 0x20, 0x32, 0x06, 0x00, 0x99, 0x09, 0x04, 0x0c, 0x18, 0x61, 0x08, \n\t0x10, 0x25, 0x41, 0xc0, 0x14, 0x03, 0x20, 0x02, 0x10, 0x4d, 0x08, 0x04, 0x07, 0x01, 0x33, 0x74, \n\t0xce, 0x22, 0x00, 0x61, 0x61, 0x38, 0x05, 0x0c, 0x46, 0x60, 0xf0, 0x41, 0x02, 0x84, 0x04, 0x08, \n\t0x3e, 0x60, 0x30, 0x0a, 0xa1, 0x41, 0xee, 0x16, 0x02, 0xd8, 0x04, 0x20, 0x83, 0x01, 0x00, 0x01, \n\t0x5b, 0x04, 0x34, 0x08, 0xa0, 0x70, 0xc0, 0xa0, 0x33, 0x5c, 0xd8, 0x03, 0x48, 0x00, 0x3a, 0x1b, \n\t0x00, 0x87, 0x41, 0x70, 0x80, 0x88, 0x00, 0x85, 0x00, 0x8c, 0x28, 0x24, 0xbb, 0x00, 0xe0, 0x50, \n\t0x4b, 0x00, 0x85, 0x10, 0x36, 0x48, 0x49, 0x20, 0x00, 0x14, 0x02, 0x12, 0x08, 0x40, 0xa4, 0x32, \n\t0x04, 0x11, 0x1b, 0x21, 0x0f, 0x80, 0x30, 0x83, 0x62, 0x86, 0x38, 0xd2, 0x25, 0x46, 0xb4, 0x00, \n\t0x89, 0x79, 0x84, 0x0e, 0x40, 0x14, 0x1a, 0x0c, 0xb4, 0x97, 0x4b, 0x0c, 0xf1, 0x00, 0x06, 0x0d, \n\t0x84, 0x02, 0x40, 0x00, 0x80, 0xb2, 0x88, 0x48, 0x02, 0x08, 0x51, 0x08, 0x90, 0x1c, 0x48, 0xa4, \n\t0x0c, 0x80, 0x08, 0xb4, 0x88, 0x8f, 0xa8, 0x64, 0x14, 0x69, 0x33, 0x81, 0x82, 0x23, 0x26, 0x46, \n\t0x8a, 0x02, 0x54, 0x08, 0xc9, 0x10, 0x33, 0x12, 0xa1, 0xc0, 0x86, 0xc0, 0x34, 0x20, 0x40, 0x09, \n\t0x10, 0x51, 0x07, 0x70, 0x41, 0x82, 0x81, 0x10, 0x1e, 0x0c, 0x3a, 0x47, 0x61, 0x02, 0x48, 0x43, \n\t0xcb, 0x0a, 0x02, 0xf1, 0x1c, 0x60, 0x10, 0x05, 0x16, 0x51, 0xaa, 0x88, 0x45, 0x98, 0x82, 0x64, \n\t0x91, 0xb0, 0x32, 0x08, 0x83, 0x01, 0x40, 0xd3, 0x00, 0x39, 0x40, 0x92, 0x40, 0x42, 0x81, 0xe1, \n\t0x08, 0x88, 0xc5, 0x2a, 0x0a, 0x05, 0x50, 0x83, 0xe4, 0x07, 0xa1, 0x10, 0x67, 0x28, 0xa4, 0x88, \n\t0x01, 0x0b, 0x20, 0x14, 0x10, 0x2a, 0xcd, 0x41, 0x28, 0x22, 0x16, 0x18, 0x90, 0xd1, 0x00, 0x44, \n\t0x18, 0x81, 0xa1, 0x00, 0x14, 0x1e, 0x04, 0x22, 0x25, 0xd1, 0x14, 0x58, 0x09, 0x4a, 0x3a, 0x06, \n\t0x83, 0x25, 0x24, 0x01, 0x4c, 0x18, 0x01, 0x22, 0xa8, 0x30, 0x08, 0x41, 0x58, 0xa7, 0x52, 0x81, \n\t0xdc, 0x52, 0x26, 0x00, 0x86, 0x00, 0x38, 0x64, 0x85, 0x07, 0x0c, 0x52, 0x1a, 0x12, 0xa8, 0x04, \n\t0x8e, 0x32, 0x01, 0x41, 0x20, 0xe9, 0x4b, 0x60, 0x76, 0x21, 0x20, 0x2c, 0xa9, 0x00, 0x82, 0x32, \n\t0x64, 0x4a, 0x30, 0x48, 0x4a, 0x02, 0x04, 0x17, 0x10, 0x16, 0x05, 0x10, 0x41, 0x68, 0x71, 0x40, \n\t0x02, 0x20, 0x92, 0x60, 0x0e, 0xc2, 0x31, 0x04, 0x11, 0x83, 0x41, 0x0a, 0xb2, 0x11, 0x00, 0x25, \n\t0x45, 0x84, 0x40, 0x00, 0xda, 0x28, 0x41, 0x00, 0x4b, 0x0c, 0xe6, 0x00, 0x85, 0x50, 0xc8, 0x0a, \n\t0x04, 0x54, 0x30, 0x09, 0x00, 0x0e, 0xa6, 0x6a, 0x02, 0x02, 0x20, 0x0d, 0x56, 0xa0, 0x48, 0x04, \n\t0xa0, 0x90, 0x14, 0x81, 0x08, 0x2a, 0x02, 0x91, 0x30, 0x00, 0x01, 0x4c, 0x20, 0x40, 0x49, 0x29, \n\t0x15, 0x89, 0x04, 0x10, 0xa5, 0x60, 0x90, 0x20, 0x5e, 0x84, 0x20, 0x45, 0x03, 0x07, 0x14, 0x09, \n\t0x24, 0x08, 0x70, 0x8a, 0x92, 0x08, 0x46, 0xe3, 0x30, 0x00, 0x08, 0x01, 0x48, 0x51, 0x89, 0x10, \n\t0x40, 0xa8, 0x08, 0xa0, 0x12, 0x81, 0x34, 0x61, 0x41, 0x24, 0x84, 0x5a, 0x44, 0x24, 0x14, 0x9a, \n\t0x28, 0x68, 0x95, 0x44, 0x60, 0x43, 0x89, 0x80, 0x64, 0x85, 0x88, 0x02, 0x50, 0x01, 0x81, 0x74, \n\t0x18, 0x23, 0x24, 0x41, 0xe1, 0x02, 0xe9, 0x00, 0x0d, 0x04, 0x36, 0xd2, 0xb1, 0x01, 0x00, 0x8d, \n\t0x0e, 0x54, 0x41, 0x09, 0x30, 0x85, 0x08, 0x48, 0x81, 0x29, 0x38, 0x84, 0x4c, 0x28, 0x74, 0x03, \n\t0xa2, 0x0e, 0x20, 0x56, 0x04, 0x22, 0xa0, 0x01, 0x08, 0xc1, 0x84, 0x20, 0x1a, 0xd2, 0x10, 0x2a, \n\t0x11, 0x02, 0x4a, 0x10, 0x01, 0x32, 0xb1, 0x01, 0x12, 0x4a, 0x42, 0x04, 0xb8, 0x0e, 0x24, 0x90, \n\t0x84, 0x16, 0x47, 0x93, 0x0a, 0x44, 0x81, 0x0a, 0x18, 0x30, 0x80, 0x92, 0xb0, 0x11, 0x03, 0x3c, \n\t0xa4, 0x08, 0x00, 0x64, 0x44, 0xca, 0x26, 0xd2, 0x0b, 0x21, 0x88, 0x00, 0xcc, 0x16, 0x83, 0x71, \n\t0x22, 0xd0, 0xd0, 0x87, 0x08, 0xd7, 0x48, 0x0d, 0x00, 0xcb, 0x20, 0x6a, 0x43, 0x82, 0x04, 0x48, \n\t0x1d, 0xc6, 0x20, 0x20, 0x30, 0x05, 0xe1, 0x15, 0x01, 0x10, 0xf1, 0xa9, 0x82, 0x09, 0x98, 0x83, \n\t0x18, 0xa0, 0x60, 0x07, 0xd1, 0x83, 0x00, 0x08, 0x75, 0x02, 0x3c, 0x00, 0x0c, 0xc1, 0x6c, 0x02, \n\t0xba, 0x9a, 0x20, 0x42, 0x26, 0x14, 0x44, 0x20, 0x10, 0x4c, 0x43, 0xe1, 0x5a, 0x81, 0x42, 0x26, \n\t0x84, 0x0d, 0x20, 0x56, 0x00, 0x91, 0x98, 0x80, 0x00, 0x65, 0x12, 0x21, 0x08, 0x00, 0x50, 0x4a, \n\t0x82, 0x02, 0x06, 0xca, 0x82, 0x8c, 0x02, 0x64, 0x00, 0x83, 0xa1, 0x82, 0x50, 0x54, 0x01, 0x54, \n\t0x30, 0xc0, 0x00, 0x09, 0x14, 0xc4, 0x04, 0xa0, 0x03, 0x07, 0xcc, 0x88, 0x48, 0x48, 0xb0, 0x11, \n\t0x14, 0x19, 0x08, 0x88, 0x24, 0xd0, 0x00, 0x12, 0x00, 0x18, 0xc1, 0x0a, 0x80, 0x22, 0x08, 0x8d, \n\t0x45, 0x84, 0x08, 0x25, 0x40, 0x22, 0x94, 0x18, 0xc0, 0x18, 0x47, 0x72, 0x00, 0x64, 0x41, 0x00, \n\t0x24, 0xe2, 0x19, 0x81, 0x14, 0x81, 0x01, 0x14, 0x06, 0x50, 0x0c, 0xc0, 0x82, 0x0c, 0x3a, 0x21, \n\t0x4a, 0x03, 0x08, 0x41, 0x49, 0x06, 0x52, 0x08, 0x85, 0xb1, 0xd2, 0x02, 0x24, 0x00, 0x68, 0x01, \n\t0xd9, 0x12, 0x04, 0x04, 0x00, 0x20, 0x01, 0x01, 0x12, 0x0e, 0x10, 0x52, 0x50, 0x81, 0x40, 0x83, \n\t0xc8, 0x6e, 0x10, 0x22, 0x20, 0x78, 0x01, 0x04, 0x4a, 0x92, 0x61, 0x0d, 0x2c, 0xc2, 0x2c, 0x62, \n\t0x45, 0x4a, 0x84, 0x34, 0x86, 0x08, 0x00, 0xc0, 0x3a, 0x84, 0x24, 0x48, 0xe7, 0x00, 0x84, 0x4a, \n\t0x12, 0x09, 0x81, 0x00, 0x24, 0x65, 0x31, 0xa5, 0x00, 0x56, 0x4c, 0x12, 0x24, 0xa8, 0x9a, 0x30, \n\t0xd2, 0x05, 0x28, 0x53, 0x49, 0x05, 0xc1, 0x4b, 0x60, 0x50, 0x94, 0x11, 0x2c, 0x10, 0x91, 0x02, \n\t0x14, 0xf2, 0xa3, 0x23, 0xdc, 0x98, 0x28, 0x04, 0x43, 0x20, 0x23, 0xd8, 0x00, 0x20, 0x0e, 0x03, \n\t0x20, 0x30, 0x6c, 0x54, 0x04, 0x12, 0x81, 0x01, 0x84, 0x60, 0x54, 0x20, 0x24, 0x11, 0xba, 0xa5, \n\t0x08, 0x0a, 0xc9, 0x40, 0x83, 0x28, 0x2e, 0x39, 0x14, 0x82, 0x52, 0x01, 0x1a, 0x00, 0x81, 0x05, \n\t0x45, 0x2a, 0xa0, 0x18, 0x20, 0x40, 0x42, 0x01, 0x48, 0x00, 0x82, 0xbd, 0x80, 0x12, 0x61, 0x00, \n\t0x31, 0x01, 0x81, 0x08, 0x52, 0x05, 0x62, 0x00, 0x08, 0x18, 0x28, 0xc0, 0x40, 0x08, 0x90, 0x58, \n\t0x06, 0xb1, 0x92, 0x82, 0x60, 0x95, 0x10, 0x36, 0x00, 0x01, 0x05, 0x00, 0x10, 0xa8, 0x81, 0x11, \n\t0x8f, 0x46, 0x38, 0x10, 0x02, 0x30, 0x48, 0x06, 0x22, 0x4a, 0x21, 0x51, 0x21, 0x2d, 0x8c, 0x80, \n\t0x00, 0x25, 0x88, 0xac, 0x51, 0x10, 0x4a, 0x04, 0x87, 0x82, 0x02, 0x0c, 0x08, 0x0b, 0x1c, 0x30, \n\t0x28, 0x12, 0xc0, 0x80, 0x0d, 0x60, 0x82, 0x40, 0xb8, 0x80, 0x91, 0x45, 0x70, 0x44, 0x41, 0x0a, \n\t0xc0, 0x40, 0xa0, 0x16, 0x84, 0x1a, 0x2c, 0x84, 0xc6, 0x09, 0x44, 0x23, 0x0b, 0xad, 0x41, 0x16, \n\t0xc2, 0x70, 0x10, 0x22, 0x1c, 0x15, 0x02, 0xc1, 0x20, 0x86, 0x08, 0x21, 0x44, 0x89, 0xe2, 0x4a, \n\t0x12, 0x01, 0xb1, 0x80, 0x11, 0x08, 0x48, 0x01, 0x48, 0x80, 0x60, 0x12, 0x28, 0x22, 0x07, 0x60, \n\t0xaa, 0x38, 0x15, 0x4e, 0x74, 0x60, 0x02, 0x12, 0x38, 0x84, 0x05, 0x00, 0x87, 0x41, 0xa0, 0x20, \n\t0x4d, 0xc1, 0x02, 0x36, 0x82, 0x0c, 0x28, 0x89, 0x44, 0x36, 0x90, 0x28, 0x18, 0x79, 0x45, 0xa0, \n\t0x00, 0x16, 0xd0, 0x04, 0x30, 0x41, 0xe5, 0x12, 0x81, 0x10, 0xa0, 0x98, 0x02, 0x84, 0x48, 0x40, \n\t0x80, 0x83, 0x90, 0xda, 0x00, 0x60, 0x00, 0xa8, 0x93, 0x20, 0x00, 0x80, 0x5a, 0x50, 0x82, 0x03, \n\t0x20, 0x50, 0x04, 0x4c, 0x70, 0x28, 0xa5, 0xc4, 0x08, 0xa1, 0x10, 0x80, 0x93, 0x80, 0x88, 0x14, \n\t0x26, 0x72, 0x57, 0xca, 0x13, 0x80, 0x41, 0x02, 0x30, 0x81, 0x68, 0x10, 0x41, 0x19, 0x4e, 0x58, \n\t0x02, 0x43, 0xb8, 0x80, 0x0c, 0x00, 0x40, 0x66, 0x31, 0x14, 0x09, 0x80, 0x08, 0x44, 0x22, 0x03, \n\t0x08, 0xc8, 0x02, 0x01, 0x40, 0x20, 0xc9, 0x27, 0x11, 0x12, 0x25, 0x14, 0x11, 0x82, 0x06, 0x90, \n\t0xc0, 0xca, 0x02, 0x44, 0x02, 0x00, 0x09, 0x85, 0xa0, 0x5a, 0x42, 0x90, 0x05, 0x00, 0x53, 0x88, \n\t0x0c, 0x04, 0xd9, 0x90, 0xe1, 0x87, 0x03, 0x2c, 0x40, 0x21, 0x18, 0x44, 0x11, 0x28, 0x62, 0xb0, \n\t0x5a, 0x20, 0x44, 0x0e, 0x0e, 0x22, 0x10, 0x01, 0x24, 0xe1, 0x90, 0x08, 0x72, 0x12, 0x00, 0x00, \n\t0x8c, 0x40, 0x04, 0x06, 0x46, 0x10, 0x0b, 0x08, 0x04, 0x2a, 0x6a, 0x84, 0x00, 0x25, 0x84, 0x40, \n\t0x01, 0x06, 0x03, 0x19, 0xa4, 0x51, 0x10, 0x2d, 0x20, 0x93, 0x23, 0x82, 0xcc, 0x1a, 0xc2, 0x2a, \n\t0x40, 0x00, 0x10, 0x45, 0x95, 0x05, 0x52, 0x40, 0x08, 0x0c, 0x00, 0x48, 0x00, 0x10, 0x24, 0x2a, \n\t0x33, 0x41, 0xcb, 0x61, 0x08, 0x22, 0x40, 0x3e, 0x08, 0x4d, 0x23, 0x20, 0x40, 0xca, 0x88, 0x08, \n\t0x03, 0x4b, 0x14, 0xc2, 0x21, 0x8b, 0x91, 0x81, 0x48, 0x4a, 0x45, 0x82, 0x24, 0xa0, 0x0f, 0x0c, \n\t0x46, 0x10, 0x8b, 0x85, 0x11, 0x04, 0x0d, 0x28, 0x92, 0x62, 0x00, 0xb1, 0x06, 0x46, 0x06, 0x42, \n\t0x90, 0x00, 0x74, 0x1e, 0xec, 0x40, 0x82, 0x90, 0x9a, 0x4d, 0xc8, 0x2e, 0x04, 0xb7, 0x90, 0x08, \n\t0x7d, 0x82, 0x01, 0x20, 0xc7, 0x30, 0x03, 0x68, 0x90, 0x08, 0x28, 0x00, 0x28, 0x05, 0x14, 0x04, \n\t0xa9, 0x20, 0x04, 0x61, 0x04, 0xb1, 0x44, 0x01, 0x50, 0x91, 0x11, 0x90, 0xa0, 0x4a, 0xe4, 0x06, \n\t0x84, 0x08, 0x0d, 0x01, 0x18, 0x4b, 0x08, 0x25, 0x62, 0x80, 0x08, 0x05, 0x08, 0x10, 0x52, 0x2b, \n\t0x88, 0x90, 0x41, 0x00, 0x6a, 0x06, 0x12, 0x21, 0xc0, 0x00, 0xe2, 0x00, 0x03, 0xd0, 0x06, 0x40, \n\t0x0c, 0x61, 0x14, 0x44, 0x62, 0x30, 0x04, 0x18, 0x62, 0x08, 0x81, 0x10, 0x13, 0x3c, 0x1b, 0xc6, \n\t0x02, 0x06, 0x73, 0x95, 0xa5, 0x88, 0x2a, 0x48, 0x40, 0x0a, 0xb0, 0x79, 0x10, 0x49, 0x02, 0xa5, \n\t0xa0, 0x26, 0x70, 0x19, 0x43, 0x26, 0x80, 0x09, 0x23, 0x60, 0xc0, 0x84, 0x00, 0x21, 0x49, 0xac, \n\t0x10, 0x14, 0xc6, 0x68, 0x54, 0x43, 0xab, 0x30, 0x44, 0x41, 0x06, 0xa5, 0xf8, 0x08, 0x40, 0x4a, \n\t0x20, 0x14, 0x20, 0x20, 0x14, 0x89, 0x40, 0xa2, 0x46, 0x62, 0x08, 0x05, 0xb9, 0x10, 0xa1, 0x10, \n\t0x10, 0x81, 0x0c, 0xc1, 0x40, 0x86, 0x42, 0x06, 0x0a, 0x9a, 0x50, 0x45, 0x24, 0x30, 0x91, 0x20, \n\t0xa2, 0x08, 0x84, 0x20, 0x3e, 0x00, 0x61, 0x23, 0xf4, 0x42, 0x89, 0x70, 0x42, 0x22, 0xa0, 0x9c, \n\t0x58, 0x8d, 0x44, 0x25, 0x81, 0xb8, 0x14, 0xce, 0x20, 0x24, 0x21, 0x60, 0x81, 0x14, 0x18, 0x47, \n\t0x50, 0x33, 0xc0, 0x02, 0x04, 0x89, 0x05, 0x30, 0xc4, 0x8a, 0x02, 0x29, 0x8e, 0x09, 0x40, 0x80, \n\t0x19, 0x20, 0x11, 0xc3, 0xc4, 0x08, 0x61, 0x32, 0xa4, 0x5c, 0x8a, 0x81, 0x20, 0x45, 0x02, 0x0b, \n\t0x41, 0xc3, 0xa9, 0x00, 0x82, 0x02, 0x1b, 0x40, 0xd9, 0x64, 0x60, 0x00, 0x70, 0x89, 0xa4, 0x8c, \n\t0x20, 0x2c, 0x05, 0x90, 0x02, 0x40, 0x8c, 0x09, 0x02, 0x64, 0x20, 0x96, 0x05, 0x45, 0xc0, 0x10, \n\t0x93, 0x40, 0x30, 0x31, 0x08, 0x88, 0x14, 0x00, 0x20, 0x11, 0x94, 0x0a, 0x8f, 0x02, 0x82, 0x0a, \n\t0x15, 0x0c, 0x0e, 0x24, 0x4c, 0x34, 0xda, 0x8e, 0x80, 0x10, 0x43, 0x22, 0x00, 0xe0, 0x0c, 0x81, \n\t0x00, 0x28, 0x16, 0x22, 0xb9, 0x0c, 0x95, 0x90, 0xaa, 0x18, 0x84, 0x52, 0x29, 0x10, 0x09, 0x41, \n\t0x20, 0x26, 0x9a, 0xa0, 0x41, 0x58, 0x80, 0x74, 0x40, 0x93, 0x0d, 0xa0, 0x90, 0x06, 0x30, 0x10, \n\t0xa3, 0x82, 0x81, 0x12, 0x80, 0x56, 0xa7, 0x50, 0x00, 0x10, 0x41, 0xcd, 0x00, 0xa7, 0x00, 0xa2, \n\t0x08, 0xcc, 0x06, 0x0e, 0xb1, 0x41, 0x36, 0x91, 0x08, 0xc4, 0x20, 0x40, 0xc2, 0xb1, 0xa0, 0x1d, \n\t0x24, 0x6c, 0x62, 0x42, 0x87, 0xb0, 0x1a, 0x0b, 0x42, 0x94, 0xb8, 0x21, 0x34, 0x07, 0x0a, 0x42, \n\t0x80, 0xd8, 0x80, 0x20, 0x02, 0xc6, 0x04, 0xe3, 0x00, 0x32, 0xd0, 0x00, 0x80, 0x66, 0xc1, 0x22, \n\t0x0c, 0x29, 0xca, 0x40, 0x08, 0x84, 0x29, 0x06, 0x25, 0x00, 0x26, 0x3c, 0x11, 0x18, 0x01, 0x84, \n\t0x08, 0x80, 0x24, 0x20, 0x42, 0x98, 0x84, 0x41, 0x20, 0x20, 0x24, 0x10, 0x8b, 0x1c, 0x43, 0x60, \n\t0x02, 0x14, 0x00, 0x27, 0x30, 0x94, 0x8d, 0x52, 0x84, 0x08, 0x14, 0x18, 0x05, 0x20, 0x38, 0x22, \n\t0xa1, 0x90, 0xa1, 0x0a, 0xcc, 0x0c, 0x00, 0x61, 0x01, 0x64, 0x57, 0x2d, 0x4c, 0x40, 0x01, 0xac, \n\t0x08, 0x16, 0x81, 0x10, 0xb1, 0xc3, 0x10, 0x4d, 0x49, 0x25, 0x46, 0x56, 0x18, 0x24, 0x38, 0x01, \n\t0x04, 0x00, 0x53, 0x80, 0x25, 0x65, 0x18, 0xa2, 0x12, 0x10, 0x13, 0xa0, 0x05, 0x89, 0x62, 0x48, \n\t0x24, 0x29, 0xa8, 0x00, 0x00, 0x01, 0x60, 0x55, 0x42, 0x29, 0x84, 0xc5, 0x80, 0x1c, 0x01, 0x78, \n\t0xb8, 0x05, 0x55, 0x48, 0x32, 0xc0, 0x00, 0x00, 0x90, 0x90, 0x2c, 0x6a, 0xa1, 0x82, 0x0d, 0xe0, \n\t0x56, 0xc9, 0x18, 0x00, 0x10, 0x01, 0x50, 0x94, 0x44, 0x42, 0x90, 0x08, 0x04, 0xa4, 0x86, 0xa2, \n\t0x2c, 0x41, 0x51, 0x9a, 0x48, 0x1b, 0x87, 0x06, 0x21, 0x00, 0x1e, 0x40, 0xc8, 0x82, 0x42, 0x82, \n\t0x20, 0x09, 0x21, 0x94, 0x80, 0x28, 0x51, 0x39, 0x04, 0x8c, 0x10, 0x0b, 0x3a, 0x63, 0x20, 0x20, \n\t0x08, 0x10, 0xe6, 0x04, 0xc1, 0x51, 0x00, 0xa0, 0x48, 0x4e, 0x08, 0x81, 0x08, 0x26, 0xd1, 0x4b, \n\t0x06, 0x40, 0xf4, 0x22, 0x20, 0x18, 0x54, 0x61, 0x38, 0x36, 0xc9, 0x8a, 0x88, 0x12, 0x4c, 0x30, \n\t0x02, 0x13, 0x01, 0x10, 0x01, 0x05, 0x02, 0x22, 0x98, 0x80, 0xe5, 0x06, 0x24, 0x50, 0x12, 0x92, \n\t0x32, 0x48, 0x10, 0x65, 0x08, 0x55, 0x02, 0xa4, 0x28, 0x04, 0xa2, 0x0a, 0x57, 0x82, 0xb1, 0xc8, \n\t0x08, 0x82, 0x42, 0x04, 0x81, 0x12, 0x94, 0x04, 0x2b, 0x0c, 0x45, 0x83, 0x88, 0x40, 0x0c, 0x22, \n\t0x64, 0x10, 0x83, 0x32, 0x70, 0x00, 0x09, 0x10, 0x72, 0x61, 0x00, 0x44, 0x50, 0xc4, 0x12, 0x80, \n\t0x40, 0x02, 0x00, 0x02, 0x01, 0x22, 0x24, 0x69, 0x04, 0x49, 0x03, 0x07, 0x34, 0x00, 0x08, 0x00, \n\t0x01, 0x46, 0x29, 0x54, 0x12, 0x20, 0xa2, 0x40, 0x10, 0xca, 0x00, 0x12, 0x21, 0x91, 0x41, 0x10, \n\t0x80, 0x0e, 0x00, 0xa8, 0x08, 0x21, 0x42, 0x40, 0x4e, 0x05, 0x89, 0x28, 0x88, 0x49, 0x0c, 0x02, \n\t0x44, 0xca, 0x25, 0xb0, 0x13, 0xc8, 0x00, 0xc5, 0x91, 0xa0, 0x28, 0x11, 0x4e, 0x76, 0x42, 0x01, \n\t0x32, 0x11, 0xc6, 0x80, 0x00, 0xc2, 0x38, 0x14, 0x51, 0x81, 0xc3, 0x28, 0x41, 0x00, 0x1a, 0x2c, \n\t0x10, 0x41, 0x58, 0x80, 0x08, 0x17, 0x38, 0xd2, 0x27, 0x02, 0x00, 0x81, 0x1c, 0x90, 0x03, 0xc5, \n\t0x52, 0x91, 0x68, 0xa4, 0x09, 0x88, 0x03, 0x48, 0xc0, 0xd0, 0x05, 0x94, 0x00, 0x20, 0x68, 0x05, \n\t0x3a, 0xae, 0x0c, 0xc2, 0xe7, 0x0a, 0x84, 0x33, 0x84, 0x08, 0x48, 0x20, 0x50, 0x40, 0xd3, 0x05, \n\t0x30, 0xd5, 0xa8, 0x20, 0x03, 0x0b, 0x84, 0x98, 0x04, 0x22, 0x44, 0x25, 0x48, 0x01, 0x64, 0x0a, \n\t0x86, 0x14, 0x82, 0x51, 0x88, 0x80, 0x0a, 0x83, 0x30, 0xa6, 0x82, 0x0a, 0xa0, 0x1c, 0x01, 0x08, \n\t0xc1, 0xb8, 0x01, 0x48, 0x04, 0x6c, 0x4a, 0x86, 0x11, 0x0d, 0x8c, 0x91, 0x8c, 0x0c, 0x02, 0x50, \n\t0x07, 0xa4, 0x08, 0x43, 0x34, 0x56, 0x60, 0x20, 0x10, 0x08, 0x06, 0x68, 0xc4, 0x20, 0xae, 0x3c, \n\t0x81, 0x46, 0x0c, 0x10, 0x40, 0x81, 0x09, 0x80, 0xa2, 0x10, 0x41, 0x93, 0x33, 0x4c, 0x80, 0x21, \n\t0x0c, 0x80, 0xa2, 0x06, 0xc4, 0x00, 0xc5, 0x30, 0xf0, 0x19, 0x03, 0xd0, 0x00, 0xc1, 0x0e, 0x36, \n\t0x00, 0x0d, 0xd1, 0x8c, 0x02, 0x22, 0x13, 0xc8, 0x82, 0x18, 0x53, 0x20, 0x08, 0x84, 0x0a, 0x9a, \n\t0xd0, 0x53, 0x48, 0x00, 0x00, 0x00, 0x10, 0x1c, 0xc4, 0x20, 0x00, 0x90, 0x6a, 0x05, 0x18, 0x06, \n\t0x09, 0x44, 0x10, 0xb1, 0x95, 0x0c, 0x90, 0x05, 0x2e, 0x21, 0x80, 0x08, 0x49, 0x05, 0x00, 0x22, \n\t0x44, 0xc3, 0x10, 0x88, 0xdd, 0xa2, 0x42, 0x35, 0x29, 0x30, 0x45, 0x08, 0x21, 0x78, 0x40, 0x52, \n\t0x04, 0x40, 0x05, 0x6a, 0x10, 0x43, 0x02, 0x88, 0x65, 0x02, 0x42, 0x1e, 0xc0, 0x18, 0x82, 0x34, \n\t0xd0, 0x08, 0x28, 0x85, 0x4a, 0x83, 0x14, 0x02, 0x41, 0x10, 0x33, 0x03, 0x12, 0xa9, 0x1c, 0x0a, \n\t0x0c, 0x04, 0x82, 0x21, 0x1c, 0x86, 0x86, 0x06, 0xd3, 0x68, 0xab, 0xc1, 0x08, 0xc0, 0x40, 0x60, \n\t0xd2, 0x20, 0x10, 0x10, 0x0e, 0x06, 0xe0, 0xa8, 0x05, 0x21, 0x05, 0x81, 0x22, 0x43, 0x9a, 0x95, \n\t0x44, 0x99, 0x06, 0x04, 0x11, 0xf0, 0x31, 0xbc, 0x12, 0x22, 0x54, 0x80, 0x63, 0x36, 0x34, 0x04, \n\t0xc2, 0x40, 0xd1, 0x4a, 0x90, 0x20, 0xc9, 0x00, 0x18, 0x40, 0x50, 0x84, 0x81, 0xc0, 0x4b, 0x68, \n\t0x00, 0x21, 0x90, 0x28, 0xd7, 0x04, 0x20, 0x60, 0x20, 0x04, 0x20, 0x43, 0x41, 0x42, 0x20, 0x18, \n\t0x24, 0x94, 0xc7, 0x80, 0x08, 0x30, 0x03, 0x87, 0x40, 0x1c, 0x46, 0x14, 0x02, 0x20, 0xa6, 0xd5, \n\t0x88, 0x04, 0x20, 0x54, 0x20, 0x29, 0x35, 0x11, 0x87, 0x52, 0x40, 0x60, 0x23, 0xa5, 0x06, 0x0c, \n\t0x44, 0x24, 0x71, 0x20, 0x20, 0xd0, 0xe2, 0x08, 0x40, 0x89, 0x8c, 0x40, 0x18, 0x81, 0x10, 0x30, \n\t0x01, 0x01, 0x09, 0x03, 0x2f, 0x20, 0x34, 0x18, 0x1c, 0x14, 0x8a, 0x0c, 0x58, 0xa0, 0x01, 0xa8, \n\t0x94, 0x47, 0x40, 0x30, 0x04, 0x42, 0x13, 0x99, 0x00, 0x2b, 0x18, 0x20, 0xf2, 0x35, 0x2c, 0x84, \n\t0x40, 0x52, 0x20, 0x83, 0x0c, 0x54, 0x88, 0x20, 0x4c, 0x62, 0xa0, 0x04, 0x15, 0x99, 0xec, 0x0e, \n\t0xa3, 0x02, 0x14, 0x21, 0x40, 0x60, 0x0a, 0x42, 0xe2, 0x80, 0x20, 0x91, 0x08, 0x2e, 0x40, 0x3a, \n\t0x22, 0xbc, 0x02, 0x22, 0x46, 0xc1, 0x60, 0x18, 0x89, 0x4c, 0xa4, 0x02, 0x90, 0x42, 0x20, 0x00, \n\t0xc3, 0xe8, 0x04, 0x10, 0x31, 0x24, 0x44, 0x87, 0x4d, 0x1a, 0x02, 0xa9, 0x0b, 0x90, 0x08, 0x2d, \n\t0x42, 0xd6, 0x6a, 0x10, 0x91, 0x10, 0x0c, 0x42, 0xa4, 0x02, 0x09, 0x48, 0x01, 0x40, 0x42, 0x51, \n\t0x82, 0x00, 0x9d, 0x04, 0xa0, 0x40, 0x36, 0x41, 0x20, 0x04, 0x51, 0x06, 0x46, 0x60, 0x8a, 0x0b, \n\t0x44, 0x01, 0x05, 0x10, 0x92, 0x11, 0x04, 0x21, 0x00, 0x88, 0x24, 0x05, 0x90, 0x13, 0x68, 0x00, \n\t0x43, 0x4c, 0x21, 0x62, 0x22, 0x80, 0x15, 0xa2, 0x14, 0x41, 0x80, 0x11, 0x44, 0x40, 0x82, 0x08, \n\t0x02, 0x40, 0x93, 0x00, 0x52, 0x8e, 0x10, 0x52, 0x82, 0xa4, 0x2c, 0x4a, 0x45, 0x40, 0x04, 0xc0, \n\t0x09, 0xa8, 0x0d, 0x4a, 0x00, 0x12, 0x48, 0x34, 0x89, 0x03, 0xa3, 0x00, 0xb1, 0xe2, 0x28, 0x15, \n\t0x10, 0x09, 0x08, 0xe1, 0x03, 0x93, 0x04, 0x82, 0xa0, 0x46, 0xe2, 0xb0, 0x08, 0x00, 0xc6, 0x00, \n\t0x1c, 0x42, 0xc0, 0x32, 0x01, 0x57, 0x00, 0x02, 0x10, 0x32, 0x06, 0x1c, 0x43, 0x81, 0x5a, 0xc2, \n\t0x01, 0x8e, 0x55, 0x14, 0xab, 0x30, 0x14, 0x09, 0x03, 0x70, 0xc4, 0x23, 0x32, 0xa0, 0x21, 0xa2, \n\t0x44, 0x4d, 0x82, 0x08, 0xd4, 0x68, 0x2a, 0x8c, 0x11, 0x60, 0x06, 0x64, 0x00, 0x16, 0x90, 0x82, \n\t0xa4, 0x00, 0x00, 0x02, 0x09, 0x29, 0x11, 0x4c, 0x44, 0x00, 0x29, 0x05, 0xf0, 0x16, 0x44, 0x50, \n\t0xa0, 0x21, 0x15, 0x1c, 0x49, 0xac, 0x20, 0x42, 0xb8, 0x80, 0x09, 0x48, 0x23, 0x50, 0x44, 0x6a, \n\t0x21, 0x41, 0xc8, 0x80, 0x20, 0x34, 0xe8, 0xb0, 0x09, 0x18, 0x02, 0x00, 0x20, 0x99, 0xb0, 0x45, \n\t0x04, 0x05, 0x04, 0x74, 0x08, 0x10, 0xe1, 0x02, 0x05, 0x0a, 0xc3, 0x40, 0x82, 0xd1, 0x94, 0x00, \n\t0x08, 0x33, 0x42, 0x25, 0xa0, 0x19, 0x40, 0x56, 0x20, 0x20, 0x11, 0xc8, 0x8a, 0x0c, 0x06, 0x86, \n\t0x58, 0x08, 0xc0, 0x04, 0xa3, 0x18, 0xa1, 0x72, 0x80, 0x51, 0x04, 0x88, 0x10, 0x00, 0xa1, 0x14, \n\t0x14, 0x02, 0xec, 0x44, 0x67, 0x02, 0x18, 0x48, 0x11, 0x41, 0x32, 0x00, 0x08, 0x23, 0x08, 0x1b, \n\t0x22, 0x60, 0x60, 0x98, 0x24, 0x10, 0x40, 0xc1, 0x6a, 0x45, 0x48, 0x2a, 0xf4, 0x40, 0x07, 0x42, \n\t0x06, 0x58, 0x98, 0x80, 0x85, 0x62, 0x20, 0x02, 0x31, 0xbb, 0x04, 0x13, 0x82, 0x60, 0x52, 0x0b, \n\t0x91, 0x24, 0x01, 0x61, 0x0c, 0x80, 0x0b, 0x01, 0x20, 0x8c, 0x2c, 0x3c, 0x00, 0x50, 0x31, 0x00, \n\t0x51, 0x48, 0x1a, 0x02, 0x20, 0x22, 0x0d, 0x80, 0xc4, 0x28, 0x06, 0x82, 0x09, 0xcc, 0x43, 0x4d, \n\t0x0a, 0xa1, 0x02, 0x1a, 0x05, 0x86, 0x82, 0x5a, 0x12, 0x62, 0xa4, 0x68, 0x09, 0x0e, 0x20, 0x44, \n\t0x09, 0x10, 0x50, 0x05, 0x89, 0x0a, 0x23, 0x28, 0x0c, 0x94, 0x05, 0x22, 0x40, 0x01, 0x12, 0x02, \n\t0x10, 0x80, 0x21, 0x02, 0x45, 0x08, 0x20, 0xa0, 0x08, 0x02, 0x1a, 0x55, 0xe0, 0x9d, 0x04, 0x51, \n\t0x09, 0x1c, 0x14, 0x23, 0x8a, 0xc1, 0x00, 0x64, 0x36, 0x20, 0xa2, 0x19, 0xd5, 0x42, 0x2c, 0x14, \n\t0x72, 0x40, 0x80, 0x90, 0x0a, 0x2e, 0x54, 0x06, 0x92, 0x26, 0xc0, 0x81, 0x61, 0x00, 0x40, 0x00, \n\t0x25, 0x68, 0x83, 0xa6, 0x34, 0x01, 0xa0, 0x01, 0x85, 0x50, 0x0a, 0x10, 0x65, 0x81, 0x87, 0x49, \n\t0x1a, 0x02, 0x12, 0xa1, 0x38, 0x94, 0x60, 0x48, 0x86, 0x20, 0x62, 0x08, 0x80, 0xe8, 0x09, 0x05, \n\t0x00, 0xf1, 0x21, 0x01, 0xc1, 0x97, 0x48, 0x60, 0xd5, 0x8a, 0x08, 0xa8, 0x10, 0x00, 0x00, 0x01, \n\t0x30, 0x04, 0x68, 0x08, 0x01, 0x1e, 0x80, 0x08, 0x09, 0x94, 0x07, 0x81, 0x00, 0x10, 0x90, 0x20, \n\t0x88, 0x12, 0x85, 0x4c, 0x56, 0x01, 0x06, 0x5d, 0x48, 0x60, 0x46, 0x02, 0x2a, 0x85, 0x40, 0x50, \n\t0x60, 0x10, 0x01, 0x02, 0xaf, 0xa8, 0x58, 0x0e, 0x4a, 0x60, 0xa0, 0x15, 0x11, 0x9d, 0x22, 0x28, \n\t0x86, 0x41, 0xb0, 0x74, 0x48, 0xa8, 0x64, 0x03, 0x02, 0x08, 0xa5, 0x02, 0x0b, 0x06, 0xb1, 0x38, \n\t0x09, 0x40, 0xd4, 0x07, 0x20, 0x84, 0x2a, 0x96, 0x2c, 0x93, 0x08, 0x50, 0x50, 0x69, 0x03, 0xb0, \n\t0x95, 0x0f, 0x70, 0x94, 0xea, 0x30, 0x00, 0x00, 0xe7, 0x02, 0x00, 0x50, 0x01, 0x19, 0x84, 0x86, \n\t0x10, 0x25, 0x02, 0x32, 0x88, 0xc9, 0xc3, 0x24, 0x31, 0xb8, 0x04, 0x24, 0x11, 0x01, 0x30, 0x94, \n\t0x11, 0x0e, 0x20, 0x49, 0x80, 0x12, 0x05, 0x10, 0xa0, 0x90, 0x9e, 0x23, 0x7c, 0x04, 0x18, 0x08, \n\t0x41, 0x08, 0x2c, 0x04, 0x03, 0xc2, 0x93, 0x05, 0x05, 0x08, 0x32, 0x92, 0x18, 0x03, 0xe0, 0x4c, \n\t0x41, 0x0a, 0x02, 0xa2, 0x9c, 0x0c, 0x16, 0x24, 0x18, 0x42, 0x49, 0x18, 0x20, 0x5a, 0x02, 0x40, \n\t0x24, 0x72, 0x19, 0x84, 0x82, 0x45, 0x58, 0x40, 0x29, 0x04, 0x40, 0x08, 0x04, 0x20, 0x73, 0xa0, \n\t0xae, 0x89, 0x59, 0x06, 0x00, 0x80, 0x30, 0x86, 0x30, 0x8d, 0x80, 0x64, 0x06, 0x62, 0x10, 0x08, \n\t0x46, 0x82, 0x40, 0x41, 0x3a, 0x81, 0x8c, 0x47, 0x00, 0x22, 0x42, 0x3b, 0x04, 0x44, 0x11, 0xa1, \n\t0x22, 0xf0, 0xc2, 0x81, 0x10, 0x44, 0x8b, 0x3a, 0x13, 0x41, 0x00, 0xb1, 0x41, 0x42, 0x68, 0x92, \n\t0xe1, 0x04, 0xa4, 0x53, 0x28, 0x00, 0xc4, 0x10, 0x92, 0x69, 0x40, 0x02, 0x16, 0x24, 0xf1, 0x24, \n\t0x2c, 0x50, 0x02, 0x4c, 0x61, 0xa0, 0xa0, 0x10, 0x0e, 0x89, 0x00, 0x41, 0x82, 0xb9, 0x98, 0x90, \n\t0x0e, 0x02, 0xb1, 0x18, 0x1d, 0x20, 0x98, 0x81, 0x10, 0x85, 0x00, 0x98, 0x20, 0x80, 0x02, 0x2a, \n\t0x00, 0x01, 0x12, 0x88, 0x03, 0x42, 0x52, 0x60, 0x70, 0x24, 0x4c, 0x1c, 0x0a, 0x34, 0x72, 0x01, \n\t0x22, 0x61, 0x43, 0x81, 0x10, 0x12, 0x18, 0x92, 0x20, 0x12, 0x00, 0x5a, 0x95, 0x68, 0x20, 0x84, \n\t0x8e, 0x45, 0x26, 0x82, 0x00, 0x8f, 0x30, 0x8c, 0x40, 0x00, 0xb2, 0x01, 0x00, 0x2c, 0x40, 0x80, \n\t0x0c, 0x03, 0x09, 0x80, 0x0c, 0x06, 0x6a, 0x28, 0xc4, 0xf3, 0x8d, 0x99, 0x08, 0x00, 0x04, 0x52, \n\t0x1a, 0xac, 0x04, 0x1b, 0x80, 0x08, 0xc0, 0x39, 0x23, 0x2c, 0x16, 0x0c, 0x62, 0x01, 0xc9, 0x02, \n\t0x24, 0x14, 0xe2, 0x26, 0x60, 0x81, 0x82, 0x80, 0x51, 0x48, 0x72, 0x61, 0x00, 0x92, 0x79, 0x02, \n\t0x86, 0x30, 0xe0, 0x48, 0x21, 0xc4, 0x13, 0x00, 0x50, 0x17, 0x28, 0x29, 0x88, 0x05, 0x09, 0x4c, \n\t0x84, 0x9a, 0x93, 0xc1, 0xc2, 0x61, 0x06, 0x80, 0xc3, 0x04, 0x60, 0x54, 0x0b, 0x18, 0x00, 0xd8, \n\t0x85, 0xc0, 0x88, 0x29, 0x38, 0x10, 0x41, 0x05, 0x50, 0x0a, 0xc6, 0x26, 0x54, 0x80, 0x10, 0x08, \n\t0x0a, 0x65, 0x58, 0x00, 0x81, 0x81, 0x64, 0x80, 0xa8, 0x40, 0x21, 0x91, 0x24, 0x01, 0x5c, 0x09, \n\t0x4c, 0x00, 0x13, 0x16, 0x18, 0x14, 0x0a, 0x42, 0xa0, 0x98, 0x00, 0x48, 0xcd, 0x08, 0x20, 0x86, \n\t0x11, 0x20, 0x00, 0xc4, 0x81, 0x2a, 0xb1, 0x00, 0x88, 0x24, 0x4d, 0x40, 0x0e, 0x84, 0x10, 0x0e, \n\t0x19, 0xda, 0x01, 0x50, 0x36, 0x18, 0x0c, 0x88, 0x86, 0x0c, 0x54, 0xc2, 0x02, 0x09, 0x0d, 0x00, \n\t0x21, 0x38, 0x11, 0x30, 0x88, 0x90, 0x42, 0x8f, 0x08, 0x07, 0x00, 0xae, 0x10, 0x04, 0x00, 0x2a, \n\t0xc6, 0x23, 0x16, 0x45, 0x50, 0x80, 0x0a, 0x50, 0x2a, 0x92, 0x95, 0x58, 0xe0, 0x28, 0x60, 0x81, \n\t0x18, 0x00, 0x54, 0xae, 0x10, 0xf0, 0x00, 0xa9, 0x40, 0x0d, 0x4d, 0x0a, 0x12, 0x58, 0x27, 0x10, \n\t0x01, 0x82, 0x2a, 0x50, 0x08, 0x24, 0x0c, 0x49, 0x68, 0x50, 0xa0, 0x48, 0x94, 0x00, 0xdb, 0x40, \n\t0x00, 0x00, 0x02, 0x11, 0x04, 0x86, 0x25, 0x4c, 0x03, 0x8a, 0x04, 0x04, 0x00, 0x28, 0x5c, 0x53, \n\t0x03, 0x25, 0x00, 0xd0, 0x26, 0x0a, 0x24, 0x28, 0x00, 0x69, 0xd8, 0x00, 0x24, 0x53, 0x50, 0x8e, \n\t0xc0, 0x44, 0x86, 0x0e, 0x20, 0xc1, 0x13, 0x01, 0x9c, 0x29, 0x28, 0x86, 0xc0, 0x14, 0x2d, 0x45, \n\t0x60, 0x02, 0x90, 0x80, 0x01, 0xe9, 0x41, 0x4c, 0x22, 0x84, 0x20, 0x92, 0xc1, 0x92, 0x0e, 0x50, \n\t0x16, 0x48, 0xa1, 0x08, 0xd0, 0x00, 0x20, 0xc0, 0x40, 0x09, 0x40, 0x01, 0x41, 0x6c, 0x12, 0x10, \n\t0x24, 0x15, 0x82, 0x8a, 0x14, 0xe0, 0xe1, 0xaa, 0xb8, 0x18, 0x45, 0x10, 0x50, 0x60, 0x21, 0x09, \n\t0x08, 0xc7, 0x04, 0x06, 0x18, 0x24, 0x40, 0x04, 0x21, 0x08, 0x07, 0x93, 0xb3, 0x05, 0x12, 0x20, \n\t0x00, 0x20, 0x91, 0x15, 0x28, 0x48, 0x29, 0x04, 0xc0, 0x18, 0x04, 0x60, 0x48, 0xa4, 0x44, 0xa2, \n\t0x0a, 0x08, 0x88, 0x88, 0x05, 0x26, 0x00, 0x00, 0xb4, 0xc4, 0x10, 0x8c, 0x30, 0x12, 0xe8, 0x90, \n\t0x10, 0x15, 0x49, 0x04, 0xa0, 0x21, 0x80, 0x70, 0x52, 0x24, 0x0a, 0xb4, 0x90, 0x05, 0x34, 0x80, \n\t0xc9, 0x4a, 0xd0, 0x0b, 0x09, 0x18, 0x82, 0x42, 0x7c, 0x23, 0x61, 0x0c, 0x0c, 0x88, 0x44, 0x04, \n\t0x93, 0xb0, 0x28, 0x3c, 0x0d, 0xa0, 0x32, 0x84, 0x6a, 0x0a, 0xa1, 0xc7, 0x06, 0x26, 0x01, 0x4a, \n\t0x22, 0x15, 0x44, 0x81, 0x14, 0x02, 0x19, 0x28, 0x4c, 0x00, 0x00, 0x10, 0x10, 0x82, 0x98, 0x04, \n\t0x02, 0x29, 0x28, 0xe0, 0x60, 0x0b, 0x01, 0x0b, 0x8a, 0x28, 0x04, 0x00, 0x85, 0x80, 0xc1, 0x08, \n\t0x1e, 0x76, 0x80, 0x01, 0xb0, 0x42, 0x2e, 0x0c, 0x12, 0x30, 0x09, 0x10, 0x15, 0xec, 0x40, 0xa3, \n\t0x02, 0x81, 0x01, 0x90, 0x8d, 0x44, 0xa3, 0xd1, 0x04, 0x14, 0x00, 0x67, 0x00, 0xc2, 0x80, 0x02, \n\t0x60, 0x8f, 0xc4, 0x06, 0x90, 0x18, 0x34, 0xc8, 0x8d, 0x06, 0x20, 0x01, 0x30, 0x20, 0x3c, 0x08, \n\t0x40, 0x00, 0xe4, 0x49, 0x12, 0xcc, 0x08, 0x41, 0x02, 0xf0, 0x08, 0x31, 0x04, 0x02, 0x40, 0x00, \n\t0x04, 0x21, 0x84, 0xa1, 0xd2, 0x43, 0x42, 0x84, 0x09, 0x03, 0x38, 0xda, 0x01, 0x18, 0x24, 0x80, \n\t0x83, 0x31, 0x92, 0xac, 0x00, 0xb0, 0x4b, 0x00, 0xe1, 0xc1, 0x08, 0x44, 0x03, 0x03, 0x00, 0x81, \n\t0x14, 0x82, 0x04, 0x12, 0x60, 0x09, 0x44, 0x11, 0x23, 0x46, 0x24, 0xa0, 0x2c, 0x05, 0x82, 0x82, \n\t0x08, 0xc6, 0x3b, 0xb4, 0x40, 0x04, 0x26, 0x28, 0x15, 0x60, 0x87, 0x10, 0x83, 0x80, 0x04, 0x02, \n\t0x11, 0x2e, 0x1c, 0x48, 0x4d, 0x74, 0x65, 0xc2, 0x92, 0x10, 0x0d, 0x29, 0x08, 0x00, 0x01, 0x01, \n\t0x14, 0xc3, 0x82, 0x38, 0x93, 0x62, 0x00, 0x00, 0x58, 0x68, 0x10, 0x45, 0x03, 0x15, 0x40, 0x04, \n\t0xcd, 0x06, 0x94, 0xb0, 0x00, 0x01, 0x42, 0xe4, 0x0e, 0x42, 0x5a, 0x29, 0xb4, 0x0e, 0xe4, 0x60, \n\t0x10, 0x02, 0x08, 0xd0, 0x80, 0x0c, 0x40, 0x17, 0x82, 0xa5, 0x58, 0x00, 0x60, 0x1e, 0x11, 0x39, \n\t0x3b, 0x85, 0x00, 0x06, 0x76, 0x05, 0x00, 0xb0, 0xe8, 0x00, 0x8b, 0x40, 0x80, 0x38, 0x00, 0x00, \n\t0x50, 0x60, 0x20, 0x04, 0x13, 0x19, 0x28, 0x00, 0x44, 0x06, 0x11, 0x20, 0x1e, 0x30, 0x45, 0x0a, \n\t0x02, 0xf1, 0x8a, 0x12, 0x8c, 0x00, 0x68, 0x50, 0x70, 0x10, 0x0d, 0x81, 0x48, 0x24, 0x12, 0x04, \n\t0x20, 0x00, 0x11, 0x80, 0x2a, 0x58, 0x02, 0xcb, 0x81, 0xa0, 0x06, 0x47, 0x00, 0x44, 0xb1, 0x88, \n\t0x01, 0x42, 0x48, 0x28, 0xe3, 0x22, 0x00, 0x31, 0x51, 0x06, 0x2e, 0x90, 0xc1, 0x10, 0xc1, 0x49, \n\t0x28, 0x50, 0x64, 0x0b, 0x01, 0x00, 0x94, 0x80, 0x08, 0x82, 0x98, 0x38, 0x09, 0x55, 0xa1, 0x24, \n\t0x00, 0x01, 0x00, 0xe1, 0x44, 0x20, 0x1a, 0x13, 0x10, 0x11, 0x04, 0x5a, 0xc4, 0x00, 0x01, 0xc0, \n\t0x26, 0x0c, 0x05, 0x01, 0x6e, 0x32, 0x01, 0x09, 0xd9, 0x89, 0x82, 0x52, 0xa4, 0x62, 0x0c, 0x81, \n\t0x10, 0xcb, 0x10, 0x70, 0x61, 0x84, 0x24, 0x00, 0x03, 0x60, 0x80, 0xa0, 0xa8, 0x50, 0x48, 0x80, \n\t0x44, 0x63, 0x08, 0x84, 0x08, 0x46, 0xc1, 0x52, 0xc4, 0x81, 0x8c, 0x49, 0x92, 0x04, 0x28, 0x10, \n\t0x53, 0x22, 0x60, 0x45, 0x01, 0x5e, 0x25, 0xd8, 0x10, 0x58, 0x00, 0x6d, 0x02, 0x84, 0x03, 0xa1, \n\t0x3c, 0x48, 0x24, 0x32, 0x04, 0x68, 0x01, 0x20, 0x09, 0xc5, 0x00, 0xc1, 0x43, 0x8e, 0x30, 0x42, \n\t0x2c, 0x42, 0xd5, 0xb8, 0x11, 0x00, 0xc2, 0x40, 0x0a, 0x04, 0x2a, 0x30, 0x30, 0x82, 0x4c, 0x00, \n\t0xb3, 0xc0, 0x26, 0x0c, 0x04, 0xe2, 0x20, 0x10, 0xa1, 0x00, 0x90, 0x93, 0x21, 0x28, 0x45, 0x10, \n\t0x30, 0x15, 0x8f, 0x44, 0x46, 0x50, 0x20, 0x0d, 0x8d, 0x01, 0x28, 0x30, 0x65, 0x58, 0x92, 0xe0, \n\t0xc0, 0x8a, 0x08, 0x20, 0x92, 0x0c, 0x20, 0x11, 0x85, 0x42, 0x14, 0x42, 0x08, 0xc1, 0x88, 0xe0, \n\t0x22, 0x13, 0x00, 0x2c, 0x61, 0xd8, 0x49, 0x0a, 0x64, 0xc0, 0x04, 0x80, 0x53, 0x64, 0x04, 0x85, \n\t0xd1, 0x80, 0x59, 0x12, 0x80, 0x08, 0x82, 0x61, 0x09, 0x11, 0x44, 0x20, 0x0e, 0x00, 0x60, 0x0d, \n\t0x19, 0x08, 0x2c, 0x04, 0xa0, 0x10, 0x38, 0x84, 0x03, 0x8e, 0x44, 0x23, 0x98, 0x18, 0x00, 0x44, \n\t0x41, 0x50, 0x53, 0x78, 0x88, 0x09, 0x45, 0x86, 0x60, 0x30, 0x20, 0x00, 0x29, 0x00, 0xc3, 0x52, \n\t0x05, 0x9a, 0x28, 0xc9, 0x15, 0xc2, 0x10, 0x63, 0x50, 0xb2, 0x20, 0x04, 0x22, 0x0a, 0x86, 0x09, \n\t0x0c, 0x45, 0x03, 0x04, 0x32, 0xd0, 0x02, 0xa6, 0x30, 0x18, 0x28, 0x68, 0x02, 0x02, 0x0a, 0x30, \n\t0x51, 0x02, 0x08, 0x06, 0x60, 0x10, 0xd1, 0xc1, 0x82, 0x06, 0xd1, 0xa2, 0x0b, 0xf9, 0x00, 0x2e, \n\t0x18, 0xa4, 0x02, 0x80, 0x4c, 0x58, 0xa3, 0x40, 0x10, 0x80, 0x04, 0x1c, 0x52, 0x03, 0x22, 0x41, \n\t0x81, 0x21, 0x04, 0x06, 0x0c, 0x10, 0x60, 0x00, 0x02, 0x55, 0x13, 0x60, 0x14, 0x00, 0x38, 0x18, \n\t0x01, 0x00, 0x45, 0x02, 0x10, 0x53, 0x31, 0x48, 0x08, 0x20, 0x06, 0xa4, 0x48, 0xaf, 0x40, 0x47, \n\t0x41, 0x60, 0x00, 0x21, 0x1a, 0x28, 0x82, 0x68, 0x74, 0x22, 0x81, 0x9e, 0x18, 0xc9, 0xe4, 0x74, \n\t0xa4, 0x43, 0x01, 0x64, 0x12, 0x23, 0x56, 0xb1, 0x50, 0x00, 0xc0, 0x00, 0x06, 0x00, 0x64, 0xc1, \n\t0xa4, 0x80, 0x03, 0x40, 0x28, 0xc1, 0x80, 0x19, 0x51, 0x04, 0xc1, 0x40, 0x41, 0x90, 0x9d, 0xa1, \n\t0x0c, 0x04, 0x0e, 0x64, 0x10, 0x00, 0x14, 0x92, 0x40, 0x42, 0x61, 0xa1, 0x90, 0xd0, 0x08, 0x0d, \n\t0x30, 0x22, 0x08, 0x00, 0x44, 0x07, 0xe2, 0x34, 0xe4, 0x41, 0x98, 0x84, 0x08, 0x41, 0x08, 0x05, \n\t0x22, 0x0f, 0x30, 0xc0, 0x44, 0x08, 0x13, 0x28, 0x06, 0x80, 0x11, 0x29, 0x48, 0x10, 0x0a, 0x3d, \n\t0x89, 0x10, 0xc2, 0x40, 0x32, 0x10, 0x04, 0xa4, 0x08, 0xcc, 0x34, 0x55, 0x03, 0xac, 0xd0, 0xc2, \n\t0x80, 0x02, 0x86, 0x0a, 0xa5, 0x50, 0x54, 0x20, 0x50, 0x04, 0xaa, 0x02, 0x6c, 0x5a, 0xa2, 0x2c, \n\t0x51, 0xfb, 0x00, 0x39, 0x03, 0x09, 0x40, 0x04, 0x92, 0xb4, 0x0d, 0x44, 0x05, 0x10, 0x86, 0x89, \n\t0x28, 0x21, 0x42, 0x47, 0x0a, 0x12, 0x68, 0x1e, 0xa0, 0x81, 0x02, 0x20, 0xd0, 0x61, 0x2f, 0x00, \n\t0x44, 0x25, 0x20, 0x04, 0x02, 0x0a, 0x98, 0x9a, 0xa0, 0x20, 0x04, 0x00, 0x24, 0x2c, 0x80, 0x02, \n\t0x00, 0x02, 0x48, 0x08, 0x14, 0x92, 0xa0, 0x00, 0x00, 0x52, 0x19, 0x49, 0x92, 0x41, 0x00, 0x44, \n\t0x20, 0x82, 0x44, 0x01, 0x81, 0x4c, 0x57, 0x98, 0x07, 0xe0, 0x96, 0x20, 0x42, 0x31, 0x02, 0xb0, \n\t0x51, 0x0d, 0x69, 0x6c, 0x85, 0x68, 0x24, 0x08, 0x05, 0x04, 0x26, 0xc4, 0xd8, 0x92, 0x85, 0x07, \n\t0x86, 0x38, 0x61, 0x40, 0x82, 0x80, 0x08, 0x02, 0x10, 0x34, 0x02, 0x3d, 0x30, 0x82, 0x0c, 0x40, \n\t0x05, 0x2a, 0x08, 0x50, 0x00, 0x40, 0x18, 0x10, 0x60, 0x15, 0x21, 0x13, 0x60, 0x02, 0x91, 0x18, \n\t0xa4, 0x81, 0x0a, 0x8a, 0x48, 0x14, 0x70, 0x94, 0x81, 0x4b, 0xc0, 0x0e, 0xb5, 0x90, 0x1a, 0x14, \n\t0x48, 0x00, 0x40, 0x12, 0x48, 0x26, 0x6c, 0x00, 0x84, 0x18, 0x10, 0x00, 0x85, 0x70, 0x82, 0xe8, \n\t0x42, 0xa0, 0x22, 0x80, 0x11, 0x40, 0x2b, 0x02, 0x96, 0xc9, 0x88, 0x58, 0x84, 0x0f, 0x30, 0xc5, \n\t0x28, 0x36, 0xe0, 0xc6, 0x4a, 0x10, 0x15, 0x00, 0x18, 0x80, 0x51, 0x08, 0x20, 0x82, 0xb1, 0x11, \n\t0xc0, 0x10, 0x09, 0x12, 0x22, 0x03, 0x21, 0x69, 0x44, 0x0e, 0x40, 0x00, 0x09, 0x02, 0x50, 0x98, \n\t0x4f, 0x00, 0x00, 0xf1, 0x1b, 0x00, 0xc2, 0x28, 0x46, 0x73, 0x82, 0x02, 0x01, 0x09, 0x83, 0x00, \n\t0x81, 0x42, 0x93, 0x0c, 0xc1, 0x02, 0x16, 0x41, 0x80, 0x83, 0x00, 0x50, 0x02, 0x60, 0x00, 0xd2, \n\t0x14, 0xa0, 0x11, 0x2a, 0x70, 0x80, 0x00, 0x03, 0xe1, 0x8b, 0x80, 0x10, 0x95, 0x08, 0x21, 0x51, \n\t0x8f, 0x00, 0x3a, 0x21, 0x83, 0x8a, 0x20, 0x94, 0x40, 0x4c, 0x73, 0x03, 0x07, 0xa8, 0x08, 0x80, \n\t0x18, 0x06, 0xc0, 0x09, 0x45, 0x40, 0x24, 0x10, 0xa0, 0x42, 0xa2, 0xa4, 0x08, 0x04, 0x18, 0x42, \n\t0x41, 0x10, 0x59, 0x01, 0x88, 0x66, 0x05, 0x1a, 0x0f, 0x14, 0x86, 0x81, 0x66, 0xd0, 0x39, 0x00, \n\t0x0c, 0x80, 0x00, 0x70, 0x11, 0x21, 0x12, 0x08, 0xc0, 0xe1, 0x0a, 0x60, 0x09, 0x9c, 0x91, 0x0c, \n\t0xe2, 0x64, 0x25, 0x5a, 0x90, 0x10, 0x08, 0x89, 0x3c, 0x74, 0x71, 0x24, 0x44, 0x05, 0x46, 0x08, \n\t0x00, 0x80, 0x80, 0xa8, 0xd9, 0x01, 0x1c, 0xb6, 0xb1, 0x8a, 0x10, 0x09, 0xaa, 0x56, 0x82, 0x58, \n\t0x00, 0x01, 0x94, 0x2d, 0x14, 0x21, 0xa2, 0x03, 0x85, 0x94, 0x20, 0x28, 0x41, 0x52, 0x80, 0xc5, \n\t0x01, 0x23, 0x08, 0x25, 0x20, 0xb1, 0x40, 0x08, 0x03, 0x00, 0x05, 0xe0, 0x0c, 0x08, 0xc2, 0xa0, \n\t0x06, 0x25, 0xaa, 0x05, 0x54, 0x1f, 0x08, 0x28, 0x60, 0x00, 0x18, 0xed, 0x50, 0x02, 0x02, 0x71, \n\t0x10, 0x28, 0x21, 0x41, 0x6d, 0x10, 0x90, 0x70, 0x22, 0x25, 0x83, 0x81, 0x50, 0xb3, 0xe0, 0x3c, \n\t0x98, 0x06, 0x20, 0x10, 0x55, 0x4b, 0x90, 0xc1, 0xd0, 0xc1, 0x40, 0x02, 0x11, 0x00, 0xb4, 0x40, \n\t0x8c, 0x10, 0x00, 0x4a, 0xa2, 0x90, 0x0c, 0x64, 0x20, 0x10, 0xc3, 0x9b, 0x19, 0x90, 0x01, 0x00, \n\t0x12, 0x28, 0x81, 0x30, 0x0e, 0x86, 0x22, 0x46, 0x99, 0x81, 0x44, 0x1a, 0x08, 0x0c, 0x05, 0xa1, \n\t0x10, 0xf0, 0x0c, 0x21, 0x00, 0xe1, 0x32, 0x00, 0x58, 0x08, 0xe8, 0x00, 0x62, 0x83, 0x18, 0x00, \n\t0x82, 0x47, 0x12, 0x62, 0x59, 0x01, 0xa0, 0x19, 0x80, 0x00, 0x50, 0xa8, 0x38, 0x80, 0x50, 0x48, \n\t0x12, 0xe0, 0x43, 0x18, 0xc8, 0xc4, 0x07, 0x40, 0x02, 0xa0, 0x01, 0x91, 0x05, 0xa8, 0x48, 0x00, \n\t0xc3, 0x0d, 0x09, 0x86, 0xe2, 0x54, 0x50, 0x10, 0x01, 0x91, 0x1a, 0x48, 0x0c, 0x71, 0x10, 0xa9, \n\t0x25, 0x80, 0x84, 0x04, 0x95, 0x48, 0x1f, 0x00, 0xd0, 0x28, 0x04, 0x30, 0x01, 0x27, 0x64, 0x88, \n\t0xe8, 0x0c, 0x06, 0x18, 0xb2, 0xd4, 0x0c, 0xe7, 0x22, 0x06, 0x00, 0x00, 0xac, 0x00, 0x28, 0x12, \n\t0x30, 0x48, 0x38, 0x11, 0x09, 0x8e, 0x42, 0x20, 0xa0, 0x24, 0x10, 0x8e, 0x09, 0x32, 0x10, 0x58, \n\t0x09, 0xd8, 0x93, 0x88, 0x44, 0x32, 0x10, 0x00, 0x84, 0x14, 0x84, 0x12, 0x21, 0x2a, 0xa6, 0x34, \n\t0x82, 0x01, 0x24, 0x43, 0x42, 0x10, 0x01, 0x42, 0x69, 0x00, 0x11, 0xb0, 0x13, 0x48, 0x81, 0x23, \n\t0x44, 0xd2, 0x2a, 0x18, 0x48, 0xd3, 0x04, 0x22, 0x70, 0xa1, 0x04, 0xb0, 0x88, 0x63, 0x06, 0x01, \n\t0x0a, 0x30, 0x81, 0x54, 0x40, 0x60, 0xd0, 0x08, 0x80, 0x30, 0x80, 0x64, 0x1e, 0x04, 0x41, 0x20, \n\t0x30, 0x0a, 0x41, 0x70, 0xe6, 0xc1, 0x19, 0x8c, 0x4e, 0x08, 0x54, 0x11, 0xca, 0x80, 0x20, 0x84, \n\t0x4e, 0x02, 0x30, 0x4b, 0x04, 0x0c, 0x80, 0x09, 0x40, 0xc0, 0x18, 0x29, 0x81, 0x00, 0x0d, 0x64, \n\t0xc6, 0x81, 0x02, 0x00, 0x13, 0x88, 0x60, 0x11, 0x10, 0x2e, 0x48, 0x0e, 0x43, 0x72, 0x50, 0x0a, \n\t0x8a, 0x84, 0xc5, 0x22, 0x20, 0x11, 0x20, 0x83, 0xa1, 0x01, 0x2a, 0x5c, 0x06, 0x32, 0x0c, 0x48, \n\t0x49, 0x8d, 0x42, 0x86, 0x98, 0x08, 0x01, 0x83, 0x43, 0x30, 0x82, 0x50, 0x98, 0x81, 0x49, 0x0a, \n\t0x22, 0x41, 0x6a, 0x84, 0x04, 0x0b, 0x0c, 0x1c, 0x03, 0x42, 0x80, 0x30, 0x56, 0xc1, 0x1c, 0x06, \n\t0x80, 0x30, 0x00, 0x04, 0xa1, 0x0a, 0x23, 0xa0, 0x01, 0x45, 0x10, 0x41, 0x28, 0x90, 0x81, 0x17, \n\t0x5c, 0x89, 0x04, 0x2c, 0x90, 0x00, 0x23, 0x4d, 0xd0, 0x05, 0x20, 0x02, 0x90, 0x8a, 0x25, 0x8a, \n\t0x22, 0x2a, 0x05, 0x30, 0x11, 0xd4, 0x06, 0xa2, 0x44, 0x65, 0x0a, 0x10, 0xc8, 0x05, 0x63, 0x10, \n\t0x50, 0x88, 0x2a, 0x01, 0xc4, 0x29, 0x28, 0x10, 0x20, 0x15, 0x51, 0x58, 0x84, 0x00, 0x44, 0x42, \n\t0x08, 0x80, 0x84, 0x41, 0x00, 0x32, 0xd2, 0x94, 0x10, 0x0c, 0x20, 0x04, 0x06, 0xea, 0x14, 0x60, \n\t0xc2, 0x6a, 0x02, 0x92, 0x21, 0x80, 0xe8, 0x10, 0x0b, 0x44, 0xc5, 0x60, 0x2f, 0x1d, 0xd0, 0x84, \n\t0x08, 0x20, 0x02, 0x84, 0x29, 0x18, 0x06, 0x42, 0x41, 0x50, 0x14, 0x48, 0x02, 0x86, 0x56, 0x21, \n\t0x48, 0x14, 0x01, 0xdb, 0x82, 0x24, 0x80, 0x5b, 0xae, 0x3c, 0x40, 0x80, 0x22, 0x10, 0x53, 0x02, \n\t0xad, 0x0a, 0x20, 0x08, 0x02, 0x18, 0xa5, 0x80, 0x1c, 0x42, 0x60, 0x70, 0xc1, 0x01, 0x0c, 0x96, \n\t0x2c, 0x0e, 0x90, 0x08, 0x09, 0x81, 0x50, 0x2d, 0x26, 0x04, 0xaa, 0x29, 0xc5, 0x01, 0x46, 0x5c, \n\t0x10, 0x53, 0x2b, 0xa8, 0x84, 0x00, 0x38, 0x53, 0x00, 0x01, 0x15, 0x98, 0x86, 0x0a, 0xc2, 0xaa, \n\t0x89, 0x60, 0x4e, 0xa0, 0x52, 0x04, 0x73, 0x8c, 0x40, 0x8a, 0x08, 0x16, 0x50, 0xa2, 0xb1, 0x24, \n\t0x0a, 0x69, 0x42, 0x05, 0x71, 0x24, 0xa0, 0x11, 0x42, 0x04, 0x90, 0xc1, 0x0a, 0x18, 0x08, 0xc9, \n\t0x26, 0x80, 0x01, 0x20, 0x35, 0x4a, 0x08, 0x58, 0xd0, 0x00, 0x91, 0x00, 0x47, 0x04, 0x76, 0x10, \n\t0x00, 0x83, 0x08, 0x80, 0x89, 0x60, 0x34, 0x2a, 0x0d, 0x88, 0x03, 0x86, 0x02, 0x82, 0x80, 0x0c, \n\t0x45, 0x82, 0x01, 0x60, 0x35, 0x60, 0x00, 0x01, 0x03, 0x6c, 0x48, 0x86, 0x90, 0x19, 0x08, 0x09, \n\t0x00, 0x18, 0x54, 0x01, 0x83, 0xe0, 0x47, 0x04, 0x14, 0x40, 0xb9, 0x80, 0x1c, 0x50, 0xaa, 0x02, \n\t0x03, 0x80, 0x00, 0x50, 0x50, 0xa8, 0x10, 0xb3, 0x00, 0x38, 0x44, 0x04, 0xe2, 0x28, 0x10, 0x20, \n\t0x2c, 0x60, 0x18, 0x40, 0x40, 0xa3, 0x41, 0x16, 0x0c, 0x09, 0x40, 0x20, 0x31, 0x31, 0x04, 0x10, \n\t0x19, 0x45, 0x22, 0xa0, 0x08, 0x28, 0x84, 0x45, 0xe0, 0x08, 0x21, 0xe0, 0x83, 0x04, 0x10, 0x43, \n\t0x54, 0x01, 0x82, 0x08, 0x80, 0x82, 0x46, 0x22, 0xe4, 0x10, 0x80, 0x70, 0x02, 0x81, 0x38, 0x51, \n\t0x33, 0x0e, 0x20, 0xcc, 0x28, 0x12, 0x11, 0x91, 0x26, 0xe1, 0x0c, 0x09, 0x18, 0x63, 0x40, 0x00, \n\t0x68, 0x19, 0x8a, 0x24, 0x50, 0x4a, 0x20, 0x25, 0x0d, 0x24, 0x2c, 0x64, 0x70, 0x0e, 0x45, 0x1c, \n\t0x0c, 0x08, 0x94, 0x83, 0x30, 0x28, 0xd7, 0x24, 0x40, 0x52, 0x70, 0x07, 0x20, 0x06, 0x00, 0x52, \n\t0x00, 0x20, 0x29, 0x60, 0x40, 0x84, 0x52, 0x40, 0x12, 0x00, 0x99, 0x10, 0x8f, 0x48, 0x11, 0x01, \n\t0x9d, 0x8c, 0x80, 0x22, 0x0e, 0x83, 0x32, 0x20, 0x4d, 0xc4, 0x03, 0x10, 0x46, 0x22, 0x22, 0xa1, \n\t0x41, 0x08, 0x3c, 0x10, 0xa0, 0x94, 0xc1, 0x91, 0x08, 0x70, 0x62, 0x1b, 0xaa, 0x31, 0x0c, 0x83, \n\t0x50, 0x17, 0xc9, 0x28, 0xc9, 0x01, 0x01, 0x0c, 0x04, 0x68, 0x30, 0x34, 0x40, 0x02, 0x00, 0xc2, \n\t0x43, 0x01, 0x00, 0x13, 0x08, 0x18, 0x00, 0xe2, 0x1f, 0x81, 0x14, 0xaa, 0x4c, 0x30, 0x98, 0x20, \n\t0x20, 0x46, 0xc7, 0x0c, 0x02, 0xc1, 0x80, 0x60, 0x00, 0x81, 0x18, 0x10, 0xe0, 0x2a, 0x49, 0xc8, \n\t0x41, 0x02, 0x26, 0xa2, 0x08, 0x25, 0x8f, 0x20, 0x72, 0x41, 0x1a, 0x00, 0xe1, 0x08, 0x00, 0x1e, \n\t0x20, 0x80, 0x84, 0xc8, 0x01, 0x03, 0x60, 0x43, 0xb9, 0x18, 0x41, 0x10, 0x8c, 0x24, 0xe6, 0x08, \n\t0x8a, 0xbc, 0x02, 0x00, 0x36, 0x41, 0x58, 0xa8, 0xa0, 0xc1, 0x00, 0x02, 0x12, 0x80, 0x83, 0x28, \n\t0x18, 0x65, 0x70, 0xa0, 0x00, 0x01, 0x18, 0x08, 0xa8, 0x22, 0x94, 0x52, 0x30, 0x01, 0x06, 0x04, \n\t0x40, 0xc0, 0x23, 0x07, 0x35, 0x00, 0xaa, 0x10, 0x44, 0x52, 0x09, 0x0c, 0x58, 0xe3, 0x0c, 0x80, \n\t0x10, 0x10, 0x78, 0x00, 0x41, 0x44, 0x41, 0xc1, 0x04, 0x29, 0x99, 0xaa, 0x00, 0x30, 0xc1, 0x10, \n\t0x05, 0x54, 0x29, 0x50, 0xc4, 0x29, 0x84, 0x60, 0x08, 0x44, 0x22, 0x24, 0xd0, 0x21, 0xc8, 0x04, \n\t0x48, 0x0c, 0x25, 0x00, 0x30, 0x40, 0xc6, 0x83, 0x68, 0x36, 0x82, 0x07, 0x1c, 0x89, 0x29, 0x02, \n\t0x22, 0x90, 0x02, 0x41, 0x85, 0x88, 0x0e, 0x02, 0x01, 0x04, 0x58, 0x11, 0x6e, 0x00, 0xb1, 0x69, \n\t0x00, 0x75, 0x94, 0x08, 0x10, 0x02, 0x70, 0x23, 0x95, 0x42, 0xe3, 0x28, 0x82, 0x10, 0x89, 0x14, \n\t0x10, 0x02, 0x0c, 0x80, 0x11, 0x04, 0x21, 0x12, 0x02, 0x66, 0x01, 0x6b, 0x21, 0xc8, 0x0a, 0xc0, \n\t0x24, 0x01, 0xe0, 0x12, 0xdc, 0x04, 0x4e, 0x20, 0x06, 0x0b, 0xb2, 0x90, 0x47, 0x05, 0x0a, 0x05, \n\t0x41, 0xb1, 0x44, 0x41, 0x01, 0x58, 0x94, 0x02, 0x32, 0x9c, 0xc8, 0x28, 0x04, 0x25, 0x50, 0x86, \n\t0x20, 0x06, 0x8b, 0x4c, 0x10, 0x10, 0x0d, 0x8c, 0x40, 0xc4, 0x12, 0x10, 0x08, 0x24, 0x20, 0x80, \n\t0x05, 0x44, 0x12, 0x42, 0x2c, 0xd9, 0x00, 0x4a, 0x04, 0xa2, 0x80, 0xa4, 0x24, 0x0d, 0x46, 0x2e, \n\t0xc4, 0x7b, 0x33, 0x80, 0x54, 0x04, 0x6a, 0x00, 0x00, 0x00, 0x21, 0x40, 0xaa, 0x10, 0xe1, 0xe0, \n\t0xa4, 0x10, 0x51, 0x01, 0x06, 0x90, 0x90, 0xa0, 0xe8, 0x80, 0x05, 0x30, 0x71, 0x28, 0x14, 0xe5, \n\t0x82, 0x43, 0x10, 0xa4, 0x42, 0x90, 0x8c, 0x84, 0x01, 0x58, 0x10, 0x1a, 0x01, 0xb9, 0x06, 0x80, \n\t0x68, 0x82, 0x40, 0x0d, 0x08, 0x14, 0x2a, 0x4c, 0x41, 0xf8, 0xa2, 0x01, 0x10, 0x22, 0x00, 0xa0, \n\t0x20, 0x90, 0xd4, 0x8a, 0x44, 0x0a, 0x52, 0x90, 0xa7, 0x70, 0x41, 0x05, 0x40, 0x01, 0x08, 0x07, \n\t0x80, 0x4d, 0x04, 0x60, 0x40, 0xc8, 0x00, 0x58, 0x94, 0xa0, 0x34, 0x02, 0xe8, 0x08, 0x00, 0x5d, \n\t0x02, 0x04, 0xe1, 0x52, 0x80, 0x28, 0x88, 0x07, 0x1e, 0xd0, 0x18, 0x9d, 0x30, 0x5e, 0x84, 0x28, \n\t0x60, 0x01, 0xbc, 0xb4, 0x0a, 0x00, 0x0e, 0x00, 0x41, 0x10, 0x21, 0x48, 0x80, 0x02, 0x30, 0x51, \n\t0x1c, 0x81, 0x00, 0x68, 0x0a, 0xc1, 0x20, 0x2d, 0x15, 0x0c, 0x61, 0x00, 0xb0, 0xd0, 0x11, 0x11, \n\t0x51, 0x00, 0x60, 0x70, 0x80, 0xb2, 0x69, 0xc5, 0x81, 0x44, 0x82, 0x03, 0x00, 0x8d, 0x41, 0xa8, \n\t0x42, 0x01, 0xaa, 0x82, 0x80, 0x44, 0x4b, 0x72, 0x00, 0x0b, 0xb2, 0x00, 0x18, 0x26, 0x54, 0xc0, \n\t0xc8, 0xa0, 0x54, 0x89, 0x2a, 0x0a, 0x82, 0x29, 0x1b, 0x51, 0x04, 0xc2, 0x52, 0x01, 0xe1, 0x3b, \n\t0x04, 0x48, 0x24, 0x40, 0x83, 0xc1, 0x04, 0x20, 0x12, 0xce, 0x00, 0xa0, 0x03, 0x04, 0x08, 0x01, \n\t0x08, 0x50, 0xd0, 0xb0, 0x08, 0xa4, 0x04, 0x26, 0x00, 0x84, 0xa2, 0x92, 0x00, 0x41, 0xcc, 0x62, \n\t0x80, 0x28, 0x15, 0x61, 0xc4, 0x41, 0x1c, 0xd1, 0x3a, 0x32, 0xc1, 0x09, 0x22, 0x08, 0x51, 0x90, \n\t0x05, 0x0d, 0x13, 0x80, 0x50, 0x00, 0x8a, 0x18, 0x48, 0x00, 0x60, 0x24, 0xe4, 0x42, 0x02, 0xc4, \n\t0x07, 0x42, 0x04, 0x11, 0x41, 0x82, 0x40, 0x00, 0x0d, 0x3a, 0xc0, 0x42, 0x94, 0x9c, 0xc2, 0x44, \n\t0x2e, 0x47, 0x70, 0x98, 0x60, 0x09, 0x2a, 0x60, 0x00, 0x33, 0x25, 0x5c, 0x14, 0x20, 0x00, 0x11, \n\t0x01, 0x08, 0x28, 0x0c, 0x2a, 0x24, 0xc0, 0x12, 0x09, 0x94, 0x0b, 0x8b, 0x22, 0xc0, 0x10, 0x16, \n\t0x70, 0x80, 0x04, 0x30, 0x00, 0xc9, 0xa6, 0xa8, 0x59, 0xa2, 0x02, 0x10, 0x1a, 0x01, 0x94, 0xc7, \n\t0xc1, 0x42, 0xa0, 0x18, 0x32, 0x18, 0x55, 0x20, 0x40, 0x63, 0x00, 0x9a, 0x24, 0xc1, 0x08, 0x00, \n\t0x32, 0x29, 0x00, 0x45, 0x41, 0x89, 0x58, 0x72, 0x80, 0x00, 0x90, 0x1c, 0x44, 0x00, 0x12, 0x18, \n\t0x02, 0x50, 0x08, 0x46, 0x2c, 0x80, 0xcb, 0x30, 0x59, 0x91, 0xec, 0x08, 0x00, 0xc2, 0x09, 0x89, \n\t0x12, 0x40, 0x0c, 0x20, 0x51, 0x02, 0x1c, 0x10, 0x05, 0x02, 0x60, 0xa8, 0xa0, 0x08, 0x0e, 0xa2, \n\t0x4c, 0x96, 0xc0, 0x9c, 0x84, 0x10, 0x82, 0x52, 0x00, 0x31, 0x20, 0xe5, 0x55, 0x28, 0x74, 0x80, \n\t0x18, 0x22, 0x24, 0x04, 0x0a, 0x02, 0xe1, 0x40, 0xa3, 0x99, 0x05, 0xe6, 0x08, 0x91, 0x50, 0x03, \n\t0x14, 0x8e, 0xc1, 0x60, 0x24, 0xeb, 0x12, 0xa0, 0x02, 0x60, 0x60, 0x40, 0x2a, 0x91, 0xf8, 0x80, \n\t0x2c, 0x14, 0x22, 0x48, 0x05, 0x34, 0x91, 0x2c, 0x12, 0xa2, 0x51, 0x81, 0x01, 0x9c, 0x62, 0x08, \n\t0xd1, 0xe1, 0x10, 0x85, 0x50, 0x2e, 0x20, 0x15, 0x80, 0x02, 0x00, 0x16, 0xe6, 0x72, 0x81, 0x13, \n\t0xa5, 0x40, 0xc2, 0x02, 0x02, 0x64, 0x09, 0x80, 0x65, 0x40, 0x80, 0x04, 0x44, 0x20, 0x30, 0x98, \n\t0x11, 0xc5, 0x32, 0x11, 0x50, 0x31, 0x08, 0x80, 0x04, 0x22, 0x77, 0x20, 0x0a, 0x24, 0x98, 0x00, \n\t0x00, 0x20, 0x48, 0xb3, 0x08, 0x88, 0x04, 0x24, 0xb3, 0x0a, 0x96, 0x00, 0x83, 0xa0, 0x34, 0x02, \n\t0x50, 0x39, 0x68, 0x04, 0x48, 0x14, 0x00, 0x00, 0x03, 0x04, 0x0a, 0xc9, 0x58, 0x01, 0x22, 0x0b, \n\t0x81, 0x49, 0x41, 0x2e, 0x25, 0x02, 0x22, 0x01, 0x90, 0x63, 0x60, 0x04, 0x80, 0x14, 0x80, 0x45, \n\t0x06, 0x3a, 0x05, 0x50, 0x23, 0x64, 0x4a, 0x89, 0x06, 0x03, 0x91, 0x84, 0xb4, 0x40, 0x88, 0x52, \n\t0x61, 0x10, 0x89, 0x1c, 0x40, 0x87, 0x20, 0x82, 0x61, 0x12, 0x84, 0x9a, 0x89, 0x40, 0x42, 0x68, \n\t0x00, 0x00, 0x9a, 0x21, 0x20, 0x11, 0xda, 0x84, 0x80, 0x46, 0x45, 0x00, 0x14, 0x01, 0x08, 0xb4, \n\t0x05, 0x24, 0x0e, 0xa1, 0xa2, 0x20, 0x44, 0x80, 0x49, 0x48, 0x06, 0x40, 0xa2, 0xc0, 0x51, 0xc4, \n\t0x68, 0x34, 0x32, 0x00, 0x3c, 0x10, 0x44, 0x1c, 0x11, 0x30, 0x08, 0x00, 0x4e, 0xa8, 0x30, 0x15, \n\t0xd8, 0x31, 0x28, 0x80, 0x28, 0x04, 0x46, 0x08, 0x20, 0xa1, 0x04, 0x42, 0x12, 0xd2, 0x0a, 0x31, \n\t0x01, 0x02, 0x00, 0x04, 0x20, 0x01, 0xac, 0x65, 0x14, 0x0d, 0x58, 0x51, 0x03, 0x10, 0x00, 0x15, \n\t0x08, 0x04, 0x46, 0x89, 0x8f, 0xf0, 0x88, 0x06, 0x08, 0x20, 0xb1, 0x09, 0x68, 0x52, 0x2a, 0x02, \n\t0x33, 0x82, 0x82, 0xa8, 0x08, 0xe4, 0x60, 0x25, 0x03, 0xac, 0x11, 0x00, 0x85, 0x40, 0xb1, 0x92, \n\t0x86, 0x01, 0xc2, 0x03, 0x28, 0x42, 0x30, 0x17, 0x28, 0xd6, 0xa0, 0x26, 0x00, 0x10, 0x00, 0x59, \n\t0x12, 0x08, 0x0a, 0xc2, 0x61, 0x80, 0x95, 0x08, 0x43, 0x62, 0x90, 0x40, 0x31, 0x90, 0x00, 0x04, \n\t0x2a, 0x92, 0x08, 0x80, 0x21, 0x57, 0x0e, 0x30, 0x00, 0x40, 0x22, 0x24, 0x03, 0x45, 0x60, 0x62, \n\t0xa0, 0x90, 0x41, 0x44, 0x00, 0x18, 0x90, 0x98, 0x15, 0x20, 0x05, 0x00, 0x4a, 0x43, 0x62, 0x00, \n\t0x08, 0x90, 0x80, 0x28, 0x00, 0xb1, 0x3f, 0x40, 0x58, 0x4d, 0x24, 0x45, 0x22, 0x18, 0x04, 0x02, \n\t0x26, 0x6a, 0x10, 0x10, 0x84, 0xcc, 0x85, 0x24, 0x28, 0x14, 0x12, 0x94, 0x41, 0x81, 0x60, 0x70, \n\t0x01, 0x88, 0x80, 0x05, 0x01, 0x23, 0x40, 0x34, 0x8a, 0x0b, 0x20, 0x89, 0x40, 0x36, 0x01, 0x21, \n\t0x00, 0x25, 0x58, 0x09, 0x40, 0x91, 0x0b, 0x18, 0x90, 0x00, 0x69, 0x3a, 0x01, 0x83, 0x84, 0x00, \n\t0xca, 0x24, 0x18, 0x02, 0xd2, 0x00, 0x10, 0x41, 0x01, 0x00, 0xc1, 0xa3, 0x04, 0x38, 0x9c, 0x25, \n\t0x04, 0x11, 0x60, 0x31, 0x40, 0xd8, 0x29, 0x20, 0x04, 0x08, 0x0a, 0x14, 0x08, 0xc0, 0x08, 0x01, \n\t0x81, 0x05, 0x0d, 0x95, 0x20, 0x42, 0x61, 0x10, 0x30, 0x8c, 0x0b, 0x08, 0x38, 0x45, 0x1a, 0x2a, \n\t0x98, 0x40, 0x46, 0x74, 0xb4, 0x40, 0x32, 0xd0, 0x08, 0x02, 0x14, 0x02, 0x39, 0x19, 0x20, 0x42, \n\t0x84, 0x22, 0x60, 0x00, 0x01, 0x08, 0x51, 0x09, 0x2c, 0x20, 0x7a, 0x0a, 0x80, 0x90, 0xe4, 0x18, \n\t0x00, 0x50, 0x18, 0x41, 0xc1, 0x27, 0x04, 0x02, 0x4a, 0x20, 0x04, 0x00, 0xc4, 0x1c, 0x15, 0xc0, \n\t0xb0, 0x0c, 0x11, 0x20, 0x06, 0xa6, 0x20, 0xb8, 0x19, 0x8a, 0xa3, 0x58, 0xc2, 0x40, 0x90, 0x01, \n\t0xcb, 0x0c, 0x20, 0x30, 0xd8, 0x83, 0x4c, 0x16, 0x80, 0x0e, 0x20, 0x09, 0x3c, 0x51, 0x54, 0x80, \n\t0x20, 0x07, 0x53, 0x30, 0x3c, 0x4e, 0x65, 0x00, 0x90, 0x48, 0x0e, 0x01, 0x06, 0x84, 0x38, 0x82, \n\t0x8a, 0x18, 0x18, 0x18, 0x40, 0x60, 0x03, 0x11, 0x89, 0x01, 0x53, 0x09, 0x42, 0x22, 0x01, 0x08, \n\t0x05, 0x92, 0x04, 0x58, 0x11, 0x12, 0x82, 0x70, 0x14, 0x82, 0x7c, 0x12, 0x00, 0xa0, 0x89, 0xc8, \n\t0x60, 0x02, 0x00, 0x20, 0x13, 0x7d, 0x48, 0x00, 0x0a, 0x40, 0x4b, 0x03, 0x49, 0x04, 0x84, 0x54, \n\t0x00, 0xb1, 0x96, 0x44, 0x16, 0x2b, 0x54, 0x46, 0x50, 0x10, 0x04, 0x01, 0xc9, 0x64, 0x05, 0x1a, \n\t0x2a, 0xc0, 0x81, 0xc3, 0x12, 0x33, 0x40, 0x12, 0xc4, 0x05, 0x0d, 0x72, 0xa0, 0x40, 0x84, 0x14, \n\t0x10, 0x20, 0x30, 0x00, 0x1a, 0x80, 0x99, 0x8e, 0xc2, 0x6e, 0x30, 0x48, 0x25, 0x45, 0x90, 0x0a, \n\t0x18, 0x60, 0x82, 0x28, 0x20, 0x86, 0x03, 0x10, 0x64, 0x91, 0x90, 0x8c, 0x8a, 0xa0, 0x2e, 0x50, \n\t0x88, 0x0d, 0x30, 0x98, 0x00, 0x08, 0x03, 0x53, 0x1a, 0x29, 0xc9, 0x00, 0x38, 0x01, 0x60, 0x20, \n\t0xc0, 0xcb, 0x00, 0x28, 0x41, 0x08, 0x82, 0xa5, 0x4c, 0x81, 0x26, 0x44, 0x02, 0x30, 0x51, 0x42, \n\t0x0e, 0x00, 0xd0, 0x10, 0xa0, 0x50, 0x81, 0x81, 0x08, 0x54, 0xa3, 0xb3, 0xa0, 0x80, 0x0c, 0x62, \n\t0xa1, 0xa8, 0x09, 0x08, 0x1e, 0x02, 0x22, 0xa4, 0x3b, 0x04, 0x1d, 0x90, 0x05, 0x48, 0x20, 0x38, \n\t0x00, 0x00, 0x08, 0x66, 0x04, 0x50, 0x90, 0x35, 0x04, 0x08, 0x28, 0x40, 0x12, 0x22, 0x01, 0x40, \n\t0xc3, 0x82, 0x04, 0x02, 0x10, 0x03, 0x64, 0xc0, 0xa0, 0x30, 0x00, 0x02, 0x84, 0x20, 0x06, 0x08, \n\t0x48, 0x20, 0xc3, 0x06, 0x68, 0x40, 0x01, 0x50, 0x33, 0x01, 0x01, 0xf8, 0x80, 0x86, 0x02, 0x05, \n\t0x01, 0x28, 0x01, 0x0e, 0x43, 0x42, 0xa3, 0x01, 0x13, 0xb4, 0xce, 0x24, 0x02, 0x00, 0xc0, 0x1c, \n\t0x00, 0x06, 0xa6, 0x40, 0xb2, 0xe2, 0x24, 0xa0, 0x94, 0x4c, 0x40, 0xe0, 0xb1, 0x23, 0x18, 0x08, \n\t0x28, 0x00, 0x05, 0x50, 0x8a, 0x80, 0x01, 0xe0, 0x40, 0x85, 0x38, 0x06, 0x50, 0x01, 0x43, 0x00, \n\t0xd2, 0x08, 0x95, 0xc8, 0x5a, 0x08, 0x00, 0x14, 0x6a, 0x81, 0x09, 0x02, 0x4a, 0x22, 0x84, 0x22, \n\t0x12, 0x00, 0x11, 0x2c, 0x46, 0x26, 0xc1, 0x81, 0x81, 0x01, 0xc8, 0x00, 0x04, 0x09, 0x30, 0x81, \n\t0xc9, 0x4b, 0x58, 0x95, 0x28, 0xa0, 0x04, 0x0c, 0x20, 0x34, 0x40, 0x89, 0x0b, 0x30, 0x4b, 0x0b, \n\t0x04, 0x00, 0x80, 0x09, 0x98, 0x02, 0x02, 0x02, 0x72, 0x52, 0x04, 0x48, 0x00, 0x48, 0x04, 0x30, \n\t0xa0, 0xb4, 0x40, 0x88, 0x87, 0x02, 0x53, 0x18, 0x22, 0x65, 0x45, 0x23, 0x24, 0x00, 0x98, 0x18, \n\t0x09, 0x08, 0x0c, 0x00, 0x60, 0x40, 0xa4, 0xd8, 0x40, 0x42, 0x50, 0xc2, 0x80, 0xa8, 0x05, 0x5d, \n\t0x28, 0x04, 0x04, 0x00, 0xb0, 0xe8, 0x80, 0x82, 0x26, 0x84, 0x20, 0x1e, 0x20, 0xd3, 0xcd, 0x08, \n\t0x07, 0x22, 0x06, 0x14, 0x10, 0x69, 0x0e, 0x05, 0x19, 0x80, 0xd1, 0x84, 0x2a, 0x38, 0x22, 0x8a, \n\t0x11, 0x91, 0x51, 0xc2, 0x06, 0x50, 0x3a, 0xa1, 0x49, 0x04, 0x82, 0x6c, 0x26, 0x52, 0x03, 0x94, \n\t0x80, 0x02, 0x40, 0x10, 0x00, 0x88, 0x50, 0x42, 0xa2, 0x4c, 0x10, 0x79, 0x34, 0x00, 0x8f, 0x84, \n\t0x34, 0x41, 0x49, 0x32, 0x09, 0x42, 0xc0, 0x14, 0x62, 0x03, 0x06, 0x28, 0x48, 0x22, 0x50, 0x60, \n\t0x00, 0xb2, 0xec, 0x00, 0xc2, 0x0e, 0x35, 0x20, 0x80, 0x50, 0x4d, 0x08, 0x00, 0x60, 0x2a, 0x1c, \n\t0xa0, 0x54, 0x20, 0x02, 0x04, 0x10, 0x05, 0x40, 0x8b, 0xe8, 0x62, 0x12, 0x82, 0x0d, 0xc1, 0x92, \n\t0x84, 0x1c, 0x11, 0x81, 0xa4, 0x00, 0x0c, 0x48, 0x54, 0x71, 0x81, 0x91, 0x44, 0x90, 0x28, 0x06, \n\t0x83, 0x8a, 0x12, 0x65, 0x50, 0x60, 0x5c, 0xc4, 0x20, 0x31, 0x05, 0x8c, 0x02, 0x4c, 0x10, 0xa2, \n\t0x94, 0x29, 0x96, 0x08, 0x40, 0x25, 0xa3, 0xb0, 0x68, 0x10, 0x0d, 0x74, 0x01, 0x98, 0x00, 0x81, \n\t0x00, 0x40, 0x00, 0xb2, 0x61, 0x94, 0xa0, 0x04, 0x88, 0x40, 0x00, 0x61, 0x31, 0x14, 0x43, 0x05, \n\t0x16, 0x20, 0xe8, 0x0b, 0x08, 0x17, 0x08, 0x10, 0x00, 0x79, 0x11, 0x01, 0x84, 0x41, 0x1c, 0x90, \n\t0x99, 0x87, 0x84, 0x1a, 0xc0, 0x6c, 0x07, 0x90, 0x82, 0x84, 0xdb, 0x89, 0x28, 0x36, 0x12, 0x11, \n\t0x20, 0x05, 0x03, 0x20, 0x85, 0x02, 0x00, 0xe0, 0x40, 0x02, 0x24, 0x05, 0x32, 0x22, 0x10, 0x09, \n\t0x20, 0x70, 0x80, 0xd0, 0x18, 0xa5, 0x18, 0x80, 0x00, 0x01, 0x80, 0x21, 0x40, 0x0b, 0x6d, 0x00, \n\t0x53, 0x08, 0x11, 0xb0, 0x08, 0x06, 0x2a, 0x62, 0xa0, 0x0d, 0x8c, 0x16, 0x65, 0x40, 0x11, 0x01, \n\t0x06, 0x30, 0x44, 0xc3, 0x02, 0x00, 0x10, 0x10, 0x34, 0xc2, 0x02, 0x0e, 0x30, 0xc8, 0x85, 0xd9, \n\t0x06, 0x09, 0x08, 0x04, 0x82, 0x28, 0x88, 0x03, 0x06, 0x08, 0x20, 0x92, 0x0e, 0x61, 0x81, 0x65, \n\t0x66, 0x01, 0x23, 0x0e, 0xc0, 0x02, 0xac, 0x1a, 0x35, 0x03, 0x13, 0x20, 0xd8, 0x2b, 0x10, 0x04, \n\t0x63, 0x04, 0x68, 0x5d, 0x22, 0x34, 0x40, 0x10, 0x08, 0x1c, 0x48, 0x00, 0x3a, 0x40, 0x50, 0x01, \n\t0x85, 0x50, 0x00, 0x00, 0x01, 0x09, 0x9d, 0x30, 0x8c, 0x08, 0x0e, 0x27, 0x50, 0x0e, 0x28, 0x91, \n\t0x86, 0x04, 0x80, 0x69, 0x30, 0xc5, 0x42, 0xe5, 0x50, 0x82, 0x10, 0x82, 0x3c, 0x86, 0x6c, 0x10, \n\t0x40, 0x43, 0x28, 0x04, 0x42, 0x23, 0x00, 0xa4, 0xb0, 0x09, 0x51, 0xcd, 0x00, 0x24, 0x06, 0xe2, \n\t0x90, 0x61, 0x96, 0x08, 0x22, 0x50, 0x09, 0x02, 0x4d, 0x59, 0x20, 0x42, 0x05, 0x10, 0x04, 0xe4, \n\t0x0c, 0xcb, 0x04, 0x14, 0xc3, 0x22, 0x80, 0x08, 0x21, 0x16, 0x95, 0x61, 0x06, 0xd0, 0x03, 0x0a, \n\t0x1a, 0x10, 0x00, 0x02, 0xb0, 0x40, 0x64, 0x42, 0x04, 0x02, 0x88, 0x40, 0x02, 0xa8, 0x54, 0x04, \n\t0x00, 0x11, 0x58, 0x54, 0x6d, 0x02, 0x23, 0xc2, 0x80, 0x64, 0x80, 0x02, 0x04, 0xf2, 0x00, 0x14, \n\t0x1d, 0x03, 0x66, 0x44, 0xa1, 0x28, 0x00, 0x04, 0x8a, 0x24, 0x62, 0x90, 0x30, 0xa5, 0x41, 0x07, \n\t0x00, 0x1a, 0x40, 0x90, 0xa4, 0x4c, 0x10, 0x41, 0x48, 0x24, 0x61, 0x3c, 0xa8, 0x10, 0x2c, 0x12, \n\t0xe0, 0x01, 0x98, 0x40, 0x80, 0x88, 0x10, 0x41, 0x40, 0x84, 0x91, 0x48, 0x04, 0x40, 0xa3, 0x00, \n\t0x9b, 0xa8, 0x90, 0x24, 0x50, 0x31, 0xa8, 0x83, 0x91, 0x44, 0x42, 0x0a, 0x12, 0x02, 0x30, 0xa8, \n\t0x55, 0xe8, 0x08, 0x41, 0x00, 0x0c, 0x08, 0x12, 0x07, 0x4c, 0xd2, 0x40, 0xac, 0x14, 0x09, 0xe2, \n\t0x02, 0x01, 0x82, 0x9c, 0x00, 0x15, 0x81, 0x20, 0x52, 0x08, 0x01, 0x60, 0x42, 0x0a, 0x46, 0x25, \n\t0x28, 0x94, 0xa5, 0x98, 0x61, 0x48, 0x84, 0x41, 0x80, 0xc4, 0x48, 0x21, 0x02, 0x47, 0x88, 0x89, \n\t0x50, 0x0f, 0x8a, 0x14, 0x12, 0x31, 0x12, 0x05, 0x87, 0x80, 0x32, 0x32, 0x29, 0x80, 0x00, 0xc8, \n\t0x24, 0x72, 0xe0, 0x33, 0x88, 0x41, 0x80, 0x0e, 0x22, 0xa6, 0x43, 0x0c, 0xd0, 0x51, 0x24, 0x48, \n\t0xa0, 0x82, 0x04, 0xfc, 0x86, 0x00, 0x38, 0x11, 0xc3, 0x02, 0x00, 0x43, 0x44, 0x08, 0x86, 0x20, \n\t0x0e, 0x18, 0x54, 0x00, 0x58, 0x01, 0xc8, 0x10, 0x04, 0x81, 0x02, 0x40, 0x20, 0xf8, 0x22, 0xa4, \n\t0x05, 0x4a, 0x24, 0x62, 0x08, 0x06, 0x2c, 0x10, 0x08, 0x06, 0x15, 0x83, 0x98, 0x9c, 0x00, 0x03, \n\t0x28, 0x50, 0x41, 0x36, 0x11, 0x04, 0x82, 0x12, 0x65, 0x28, 0x08, 0x8c, 0x82, 0x68, 0x10, 0x30, \n\t0x82, 0x1f, 0x80, 0x03, 0x63, 0x04, 0x02, 0x82, 0x1c, 0xc4, 0x80, 0xc1, 0x0c, 0x21, 0xa1, 0x04, \n\t0x30, 0x10, 0x08, 0x00, 0xa2, 0xd3, 0xbd, 0x01, 0xc1, 0x41, 0x60, 0x10, 0x08, 0x12, 0x1c, 0x98, \n\t0x44, 0x02, 0x82, 0x7b, 0xa3, 0x40, 0x14, 0xa4, 0x4e, 0x05, 0xc2, 0x04, 0x48, 0x8c, 0x80, 0x04, \n\t0xa2, 0x41, 0x14, 0x21, 0x01, 0x86, 0x22, 0xe5, 0xca, 0x09, 0xbc, 0x0e, 0x81, 0x10, 0xe3, 0x00, \n\t0x38, 0x20, 0x01, 0x88, 0x50, 0x10, 0xa3, 0x8e, 0x20, 0x5c, 0x45, 0x30, 0x54, 0x29, 0x91, 0x68, \n\t0x01, 0xa4, 0x14, 0xa0, 0x10, 0x20, 0x1c, 0x82, 0x6a, 0x44, 0x62, 0x20, 0x02, 0x68, 0x10, 0xc9, \n\t0x4c, 0x40, 0x02, 0x10, 0x0c, 0x0a, 0x4c, 0x68, 0x05, 0xaa, 0xa1, 0x60, 0x50, 0x46, 0x60, 0x80, \n\t0x02, 0x81, 0x40, 0x00, 0x08, 0x3e, 0x14, 0x08, 0x31, 0x31, 0x80, 0x02, 0x3a, 0x46, 0x12, 0x9a, \n\t0x61, 0x00, 0x2d, 0x10, 0x21, 0x81, 0x82, 0xe0, 0xc0, 0x01, 0x00, 0x45, 0x38, 0x01, 0x05, 0x84, \n\t0x0c, 0x48, 0x20, 0x09, 0x9d, 0x00, 0x1e, 0x41, 0x12, 0x23, 0xf1, 0x11, 0x00, 0xc4, 0x42, 0x36, \n\t0x10, 0x89, 0x04, 0xb1, 0x82, 0x43, 0x08, 0x81, 0x08, 0xa6, 0x60, 0x86, 0x60, 0x04, 0xc4, 0x20, \n\t0x2c, 0x41, 0x40, 0x40, 0x00, 0x02, 0x00, 0x12, 0x00, 0x04, 0x60, 0x6e, 0x90, 0xa1, 0x0b, 0x00, \n\t0x93, 0x28, 0x16, 0x01, 0x49, 0x01, 0xf1, 0x40, 0xa0, 0x62, 0xa0, 0xc0, 0x20, 0x90, 0x51, 0x0b, \n\t0x50, 0x01, 0x00, 0x03, 0x39, 0x85, 0x80, 0x34, 0xc5, 0x18, 0x89, 0x01, 0x10, 0x04, 0x02, 0x06, \n\t0xa2, 0xbb, 0x14, 0x08, 0x08, 0x06, 0x80, 0xfa, 0x10, 0x49, 0x1b, 0x84, 0x04, 0xb4, 0x01, 0x30, \n\t0xa0, 0x02, 0xc2, 0x54, 0x23, 0x21, 0x0a, 0xc9, 0x88, 0xa0, 0x00, 0x12, 0x71, 0x16, 0x8c, 0x50, \n\t0xc2, 0x22, 0x60, 0x08, 0xb1, 0x40, 0x06, 0x44, 0x60, 0x12, 0x8a, 0x04, 0x09, 0x46, 0xa2, 0x60, \n\t0x54, 0x40, 0x85, 0x81, 0x84, 0x88, 0x26, 0x62, 0x88, 0x98, 0x08, 0x11, 0x09, 0x16, 0x84, 0x18, \n\t0x02, 0xc5, 0x40, 0x06, 0x04, 0x91, 0x48, 0x30, 0x01, 0x14, 0x01, 0x4a, 0xc7, 0x83, 0x85, 0xa0, \n\t0x8c, 0x28, 0x1a, 0x56, 0x31, 0x89, 0x38, 0x04, 0x69, 0x54, 0x24, 0x30, 0x00, 0x60, 0x40, 0x28, \n\t0x04, 0x10, 0x52, 0x80, 0x4c, 0x02, 0x08, 0x40, 0x92, 0x63, 0x1b, 0xc0, 0x09, 0x09, 0x6a, 0x52, \n\t0x80, 0x20, 0x68, 0x8c, 0x27, 0x10, 0xc0, 0x43, 0x14, 0x0c, 0x43, 0xa2, 0x00, 0x75, 0x31, 0xb7, \n\t0x90, 0x88, 0x60, 0x2a, 0xe0, 0xf0, 0x30, 0x00, 0x00, 0x82, 0x54, 0x15, 0x02, 0x20, 0x01, 0x41, \n\t0x85, 0x04, 0x02, 0x30, 0x89, 0x50, 0x81, 0xc9, 0x00, 0xa6, 0x68, 0x20, 0x04, 0x52, 0x41, 0x20, \n\t0x21, 0x41, 0x04, 0x18, 0x09, 0x40, 0x00, 0x82, 0xca, 0x35, 0xa5, 0x87, 0x40, 0x1e, 0x93, 0x40, \n\t0x20, 0x19, 0x12, 0x80, 0x00, 0x66, 0x62, 0x0c, 0xcd, 0x12, 0x84, 0x4e, 0x81, 0x28, 0x14, 0x00, \n\t0xd1, 0x80, 0x0a, 0x01, 0x81, 0xad, 0x44, 0x97, 0x08, 0x00, 0x40, 0x60, 0x01, 0x11, 0x9a, 0x61, \n\t0x26, 0xc0, 0x81, 0x38, 0x30, 0x54, 0x27, 0x60, 0x21, 0x02, 0x01, 0x34, 0xc4, 0xa0, 0x02, 0xb0, \n\t0x48, 0x86, 0x15, 0xc0, 0x40, 0x40, 0x00, 0x88, 0x06, 0x80, 0x84, 0x40, 0x56, 0x46, 0x01, 0x82, \n\t0x80, 0x41, 0xa9, 0x56, 0x94, 0x0b, 0x25, 0x11, 0x06, 0x2e, 0x10, 0x12, 0x40, 0x2e, 0x00, 0x80, \n\t0x4d, 0x10, 0x11, 0x40, 0x94, 0x0d, 0x00, 0x6c, 0x0c, 0x02, 0x90, 0x12, 0x1c, 0x10, 0x02, 0x62, \n\t0x41, 0x02, 0x02, 0x04, 0x10, 0x2a, 0x08, 0x40, 0x12, 0x11, 0x0c, 0x08, 0xa2, 0x64, 0x27, 0x08, \n\t0xa0, 0x80, 0x0c, 0x46, 0x74, 0x11, 0x89, 0x29, 0x40, 0x49, 0xc6, 0x06, 0xf7, 0x00, 0x80, 0xa5, \n\t0xde, 0x80, 0x68, 0x20, 0x09, 0x03, 0xac, 0x84, 0x00, 0x38, 0x11, 0x02, 0x19, 0x98, 0x09, 0xe2, \n\t0x20, 0x30, 0xa2, 0x08, 0x6c, 0xc1, 0x4a, 0x44, 0x10, 0x31, 0x03, 0x01, 0x1a, 0x28, 0x20, 0xa5, \n\t0x40, 0x0f, 0x44, 0xc2, 0x8a, 0x62, 0xb3, 0x08, 0x27, 0x69, 0x90, 0x20, 0x0e, 0xc2, 0x80, 0x91, \n\t0x68, 0x90, 0x08, 0x3c, 0x14, 0x0b, 0x92, 0x15, 0x4d, 0x80, 0x38, 0x24, 0x30, 0x12, 0x49, 0x14, \n\t0x04, 0x02, 0xa0, 0x42, 0x28, 0x04, 0xc6, 0x01, 0x22, 0x20, 0x71, 0x25, 0x34, 0x83, 0x41, 0x12, \n\t0x91, 0x00, 0x24, 0x3c, 0x41, 0x04, 0x06, 0x07, 0xb8, 0x82, 0x01, 0x1b, 0x8c, 0x50, 0x20, 0x4a, \n\t0x11, 0x98, 0x80, 0x06, 0x48, 0x83, 0xc8, 0x01, 0x88, 0x08, 0x29, 0x74, 0x26, 0x90, 0xa8, 0x00, \n\t0x00, 0x0f, 0x08, 0xa2, 0x92, 0x90, 0x19, 0x1b, 0x44, 0x00, 0x97, 0x42, 0x29, 0x24, 0x11, 0x00, \n\t0x12, 0x10, 0xc2, 0x30, 0xe8, 0x44, 0x22, 0x24, 0x00, 0x00, 0x04, 0x48, 0x11, 0x40, 0x04, 0x03, \n\t0x19, 0xa0, 0xa8, 0x00, 0x04, 0x04, 0x43, 0x60, 0x0a, 0x15, 0x06, 0x03, 0x52, 0xf5, 0x48, 0x00, \n\t0x10, 0x54, 0x00, 0x0c, 0xd4, 0x29, 0x93, 0xd0, 0x90, 0x4d, 0x4e, 0xa2, 0xc9, 0x10, 0x08, 0x12, \n\t0x42, 0x00, 0xe1, 0x03, 0x0a, 0x04, 0x86, 0x80, 0x70, 0x84, 0x32, 0x28, 0x90, 0x4a, 0x61, 0x08, \n\t0x10, 0xb2, 0x94, 0x10, 0x1a, 0x40, 0x40, 0x06, 0x73, 0xac, 0x20, 0x91, 0x20, 0x40, 0x20, 0x99, \n\t0x84, 0x24, 0x4b, 0xe9, 0x08, 0x81, 0x82, 0x00, 0x31, 0x04, 0x86, 0x30, 0x34, 0x09, 0x32, 0x28, \n\t0x41, 0x2c, 0x16, 0x00, 0x61, 0x95, 0xa0, 0x10, 0xca, 0x2a, 0x44, 0x20, 0xa0, 0x00, 0x10, 0x20, \n\t0x68, 0xc6, 0xb1, 0x15, 0xb0, 0x10, 0x2d, 0x18, 0x26, 0x00, 0x30, 0x08, 0xc6, 0x68, 0x00, 0x50, \n\t0x62, 0x28, 0xc8, 0x00, 0x09, 0x08, 0x81, 0x80, 0x11, 0xc0, 0x03, 0x89, 0x06, 0x50, 0x88, 0x1c, \n\t0x01, 0xc2, 0x63, 0x7a, 0x05, 0x49, 0x34, 0x25, 0x8d, 0x00, 0x48, 0x00, 0xa2, 0x16, 0x8d, 0xc0, \n\t0x4a, 0x5c, 0x46, 0x21, 0x0e, 0x25, 0x44, 0x40, 0x16, 0x60, 0x11, 0x91, 0xd0, 0x82, 0xa8, 0x02, \n\t0x40, 0x51, 0x21, 0x11, 0x48, 0x06, 0x58, 0x12, 0xc1, 0x22, 0x10, 0x51, 0x60, 0x10, 0x22, 0x28, \n\t0x82, 0x58, 0x49, 0x0e, 0x02, 0x04, 0x09, 0x09, 0x01, 0x17, 0xa6, 0x10, 0x62, 0x53, 0x8a, 0x08, \n\t0x00, 0x87, 0x10, 0x20, 0xa3, 0x20, 0x44, 0x41, 0x67, 0x0a, 0x05, 0x02, 0x84, 0x18, 0x96, 0x84, \n\t0x06, 0x91, 0x68, 0x04, 0x85, 0x03, 0x20, 0x00, 0x05, 0x73, 0x24, 0x01, 0xc0, 0x48, 0x00, 0xa5, \n\t0x1a, 0x06, 0xf1, 0x4c, 0x26, 0x74, 0x14, 0x00, 0x82, 0x88, 0x88, 0x62, 0x08, 0x02, 0x40, 0xa0, \n\t0x45, 0x40, 0x04, 0x12, 0x92, 0xaa, 0x10, 0x8c, 0x41, 0x09, 0x28, 0x86, 0x00, 0x89, 0x80, 0x01, \n\t0x02, 0x0a, 0x82, 0x81, 0x31, 0xa0, 0x40, 0x00, 0x06, 0x10, 0x89, 0x80, 0x25, 0x0e, 0xec, 0x00, \n\t0x05, 0x82, 0x22, 0xd8, 0x08, 0xa1, 0x40, 0x44, 0xa0, 0x00, 0x41, 0xc8, 0x01, 0x14, 0x05, 0x9b, \n\t0xbc, 0x60, 0x90, 0x88, 0x0e, 0x14, 0x9b, 0x85, 0xc0, 0x94, 0x02, 0x64, 0xa1, 0x10, 0x34, 0x01, \n\t0x01, 0xa1, 0x60, 0xb3, 0x50, 0x0a, 0xb1, 0x4b, 0xc5, 0x02, 0x40, 0x71, 0x10, 0x05, 0x04, 0x47, \n\t0x20, 0x96, 0x48, 0xa5, 0x00, 0x01, 0x09, 0x08, 0x72, 0xd0, 0x08, 0x20, 0x06, 0xa1, 0x0a, 0x92, \n\t0xb2, 0x00, 0x08, 0x10, 0x08, 0x50, 0xc2, 0x08, 0x2e, 0x15, 0x00, 0x4a, 0x78, 0x80, 0x01, 0xa3, \n\t0x80, 0xd1, 0x07, 0x6e, 0x82, 0xa8, 0x30, 0x24, 0x07, 0x00, 0x08, 0x83, 0x80, 0x28, 0xa4, 0x07, \n\t0x08, 0x00, 0x60, 0x43, 0x80, 0x1d, 0xc0, 0xaa, 0x56, 0x87, 0x10, 0x10, 0x1d, 0x4c, 0xa4, 0x06, \n\t0xa3, 0x88, 0x01, 0x00, 0x06, 0x42, 0x2c, 0x80, 0x01, 0x2e, 0x84, 0x00, 0x83, 0x72, 0x06, 0xa2, \n\t0xb4, 0x14, 0x05, 0x04, 0x10, 0x60, 0x2a, 0x99, 0x38, 0x82, 0x23, 0x06, 0x14, 0x12, 0x29, 0x00, \n\t0x54, 0x69, 0x14, 0x61, 0x32, 0x21, 0x28, 0x14, 0x25, 0x60, 0xd0, 0x21, 0x92, 0x00, 0x80, 0x20, \n\t0x40, 0x73, 0xb0, 0x80, 0x00, 0x01, 0x80, 0x58, 0x05, 0x58, 0xa8, 0x29, 0x48, 0x0a, 0x02, 0x55, \n\t0x4a, 0x82, 0x00, 0xd6, 0xc0, 0x20, 0x81, 0x51, 0x0a, 0x88, 0x59, 0x0c, 0x70, 0x82, 0x02, 0x81, \n\t0xe1, 0x88, 0xa8, 0x0a, 0x55, 0x11, 0x04, 0x15, 0x80, 0x07, 0x08, 0x02, 0xc1, 0xb3, 0x08, 0x1b, \n\t0x04, 0x6e, 0x40, 0x60, 0x0d, 0x50, 0x40, 0x4f, 0x70, 0x30, 0x10, 0x20, 0x01, 0x10, 0x63, 0x10, \n\t0xd1, 0x28, 0x86, 0x0c, 0x0a, 0x04, 0x00, 0x44, 0x00, 0xa0, 0x4d, 0x1a, 0xa1, 0x20, 0x51, 0x38, \n\t0x12, 0x44, 0x11, 0x67, 0x12, 0x04, 0x00, 0x89, 0x00, 0xc9, 0x00, 0x28, 0x00, 0x83, 0x00, 0x64, \n\t0x88, 0x00, 0x0a, 0x03, 0xc2, 0x98, 0xc0, 0x08, 0x23, 0x16, 0x07, 0x09, 0xb1, 0x60, 0x08, 0x6a, \n\t0x04, 0xd2, 0x28, 0x08, 0xb5, 0x11, 0x05, 0x10, 0x25, 0x00, 0xa2, 0x08, 0x16, 0x0c, 0x0a, 0x40, \n\t0x00, 0x00, 0x59, 0x03, 0x04, 0x02, 0x92, 0xe3, 0x30, 0x00, 0x81, 0xc5, 0x06, 0x30, 0x98, 0x24, \n\t0x1c, 0x0e, 0x68, 0x20, 0x81, 0x40, 0x02, 0x1d, 0x03, 0x6a, 0x40, 0x41, 0x02, 0x24, 0x24, 0x05, \n\t0x23, 0x54, 0x92, 0x98, 0x08, 0x88, 0x49, 0x02, 0x20, 0x10, 0x90, 0x30, 0xa0, 0x03, 0x82, 0x24, \n\t0x20, 0x31, 0x8a, 0x39, 0x58, 0xa8, 0x32, 0x86, 0x80, 0x89, 0x35, 0x88, 0x85, 0x24, 0x05, 0x41, \n\t0x81, 0x10, 0x08, 0x41, 0x00, 0xd4, 0x00, 0x16, 0x00, 0x12, 0x44, 0x36, 0xc0, 0x68, 0x81, 0x90, \n\t0x0c, 0xcc, 0x76, 0x20, 0x51, 0x2c, 0x21, 0x50, 0xab, 0x14, 0xb0, 0x4a, 0x00, 0x64, 0x14, 0x4d, \n\t0x40, 0xc2, 0x12, 0x8e, 0x54, 0x08, 0x02, 0x40, 0x41, 0x28, 0x00, 0x01, 0x9e, 0x81, 0x40, 0xd4, \n\t0x29, 0x12, 0x24, 0x87, 0x82, 0x08, 0x01, 0x63, 0xa1, 0x00, 0x83, 0x01, 0x00, 0x44, 0xca, 0xa4, \n\t0x45, 0x48, 0x20, 0x20, 0x22, 0x49, 0x1a, 0xc0, 0x02, 0xc5, 0x3a, 0xa0, 0x10, 0x15, 0x45, 0xd1, \n\t0xc0, 0x48, 0xa1, 0xe3, 0x04, 0x10, 0xc0, 0x20, 0x74, 0x11, 0x10, 0x83, 0xb1, 0x49, 0x02, 0x52, \n\t0x14, 0x28, 0x11, 0x75, 0x96, 0xa8, 0x1e, 0x10, 0x60, 0x02, 0xe8, 0x1c, 0x49, 0x28, 0xc2, 0x12, \n\t0x3c, 0x95, 0x00, 0xa2, 0x42, 0x12, 0x00, 0x80, 0x28, 0x13, 0x04, 0x2c, 0x44, 0x20, 0x00, 0x08, \n\t0x09, 0x80, 0x40, 0x10, 0xa9, 0x03, 0x74, 0x41, 0x89, 0x20, 0x22, 0x8a, 0xac, 0xa8, 0x11, 0xa0, \n\t0x42, 0x35, 0x48, 0x8b, 0x40, 0x42, 0x67, 0x10, 0x62, 0x40, 0x12, 0x40, 0x94, 0x42, 0x10, 0x01, \n\t0x4a, 0x0d, 0xa4, 0xc0, 0x60, 0x5e, 0x50, 0x81, 0x16, 0x40, 0xd2, 0x41, 0x44, 0x22, 0x31, 0x08, \n\t0x81, 0x14, 0xc9, 0x10, 0x83, 0x80, 0x84, 0x28, 0x04, 0x21, 0x08, 0x82, 0x83, 0x02, 0x04, 0x42, \n\t0x4c, 0x00, 0x50, 0x8a, 0x2b, 0x54, 0x50, 0x82, 0x46, 0x86, 0x62, 0x02, 0xe9, 0x9c, 0x0c, 0x56, \n\t0x75, 0x01, 0xa1, 0x34, 0x8c, 0x20, 0x2c, 0x84, 0x58, 0x84, 0xd8, 0x05, 0x08, 0x10, 0xc2, 0x19, \n\t0x12, 0xe0, 0xc8, 0x01, 0x14, 0x82, 0x08, 0x08, 0x01, 0x40, 0x88, 0x30, 0xc0, 0x4a, 0x8a, 0xa0, \n\t0x03, 0x40, 0x02, 0x10, 0x8a, 0x1d, 0x00, 0x15, 0x03, 0x6c, 0x10, 0x91, 0x01, 0x81, 0x46, 0x8e, \n\t0x00, 0x22, 0x13, 0x81, 0x38, 0x80, 0xc9, 0x4c, 0xa0, 0x81, 0xa2, 0x50, 0x59, 0x25, 0x64, 0x03, \n\t0x1a, 0x85, 0x18, 0x0c, 0x24, 0x20, 0x00, 0x80, 0x90, 0x01, 0x46, 0x28, 0x1c, 0x05, 0xab, 0x00, \n\t0xac, 0x48, 0xc9, 0x06, 0x66, 0xe0, 0x1c, 0x41, 0x48, 0x08, 0x00, 0x30, 0x41, 0xb0, 0x59, 0xc2, \n\t0x63, 0x24, 0x33, 0x71, 0x24, 0x80, 0x02, 0x4d, 0x48, 0x83, 0x08, 0x20, 0x90, 0x92, 0x40, 0x04, \n\t0x22, 0x12, 0x88, 0xb0, 0x8a, 0x40, 0x2a, 0x90, 0x60, 0x20, 0x75, 0x86, 0x03, 0x08, 0xa3, 0x22, \n\t0xa2, 0xc8, 0x92, 0x4a, 0x10, 0x01, 0x11, 0x88, 0x44, 0x90, 0x89, 0x20, 0x02, 0xa0, 0x8c, 0x25, \n\t0x02, 0x80, 0x72, 0x02, 0xea, 0x06, 0x01, 0x0d, 0x0c, 0x04, 0x21, 0x1b, 0x83, 0x00, 0x04, 0x22, \n\t0x1e, 0xc0, 0x61, 0x22, 0x55, 0x01, 0x84, 0x20, 0x02, 0x92, 0xb0, 0xd4, 0x01, 0x6a, 0x14, 0x83, \n\t0x21, 0x1e, 0xa4, 0x16, 0x00, 0x12, 0x27, 0x08, 0x28, 0x30, 0x11, 0x48, 0x04, 0x00, 0x5a, 0x04, \n\t0x10, 0x0e, 0x4c, 0x44, 0x92, 0x11, 0x14, 0x80, 0x02, 0x09, 0x50, 0x60, 0x29, 0x20, 0x18, 0x12, \n\t0x08, 0x00, 0x24, 0x11, 0x00, 0x40, 0x88, 0xc3, 0x26, 0xd4, 0x02, 0x21, 0x00, 0x18, 0x81, 0x20, \n\t0x41, 0x93, 0x90, 0x8d, 0x54, 0x26, 0x38, 0x04, 0x81, 0x84, 0x68, 0x82, 0x08, 0x3c, 0x61, 0xc0, \n\t0xaa, 0x80, 0x4c, 0x20, 0x46, 0x10, 0x8a, 0x19, 0xa0, 0x40, 0x22, 0x36, 0x40, 0x61, 0x83, 0x21, \n\t0x90, 0x08, 0x22, 0x55, 0xa8, 0xba, 0xa8, 0x42, 0x6c, 0x64, 0x40, 0x40, 0x10, 0x50, 0x0a, 0x0d, \n\t0x00, 0x80, 0x82, 0x24, 0x04, 0x04, 0xa8, 0x0c, 0xf0, 0x70, 0x05, 0xc4, 0x08, 0x05, 0x64, 0x60, \n\t0x51, 0x0a, 0x1d, 0xc0, 0xa0, 0x02, 0x26, 0x30, 0x22, 0x2c, 0x14, 0x05, 0x10, 0x80, 0x69, 0xaa, \n\t0x05, 0x04, 0x20, 0x20, 0x61, 0x50, 0x05, 0x00, 0xc2, 0xc2, 0x08, 0x04, 0xf1, 0x24, 0x64, 0x00, \n\t0xc1, 0x62, 0x82, 0x00, 0x01, 0x50, 0x03, 0x05, 0x18, 0x70, 0x00, 0xa2, 0x10, 0xc0, 0x01, 0x0a, \n\t0x84, 0xc0, 0x19, 0x00, 0x84, 0x04, 0x08, 0xd5, 0x82, 0x07, 0x59, 0x58, 0x40, 0x0c, 0x94, 0x20, \n\t0x08, 0x09, 0x06, 0x44, 0x0a, 0x23, 0x00, 0x0b, 0x14, 0x04, 0x86, 0x54, 0x40, 0xa0, 0x11, 0x51, \n\t0x01, 0x21, 0x68, 0xf2, 0x0a, 0x32, 0x10, 0x11, 0x40, 0x0c, 0x42, 0x28, 0x14, 0x40, 0x08, 0x08, \n\t0x72, 0x30, 0xc0, 0x20, 0xad, 0x58, 0x61, 0x28, 0x45, 0x29, 0x00, 0x48, 0x01, 0x27, 0x24, 0x62, \n\t0xc0, 0x80, 0x05, 0x0a, 0xc1, 0x18, 0x25, 0x19, 0xac, 0x25, 0x80, 0x0b, 0x5a, 0x20, 0x00, 0x15, \n\t0x10, 0x82, 0x01, 0x36, 0x40, 0x51, 0x0a, 0x40, 0xd8, 0x0c, 0x20, 0x92, 0x92, 0x09, 0x19, 0x45, \n\t0x4b, 0x50, 0x83, 0x82, 0xa3, 0xe1, 0x86, 0xea, 0x08, 0x43, 0x91, 0x19, 0x89, 0x13, 0x80, 0x04, \n\t0x84, 0x80, 0x10, 0x15, 0xc2, 0x05, 0x0c, 0xd2, 0xc0, 0x00, 0x48, 0x00, 0xa8, 0x40, 0x21, 0x01, \n\t0x85, 0x14, 0x19, 0xc2, 0x42, 0x60, 0xf0, 0x0a, 0x40, 0x50, 0x42, 0x26, 0x47, 0xc9, 0x22, 0x14, \n\t0x81, 0xa2, 0x20, 0x31, 0x08, 0x21, 0xc1, 0xc0, 0x00, 0x48, 0x22, 0x40, 0x93, 0x88, 0x00, 0x61, \n\t0x44, 0x40, 0x0b, 0x80, 0x69, 0x86, 0xec, 0x0a, 0x36, 0x89, 0x14, 0xf0, 0x51, 0x20, 0x42, 0x21, \n\t0x71, 0x21, 0xd1, 0x0c, 0x20, 0x6c, 0x30, 0x53, 0x00, 0x01, 0x00, 0x23, 0x04, 0x74, 0xa8, 0x34, \n\t0x40, 0x5b, 0xa0, 0x1a, 0x16, 0x01, 0x80, 0x28, 0x0f, 0x08, 0x10, 0x24, 0x80, 0x12, 0x69, 0x04, \n\t0x00, 0x48, 0x40, 0xab, 0x94, 0x38, 0x51, 0x4a, 0x26, 0x67, 0x01, 0x00, 0x6c, 0x86, 0x0e, 0x0a, \n\t0x52, 0x20, 0x0c, 0xa0, 0x14, 0x8c, 0x00, 0x11, 0x83, 0x2c, 0xb0, 0x81, 0x24, 0x00, 0x40, 0x48, \n\t0x1e, 0x31, 0xc5, 0x40, 0x32, 0x20, 0x90, 0x14, 0x80, 0x52, 0x80, 0x48, 0x11, 0x40, 0x23, 0x80, \n\t0x14, 0x02, 0x1c, 0x94, 0xa0, 0x08, 0xcc, 0x4a, 0x08, 0x04, 0x37, 0xb0, 0x2a, 0x05, 0x04, 0x00, \n\t0x30, 0x03, 0x03, 0x36, 0xc1, 0x04, 0x2a, 0x12, 0x54, 0x20, 0xa0, 0xe5, 0x94, 0xa0, 0x16, 0x00, \n\t0x81, 0x92, 0x81, 0x09, 0xc0, 0x54, 0x44, 0xc0, 0xa9, 0x81, 0x8c, 0x00, 0x0c, 0xb0, 0x28, 0x05, \n\t0x34, 0x8f, 0x42, 0x42, 0x21, 0xa0, 0x10, 0x24, 0x99, 0x01, 0x04, 0x91, 0x40, 0x09, 0x50, 0x44, \n\t0x63, 0x62, 0x86, 0x52, 0x18, 0x30, 0x01, 0xa8, 0x00, 0x51, 0x12, 0x82, 0x10, 0x88, 0x01, 0x08, \n\t0x31, 0x00, 0x34, 0x49, 0x42, 0x80, 0x0c, 0x50, 0x02, 0x94, 0x00, 0x13, 0xc7, 0x00, 0x90, 0x22, \n\t0x94, 0xc9, 0x19, 0x04, 0x60, 0x74, 0x71, 0x25, 0x35, 0x8b, 0x41, 0x60, 0x86, 0x08, 0x00, 0x60, \n\t0x40, 0x66, 0x02, 0x90, 0x41, 0x81, 0x81, 0x8e, 0x48, 0x00, 0x43, 0x58, 0x11, 0xb4, 0x13, 0x0b, \n\t0x2a, 0xa5, 0xc0, 0x90, 0x84, 0x06, 0x04, 0x04, 0x03, 0x2a, 0x1d, 0x30, 0x09, 0x89, 0x20, 0x04, \n\t0x81, 0x10, 0x90, 0x10, 0x42, 0x50, 0x02, 0x21, 0x08, 0x30, 0x04, 0xa6, 0x10, 0x00, 0xc2, 0x8e, \n\t0x89, 0x18, 0xa8, 0x00, 0x10, 0x1a, 0xae, 0x64, 0x4a, 0xa2, 0x64, 0x40, 0x60, 0x28, 0x40, 0x1b, \n\t0x00, 0x18, 0x04, 0xc8, 0xa5, 0xc8, 0x17, 0x22, 0x50, 0xe0, 0x20, 0x08, 0x10, 0x40, 0x2c, 0x24, \n\t0x10, 0x5a, 0x89, 0x04, 0x0c, 0xac, 0x06, 0x23, 0x18, 0x27, 0x21, 0x89, 0x4d, 0x10, 0x84, 0xc0, \n\t0x04, 0x38, 0x06, 0x08, 0x22, 0x97, 0xe3, 0x10, 0xd9, 0x44, 0x01, 0x08, 0x00, 0xa0, 0x14, 0x9c, \n\t0x44, 0x01, 0x00, 0x11, 0x41, 0x88, 0x68, 0x84, 0x24, 0x20, 0x72, 0x41, 0x22, 0x44, 0x88, 0x06, \n\t0x2a, 0x00, 0x10, 0x30, 0x59, 0x93, 0x22, 0x00, 0x06, 0xd8, 0x14, 0x2d, 0x41, 0xae, 0x50, 0x20, \n\t0x22, 0x34, 0x80, 0x01, 0x81, 0x20, 0x01, 0x12, 0x00, 0x1d, 0x40, 0xca, 0x34, 0x66, 0x80, 0xb1, \n\t0x48, 0x45, 0x06, 0x12, 0x10, 0x08, 0x89, 0x94, 0x1a, 0x09, 0x58, 0x44, 0x20, 0x02, 0x24, 0xc5, \n\t0x09, 0x3c, 0x02, 0xd0, 0x12, 0x00, 0x10, 0x6a, 0x50, 0x92, 0x8a, 0x04, 0xd8, 0x90, 0xa0, 0x12, \n\t0x41, 0x39, 0x01, 0x21, 0x08, 0x4f, 0x70, 0x60, 0x62, 0x8b, 0x81, 0x42, 0x09, 0x06, 0x87, 0x8a, \n\t0x81, 0x65, 0xd5, 0x04, 0x60, 0x10, 0x01, 0x10, 0xe0, 0x88, 0x82, 0x2c, 0x01, 0x81, 0x24, 0x08, \n\t0x0b, 0x21, 0x62, 0x60, 0x52, 0x32, 0x0d, 0x1c, 0x05, 0x22, 0x14, 0x00, 0xb8, 0x38, 0x00, 0x00, \n\t0x3e, 0xe3, 0x60, 0x83, 0x01, 0x04, 0x00, 0x10, 0x10, 0x20, 0x82, 0x24, 0x06, 0x01, 0x50, 0x50, \n\t0x18, 0x86, 0x08, 0x13, 0x45, 0x0a, 0x82, 0x2b, 0x28, 0xa4, 0x91, 0x60, 0x18, 0x00, 0x89, 0x8f, \n\t0x90, 0x0c, 0x00, 0x4c, 0x01, 0x60, 0x36, 0x1c, 0x58, 0x0c, 0x22, 0x51, 0x18, 0xb0, 0x50, 0x0a, \n\t0xa6, 0x40, 0x46, 0x12, 0x34, 0x80, 0x84, 0x84, 0x48, 0x44, 0x30, 0x01, 0x49, 0x10, 0x0b, 0x42, \n\t0x00, 0x39, 0x24, 0x68, 0x0d, 0x41, 0x22, 0xa2, 0x88, 0x02, 0x2c, 0x40, 0x08, 0x10, 0x50, 0x41, \n\t0x02, 0x15, 0x91, 0x46, 0x22, 0x70, 0x42, 0x91, 0x08, 0x07, 0x25, 0x62, 0x07, 0x48, 0x99, 0x11, \n\t0x44, 0x48, 0x1c, 0x16, 0xe9, 0x3c, 0xc0, 0xc0, 0x40, 0x4e, 0x60, 0x20, 0x0c, 0x9d, 0x00, 0x28, \n\t0x08, 0x24, 0x93, 0x88, 0xd0, 0x01, 0x20, 0x44, 0x33, 0x00, 0x0d, 0x29, 0x90, 0x40, 0x4c, 0x85, \n\t0x01, 0x12, 0x80, 0x42, 0x2c, 0x24, 0x11, 0xc0, 0x00, 0x59, 0x40, 0x8b, 0x04, 0x65, 0x00, 0x2c, \n\t0x55, 0x1c, 0x22, 0x00, 0x04, 0x80, 0x00, 0x5c, 0x88, 0x84, 0x20, 0x07, 0x49, 0x35, 0x84, 0x17, \n\t0x08, 0x0a, 0x70, 0x08, 0x08, 0x00, 0x1e, 0x08, 0x64, 0x04, 0xf2, 0x8c, 0x00, 0xc3, 0xc0, 0x00, \n\t0x04, 0x73, 0x21, 0x01, 0x00, 0xc3, 0x50, 0xb2, 0x0a, 0x88, 0x04, 0x0a, 0x21, 0x14, 0x62, 0x00, \n\t0x13, 0x0c, 0xc0, 0xad, 0x4c, 0xd0, 0x10, 0x0a, 0x21, 0x89, 0x80, 0x10, 0x80, 0x2a, 0xa7, 0x20, \n\t0x91, 0x00, 0x4a, 0x31, 0x0b, 0x30, 0x28, 0x11, 0x00, 0x00, 0x63, 0xc0, 0x10, 0x2d, 0x10, 0xa2, \n\t0x20, 0xc4, 0x8b, 0x3b, 0x28, 0x01, 0xe9, 0x10, 0xc4, 0x40, 0x02, 0x41, 0x10, 0x00, 0x10, 0x80, \n\t0xc1, 0x84, 0x00, 0x90, 0x61, 0x04, 0x11, 0x30, 0x89, 0x98, 0x01, 0x05, 0x4e, 0x02, 0x30, 0x20, \n\t0x08, 0x54, 0x40, 0x12, 0x80, 0x62, 0x84, 0x0c, 0x08, 0x09, 0x40, 0x94, 0x33, 0x04, 0x01, 0x48, \n\t0x81, 0x22, 0x80, 0x02, 0xa6, 0x11, 0x14, 0x23, 0x14, 0x04, 0x6b, 0x20, 0x40, 0x14, 0xa4, 0x10, \n\t0x44, 0x1a, 0x11, 0x40, 0x42, 0x01, 0x34, 0x01, 0x39, 0x08, 0x14, 0x50, 0xa2, 0x14, 0x00, 0x00, \n\t0x03, 0x90, 0x09, 0x0a, 0x24, 0x85, 0x40, 0xb0, 0x51, 0x1f, 0x00, 0x10, 0x82, 0x08, 0x08, 0x2c, \n\t0x41, 0x29, 0x4a, 0x83, 0x80, 0x93, 0x40, 0x56, 0x2b, 0x4e, 0x10, 0xc2, 0x20, 0x48, 0x01, 0x8c, \n\t0x00, 0x70, 0x3a, 0x0c, 0x0c, 0x10, 0x00, 0x28, 0x03, 0x40, 0x3a, 0x18, 0x53, 0x60, 0x60, 0x64, \n\t0x80, 0xb4, 0x24, 0x00, 0x62, 0x08, 0x50, 0x20, 0x06, 0x60, 0x88, 0x20, 0x1a, 0x60, 0x08, 0x11, \n\t0x15, 0x83, 0x0b, 0x38, 0x24, 0x52, 0x98, 0x24, 0x10, 0x28, 0x40, 0x54, 0x08, 0x01, 0xf1, 0xc9, \n\t0x21, 0x30, 0x44, 0x30, 0x89, 0x21, 0x02, 0x0c, 0x40, 0x80, 0x88, 0x36, 0x20, 0x4c, 0x04, 0x74, \n\t0x84, 0x02, 0x00, 0x49, 0x95, 0x48, 0x04, 0x82, 0x6a, 0x38, 0x20, 0x46, 0x2b, 0x40, 0x22, 0xf3, \n\t0x21, 0xd5, 0x00, 0x09, 0x48, 0x03, 0x11, 0x84, 0x4c, 0x80, 0x6a, 0x46, 0xa2, 0x90, 0x92, 0x30, \n\t0x88, 0x06, 0x48, 0xc1, 0x69, 0x07, 0x00, 0x40, 0x02, 0x02, 0x00, 0x29, 0x02, 0x85, 0x14, 0x29, \n\t0x38, 0x40, 0x09, 0xac, 0x98, 0x01, 0x41, 0x20, 0x82, 0x50, 0x82, 0x1d, 0xcf, 0xc0, 0x28, 0x00, \n\t0x10, 0x0c, 0x40, 0x40, 0xc4, 0x10, 0x42, 0x82, 0x06, 0x08, 0x81, 0x08, 0x44, 0x23, 0xd1, 0x81, \n\t0x20, 0xd6, 0x22, 0x58, 0x00, 0x90, 0x08, 0x51, 0x14, 0x03, 0x06, 0x42, 0xc8, 0x07, 0xec, 0x12, \n\t0x82, 0x18, 0x97, 0x43, 0x9b, 0x00, 0x09, 0x4a, 0x04, 0xc0, 0x20, 0x22, 0x60, 0x5e, 0x24, 0x04, \n\t0x93, 0x6a, 0x90, 0x48, 0x44, 0x26, 0x64, 0x41, 0x22, 0x92, 0x48, 0x08, 0x48, 0x16, 0x22, 0xd0, \n\t0x1e, 0x00, 0x49, 0x6f, 0x00, 0x24, 0x08, 0x08, 0xb1, 0xc0, 0xc8, 0x02, 0x20, 0x49, 0x90, 0x04, \n\t0x8c, 0x03, 0x10, 0x84, 0xaa, 0x0d, 0x14, 0x45, 0x61, 0x00, 0x42, 0x63, 0x01, 0x20, 0x01, 0x6a, \n\t0x04, 0x16, 0x20, 0x10, 0x00, 0x82, 0x44, 0x4a, 0x20, 0x33, 0x0c, 0x30, 0x10, 0x82, 0x38, 0x34, \n\t0x91, 0xb0, 0x91, 0x51, 0x41, 0x68, 0x85, 0x22, 0x00, 0x00, 0x97, 0x60, 0x08, 0x52, 0x52, 0xa9, \n\t0x4d, 0x18, 0x0c, 0x56, 0x24, 0xe2, 0x06, 0x58, 0xd0, 0x21, 0x16, 0x44, 0x28, 0x08, 0x21, 0x58, \n\t0x02, 0x22, 0x01, 0xc0, 0x8b, 0x04, 0x05, 0x84, 0x00, 0x11, 0x19, 0x35, 0xf0, 0x8d, 0x40, 0x10, \n\t0x17, 0x02, 0x1a, 0x0c, 0x48, 0x28, 0x52, 0x80, 0x63, 0x14, 0xd1, 0x09, 0x26, 0x48, 0x20, 0x20, \n\t0x35, 0x18, 0x12, 0x40, 0x04, 0x32, 0x82, 0x86, 0x61, 0x00, 0xac, 0x60, 0x00, 0xa0, 0x02, 0x44, \n\t0x48, 0x00, 0x06, 0xa6, 0x90, 0x24, 0x10, 0x0e, 0x65, 0x60, 0x01, 0x08, 0x88, 0x49, 0x18, 0x00, \n\t0x50, 0x41, 0x41, 0x83, 0x24, 0xca, 0xa8, 0x22, 0x40, 0x20, 0xa0, 0x88, 0x14, 0x60, 0x00, 0x07, \n\t0x80, 0x20, 0x18, 0x80, 0x01, 0x14, 0x05, 0x01, 0x9c, 0x04, 0x93, 0x46, 0x08, 0xc3, 0x62, 0x10, \n\t0x14, 0x1a, 0x48, 0x70, 0x10, 0x08, 0x05, 0xa8, 0x11, 0x4c, 0x40, 0xa6, 0x00, 0x20, 0x28, 0x52, \n\t0x01, 0x58, 0x20, 0x09, 0x89, 0x05, 0x86, 0xa0, 0x0c, 0x56, 0xf0, 0x20, 0x88, 0x51, 0x48, 0x04, \n\t0x65, 0x00, 0x8d, 0x01, 0xc5, 0x20, 0x62, 0x00, 0x91, 0x8e, 0x4d, 0xc2, 0x80, 0x12, 0x11, 0x2a, \n\t0x20, 0xd1, 0x11, 0xa1, 0x52, 0x80, 0x48, 0x84, 0xd0, 0x09, 0x28, 0x40, 0x50, 0x89, 0x80, 0x14, \n\t0x06, 0x0c, 0x1a, 0x44, 0x08, 0xba, 0xa5, 0x50, 0xc7, 0x08, 0xa7, 0x22, 0x0a, 0x30, 0x44, 0x00, \n\t0x44, 0xc4, 0xd0, 0x09, 0x10, 0x40, 0x88, 0x48, 0x22, 0xcb, 0x18, 0x84, 0x07, 0x8b, 0x06, 0x41, \n\t0x50, 0x00, 0x49, 0x1a, 0xa2, 0x24, 0x63, 0x23, 0x90, 0x91, 0x02, 0x08, 0x28, 0xa0, 0x08, 0x0a, \n\t0x1c, 0x04, 0x47, 0x2a, 0x05, 0xd8, 0x08, 0x84, 0x10, 0xa8, 0x40, 0x71, 0x58, 0x82, 0x0d, 0x14, \n\t0x00, 0x56, 0xe6, 0x92, 0x8e, 0xd4, 0x00, 0x4d, 0x14, 0x54, 0x49, 0x80, 0x25, 0x0c, 0x01, 0x38, \n\t0x30, 0x08, 0xac, 0x10, 0x90, 0x40, 0x4a, 0x13, 0x63, 0x01, 0x04, 0x01, 0x00, 0x02, 0xd1, 0x19, \n\t0x02, 0xa0, 0x00, 0xae, 0x36, 0x00, 0x80, 0x24, 0xa0, 0x52, 0x8b, 0x00, 0xd0, 0x02, 0x00, 0x51, \n\t0x84, 0x84, 0x0c, 0x02, 0xc3, 0x39, 0x80, 0x8a, 0x44, 0x66, 0x50, 0x08, 0x09, 0x31, 0x08, 0x41, \n\t0x02, 0x07, 0x18, 0xa0, 0x20, 0xc5, 0x2a, 0x12, 0x45, 0x48, 0xa0, 0x68, 0xc6, 0x83, 0x48, 0x20, \n\t0x80, 0x1c, 0x11, 0x45, 0x88, 0x60, 0x56, 0x53, 0x12, 0x60, 0x07, 0x2d, 0x24, 0x04, 0x29, 0x84, \n\t0x20, 0x88, 0x45, 0x08, 0x96, 0x81, 0x84, 0x00, 0x91, 0x04, 0x04, 0x21, 0x09, 0x0e, 0x39, 0x10, \n\t0x28, 0x70, 0x00, 0xc0, 0x20, 0xb0, 0x02, 0x6e, 0x00, 0x82, 0xe3, 0x02, 0x9d, 0x00, 0x2b, 0x74, \n\t0x21, 0xe1, 0x31, 0x15, 0x58, 0xaa, 0x40, 0xe0, 0x20, 0x30, 0x14, 0x52, 0xc4, 0x00, 0x16, 0x68, \n\t0xa0, 0x08, 0x10, 0x82, 0x58, 0x01, 0x18, 0x36, 0xe4, 0x0a, 0x61, 0x44, 0x01, 0xa1, 0x90, 0x94, \n\t0x11, 0xc0, 0x12, 0xc4, 0x13, 0x19, 0x44, 0x09, 0x66, 0x2a, 0x84, 0x18, 0x13, 0x05, 0xcd, 0x40, \n\t0x20, 0x30, 0x81, 0x02, 0x84, 0xd0, 0x40, 0x1e, 0x00, 0x1b, 0x15, 0x70, 0x12, 0x20, 0x22, 0x04, \n\t0x61, 0x05, 0x51, 0x03, 0x08, 0x40, 0x80, 0x8a, 0x8e, 0x30, 0x84, 0x40, 0x08, 0x84, 0x60, 0xb3, \n\t0x01, 0x52, 0x4a, 0x02, 0x06, 0x82, 0xb0, 0x49, 0x40, 0x46, 0x3a, 0x81, 0x00, 0x14, 0x00, 0x88, \n\t0xa4, 0x08, 0x14, 0x2a, 0x34, 0x7c, 0x04, 0x61, 0x00, 0xe1, 0xd8, 0x9c, 0xa4, 0x14, 0x86, 0x44, \n\t0x00, 0x41, 0x21, 0xc8, 0x4d, 0x04, 0x00, 0x02, 0x51, 0x2a, 0x01, 0x9d, 0x04, 0x40, 0x45, 0x60, \n\t0x98, 0x28, 0x42, 0x05, 0x0a, 0xa6, 0x00, 0x02, 0x99, 0x89, 0xa2, 0x20, 0x02, 0x02, 0x2d, 0xe8, \n\t0x10, 0x00, 0x5c, 0xb0, 0x83, 0x02, 0x4c, 0x02, 0xe8, 0x04, 0xa4, 0x02, 0x02, 0x04, 0x88, 0x42, \n\t0x4c, 0x32, 0x90, 0xbb, 0x00, 0xcd, 0x00, 0x72, 0x11, 0x2a, 0x04, 0x85, 0x01, 0x28, 0x10, 0x11, \n\t0xb2, 0x00, 0x88, 0x1a, 0xc3, 0x16, 0x81, 0xd3, 0x00, 0x00, 0x04, 0x87, 0x44, 0x70, 0x58, 0x91, \n\t0x30, 0x04, 0x45, 0x2c, 0x33, 0x28, 0x21, 0x40, 0x88, 0x81, 0x52, 0x80, 0xe8, 0x01, 0xa0, 0x80, \n\t0x0c, 0x36, 0x44, 0xe1, 0x12, 0x88, 0x18, 0xe2, 0x4a, 0x20, 0x0b, 0x20, 0x28, 0x81, 0x00, 0x48, \n\t0xb2, 0x10, 0x06, 0x0d, 0x8e, 0x00, 0x44, 0x15, 0x90, 0xa2, 0x04, 0x82, 0x01, 0x28, 0x42, 0xa8, \n\t0x90, 0x4d, 0x80, 0x25, 0x42, 0x10, 0x02, 0x0e, 0x81, 0x84, 0x2e, 0x54, 0x04, 0x10, 0x21, 0x00, \n\t0xd8, 0x02, 0x78, 0x81, 0x08, 0x06, 0xbc, 0x50, 0x4c, 0x10, 0xd0, 0x00, 0x30, 0xa4, 0x41, 0x22, \n\t0x02, 0x41, 0x51, 0x12, 0x50, 0x08, 0x07, 0x18, 0xb4, 0xe0, 0x01, 0x30, 0x4c, 0x68, 0x00, 0x32, \n\t0x08, 0x95, 0xb8, 0x90, 0xc0, 0x0c, 0xb0, 0x51, 0x10, 0x4c, 0x90, 0xce, 0x44, 0x21, 0xea, 0x00, \n\t0x28, 0x18, 0x0a, 0x10, 0x00, 0x22, 0x18, 0x04, 0x09, 0x05, 0x6a, 0x81, 0x08, 0x27, 0x09, 0x08, \n\t0xc2, 0x74, 0x45, 0x58, 0x00, 0xa1, 0x81, 0x00, 0x12, 0x50, 0x8a, 0x16, 0x04, 0x5a, 0x60, 0x00, \n\t0x86, 0x0a, 0x20, 0xc0, 0x1c, 0x08, 0x02, 0x05, 0x02, 0x1a, 0x41, 0x08, 0x4c, 0x2a, 0x24, 0x01, \n\t0xa1, 0x11, 0x12, 0x46, 0x00, 0x85, 0x80, 0xb8, 0x08, 0x42, 0x20, 0x32, 0x82, 0x30, 0x8a, 0x78, \n\t0x84, 0x89, 0x12, 0x02, 0x12, 0x10, 0x20, 0x81, 0x60, 0x46, 0x52, 0x01, 0x2f, 0x20, 0x10, 0x04, \n\t0x48, 0xa0, 0xe0, 0x00, 0xc4, 0x10, 0xa5, 0x22, 0x04, 0x82, 0x1a, 0x0d, 0x05, 0x04, 0x2a, 0x50, \n\t0x71, 0xa7, 0x04, 0x87, 0x02, 0x18, 0x60, 0xc8, 0x81, 0x1d, 0xc9, 0x00, 0x00, 0x05, 0x29, 0x30, \n\t0x0c, 0x55, 0x00, 0x54, 0x24, 0x03, 0x82, 0x70, 0x03, 0x25, 0x00, 0xb0, 0x40, 0x82, 0x85, 0x95, \n\t0x0d, 0x48, 0x10, 0x49, 0x16, 0x00, 0xd4, 0x08, 0x0e, 0xd4, 0x82, 0x80, 0x00, 0xce, 0xc6, 0x22, \n\t0x02, 0x48, 0x18, 0xb9, 0x52, 0xe0, 0x42, 0x20, 0x11, 0x2c, 0x58, 0x0a, 0x89, 0x48, 0x85, 0xc0, \n\t0x04, 0x05, 0x83, 0x88, 0x00, 0xa5, 0x10, 0x00, 0x30, 0x1f, 0x02, 0x08, 0x00, 0x90, 0x10, 0x45, \n\t0xcc, 0xac, 0x06, 0x70, 0xc0, 0x02, 0x31, 0x07, 0x03, 0x12, 0xe0, 0x22, 0x90, 0x00, 0x4d, 0x80, \n\t0x36, 0x01, 0x80, 0x02, 0xc8, 0x0c, 0x49, 0x18, 0x10, 0x40, 0x18, 0xe4, 0x06, 0x09, 0x22, 0x20, \n\t0x08, 0x08, 0x18, 0x09, 0x21, 0x66, 0x92, 0x09, 0x00, 0xe0, 0x4a, 0x8d, 0x32, 0x10, 0x41, 0x0d, \n\t0x19, 0x41, 0x29, 0x02, 0xb3, 0x40, 0x81, 0x94, 0x18, 0x44, 0x34, 0x03, 0x33, 0xb2, 0x58, 0x08, \n\t0x4c, 0x6c, 0x81, 0x82, 0x94, 0x0c, 0x44, 0x01, 0x44, 0x01, 0x81, 0x31, 0x40, 0xc3, 0x82, 0x00, \n\t0x75, 0xf2, 0x01, 0x18, 0x19, 0xca, 0x36, 0xc0, 0xa1, 0x04, 0x19, 0x10, 0xa1, 0x00, 0x75, 0x80, \n\t0x08, 0x89, 0x86, 0x20, 0x00, 0x01, 0x01, 0xa1, 0x31, 0x46, 0x00, 0x50, 0x01, 0xa0, 0x04, 0x04, \n\t0x05, 0x41, 0x4c, 0x66, 0x08, 0x90, 0x80, 0xd5, 0x01, 0x1c, 0x10, 0xb2, 0x08, 0xd0, 0x82, 0x29, \n\t0x50, 0x01, 0x40, 0x02, 0x70, 0x98, 0x81, 0x28, 0x14, 0x91, 0x9d, 0xd9, 0x98, 0x6f, 0x20, 0x80, \n\t0x02, 0x00, 0x41, 0x00, 0x20, 0x20, 0x04, 0xd3, 0x22, 0x08, 0x0d, 0xac, 0x28, 0x40, 0x70, 0x83, \n\t0xd1, 0x82, 0x09, 0x56, 0x25, 0x09, 0x1c, 0x59, 0x08, 0x82, 0x04, 0x12, 0x1a, 0x08, 0xa0, 0x00, \n\t0x87, 0x02, 0xc2, 0x20, 0x06, 0x41, 0x42, 0x08, 0x40, 0xe3, 0xc8, 0x02, 0x98, 0x83, 0x20, 0x6a, \n\t0x65, 0x5b, 0x02, 0x48, 0x81, 0x41, 0x0c, 0x92, 0xe0, 0x14, 0x18, 0x05, 0x41, 0x10, 0x43, 0x38, \n\t0x2c, 0x20, 0x86, 0x40, 0x0c, 0x46, 0x00, 0x19, 0xd1, 0x11, 0x20, 0x02, 0xd1, 0x10, 0x09, 0x05, \n\t0x01, 0xa6, 0x22, 0x04, 0x90, 0x8c, 0x20, 0x04, 0x00, 0x0e, 0x30, 0x88, 0x80, 0x09, 0x9f, 0x20, \n\t0x08, 0x40, 0x68, 0x20, 0x34, 0x01, 0xa7, 0x64, 0x00, 0x41, 0xb3, 0x24, 0x88, 0x08, 0x14, 0x12, \n\t0x08, 0x91, 0x20, 0x1c, 0x06, 0x00, 0xf0, 0x82, 0x2a, 0xb8, 0x16, 0x08, 0x24, 0xa1, 0x10, 0x10, \n\t0x01, 0x96, 0x4b, 0x56, 0x02, 0x60, 0x18, 0x20, 0x40, 0xa9, 0x58, 0x01, 0x73, 0x82, 0xc0, 0x8a, \n\t0x60, 0x04, 0x14, 0x82, 0x06, 0xdc, 0xda, 0xa8, 0x20, 0x22, 0x02, 0x97, 0x2c, 0x40, 0x04, 0x24, \n\t0x12, 0x21, 0x00, 0xa1, 0xc0, 0x80, 0x78, 0x54, 0x50, 0x23, 0xc1, 0x91, 0x01, 0x12, 0x27, 0x99, \n\t0x20, 0x01, 0x14, 0x04, 0x00, 0x44, 0x09, 0x92, 0x91, 0x40, 0x40, 0x0c, 0x51, 0x10, 0x33, 0x44, \n\t0x41, 0xcc, 0x60, 0xa5, 0x00, 0x08, 0x28, 0x16, 0x08, 0x00, 0x84, 0x33, 0x08, 0x49, 0x0b, 0x2a, \n\t0x04, 0x80, 0xa1, 0x21, 0x04, 0x95, 0x01, 0x0e, 0xa1, 0x50, 0x26, 0x24, 0x04, 0xe9, 0x10, 0xc2, \n\t0x50, 0x98, 0x01, 0xd8, 0xc0, 0x0a, 0x44, 0x30, 0x09, 0x65, 0x02, 0x02, 0x36, 0xd4, 0x22, 0x0a, \n\t0xc4, 0x14, 0x82, 0x00, 0x25, 0x0a, 0x07, 0x84, 0x07, 0x42, 0x12, 0x24, 0x19, 0x88, 0x80, 0x40, \n\t0x6c, 0x20, 0x30, 0x50, 0x82, 0x00, 0x00, 0xc8, 0x0e, 0x82, 0x01, 0xb6, 0x70, 0x84, 0x41, 0x40, \n\t0x27, 0x0b, 0xb4, 0x04, 0x89, 0x00, 0x38, 0x53, 0xca, 0x13, 0x80, 0x54, 0x42, 0x40, 0x84, 0x03, \n\t0x24, 0x6c, 0x44, 0x89, 0x1e, 0xa2, 0x6b, 0x04, 0x21, 0x18, 0x04, 0x00, 0x45, 0xa2, 0x84, 0xc8, \n\t0x01, 0x40, 0x20, 0x60, 0xa8, 0x20, 0x34, 0x82, 0x40, 0x20, 0x06, 0x5a, 0x80, 0x20, 0x80, 0x0a, \n\t0x70, 0x34, 0x52, 0x01, 0x15, 0x0b, 0x60, 0x24, 0xc7, 0x90, 0x32, 0x08, 0x4c, 0x82, 0x04, 0x26, \n\t0x92, 0xa1, 0xc9, 0x41, 0x23, 0x2c, 0x66, 0x29, 0x1d, 0xa5, 0x00, 0x00, 0x10, 0x41, 0xa8, 0x0a, \n\t0x20, 0x5c, 0x21, 0x54, 0xa3, 0x0a, 0x00, 0xb9, 0x40, 0x04, 0x2c, 0x20, 0x00, 0x04, 0x80, 0x03, \n\t0x0c, 0x18, 0xc0, 0x43, 0x00, 0x74, 0x0e, 0xa3, 0x04, 0x42, 0xc3, 0x0c, 0x80, 0xc2, 0x2a, 0x00, \n\t0x00, 0x82, 0x94, 0x48, 0xd2, 0x04, 0x24, 0x01, 0xf8, 0x23, 0x68, 0x12, 0x0c, 0x7c, 0x30, 0x00, \n\t0x03, 0x18, 0x1f, 0x60, 0x26, 0x00, 0x18, 0x04, 0x84, 0x05, 0x67, 0x10, 0x90, 0x02, 0x19, 0x30, \n\t0xcc, 0x86, 0x00, 0x26, 0x50, 0x10, 0x45, 0x47, 0x81, 0x08, 0x42, 0xaa, 0x01, 0xa4, 0x86, 0x29, \n\t0x70, 0x96, 0x00, 0x1d, 0x31, 0xc1, 0xe4, 0x5c, 0x02, 0x20, 0x09, 0x05, 0x14, 0x00, 0x40, 0x83, \n\t0x41, 0x28, 0xa8, 0x90, 0x00, 0x08, 0x32, 0xa0, 0xb7, 0x0d, 0x51, 0x02, 0x24, 0x85, 0x18, 0x0a, \n\t0x40, 0x08, 0x21, 0x12, 0x43, 0x12, 0x12, 0x40, 0x88, 0xa6, 0x06, 0x65, 0xc1, 0x34, 0x1c, 0x54, \n\t0x41, 0x20, 0x01, 0x48, 0x2a, 0x40, 0x05, 0x43, 0x56, 0x80, 0x80, 0x08, 0x34, 0x02, 0x47, 0x12, \n\t0x43, 0x21, 0x08, 0x00, 0x11, 0xc4, 0x0a, 0x01, 0x08, 0x05, 0x0c, 0x4c, 0x00, 0x06, 0x01, 0x70, \n\t0x80, 0x00, 0x5d, 0x48, 0x2c, 0x00, 0x12, 0x09, 0x2d, 0xc2, 0x48, 0x08, 0xe0, 0x19, 0x87, 0x00, \n\t0x98, 0x29, 0x20, 0x13, 0xc2, 0x08, 0x01, 0x81, 0x84, 0x2c, 0x21, 0x18, 0x2a, 0x78, 0x89, 0x05, \n\t0x60, 0x55, 0x00, 0x07, 0x61, 0x14, 0x80, 0x32, 0x14, 0x58, 0xa2, 0xb9, 0x42, 0x2a, 0x0c, 0xe6, \n\t0x52, 0x86, 0x8d, 0x48, 0x04, 0x00, 0xc4, 0xd0, 0x08, 0x28, 0xc3, 0x27, 0x02, 0x31, 0x18, 0x12, \n\t0x80, 0x12, 0x02, 0x02, 0x62, 0x01, 0x27, 0x24, 0x98, 0x01, 0x24, 0x42, 0x82, 0x94, 0x01, 0x16, \n\t0x05, 0x50, 0x34, 0x08, 0x04, 0x84, 0x43, 0x21, 0x08, 0x00, 0xb0, 0x88, 0x90, 0x16, 0x40, 0x40, \n\t0x74, 0x63, 0x2e, 0x00, 0x41, 0x60, 0x02, 0x24, 0x02, 0x02, 0x04, 0x49, 0x81, 0x44, 0x01, 0xc8, \n\t0x2a, 0xc0, 0x15, 0x80, 0x64, 0x24, 0xda, 0x84, 0x01, 0x08, 0x60, 0x08, 0xa1, 0x02, 0x10, 0x39, \n\t0x50, 0x20, 0x04, 0x84, 0x10, 0x12, 0x61, 0x02, 0x49, 0x22, 0xe0, 0x10, 0x3c, 0x61, 0xc6, 0x80, \n\t0x00, 0x86, 0x29, 0xa4, 0x10, 0x90, 0x25, 0x00, 0xc0, 0x80, 0x12, 0x18, 0x95, 0x40, 0x32, 0x12, \n\t0x89, 0x18, 0xd1, 0x02, 0x86, 0x54, 0x81, 0x20, 0x0c, 0x98, 0x06, 0x46, 0x20, 0xc0, 0x40, 0x18, \n\t0x0d, 0x09, 0x27, 0x2e, 0x40, 0x80, 0x2a, 0x40, 0x17, 0x40, 0x68, 0x12, 0x62, 0xa9, 0x0c, 0xc0, \n\t0x82, 0x1e, 0x54, 0xb1, 0x05, 0x28, 0x12, 0x68, 0x24, 0xa6, 0x62, 0x2e, 0x20, 0x51, 0x04, 0x44, \n\t0x91, 0x53, 0x83, 0xc8, 0x00, 0x28, 0x00, 0x42, 0x29, 0x11, 0xa0, 0x06, 0xc8, 0x1a, 0x45, 0x08, \n\t0x10, 0x84, 0x5b, 0x25, 0x10, 0x86, 0xc2, 0x10, 0x48, 0x08, 0x2e, 0x14, 0x22, 0xc0, 0x2d, 0x00, \n\t0x50, 0x42, 0x48, 0xc1, 0x80, 0x81, 0x80, 0x10, 0x01, 0x20, 0x02, 0xc1, 0x15, 0x01, 0x02, 0x48, \n\t0x22, 0x07, 0x82, 0x14, 0x00, 0xd4, 0xc2, 0x02, 0x01, 0x5b, 0x06, 0x25, 0x84, 0x00, 0x02, 0x64, \n\t0xb8, 0x02, 0xc8, 0x8e, 0x89, 0x20, 0x01, 0x8a, 0x12, 0x80, 0x10, 0x8c, 0x02, 0x92, 0x02, 0x80, \n\t0x01, 0x43, 0x2d, 0x08, 0x82, 0x21, 0x00, 0x11, 0x01, 0x8a, 0x12, 0x94, 0x02, 0x03, 0x30, 0xc0, \n\t0x6d, 0x24, 0x86, 0x21, 0x04, 0x50, 0xc0, 0xa0, 0x0e, 0x12, 0x81, 0x29, 0xc4, 0x06, 0x63, 0x00, \n\t0x42, 0x02, 0x80, 0x10, 0x06, 0x0d, 0x08, 0x45, 0x50, 0x01, 0x1c, 0x98, 0x4c, 0x64, 0x64, 0x90, \n\t0x88, 0x30, 0x8a, 0x43, 0x5a, 0x01, 0x11, 0x03, 0xa8, 0x43, 0x20, 0x00, 0x00, 0xa3, 0xb6, 0x24, \n\t0x0e, 0x6b, 0x20, 0xc4, 0x22, 0x00, 0x4c, 0x48, 0xe0, 0x24, 0x21, 0x90, 0x01, 0x8c, 0x88, 0xa8, \n\t0x04, 0x22, 0x68, 0xb3, 0xa5, 0x52, 0x42, 0x4a, 0xc2, 0x0b, 0x1d, 0x00, 0xc8, 0x04, 0x02, 0x10, \n\t0x2a, 0x84, 0x80, 0x08, 0x45, 0x4a, 0x24, 0x8b, 0x00, 0x30, 0x10, 0x21, 0x18, 0x52, 0xc9, 0x02, \n\t0xc5, 0x98, 0x02, 0x10, 0x81, 0x02, 0x21, 0x91, 0x40, 0x65, 0x40, 0x41, 0x90, 0x92, 0x11, 0xd4, \n\t0x20, 0x5a, 0x83, 0x20, 0x00, 0x25, 0x82, 0x0c, 0x06, 0x15, 0x41, 0x16, 0x04, 0x81, 0x02, 0x6a, \n\t0x41, 0x89, 0x12, 0xb1, 0x00, 0x6f, 0x54, 0x01, 0x09, 0x1a, 0x8d, 0x02, 0x00, 0x32, 0xd0, 0x01, \n\t0xa5, 0x15, 0x81, 0x01, 0x10, 0x80, 0x22, 0x00, 0x84, 0xc0, 0x00, 0x58, 0x24, 0xc1, 0x13, 0x09, \n\t0x12, 0xe0, 0x16, 0x84, 0x9a, 0x05, 0x08, 0x53, 0x84, 0x42, 0x00, 0x68, 0x21, 0x21, 0x0a, 0x49, \n\t0x10, 0x10, 0x12, 0x81, 0x10, 0x10, 0x63, 0x42, 0x41, 0x02, 0x01, 0x05, 0xdb, 0xc4, 0x3c, 0x11, \n\t0xb0, 0x00, 0xc9, 0x0c, 0x0e, 0x20, 0x20, 0x12, 0x90, 0x69, 0x08, 0x82, 0x42, 0x01, 0x8b, 0x30, \n\t0x2c, 0x4c, 0x00, 0x22, 0x02, 0x43, 0xa9, 0xc0, 0x84, 0xc8, 0x0c, 0xf2, 0x00, 0x04, 0x60, 0x4a, \n\t0x00, 0x40, 0xa4, 0x08, 0x22, 0x04, 0xc7, 0x04, 0x42, 0x05, 0x20, 0x1d, 0xc1, 0x04, 0x85, 0x6a, \n\t0x20, 0x22, 0x1c, 0xc8, 0x55, 0x88, 0x00, 0x00, 0xa0, 0x05, 0x21, 0x14, 0xc8, 0x48, 0x22, 0x20, \n\t0x1a, 0x10, 0x49, 0x0d, 0x2e, 0xc4, 0x9a, 0x04, 0x01, 0x90, 0x44, 0x12, 0x04, 0x42, 0x21, 0x20, \n\t0x84, 0x22, 0x74, 0x00, 0x60, 0x82, 0x29, 0x40, 0xa8, 0x00, 0x87, 0xb3, 0x98, 0xb4, 0x14, 0x05, \n\t0x40, 0xa2, 0x41, 0x0b, 0x19, 0xce, 0x08, 0x04, 0x02, 0x38, 0x89, 0x15, 0x82, 0xc0, 0x40, 0x50, \n\t0x08, 0xa0, 0x20, 0x03, 0x08, 0x10, 0xa1, 0x90, 0x1d, 0x90, 0x5a, 0x40, 0x06, 0x96, 0xd3, 0x08, \n\t0x81, 0x02, 0x07, 0x00, 0xc0, 0x49, 0x08, 0x8c, 0x80, 0xa4, 0x00, 0xc7, 0x90, 0x2b, 0xc9, 0x88, \n\t0x40, 0x08, 0x20, 0x00, 0xa4, 0x41, 0x04, 0x20, 0x38, 0x52, 0x00, 0x00, 0xc0, 0x13, 0x00, 0x12, \n\t0x00, 0xe2, 0x82, 0x91, 0x03, 0x49, 0x04, 0x84, 0x52, 0x02, 0xa0, 0x4d, 0x21, 0x36, 0x00, 0x8a, \n\t0xb1, 0xd4, 0x4a, 0xee, 0x08, 0x40, 0x48, 0xb2, 0xd0, 0x08, 0x85, 0x30, 0x64, 0x23, 0x39, 0x08, \n\t0x80, 0x0c, 0x0a, 0x90, 0x01, 0x10, 0x51, 0x88, 0x62, 0x40, 0x12, 0x49, 0x1d, 0x2c, 0x80, 0xcd, \n\t0x14, 0xa0, 0x31, 0x21, 0x24, 0x00, 0x86, 0x10, 0xa2, 0xd2, 0x82, 0x05, 0x49, 0x6a, 0x60, 0x00, \n\t0x02, 0x08, 0x35, 0x03, 0x22, 0x54, 0x90, 0xd8, 0xa4, 0x09, 0x59, 0x0a, 0x30, 0x00, 0x08, 0x15, \n\t0x61, 0x00, 0x0a, 0x04, 0xa4, 0xb3, 0x92, 0x00, 0x41, 0x40, 0x00, 0x47, 0x02, 0x00, 0xd4, 0x04, \n\t0xac, 0x0a, 0xa7, 0x10, 0x81, 0x01, 0xc1, 0x0e, 0x22, 0x22, 0x40, 0x24, 0x3c, 0x14, 0x6c, 0x28, \n\t0xc2, 0xd8, 0x18, 0xe1, 0x11, 0x0c, 0x00, 0x00, 0x82, 0x1d, 0xb5, 0x06, 0x01, 0x4e, 0x43, 0x63, \n\t0x0c, 0x4d, 0x8c, 0x08, 0x6c, 0x03, 0x20, 0x8c, 0x4c, 0x08, 0x01, 0x00, 0x32, 0x88, 0x0a, 0x21, \n\t0x0f, 0x45, 0x20, 0x90, 0x43, 0x20, 0x04, 0x16, 0xac, 0x20, 0x54, 0x08, 0x85, 0x51, 0x89, 0xc0, \n\t0x3e, 0x23, 0xb2, 0xa0, 0x0d, 0x10, 0x48, 0x00, 0x34, 0x19, 0xa2, 0xc0, 0x86, 0x40, 0x12, 0xe0, \n\t0x01, 0x0e, 0x20, 0x03, 0x80, 0x00, 0xc0, 0x29, 0x8a, 0x90, 0x46, 0x24, 0x08, 0x84, 0x00, 0x87, \n\t0x89, 0x41, 0x64, 0x38, 0x04, 0x49, 0x04, 0x28, 0xc5, 0x06, 0x0e, 0x93, 0xb0, 0x0a, 0x34, 0x04, \n\t0x04, 0x6c, 0x20, 0x23, 0x1e, 0x81, 0x5a, 0x81, 0x4a, 0x61, 0x90, 0x84, 0x50, 0x0e, 0x42, 0x0c, \n\t0x12, 0xa1, 0x26, 0xa8, 0x88, 0x04, 0x34, 0x10, 0x28, 0x20, 0x90, 0x45, 0x83, 0x30, 0x25, 0x1a, \n\t0x20, 0x8c, 0x41, 0x05, 0x00, 0xc4, 0x48, 0xa8, 0x89, 0x4d, 0x01, 0x08, 0xc2, 0x00, 0xa4, 0x45, \n\t0x58, 0x01, 0x78, 0x31, 0x2b, 0x28, 0x88, 0x06, 0x21, 0x62, 0x10, 0x23, 0x9a, 0x90, 0x88, 0x41, \n\t0x10, 0x80, 0x19, 0x01, 0x40, 0x06, 0x21, 0x48, 0x11, 0x82, 0x20, 0xd0, 0x18, 0x09, 0x04, 0xb1, \n\t0x00, 0x25, 0xc0, 0x00, 0xc6, 0x20, 0x06, 0x22, 0x29, 0x59, 0x53, 0x60, 0x38, 0x81, 0x30, 0x8e, \n\t0x88, 0x06, 0xa4, 0x0e, 0x20, 0xa0, 0x84, 0x00, 0x02, 0x00, 0x20, 0x65, 0x32, 0x84, 0x00, 0x00, \n\t0x0a, 0x12, 0x12, 0x01, 0x2a, 0x18, 0x0f, 0x45, 0x02, 0x92, 0x69, 0x20, 0xa5, 0x51, 0x44, 0x12, \n\t0x44, 0x00, 0x2a, 0x18, 0x0d, 0x24, 0x52, 0xc4, 0x22, 0x8a, 0x80, 0x80, 0x00, 0x20, 0x00, 0xd8, \n\t0x00, 0x25, 0x12, 0x01, 0x44, 0x72, 0x02, 0x8a, 0x7c, 0x10, 0x20, 0x2c, 0x35, 0x52, 0x00, 0x80, \n\t0x90, 0x4a, 0x02, 0x05, 0x80, 0x14, 0x49, 0x18, 0x01, 0x18, 0x92, 0x88, 0xb1, 0x69, 0x18, 0x2c, \n\t0x34, 0x50, 0x4a, 0x80, 0x95, 0x16, 0x82, 0x10, 0x42, 0xa0, 0x0c, 0x90, 0x04, 0xaa, 0x44, 0x26, \n\t0x89, 0x10, 0x24, 0x40, 0x0b, 0x0e, 0x21, 0x20, 0x1c, 0x04, 0x86, 0x08, 0x10, 0xc1, 0x00, 0x0f, \n\t0x30, 0x5c, 0x04, 0x40, 0xa0, 0x2b, 0x98, 0x30, 0xd9, 0x61, 0x72, 0x24, 0x23, 0x21, 0x25, 0x46, \n\t0xe4, 0x1c, 0x00, 0x42, 0x08, 0x00, 0x88, 0xc1, 0x2c, 0x35, 0x20, 0x14, 0x40, 0x00, 0x23, 0x26, \n\t0xf4, 0x20, 0x15, 0x14, 0xda, 0x20, 0x00, 0x40, 0x53, 0x2f, 0xc0, 0xcb, 0x26, 0x52, 0x11, 0x01, \n\t0x06, 0xe1, 0xc0, 0x4a, 0x6a, 0x82, 0x48, 0x12, 0x80, 0x11, 0x00, 0x34, 0x87, 0x00, 0x21, 0xa9, \n\t0x00, 0x4a, 0x22, 0x80, 0x60, 0x33, 0x21, 0x10, 0x0a, 0x18, 0x42, 0xa0, 0x20, 0x3c, 0x92, 0x40, \n\t0x04, 0x61, 0x42, 0x1a, 0x58, 0x02, 0x82, 0x4a, 0x80, 0x00, 0x10, 0xdc, 0x01, 0x21, 0x04, 0xb0, \n\t0x9a, 0x04, 0x04, 0x02, 0x00, 0x28, 0x20, 0x52, 0x19, 0x80, 0xc1, 0xc6, 0x4c, 0x04, 0x28, 0x01, \n\t0x44, 0x93, 0x21, 0x30, 0x40, 0x08, 0xb4, 0x41, 0xc5, 0x28, 0x00, 0x30, 0x8a, 0x01, 0x00, 0x1a, \n\t0x60, 0x04, 0xc0, 0x03, 0xa0, 0x24, 0x14, 0xad, 0x20, 0x04, 0xc1, 0x00, 0x39, 0x48, 0x4c, 0x02, \n\t0xc6, 0x20, 0x20, 0x74, 0x95, 0x00, 0x22, 0x16, 0xc3, 0x1a, 0x00, 0x42, 0x01, 0x12, 0xe3, 0xc1, \n\t0x89, 0x68, 0x10, 0x24, 0x12, 0x86, 0x12, 0x08, 0x20, 0x14, 0x27, 0x00, 0x70, 0x80, 0x09, 0x50, \n\t0x8a, 0x8b, 0x70, 0x81, 0x10, 0x29, 0xcc, 0x01, 0x86, 0x04, 0x01, 0x10, 0x98, 0x3c, 0x50, 0xa0, \n\t0x02, 0x44, 0x00, 0x10, 0x49, 0x0a, 0x80, 0x3a, 0x60, 0x20, 0x15, 0xd0, 0x44, 0x00, 0x08, 0x25, \n\t0x81, 0x3a, 0x00, 0x15, 0xc0, 0x10, 0x42, 0x0a, 0x10, 0xc0, 0x0b, 0x20, 0x08, 0x71, 0x28, 0x2c, \n\t0xc0, 0x99, 0x41, 0x02, 0x30, 0x00, 0x00, 0x80, 0x99, 0x6c, 0x24, 0x63, 0x09, 0x10, 0x50, 0xc5, \n\t0x66, 0x0c, 0x12, 0x0a, 0x01, 0x94, 0x07, 0x0a, 0x42, 0x80, 0xe2, 0xa6, 0x29, 0x8c, 0x20, 0x04, \n\t0x11, 0x10, 0x01, 0x01, 0x18, 0x03, 0x24, 0x40, 0x18, 0x8c, 0x04, 0x88, 0xc6, 0x4c, 0x83, 0x20, \n\t0x09, 0xe0, 0x47, 0x8c, 0x40, 0x40, 0x01, 0x06, 0x25, 0x14, 0xc0, 0x72, 0x05, 0x70, 0x84, 0x40, \n\t0x40, 0x43, 0x20, 0xb0, 0x88, 0x13, 0x88, 0x89, 0xa2, 0x20, 0x55, 0x00, 0x00, 0x20, 0xd3, 0x04, \n\t0x08, 0x12, 0x21, 0x05, 0x08, 0x41, 0x68, 0x4a, 0x16, 0x00, 0x8e, 0x61, 0x00, 0xc6, 0x0c, 0xa2, \n\t0xc9, 0x01, 0xa8, 0x55, 0x00, 0x12, 0x60, 0x6a, 0x87, 0xd8, 0x12, 0x8a, 0x20, 0x14, 0x11, 0x32, \n\t0x00, 0x00, 0xa4, 0x08, 0x06, 0x10, 0x0d, 0x14, 0x10, 0x05, 0x40, 0x01, 0xa0, 0xa8, 0x40, 0x0f, \n\t0x80, 0x42, 0x04, 0x43, 0x37, 0x0c, 0x94, 0x4b, 0x28, 0x80, 0x90, 0x0c, 0x8d, 0x0d, 0xc9, 0x72, \n\t0x30, 0xd8, 0x92, 0x05, 0x01, 0x23, 0x1a, 0x10, 0x00, 0x81, 0x90, 0x06, 0xc5, 0x00, 0xa2, 0x02, \n\t0x88, 0x94, 0x56, 0x00, 0x08, 0x22, 0x49, 0x16, 0xc0, 0x81, 0x21, 0x18, 0xa0, 0x03, 0x11, 0x75, \n\t0x02, 0xc0, 0x46, 0x52, 0x90, 0x28, 0x30, 0x8a, 0x28, 0x30, 0x04, 0x10, 0x8a, 0x19, 0x49, 0x01, \n\t0x2c, 0x07, 0x00, 0x00, 0x44, 0x40, 0x24, 0x0a, 0x97, 0x59, 0x98, 0x01, 0x58, 0xa0, 0x22, 0x01, \n\t0x21, 0x00, 0xf4, 0xda, 0xa8, 0x5e, 0x60, 0x00, 0xac, 0x65, 0x01, 0x80, 0x42, 0xd0, 0x03, 0x00, \n\t0x14, 0x03, 0x4b, 0x02, 0x02, 0x60, 0x16, 0x81, 0x88, 0x84, 0x02, 0x62, 0xaa, 0x14, 0x84, 0xc2, \n\t0x40, 0x52, 0x15, 0x00, 0x95, 0x80, 0x01, 0x04, 0x10, 0x20, 0x08, 0x38, 0x08, 0xd0, 0x60, 0x14, \n\t0x20, 0x88, 0x88, 0x89, 0x14, 0x85, 0x3c, 0x00, 0x82, 0x03, 0x40, 0x90, 0x84, 0x02, 0x62, 0x22, \n\t0x01, 0x40, 0xcc, 0xc1, 0x1e, 0x13, 0x02, 0x2a, 0x20, 0x40, 0x22, 0x00, 0x10, 0x8b, 0x00, 0xa9, \n\t0x83, 0x00, 0x08, 0x85, 0x03, 0x38, 0x69, 0x59, 0x22, 0x54, 0xe1, 0xd0, 0xa0, 0xd4, 0x40, 0x29, \n\t0x12, 0x74, 0x20, 0x21, 0x54, 0x08, 0x08, 0x08, 0xc2, 0x22, 0x2b, 0x90, 0x14, 0x01, 0x4a, 0x53, \n\t0x30, 0x01, 0x30, 0x18, 0x40, 0x44, 0x84, 0x98, 0x30, 0x1c, 0x02, 0x04, 0x10, 0x61, 0x29, 0x08, \n\t0x4c, 0x02, 0x61, 0x10, 0x04, 0x60, 0x98, 0xd0, 0x08, 0x8b, 0x00, 0x14, 0x92, 0x2c, 0x61, 0x06, \n\t0x85, 0x0a, 0x12, 0xa1, 0x1b, 0xe0, 0x83, 0x88, 0x5c, 0x21, 0x48, 0x20, 0x30, 0x41, 0x8a, 0x46, \n\t0x84, 0x50, 0x0e, 0x09, 0x01, 0x05, 0x70, 0x40, 0x81, 0x02, 0x14, 0x01, 0xc8, 0x00, 0xd5, 0x01, \n\t0x20, 0x00, 0x0d, 0x4f, 0x58, 0x00, 0xe0, 0x90, 0x08, 0x50, 0x09, 0x0a, 0x23, 0xcb, 0x0c, 0x09, \n\t0xc4, 0x02, 0x26, 0x86, 0x58, 0x0d, 0x0c, 0x94, 0x41, 0x5a, 0xd2, 0x18, 0x04, 0x80, 0x02, 0x06, \n\t0x40, 0x14, 0xc0, 0x04, 0x11, 0x08, 0x04, 0x42, 0x60, 0x20, 0x03, 0x48, 0xc1, 0x80, 0x42, 0x15, \n\t0x50, 0x18, 0xc1, 0x14, 0x2a, 0x24, 0x55, 0x58, 0x14, 0x64, 0x54, 0x69, 0x20, 0x04, 0x91, 0x90, \n\t0x60, 0x50, 0xc8, 0x22, 0x23, 0x40, 0x21, 0x01, 0x4e, 0x65, 0x08, 0x25, 0x00, 0x18, 0x01, 0x0c, \n\t0x03, 0x20, 0x04, 0xe1, 0x91, 0x34, 0xc1, 0x68, 0x30, 0x41, 0x10, 0x02, 0x21, 0x12, 0x0a, 0x00, \n\t0x04, 0xf0, 0x2c, 0x58, 0x04, 0x8d, 0x00, 0x80, 0x2b, 0xa8, 0x70, 0x16, 0x65, 0x08, 0xc2, 0x80, \n\t0x12, 0x8c, 0x82, 0x44, 0x48, 0x20, 0x30, 0x14, 0x04, 0xc0, 0x81, 0x20, 0x02, 0x42, 0xb0, 0x00, \n\t0x46, 0x80, 0x18, 0x14, 0x02, 0x10, 0x38, 0x4a, 0xc2, 0x60, 0xc0, 0x6a, 0x0a, 0x88, 0x4c, 0x88, \n\t0x20, 0x21, 0xc2, 0x0b, 0xe8, 0xc4, 0xa4, 0x04, 0x40, 0x00, 0x0a, 0x60, 0x58, 0x4c, 0x18, 0x72, \n\t0x89, 0x23, 0x00, 0x0a, 0x20, 0x2a, 0x26, 0x02, 0x08, 0x88, 0x10, 0x04, 0x14, 0x80, 0x20, 0x31, \n\t0x3c, 0x54, 0xc0, 0x00, 0x81, 0xa3, 0x80, 0x44, 0x00, 0x66, 0x24, 0x81, 0x43, 0x16, 0x81, 0x18, \n\t0x87, 0x06, 0x14, 0x20, 0x15, 0x00, 0x04, 0x23, 0x04, 0x46, 0xe2, 0x3f, 0x00, 0x03, 0x04, 0x54, \n\t0x30, 0x61, 0x12, 0xc0, 0x02, 0x41, 0x46, 0x21, 0xc3, 0x8a, 0x14, 0x08, 0x26, 0x30, 0x24, 0x48, \n\t0x21, 0x0d, 0x07, 0xa1, 0x18, 0xa2, 0x70, 0x06, 0x00, 0x92, 0x00, 0x78, 0x47, 0x20, 0xb0, 0x0c, \n\t0x55, 0x00, 0x2e, 0xe2, 0x20, 0x88, 0xb1, 0x8a, 0x8c, 0x02, 0x02, 0x03, 0x0c, 0x81, 0x50, 0x83, \n\t0x44, 0x93, 0x00, 0x26, 0xc1, 0x04, 0x40, 0x20, 0xf1, 0x01, 0x20, 0xc8, 0x11, 0x4e, 0x2e, 0x00, \n\t0x20, 0x23, 0x51, 0x50, 0x20, 0x7c, 0x06, 0x81, 0x08, 0x48, 0x4c, 0x82, 0x14, 0x00, 0xca, 0xa5, \n\t0x44, 0x17, 0x00, 0x08, 0x02, 0x0a, 0x9a, 0x50, 0x10, 0x40, 0x22, 0x40, 0x01, 0x08, 0x75, 0x80, \n\t0x2a, 0x02, 0x46, 0x21, 0x8a, 0x24, 0x49, 0x81, 0x0a, 0x94, 0x03, 0x8d, 0x04, 0x00, 0x24, 0x48, \n\t0xa0, 0x3a, 0x02, 0x01, 0x4c, 0x09, 0x48, 0x22, 0x42, 0x08, 0xc0, 0x13, 0xac, 0x08, 0xb2, 0x91, \n\t0x00, 0x04, 0x98, 0x41, 0x64, 0x01, 0xc1, 0x2a, 0x40, 0x83, 0x21, 0x64, 0x33, 0x1a, 0x08, 0x00, \n\t0x00, 0x20, 0x12, 0x94, 0x4b, 0x95, 0xcc, 0x58, 0x04, 0x20, 0x54, 0x48, 0xa0, 0xa9, 0x08, 0x43, \n\t0x20, 0x01, 0xd0, 0xa0, 0xe1, 0x40, 0x04, 0x06, 0xb7, 0x91, 0x01, 0x29, 0xcb, 0xe0, 0x20, 0x25, \n\t0x18, 0x24, 0x84, 0x00, 0xc0, 0x10, 0x50, 0x01, 0x01, 0x38, 0x00, 0x2c, 0x00, 0x67, 0xa1, 0x18, \n\t0x90, 0x00, 0x8d, 0x68, 0x04, 0x70, 0x28, 0x18, 0x87, 0x83, 0x16, 0x30, 0x62, 0x0c, 0x14, 0x10, \n\t0xaa, 0x30, 0x17, 0xa2, 0xa5, 0xc9, 0x92, 0x44, 0x20, 0xb2, 0x0a, 0x03, 0x5d, 0x01, 0xc4, 0x4e, \n\t0x10, 0x8a, 0x21, 0x40, 0x90, 0x80, 0x2a, 0x24, 0x00, 0x21, 0xf0, 0x41, 0x42, 0x56, 0x02, 0x02, \n\t0x14, 0x60, 0x49, 0x20, 0x02, 0x04, 0x81, 0xa2, 0x08, 0x40, 0x42, 0x00, 0x00, 0x20, 0x23, 0x31, \n\t0x04, 0x88, 0x40, 0x01, 0x61, 0x84, 0x28, 0x46, 0x0c, 0x48, 0xb1, 0xb2, 0x06, 0x20, 0x08, 0x8e, \n\t0x72, 0x30, 0x99, 0x15, 0x31, 0x44, 0x0d, 0x04, 0xa2, 0x63, 0x84, 0x21, 0x90, 0xa2, 0x00, 0xc4, \n\t0x41, 0x05, 0x1c, 0xc8, 0x05, 0x28, 0x11, 0x18, 0x02, 0x49, 0x03, 0x00, 0x18, 0x15, 0xd0, 0xa2, \n\t0x0c, 0xc0, 0x26, 0x46, 0x04, 0x28, 0x02, 0x1d, 0xd1, 0x01, 0x54, 0xe3, 0x8a, 0x80, 0x00, 0x10, \n\t0xce, 0x04, 0x02, 0x10, 0xa3, 0x70, 0x04, 0x03, 0x26, 0x97, 0x09, 0xb3, 0x90, 0x96, 0x00, 0x18, \n\t0x82, 0xc8, 0x21, 0x1c, 0x5c, 0x61, 0x00, 0x41, 0x42, 0x05, 0x80, 0x88, 0x21, 0x08, 0xa0, 0x10, \n\t0x09, 0x15, 0xc0, 0x00, 0x40, 0x01, 0xa8, 0x09, 0x68, 0x1a, 0x8a, 0x50, 0x80, 0xc0, 0x23, 0x80, \n\t0x52, 0xc9, 0x00, 0x47, 0x82, 0x22, 0x01, 0x45, 0x45, 0x40, 0x51, 0x78, 0x05, 0x21, 0x0a, 0x84, \n\t0x66, 0x44, 0x1a, 0x82, 0x01, 0x4b, 0x23, 0x70, 0x45, 0xb0, 0x84, 0x48, 0x40, 0x49, 0x32, 0x10, \n\t0x11, 0x08, 0x98, 0x00, 0x81, 0x28, 0x61, 0x41, 0x0d, 0x14, 0x83, 0x84, 0x20, 0x16, 0x41, 0x96, \n\t0xa0, 0x91, 0x08, 0x2c, 0x70, 0x80, 0x83, 0x51, 0x48, 0x20, 0x28, 0x14, 0x90, 0x01, 0xd9, 0x11, \n\t0x24, 0x5a, 0x21, 0x70, 0x03, 0x38, 0x86, 0xa8, 0x04, 0x20, 0x43, 0x28, 0x08, 0x88, 0x43, 0x6c, \n\t0x86, 0x80, 0x85, 0x28, 0x0a, 0x87, 0x04, 0x41, 0x89, 0x32, 0x00, 0x50, 0x28, 0x12, 0x50, 0x38, \n\t0xb0, 0x80, 0x88, 0xaa, 0x10, 0x24, 0x28, 0x0a, 0xb1, 0x40, 0x22, 0x16, 0x65, 0x10, 0xa9, 0x09, \n\t0x09, 0xc1, 0x04, 0x02, 0x59, 0x1c, 0x84, 0x14, 0x42, 0x02, 0x62, 0x89, 0x0c, 0x20, 0x09, 0x64, \n\t0x40, 0x82, 0x49, 0x0a, 0x21, 0x97, 0x41, 0x52, 0x06, 0x13, 0x04, 0x40, 0x00, 0x62, 0x06, 0x80, \n\t0xa1, 0x84, 0x08, 0x90, 0x00, 0x08, 0x80, 0x60, 0x02, 0x18, 0x41, 0x84, 0x42, 0xe1, 0x82, 0x03, \n\t0x10, 0x40, 0x21, 0x50, 0x02, 0x42, 0x84, 0x04, 0x4a, 0x0a, 0x4a, 0x11, 0xa3, 0x82, 0xac, 0x99, \n\t0x08, 0x56, 0x23, 0x01, 0x0a, 0x8c, 0x5c, 0xa4, 0x46, 0x34, 0x00, 0x88, 0x1c, 0x82, 0x0d, 0x32, \n\t0x11, 0x00, 0x33, 0x81, 0x01, 0x40, 0x08, 0x00, 0x08, 0x2e, 0x80, 0x10, 0x28, 0x68, 0x61, 0x29, \n\t0x02, 0x80, 0x00, 0x46, 0x40, 0x30, 0xa9, 0x00, 0x98, 0x13, 0x2c, 0x10, 0xb0, 0x89, 0x01, 0x30, \n\t0x8c, 0x86, 0x30, 0x23, 0x50, 0x03, 0x00, 0x40, 0x02, 0x08, 0x80, 0xa0, 0x25, 0x10, 0x08, 0xe6, \n\t0x16, 0x04, 0x40, 0x98, 0x20, 0x16, 0x0c, 0x54, 0x41, 0xd2, 0x10, 0x30, 0x12, 0x00, 0x1a, 0x42, \n\t0x82, 0x30, 0x45, 0x19, 0xad, 0x40, 0x83, 0x4a, 0x91, 0xa8, 0x81, 0x00, 0x12, 0x02, 0x51, 0x00, \n\t0x20, 0x9a, 0x04, 0x40, 0x64, 0x68, 0x3c, 0x30, 0xda, 0x41, 0x62, 0xb0, 0x18, 0x10, 0xe9, 0x41, \n\t0x80, 0x0c, 0x36, 0x62, 0x2c, 0x15, 0x85, 0x69, 0x08, 0x11, 0x01, 0x08, 0x68, 0x82, 0x0c, 0x7c, \n\t0x04, 0x32, 0x1a, 0x95, 0x00, 0x6d, 0x60, 0x50, 0x10, 0x87, 0x25, 0x0c, 0x00, 0x4c, 0x80, 0x11, \n\t0x28, 0x80, 0x44, 0x26, 0x58, 0x11, 0x80, 0x85, 0x25, 0x16, 0x4a, 0x0c, 0x41, 0x88, 0x10, 0x04, \n\t0x08, 0x42, 0x42, 0x84, 0x43, 0x80, 0x94, 0x48, 0x02, 0x02, 0x47, 0x49, 0x95, 0x70, 0x09, 0xc0, \n\t0x00, 0x00, 0x09, 0x1a, 0xa4, 0x01, 0x05, 0x20, 0x80, 0x00, 0x09, 0x50, 0x4a, 0x6e, 0x30, 0xb0, \n\t0x00, 0x10, 0x8d, 0x01, 0xaa, 0x0a, 0xd1, 0x4a, 0x07, 0x21, 0x80, 0xa6, 0x00, 0x20, 0x12, 0x2c, \n\t0x48, 0x82, 0x40, 0x20, 0x51, 0x98, 0x24, 0x65, 0x86, 0x20, 0x2a, 0xd0, 0x02, 0x1d, 0x69, 0x08, \n\t0xa0, 0x18, 0x30, 0x43, 0x01, 0x81, 0xca, 0x48, 0x30, 0x21, 0x90, 0xa2, 0x99, 0x00, 0x4d, 0x04, \n\t0x45, 0x80, 0x02, 0x08, 0xc8, 0x08, 0x0c, 0xd2, 0x60, 0xab, 0x75, 0x41, 0x00, 0x30, 0x86, 0x60, \n\t0x04, 0x30, 0x44, 0x29, 0x14, 0x47, 0x32, 0x94, 0x50, 0x0c, 0x80, 0x64, 0xb0, 0x40, 0x0c, 0xd4, \n\t0x14, 0x80, 0x1c, 0x00, 0x18, 0x28, 0xcd, 0x8c, 0x08, 0x00, 0x54, 0xe3, 0x38, 0x04, 0xc0, 0x69, \n\t0x40, 0x45, 0x38, 0xa0, 0x05, 0xc9, 0x22, 0x10, 0x83, 0x20, 0x9c, 0x0c, 0x93, 0x88, 0x60, 0x00, \n\t0x53, 0x94, 0x40, 0x16, 0x22, 0x3c, 0x20, 0x3a, 0x00, 0x14, 0x01, 0xc1, 0x04, 0x86, 0x08, 0x20, \n\t0x40, 0x88, 0x00, 0x30, 0x83, 0x48, 0x18, 0xb0, 0x11, 0x47, 0x08, 0x20, 0xe2, 0x22, 0x80, 0x4f, \n\t0x20, 0x08, 0x80, 0x92, 0x01, 0xa8, 0x05, 0x05, 0x22, 0x04, 0xd3, 0x10, 0xc1, 0x00, 0x8e, 0x0a, \n\t0xc1, 0x00, 0x08, 0x44, 0x0e, 0x4a, 0x48, 0x23, 0x40, 0x80, 0x44, 0x8a, 0x07, 0x40, 0x50, 0x98, \n\t0x37, 0x28, 0x10, 0x66, 0x02, 0x94, 0x69, 0x04, 0x29, 0x10, 0x22, 0x30, 0x40, 0x23, 0x14, 0x74, \n\t0xc4, 0x40, 0x0e, 0x02, 0x00, 0x94, 0x00, 0x09, 0xe8, 0x44, 0x21, 0x90, 0x12, 0x84, 0x81, 0x46, \n\t0x04, 0x46, 0x31, 0x8a, 0x05, 0xc9, 0x01, 0x50, 0x46, 0xc0, 0x07, 0x10, 0xc0, 0x0c, 0x02, 0x84, \n\t0xc0, 0x10, 0x08, 0x80, 0x49, 0x06, 0x02, 0x21, 0x04, 0x24, 0x96, 0x40, 0x04, 0x41, 0x1b, 0x0a, \n\t0x2c, 0x02, 0xca, 0x54, 0x20, 0x03, 0x81, 0xc4, 0x0a, 0x83, 0x40, 0xd2, 0x22, 0x0c, 0x20, 0x46, \n\t0x00, 0x20, 0x40, 0x1b, 0x20, 0x4c, 0x8d, 0x80, 0x6c, 0x60, 0x99, 0x17, 0xd1, 0x45, 0x20, 0x10, \n\t0x22, 0x40, 0xae, 0x00, 0x1c, 0x44, 0x50, 0xb0, 0x10, 0x03, 0x74, 0xc8, 0x41, 0x34, 0x36, 0x40, \n\t0xb1, 0x40, 0x19, 0x00, 0x00, 0x27, 0xc2, 0x22, 0x80, 0x02, 0x61, 0x00, 0xf0, 0x2b, 0x02, 0xb0, \n\t0x40, 0x09, 0x4c, 0x14, 0x09, 0x08, 0x34, 0x04, 0x49, 0x00, 0x92, 0x41, 0xa4, 0x60, 0x08, 0x48, \n\t0x70, 0x21, 0x62, 0xb5, 0x45, 0x13, 0xa8, 0x00, 0x80, 0xb2, 0x10, 0x40, 0x0d, 0x03, 0x30, 0x05, \n\t0x90, 0x11, 0x29, 0x48, 0x8e, 0x40, 0x01, 0x52, 0x11, 0x68, 0x80, 0x89, 0x62, 0x46, 0xa3, 0x28, \n\t0x40, 0x11, 0x00, 0x40, 0xc3, 0xc1, 0x01, 0x11, 0xc5, 0xa9, 0x10, 0x90, 0x11, 0x30, 0x81, 0xc3, \n\t0x06, 0x72, 0x21, 0x03, 0x88, 0x00, 0x03, 0x04, 0x12, 0xa5, 0x60, 0x92, 0x59, 0x04, 0xa1, 0x08, \n\t0x24, 0x21, 0x00, 0xa0, 0x02, 0x24, 0x42, 0x72, 0x10, 0x82, 0x08, 0x80, 0x00, 0x3c, 0x35, 0x11, \n\t0x0b, 0x50, 0x11, 0x48, 0x08, 0xb6, 0x90, 0x11, 0x00, 0x15, 0x00, 0x46, 0x42, 0x00, 0x03, 0xa0, \n\t0x86, 0x02, 0x04, 0x44, 0x09, 0x90, 0x00, 0x18, 0x09, 0x16, 0x02, 0x81, 0x2a, 0x49, 0x1c, 0x0b, \n\t0x50, 0xd1, 0xc0, 0x11, 0x30, 0x03, 0x0d, 0x08, 0xc5, 0x00, 0x88, 0x04, 0x12, 0xc4, 0x20, 0xb0, \n\t0x21, 0x23, 0x00, 0x8f, 0x0c, 0x74, 0x53, 0x91, 0x98, 0x31, 0x10, 0xc0, 0x18, 0xb0, 0x3a, 0x24, \n\t0xf0, 0xc2, 0x00, 0x42, 0x83, 0x82, 0x82, 0x5c, 0x08, 0xa9, 0x20, 0x20, 0x62, 0x07, 0x01, 0x01, \n\t0x03, 0x06, 0xc4, 0x10, 0x05, 0x48, 0xd1, 0x20, 0x2a, 0x42, 0x1a, 0x80, 0x40, 0x52, 0x0e, 0x10, \n\t0x24, 0x11, 0x84, 0x08, 0x41, 0x62, 0x68, 0x25, 0xc0, 0x36, 0x31, 0x41, 0xc0, 0x12, 0x06, 0x01, \n\t0x82, 0x65, 0x0c, 0xaa, 0x24, 0xa0, 0x20, 0x81, 0x10, 0xc4, 0x00, 0x18, 0x05, 0x61, 0x08, 0x10, \n\t0x02, 0x21, 0x4a, 0x51, 0xe2, 0x00, 0xa0, 0x04, 0x82, 0x0a, 0xa2, 0x30, 0x15, 0xcd, 0xd5, 0x22, \n\t0x16, 0x81, 0x08, 0x04, 0xb9, 0x86, 0x01, 0x40, 0x15, 0x23, 0x24, 0x0c, 0x0a, 0x82, 0x60, 0x85, \n\t0x88, 0x0c, 0x01, 0x80, 0x41, 0x50, 0x10, 0x08, 0x3a, 0xa0, 0x81, 0x02, 0x50, 0x34, 0x21, 0x04, \n\t0x5d, 0x50, 0xe1, 0x48, 0x07, 0x0a, 0x0c, 0xd0, 0x01, 0x82, 0x40, 0x24, 0x41, 0x8a, 0x71, 0xc5, \n\t0x24, 0x10, 0xb3, 0x49, 0x04, 0xa1, 0x4c, 0x0a, 0x02, 0xc2, 0x00, 0x82, 0x00, 0x4f, 0x08, 0x02, \n\t0x05, 0x00, 0x08, 0x39, 0x18, 0x8b, 0x04, 0x10, 0x78, 0x20, 0x21, 0xd5, 0x46, 0x02, 0x42, 0x82, \n\t0x06, 0x70, 0x00, 0x44, 0x08, 0x10, 0x90, 0x10, 0x14, 0x4a, 0x08, 0x26, 0xe0, 0x12, 0x8c, 0x18, \n\t0x0a, 0x04, 0x28, 0xc5, 0x01, 0xb3, 0xa0, 0x08, 0x04, 0x48, 0x74, 0x30, 0x12, 0x58, 0x47, 0x83, \n\t0x30, 0x04, 0x39, 0x02, 0x81, 0x01, 0x22, 0x02, 0x96, 0x02, 0x11, 0x44, 0xc0, 0x08, 0x38, 0x94, \n\t0x60, 0x0a, 0xa5, 0x4c, 0xcd, 0x60, 0x91, 0x02, 0x24, 0x80, 0x9c, 0x20, 0x4e, 0x60, 0x68, 0x01, \n\t0x50, 0x01, 0x6c, 0x04, 0x12, 0xc8, 0x10, 0x68, 0x40, 0x8a, 0x02, 0x03, 0x01, 0x83, 0x00, 0x94, \n\t0x00, 0x40, 0xe0, 0xf1, 0x20, 0x19, 0x48, 0x84, 0x04, 0x00, 0x10, 0x89, 0x10, 0x1a, 0x81, 0x14, \n\t0x00, 0x00, 0x03, 0x20, 0x55, 0x24, 0x60, 0x21, 0x11, 0x84, 0x09, 0x4d, 0x82, 0x00, 0x05, 0x23, \n\t0x02, 0x81, 0x09, 0xe1, 0x26, 0x02, 0x42, 0x29, 0x58, 0x82, 0x21, 0x00, 0x22, 0x40, 0x04, 0x05, \n\t0x81, 0xcc, 0x7a, 0x42, 0xa0, 0x8c, 0x84, 0x50, 0x4d, 0x50, 0x06, 0xc0, 0x00, 0x90, 0x83, 0x0c, \n\t0x72, 0x00, 0x98, 0x18, 0x41, 0x81, 0x4b, 0x0e, 0x70, 0x28, 0x20, 0x28, 0x10, 0x60, 0x38, 0x17, \n\t0xa1, 0x99, 0x10, 0x02, 0x41, 0x40, 0x82, 0x82, 0x82, 0x05, 0x14, 0x24, 0x04, 0x01, 0xb1, 0x14, \n\t0x48, 0x98, 0xa2, 0x0a, 0x30, 0x20, 0x06, 0x20, 0x05, 0x02, 0x0c, 0x61, 0x41, 0x16, 0x20, 0x09, \n\t0x22, 0x54, 0x14, 0x01, 0xa8, 0x34, 0x81, 0xa8, 0x12, 0x60, 0x40, 0x97, 0x10, 0x83, 0x40, 0x40, \n\t0x40, 0x48, 0x17, 0x90, 0x02, 0x28, 0x28, 0x40, 0x89, 0x10, 0x09, 0x94, 0x00, 0x44, 0x92, 0x82, \n\t0x19, 0xc1, 0x83, 0x08, 0x10, 0xc3, 0x00, 0x0a, 0x24, 0x18, 0x25, 0x00, 0x07, 0x41, 0x10, 0x01, \n\t0x89, 0x28, 0x20, 0x22, 0x80, 0x82, 0x70, 0x5a, 0x06, 0x12, 0x44, 0x33, 0x00, 0xc1, 0x0a, 0x00, \n\t0x26, 0x20, 0x00, 0x21, 0xa8, 0x5c, 0x81, 0x18, 0x84, 0x5a, 0x9c, 0x19, 0x54, 0xa0, 0x66, 0x45, \n\t0x10, 0x2b, 0x9c, 0x0c, 0x00, 0x32, 0x01, 0x28, 0x19, 0x44, 0x1a, 0x87, 0x72, 0x82, 0x20, 0x34, \n\t0xa0, 0x02, 0x04, 0x08, 0x60, 0x11, 0x13, 0x00, 0x01, 0x23, 0x26, 0x26, 0x5a, 0x29, 0x80, 0x43, \n\t0x88, 0x48, 0x00, 0x90, 0x0a, 0x64, 0x80, 0xce, 0x08, 0x80, 0x90, 0x09, 0x80, 0x52, 0x61, 0x60, \n\t0x60, 0x98, 0x29, 0x54, 0x09, 0x07, 0x44, 0x13, 0x8a, 0x11, 0x20, 0x19, 0x24, 0x28, 0x55, 0x82, \n\t0x93, 0x88, 0x8a, 0x82, 0x04, 0xc5, 0x29, 0x08, 0x80, 0x05, 0x48, 0x20, 0xc1, 0xc1, 0x88, 0xdc, \n\t0x82, 0x22, 0x06, 0x05, 0x38, 0x3c, 0x50, 0x92, 0x45, 0x0a, 0x20, 0xc3, 0x00, 0x10, 0x1b, 0x4c, \n\t0x5a, 0x30, 0x40, 0x0e, 0x29, 0x04, 0x61, 0x02, 0x32, 0x70, 0x00, 0x19, 0x05, 0x89, 0x42, 0x60, \n\t0x42, 0x89, 0x00, 0x02, 0x06, 0x68, 0x06, 0x30, 0xa4, 0x84, 0x49, 0xeb, 0x40, 0x55, 0x1a, 0x88, \n\t0x01, 0x44, 0xa5, 0x04, 0xd2, 0x81, 0x8f, 0x89, 0x11, 0x28, 0x40, 0x60, 0x1b, 0x85, 0xd1, 0x08, \n\t0x41, 0x40, 0x82, 0x0b, 0xb4, 0xb1, 0x0d, 0x64, 0x24, 0x10, 0x0b, 0x01, 0xa4, 0x03, 0x82, 0x0c, \n\t0x03, 0x60, 0x03, 0x54, 0x54, 0xc6, 0x60, 0x60, 0xa2, 0x17, 0x00, 0x1c, 0x08, 0x04, 0x21, 0xf8, \n\t0x94, 0x01, 0x83, 0xab, 0x00, 0x30, 0x10, 0x00, 0x24, 0x00, 0x04, 0x1e, 0x01, 0x60, 0x00, 0x51, \n\t0x88, 0x47, 0x04, 0x84, 0x01, 0x06, 0x95, 0x12, 0x60, 0x40, 0x20, 0x20, 0x02, 0x41, 0xc9, 0x40, \n\t0x32, 0x85, 0x90, 0x2f, 0x84, 0x8e, 0x20, 0x4c, 0x15, 0x71, 0x01, 0x28, 0xc2, 0x00, 0x18, 0x82, \n\t0x00, 0x18, 0x44, 0x50, 0x2d, 0x62, 0x22, 0x58, 0x80, 0x34, 0xc5, 0x68, 0x02, 0xb6, 0x00, 0x02, \n\t0x71, 0xc1, 0x08, 0x00, 0x50, 0x0a, 0x93, 0x84, 0x10, 0x00, 0x2a, 0x02, 0x6b, 0x80, 0x39, 0x17, \n\t0xcd, 0x20, 0x04, 0x00, 0x31, 0x00, 0x00, 0x02, 0x48, 0xb0, 0xa8, 0xac, 0x01, 0x84, 0xc4, 0x2c, \n\t0x41, 0x32, 0x18, 0x40, 0x80, 0x04, 0x0a, 0x10, 0x90, 0x20, 0x20, 0x17, 0x40, 0x10, 0x46, 0x13, \n\t0x18, 0x08, 0x00, 0xac, 0x00, 0x30, 0x00, 0x82, 0x88, 0x08, 0x81, 0x04, 0x40, 0x88, 0x10, 0x49, \n\t0x00, 0x21, 0x14, 0x03, 0x00, 0x10, 0x01, 0x81, 0xc1, 0x30, 0xa2, 0x08, 0x94, 0xf4, 0x01, 0x80, \n\t0x28, 0x13, 0xc1, 0x09, 0xa4, 0x95, 0x21, 0x12, 0x00, 0x49, 0x03, 0xd0, 0xc5, 0x42, 0x56, 0x16, \n\t0x00, 0x05, 0x05, 0x92, 0x64, 0x06, 0x40, 0x60, 0x02, 0x75, 0x0c, 0x2e, 0x08, 0x05, 0x40, 0x22, \n\t0x01, 0x10, 0x81, 0x02, 0xd0, 0x12, 0x30, 0x4d, 0x85, 0x40, 0x0a, 0x16, 0x2a, 0x20, 0x80, 0x84, \n\t0x04, 0x34, 0x30, 0x09, 0x01, 0x8c, 0x46, 0xe0, 0x34, 0x81, 0x3a, 0x38, 0x80, 0x09, 0x81, 0x30, \n\t0x14, 0x02, 0x03, 0xd5, 0x03, 0x07, 0x02, 0x45, 0x40, 0x89, 0x81, 0x40, 0x40, 0x00, 0x15, 0x00, \n\t0x87, 0x24, 0x50, 0x2c, 0x44, 0x60, 0x80, 0x0d, 0x68, 0x59, 0xc4, 0x28, 0xa0, 0x72, 0x01, 0x05, \n\t0x52, 0x48, 0x04, 0x02, 0x88, 0x05, 0xc8, 0x80, 0x42, 0x0c, 0x63, 0xa1, 0x30, 0x88, 0xc2, 0xce, \n\t0x28, 0xd6, 0x20, 0x0a, 0x18, 0x04, 0x41, 0x24, 0x04, 0xa2, 0x28, 0xe4, 0x46, 0xa8, 0x08, 0x70, \n\t0x08, 0xa1, 0x54, 0x85, 0x02, 0x6c, 0x20, 0x11, 0xa0, 0x40, 0x1c, 0x08, 0x54, 0x70, 0x00, 0x18, \n\t0x99, 0x0a, 0xa8, 0x10, 0xa2, 0x08, 0xb8, 0x84, 0xc0, 0x0d, 0x18, 0x81, 0x21, 0x8a, 0x28, 0xc0, \n\t0x61, 0x02, 0xc4, 0x90, 0x01, 0x89, 0x1e, 0x02, 0x00, 0x24, 0x81, 0x04, 0x41, 0x05, 0x80, 0x4c, \n\t0x20, 0xb0, 0x84, 0x54, 0x80, 0x44, 0x4c, 0xb2, 0xa1, 0x00, 0x85, 0x08, 0x00, 0x42, 0x32, 0x02, \n\t0xae, 0x08, 0xd8, 0x05, 0x48, 0x10, 0xc3, 0x26, 0x0c, 0x1a, 0xa2, 0x20, 0x04, 0x80, 0x00, 0x0d, \n\t0x12, 0x83, 0x4c, 0xc1, 0x11, 0x8a, 0x28, 0x04, 0x04, 0x56, 0x81, 0x8b, 0x01, 0x28, 0x01, 0xc9, \n\t0x22, 0x74, 0x48, 0x31, 0x50, 0x00, 0x41, 0x28, 0x30, 0x00, 0x1a, 0x34, 0x0a, 0x40, 0x24, 0x85, \n\t0x1a, 0x12, 0x08, 0xd8, 0x85, 0x02, 0x84, 0x01, 0x31, 0x2d, 0x81, 0x80, 0x00, 0x73, 0xf2, 0x23, \n\t0x08, 0x80, 0x00, 0x54, 0x12, 0xc1, 0x29, 0x0d, 0x13, 0x04, 0x08, 0x54, 0xb0, 0x1c, 0x21, 0x01, \n\t0xc4, 0x76, 0x90, 0x21, 0xa2, 0x01, 0x04, 0x0a, 0x40, 0x01, 0x12, 0x04, 0x40, 0x08, 0x2a, 0x0e, \n\t0x00, 0xc2, 0x16, 0x74, 0x0c, 0xaa, 0x00, 0x80, 0x41, 0x83, 0x91, 0x06, 0x66, 0x06, 0x64, 0x60, \n\t0x95, 0x65, 0x02, 0x09, 0x50, 0x25, 0x08, 0x88, 0x20, 0x88, 0x25, 0x40, 0xa2, 0x6a, 0x1b, 0x60, \n\t0x8f, 0x48, 0x26, 0x20, 0x41, 0x14, 0x00, 0x81, 0x8c, 0x40, 0x82, 0x41, 0x8e, 0x15, 0x08, 0x68, \n\t0x38, 0x14, 0x00, 0x11, 0x8c, 0x41, 0xe2, 0x46, 0xe3, 0x88, 0x31, 0x01, 0x07, 0x82, 0x00, 0x03, \n\t0x82, 0x2a, 0xc9, 0xd3, 0x06, 0x6a, 0x64, 0x10, 0x06, 0x2c, 0x11, 0xa0, 0x60, 0xa6, 0x08, 0x82, \n\t0x90, 0x59, 0x80, 0x30, 0x92, 0x91, 0xa8, 0x10, 0x44, 0x01, 0x28, 0x40, 0x29, 0x00, 0x45, 0xd1, \n\t0x84, 0x12, 0x52, 0x00, 0xb2, 0x8c, 0x41, 0x65, 0x08, 0x22, 0x41, 0x88, 0x10, 0x1c, 0xa2, 0x44, \n\t0x02, 0x83, 0x18, 0x18, 0x16, 0x03, 0x4a, 0xb0, 0x21, 0x03, 0x14, 0x12, 0x8a, 0x40, 0x91, 0x60, \n\t0x04, 0x50, 0x0b, 0x0b, 0x20, 0xd0, 0x02, 0x90, 0x14, 0x06, 0x60, 0x20, 0x10, 0x59, 0x00, 0x09, \n\t0x0a, 0x24, 0x00, 0x14, 0x62, 0x91, 0x10, 0x80, 0x69, 0x54, 0x20, 0x42, 0xa8, 0x44, 0x44, 0xcb, \n\t0x00, 0x00, 0x00, 0x0b, 0x04, 0x40, 0x89, 0x30, 0x81, 0x79, 0x02, 0x40, 0x41, 0x8e, 0x50, 0x14, \n\t0x01, 0xa0, 0x38, 0xd8, 0x01, 0x08, 0x90, 0x01, 0x92, 0xd1, 0x85, 0x60, 0x00, 0x80, 0xd1, 0x38, \n\t0xa0, 0x44, 0x48, 0x0a, 0x80, 0xc0, 0x29, 0xf4, 0x1a, 0x88, 0x44, 0x05, 0x32, 0x20, 0x05, 0x49, \n\t0x49, 0x00, 0xe4, 0x30, 0x81, 0x40, 0x16, 0x82, 0x46, 0x83, 0xb8, 0x03, 0x41, 0x10, 0x2e, 0x10, \n\t0x71, 0x40, 0x24, 0x15, 0x00, 0x49, 0x0a, 0x04, 0x08, 0xbc, 0xc4, 0x00, 0xc2, 0x36, 0x21, 0x80, \n\t0x3a, 0x41, 0x02, 0xa0, 0x20, 0x10, 0x30, 0xa5, 0x00, 0x86, 0x49, 0x30, 0x42, 0x82, 0x90, 0x90, \n\t0xc8, 0x00, 0x12, 0x63, 0x20, 0x04, 0x01, 0x98, 0x49, 0x00, 0x10, 0x12, 0x38, 0xc8, 0xc4, 0x08, \n\t0x06, 0x82, 0xe8, 0x00, 0x09, 0x02, 0x06, 0x00, 0x90, 0x90, 0x0a, 0x1c, 0x02, 0x21, 0x02, 0x84, \n\t0xb0, 0x16, 0x2c, 0x04, 0xa2, 0x58, 0x54, 0xc9, 0x10, 0x61, 0x84, 0x04, 0x04, 0x31, 0x61, 0x90, \n\t0xb8, 0x07, 0x02, 0x40, 0x42, 0x19, 0x00, 0x38, 0x15, 0x4c, 0x42, 0x91, 0x9a, 0x9a, 0x00, 0x46, \n\t0x0e, 0x00, 0x20, 0x61, 0x8c, 0x20, 0x88, 0x02, 0x1a, 0xc7, 0x88, 0x21, 0x90, 0x0b, 0x00, 0x00, \n\t0x43, 0xa0, 0x06, 0xe1, 0x40, 0xa9, 0x20, 0x80, 0x1a, 0x09, 0x88, 0x10, 0x08, 0x4c, 0x00, 0x0b, \n\t0x28, 0x14, 0x18, 0x20, 0x04, 0x93, 0x83, 0x0e, 0x48, 0x40, 0x69, 0x2a, 0x24, 0xa8, 0xb3, 0x00, \n\t0x17, 0x24, 0x10, 0xc0, 0xc8, 0x10, 0x85, 0x40, 0x00, 0x6a, 0x20, 0xc1, 0xb4, 0x50, 0x1a, 0x23, \n\t0x5a, 0x20, 0x60, 0x08, 0x4c, 0x48, 0xc1, 0x04, 0x43, 0xc1, 0xb3, 0x60, 0x85, 0x41, 0x0c, 0x60, \n\t0x41, 0x0a, 0x30, 0xc2, 0x46, 0x40, 0x06, 0x40, 0x80, 0x28, 0xc6, 0x48, 0x18, 0x81, 0x50, 0x14, \n\t0x00, 0x4f, 0x84, 0x0c, 0xb2, 0x32, 0x00, 0x15, 0xc1, 0x62, 0x04, 0x60, 0x00, 0x00, 0x81, 0x82, \n\t0x40, 0x00, 0xc2, 0x02, 0x85, 0x51, 0x58, 0x28, 0x0c, 0xa4, 0x00, 0x21, 0x55, 0x10, 0x21, 0x2a, \n\t0x95, 0x10, 0x92, 0x20, 0x90, 0x2a, 0x62, 0x34, 0xe0, 0x10, 0x11, 0x80, 0x20, 0x36, 0x46, 0x02, \n\t0x38, 0x8c, 0x10, 0x00, 0x14, 0x06, 0x11, 0x82, 0x4d, 0x00, 0x00, 0x14, 0xc1, 0x00, 0x24, 0x60, \n\t0x06, 0x05, 0x02, 0x94, 0x41, 0x3a, 0x9c, 0x89, 0x04, 0x06, 0x22, 0x69, 0x14, 0x50, 0x8d, 0xc2, \n\t0x20, 0x04, 0x5a, 0x3c, 0xa9, 0x92, 0x00, 0x40, 0x90, 0x48, 0x8b, 0x88, 0x08, 0xa7, 0x50, 0x00, \n\t0xd2, 0x00, 0x11, 0x18, 0x68, 0x04, 0x03, 0x20, 0x06, 0x08, 0x10, 0x01, 0x18, 0x46, 0xa2, 0x01, \n\t0x84, 0xca, 0x2c, 0x26, 0x00, 0x81, 0xa1, 0x01, 0x92, 0x49, 0x20, 0x02, 0xd0, 0x10, 0xb0, 0x19, \n\t0x41, 0x64, 0x21, 0x02, 0x01, 0x04, 0x84, 0x4c, 0x20, 0x11, 0x50, 0xb0, 0x70, 0x0c, 0x88, 0x0a, \n\t0x05, 0x41, 0x01, 0x8c, 0x8e, 0x04, 0x50, 0x12, 0x10, 0x90, 0x28, 0xc1, 0xa4, 0x24, 0x86, 0x82, \n\t0x25, 0x60, 0x04, 0x80, 0x0a, 0xc1, 0x79, 0x08, 0x90, 0x80, 0x20, 0x44, 0xd4, 0x20, 0x1c, 0x99, \n\t0x40, 0xa4, 0x48, 0x85, 0x02, 0x89, 0x19, 0x01, 0xc0, 0x70, 0xc1, 0x22, 0x34, 0x81, 0x19, 0xa0, \n\t0x28, 0x24, 0x08, 0x82, 0x64, 0x87, 0xe9, 0x10, 0x46, 0xa8, 0x02, 0xc9, 0x09, 0x41, 0x56, 0x04, \n\t0x41, 0x20, 0x84, 0x40, 0x61, 0x02, 0xa5, 0x18, 0x2f, 0x21, 0x45, 0x40, 0x38, 0x22, 0x0a, 0x92, \n\t0x00, 0x1d, 0x04, 0x06, 0x04, 0xb8, 0x80, 0x80, 0x14, 0x81, 0x4a, 0x02, 0xc2, 0x01, 0xa1, 0x82, \n\t0x88, 0x02, 0x11, 0xba, 0xa8, 0x11, 0x08, 0x60, 0x68, 0x44, 0xc2, 0x15, 0x90, 0x18, 0x88, 0x28, \n\t0x21, 0x98, 0x1c, 0x41, 0x5a, 0xc2, 0x24, 0x00, 0x83, 0x04, 0x0c, 0x86, 0x0c, 0x10, 0x01, 0x28, \n\t0x20, 0xd5, 0x8e, 0x21, 0x2e, 0x04, 0x68, 0x04, 0x11, 0x40, 0xa2, 0x00, 0x03, 0x40, 0x3a, 0x21, \n\t0x01, 0x28, 0x0e, 0x90, 0x20, 0x80, 0xf0, 0x90, 0x41, 0x0a, 0x83, 0x4b, 0x8d, 0x84, 0x04, 0x24, \n\t0x32, 0x95, 0x01, 0x18, 0x08, 0x09, 0x42, 0x3a, 0x20, 0xc8, 0x10, 0x00, 0x83, 0x80, 0x08, 0x40, \n\t0x81, 0x80, 0x51, 0x00, 0x60, 0x00, 0xa5, 0x92, 0x23, 0x04, 0xca, 0x01, 0x04, 0x02, 0x32, 0x81, \n\t0x11, 0x1c, 0x04, 0x2c, 0x10, 0xa2, 0x0b, 0x04, 0x9c, 0x82, 0x2e, 0x41, 0x08, 0x15, 0x80, 0x8d, \n\t0x49, 0x40, 0x42, 0x42, 0x20, 0x08, 0x11, 0x06, 0x30, 0x14, 0x03, 0xa8, 0x30, 0x0e, 0x20, 0x28, \n\t0x10, 0x00, 0x3c, 0x11, 0x52, 0x89, 0x08, 0x61, 0xc0, 0x19, 0x84, 0xc4, 0x24, 0x1a, 0x50, 0x00, \n\t0x08, 0xa0, 0x02, 0x44, 0x0a, 0x20, 0x08, 0x20, 0x10, 0x95, 0x2e, 0x5e, 0x21, 0x40, 0x24, 0x20, \n\t0x84, 0x40, 0x14, 0x27, 0x00, 0xa6, 0x5c, 0x48, 0x88, 0x08, 0x47, 0x08, 0x13, 0x60, 0x10, 0xa2, \n\t0x64, 0x83, 0x01, 0xa8, 0x61, 0x02, 0x00, 0x4a, 0x54, 0x10, 0x21, 0x10, 0x1d, 0xe2, 0x22, 0x02, \n\t0x42, 0x16, 0x44, 0x00, 0x80, 0x04, 0x50, 0x81, 0x10, 0x30, 0x80, 0x0a, 0x12, 0x83, 0x18, 0x8c, \n\t0x84, 0x59, 0x01, 0x00, 0x25, 0x2a, 0x01, 0x0c, 0x4c, 0x01, 0x18, 0x00, 0x00, 0x87, 0x98, 0x0d, \n\t0x03, 0x58, 0x00, 0xc2, 0x30, 0xcd, 0x51, 0x26, 0x40, 0x20, 0x23, 0x04, 0x60, 0x80, 0x09, 0x34, \n\t0xd7, 0x92, 0xa8, 0x01, 0x89, 0x04, 0x20, 0x31, 0x10, 0x2f, 0x21, 0x01, 0x60, 0x52, 0x40, 0x41, \n\t0x90, 0x69, 0x96, 0x06, 0x22, 0x00, 0xc3, 0x02, 0xe5, 0x50, 0x4a, 0x40, 0xe1, 0x30, 0xb0, 0x00, \n\t0x54, 0x2a, 0x40, 0xe1, 0xd0, 0xa1, 0x35, 0x04, 0x05, 0x08, 0x04, 0x20, 0x8e, 0x00, 0x0d, 0x8b, \n\t0x50, 0x92, 0xa0, 0x14, 0x00, 0x18, 0x2d, 0x40, 0xb6, 0x80, 0x02, 0x80, 0x00, 0x47, 0x20, 0x24, \n\t0x50, 0x04, 0x8c, 0x02, 0x26, 0x10, 0x42, 0x12, 0x2b, 0xc5, 0x88, 0xa2, 0x50, 0x30, 0x43, 0x80, \n\t0x88, 0x11, 0xa8, 0x00, 0x14, 0x0a, 0x94, 0x48, 0x82, 0x80, 0x32, 0x87, 0x80, 0x09, 0x21, 0xcc, \n\t0x88, 0x58, 0x00, 0x5b, 0x92, 0x11, 0x88, 0x09, 0x46, 0x04, 0x21, 0x24, 0x01, 0x51, 0x44, 0x10, \n\t0x44, 0x03, 0x80, 0x00, 0x0b, 0x48, 0x1e, 0x61, 0x11, 0x08, 0x84, 0x06, 0x85, 0x02, 0x11, 0x88, \n\t0x01, 0x04, 0x45, 0x01, 0x2a, 0x81, 0x1a, 0x07, 0x08, 0x02, 0x0a, 0x2c, 0x12, 0xc1, 0x24, 0xf8, \n\t0x12, 0x62, 0x00, 0x32, 0x21, 0x08, 0x25, 0x94, 0x82, 0x00, 0x81, 0x60, 0x24, 0x14, 0xc2, 0x42, \n\t0x0a, 0x00, 0x30, 0x9e, 0x01, 0xd4, 0x00, 0x3c, 0x01, 0x30, 0x0d, 0x4c, 0x90, 0x0a, 0x48, 0x54, \n\t0x08, 0x17, 0xf0, 0x18, 0x88, 0x04, 0xc0, 0x91, 0x0e, 0x05, 0x04, 0x00, 0x54, 0x80, 0x02, 0x98, \n\t0x31, 0x80, 0x46, 0x2a, 0x44, 0x60, 0x85, 0x30, 0x1b, 0x4e, 0x00, 0x14, 0x08, 0x2a, 0x18, 0x10, \n\t0x00, 0x14, 0x64, 0x41, 0x01, 0x19, 0xda, 0x81, 0x00, 0x10, 0x48, 0x01, 0x20, 0x02, 0x42, 0x00, \n\t0xa0, 0x48, 0xa0, 0x80, 0x04, 0xc4, 0x04, 0xc1, 0x20, 0x0d, 0xd0, 0x00, 0x8f, 0x04, 0xb3, 0x28, \n\t0x24, 0x09, 0x05, 0x43, 0x20, 0x10, 0x23, 0x01, 0xe8, 0x0c, 0x00, 0x20, 0x20, 0x5a, 0x90, 0x05, \n\t0x8c, 0x00, 0x2c, 0x05, 0x61, 0x00, 0x0d, 0x04, 0x23, 0x10, 0xe2, 0x10, 0x11, 0xe1, 0x0b, 0x00, \n\t0x0c, 0x61, 0x48, 0x08, 0x80, 0x81, 0xc0, 0x6a, 0x37, 0x09, 0x88, 0x20, 0x94, 0x61, 0x7c, 0x10, \n\t0x20, 0x12, 0xf0, 0x0a, 0xa0, 0x00, 0x12, 0xa2, 0x28, 0x54, 0x06, 0x0d, 0x5a, 0x80, 0x00, 0x00, \n\t0xc8, 0x00, 0xa9, 0x48, 0xb0, 0x12, 0xb8, 0x00, 0xc8, 0xc4, 0x2a, 0x00, 0x20, 0xbf, 0x00, 0x08, \n\t0x84, 0x50, 0x12, 0x20, 0x26, 0x60, 0x82, 0x28, 0x24, 0x04, 0xf8, 0x02, 0x15, 0x8b, 0x00, 0x30, \n\t0xe1, 0x10, 0x80, 0x35, 0x41, 0x24, 0x22, 0x24, 0xc0, 0x80, 0x45, 0xc8, 0x80, 0x00, 0x10, 0x38, \n\t0x1c, 0x80, 0x54, 0x01, 0x3a, 0x12, 0x29, 0x10, 0x08, 0xc8, 0x60, 0x40, 0x20, 0x00, 0x07, 0xd1, \n\t0x09, 0x09, 0x78, 0xb6, 0xca, 0x35, 0x38, 0x01, 0x0c, 0x58, 0xc0, 0x20, 0x00, 0x38, 0x10, 0x2e, \n\t0x10, 0x86, 0x31, 0x02, 0xc4, 0x5a, 0x8e, 0x46, 0xe0, 0x92, 0x2a, 0x1c, 0x54, 0x25, 0x00, 0x52, \n\t0x42, 0x8d, 0x41, 0x45, 0x82, 0x20, 0x01, 0x11, 0x02, 0x58, 0x12, 0xc0, 0x00, 0x41, 0x00, 0x18, \n\t0x95, 0x15, 0x2a, 0x50, 0x24, 0xc2, 0x1a, 0x88, 0x0f, 0x00, 0x1a, 0xe0, 0x11, 0x30, 0x34, 0xc0, \n\t0x05, 0x60, 0x41, 0x20, 0x19, 0x00, 0x0a, 0x41, 0x48, 0x07, 0x99, 0x09, 0x88, 0x45, 0x2d, 0x22, \n\t0x82, 0x02, 0x04, 0x35, 0x00, 0x20, 0x04, 0x83, 0xc8, 0x82, 0xb5, 0x04, 0x8d, 0x28, 0x83, 0x43, \n\t0x83, 0x09, 0x08, 0x28, 0x20, 0xa3, 0x00, 0x11, 0x40, 0x0c, 0x80, 0x3a, 0xc0, 0xc3, 0x2a, 0x28, \n\t0x4b, 0x00, 0x4a, 0x40, 0x80, 0x33, 0x81, 0xd4, 0x20, 0x10, 0x84, 0x58, 0x04, 0x18, 0x58, 0xc0, \n\t0x00, 0xe5, 0x42, 0x2a, 0x70, 0x01, 0x08, 0x22, 0x30, 0x19, 0x11, 0xb5, 0x07, 0x8a, 0x10, 0x44, \n\t0x22, 0x90, 0x80, 0xc7, 0x48, 0x42, 0x91, 0x08, 0x11, 0x40, 0x8d, 0x22, 0x02, 0x04, 0xa0, 0x38, \n\t0x05, 0x40, 0x03, 0x08, 0x10, 0xc8, 0x28, 0x8c, 0x04, 0x00, 0x60, 0xa0, 0x02, 0x94, 0x55, 0x11, \n\t0x41, 0x6a, 0x52, 0xb8, 0xa4, 0x24, 0x08, 0xa5, 0x14, 0x12, 0x08, 0x38, 0xc1, 0x11, 0x00, 0x02, \n\t0x01, 0x41, 0x02, 0xc0, 0x49, 0x6a, 0x02, 0x05, 0x8b, 0x80, 0x04, 0x00, 0xa1, 0x00, 0x01, 0x81, \n\t0x80, 0x81, 0x82, 0x8b, 0x0c, 0x14, 0x30, 0x25, 0x44, 0x87, 0x00, 0x42, 0x10, 0x02, 0x18, 0xa8, \n\t0x84, 0x4c, 0x14, 0x60, 0x99, 0x18, 0x88, 0x14, 0x85, 0x60, 0x16, 0x41, 0x20, 0x1d, 0x96, 0x08, \n\t0x42, 0x30, 0x59, 0x24, 0x65, 0x08, 0x26, 0x60, 0x83, 0x22, 0x8c, 0x11, 0x52, 0x08, 0x00, 0x63, \n\t0xa0, 0x88, 0x01, 0x01, 0xa4, 0x06, 0x82, 0x90, 0x83, 0x60, 0x01, 0x04, 0x26, 0x44, 0x62, 0x24, \n\t0x90, 0x01, 0xc0, 0x38, 0x01, 0x01, 0x9c, 0x10, 0x18, 0x4d, 0x16, 0xd1, 0x40, 0xa0, 0xc0, 0x00, \n\t0x06, 0x36, 0xc0, 0x41, 0x1a, 0x94, 0x04, 0xc4, 0x22, 0xe6, 0x00, 0x90, 0x00, 0x46, 0x2d, 0x06, \n\t0x41, 0x02, 0x00, 0x39, 0x93, 0x23, 0x4a, 0x00, 0x01, 0x04, 0x4c, 0x93, 0x44, 0x00, 0x22, 0x49, \n\t0x08, 0x48, 0x12, 0x22, 0x04, 0x02, 0xf2, 0x98, 0x90, 0x53, 0x28, 0x62, 0x34, 0x32, 0xb4, 0x4c, \n\t0xc2, 0x04, 0x6c, 0x14, 0x12, 0x10, 0xc9, 0x85, 0x80, 0x18, 0x35, 0xa1, 0x04, 0x68, 0x45, 0x81, \n\t0x2c, 0x04, 0x80, 0x0c, 0xc8, 0x48, 0xc0, 0x42, 0x00, 0x09, 0x0b, 0x60, 0xc6, 0x24, 0x26, 0x91, \n\t0x11, 0x24, 0xc1, 0x1d, 0x0c, 0x30, 0x34, 0x60, 0x03, 0xa8, 0x5a, 0x08, 0x38, 0x46, 0x60, 0x09, \n\t0x40, 0x10, 0x86, 0x4c, 0x22, 0x61, 0x04, 0x01, 0x00, 0x2a, 0x58, 0x82, 0x90, 0x01, 0x0c, 0x12, \n\t0x0d, 0x0c, 0x73, 0x21, 0x20, 0x84, 0x12, 0x08, 0x40, 0xf0, 0x00, 0x0d, 0x50, 0x92, 0x85, 0x20, \n\t0x10, 0xc0, 0x12, 0x01, 0x03, 0x04, 0x22, 0x05, 0x10, 0x30, 0x34, 0x49, 0x42, 0x00, 0x87, 0x00, \n\t0x02, 0xc0, 0x40, 0x49, 0x20, 0x42, 0x9a, 0xb3, 0x40, 0x80, 0xe4, 0x08, 0x22, 0x20, 0x18, 0x35, \n\t0x8b, 0x88, 0x52, 0x34, 0x0b, 0x25, 0x00, 0x1c, 0x00, 0x0e, 0x32, 0x09, 0x88, 0x91, 0xdc, 0x06, \n\t0x18, 0xb0, 0xab, 0x14, 0x60, 0xc4, 0x00, 0x08, 0x03, 0x2b, 0x02, 0x70, 0x16, 0x48, 0x08, 0xe2, \n\t0x00, 0x2b, 0x08, 0x98, 0x0c, 0x0c, 0x84, 0xa0, 0x28, 0x05, 0x05, 0x64, 0x00, 0x50, 0x19, 0x92, \n\t0x88, 0x03, 0x0c, 0x12, 0x61, 0x28, 0x00, 0xcc, 0x12, 0x02, 0x52, 0x04, 0x41, 0x24, 0x3c, 0x00, \n\t0x21, 0x40, 0x81, 0x1a, 0x2b, 0x09, 0xc2, 0x05, 0x14, 0x71, 0x20, 0xa0, 0x14, 0x00, 0x82, 0x50, \n\t0x60, 0x40, 0xa0, 0x08, 0x03, 0x04, 0x0c, 0x92, 0x10, 0x02, 0x30, 0x42, 0x29, 0x68, 0x22, 0x20, \n\t0x08, 0xf4, 0x00, 0x0e, 0x12, 0x00, 0x50, 0x21, 0x10, 0x8c, 0x21, 0x00, 0x45, 0x60, 0x10, 0x01, \n\t0xc9, 0x84, 0x04, 0x11, 0x18, 0x00, 0x01, 0x17, 0x67, 0x3e, 0x41, 0x80, 0x83, 0xc1, 0xca, 0x80, \n\t0x1a, 0x40, 0xba, 0x80, 0x48, 0x82, 0xca, 0x04, 0x05, 0x81, 0x80, 0x34, 0x18, 0xc0, 0x42, 0xc2, \n\t0x40, 0x30, 0x84, 0x4c, 0x09, 0x12, 0x11, 0x08, 0x26, 0x14, 0x0c, 0xc8, 0x02, 0x60, 0x23, 0xa7, \n\t0x00, 0x49, 0x41, 0x5a, 0xe4, 0x40, 0x88, 0x10, 0x05, 0xa0, 0x6c, 0x02, 0x00, 0x00, 0x01, 0x84, \n\t0x02, 0x12, 0x10, 0x22, 0x01, 0xc8, 0x90, 0x81, 0x20, 0x02, 0x10, 0x82, 0x05, 0x12, 0xa3, 0x28, \n\t0x82, 0x80, 0x04, 0x28, 0x14, 0x40, 0x42, 0x51, 0xa1, 0x84, 0x09, 0x80, 0x82, 0x2e, 0x04, 0x01, \n\t0x32, 0xb4, 0x01, 0x08, 0x0c, 0x06, 0x01, 0xba, 0x05, 0x50, 0x80, 0x54, 0x22, 0x1b, 0x01, 0x38, \n\t0x41, 0xa2, 0x04, 0x41, 0x39, 0x25, 0x00, 0x18, 0x83, 0x70, 0x51, 0x09, 0x1a, 0x80, 0x92, 0x41, \n\t0x42, 0x40, 0x5b, 0x04, 0x20, 0x90, 0x0b, 0x00, 0x30, 0x28, 0x34, 0x61, 0x00, 0x01, 0x1e, 0x72, \n\t0x42, 0x06, 0x19, 0x1c, 0x01, 0x0c, 0x04, 0x71, 0x09, 0x49, 0x00, 0x08, 0x60, 0x00, 0x80, 0x9c, \n\t0x48, 0x49, 0x00, 0x5a, 0x00, 0xa1, 0x2a, 0xa1, 0x1c, 0x06, 0x28, 0x24, 0x50, 0x01, 0x00, 0xc0, \n\t0x08, 0x68, 0x65, 0xa8, 0x22, 0x68, 0x14, 0x20, 0x32, 0x42, 0x03, 0x82, 0x3d, 0x01, 0xc1, 0x0e, \n\t0x82, 0x11, 0x02, 0x20, 0x80, 0x01, 0x02, 0xd4, 0xe9, 0x80, 0x0c, 0x01, 0x29, 0x04, 0x50, 0x12, \n\t0x92, 0x40, 0x81, 0x83, 0x10, 0x20, 0x01, 0x09, 0x80, 0xc3, 0xe6, 0x42, 0x53, 0x13, 0x06, 0x15, \n\t0x80, 0x41, 0x58, 0x14, 0x00, 0x82, 0x1c, 0x88, 0x06, 0x00, 0x02, 0x2a, 0x06, 0x5c, 0x91, 0x00, \n\t0x58, 0x02, 0x8a, 0x90, 0x24, 0x04, 0x06, 0x28, 0x40, 0x30, 0x15, 0x24, 0x81, 0x60, 0x42, 0x46, \n\t0xd9, 0xa0, 0x11, 0x04, 0x46, 0x24, 0x92, 0xc0, 0x28, 0x21, 0x8c, 0x22, 0x00, 0x16, 0x08, 0x11, \n\t0xe1, 0x1d, 0x08, 0x0a, 0x01, 0x09, 0x3b, 0x90, 0x53, 0x20, 0x12, 0x03, 0xc0, 0x84, 0x00, 0x94, \n\t0x02, 0x14, 0xb2, 0x48, 0x38, 0x39, 0x42, 0x21, 0x40, 0xb2, 0xa2, 0x22, 0xc4, 0x90, 0x03, 0x40, \n\t0x70, 0x61, 0x2c, 0xc8, 0x48, 0xe3, 0x06, 0x42, 0x00, 0xac, 0x11, 0x04, 0xc0, 0x08, 0x40, 0x41, \n\t0x01, 0x08, 0x4a, 0x84, 0x48, 0x21, 0xd0, 0x02, 0x81, 0x00, 0x42, 0x20, 0x00, 0xd8, 0x04, 0x84, \n\t0x00, 0x8c, 0x04, 0x64, 0x13, 0x09, 0x35, 0x88, 0x21, 0x12, 0x80, 0x38, 0x0b, 0x24, 0xc2, 0x41, \n\t0x12, 0x80, 0x82, 0x28, 0x28, 0x05, 0x24, 0x74, 0x11, 0xc0, 0x05, 0x09, 0x51, 0x60, 0x28, 0x80, \n\t0xa2, 0x11, 0x24, 0x10, 0x89, 0x00, 0x21, 0x20, 0x85, 0x60, 0x00, 0x0c, 0x00, 0xa4, 0x81, 0x88, \n\t0x1c, 0x0b, 0x06, 0x64, 0x04, 0x32, 0x10, 0x08, 0x86, 0x01, 0x28, 0x43, 0x11, 0x20, 0x68, 0x51, \n\t0x0a, 0x36, 0x60, 0x82, 0xa6, 0x24, 0x87, 0x49, 0x4a, 0x00, 0x00, 0x10, 0xa9, 0x01, 0x81, 0x20, \n\t0x76, 0xca, 0xa1, 0xd5, 0x02, 0x00, 0x28, 0x52, 0x29, 0x22, 0xe0, 0x00, 0x0b, 0x08, 0x90, 0x08, \n\t0x14, 0xb0, 0x00, 0x05, 0x74, 0x50, 0x40, 0x8b, 0x20, 0x56, 0xea, 0x04, 0x30, 0x02, 0x15, 0xd1, \n\t0x00, 0x09, 0x40, 0x42, 0x02, 0x83, 0x30, 0x0a, 0xc8, 0x04, 0x15, 0x22, 0x98, 0x49, 0x09, 0x48, \n\t0x4a, 0x05, 0x02, 0x14, 0x00, 0xce, 0x24, 0x46, 0xc7, 0x23, 0x0d, 0x04, 0x10, 0x8c, 0x44, 0x60, \n\t0x80, 0x84, 0x38, 0x81, 0x02, 0x70, 0x41, 0x90, 0x26, 0x01, 0x40, 0xa1, 0x04, 0xc4, 0x48, 0x20, \n\t0x20, 0x43, 0x02, 0x10, 0xa4, 0x40, 0x1e, 0x44, 0x0a, 0x43, 0x08, 0x05, 0x62, 0x20, 0x18, 0x11, \n\t0x20, 0x70, 0x43, 0x8b, 0x18, 0x60, 0x04, 0x02, 0x16, 0x14, 0x91, 0x09, 0x10, 0x11, 0x20, 0x14, \n\t0x10, 0xe0, 0x08, 0x00, 0x88, 0x09, 0x1c, 0x85, 0x50, 0x2a, 0x08, 0x51, 0x42, 0x22, 0x71, 0x0a, \n\t0x00, 0x41, 0xcc, 0x80, 0x36, 0x04, 0xba, 0x31, 0x28, 0x0c, 0x02, 0x1a, 0x21, 0x01, 0xa0, 0x65, \n\t0x08, 0x01, 0x1a, 0xa4, 0x0b, 0x84, 0x40, 0x1c, 0x43, 0x26, 0x54, 0x8a, 0x08, 0x94, 0x08, 0x0c, \n\t0x04, 0x30, 0x10, 0x0a, 0x80, 0x52, 0x40, 0x40, 0xb0, 0xc3, 0x96, 0x00, 0x19, 0x05, 0x40, 0xa4, \n\t0x51, 0x0e, 0x09, 0xc5, 0x82, 0x28, 0x12, 0x40, 0x05, 0x08, 0x00, 0xc3, 0x10, 0x31, 0x38, 0x25, \n\t0x20, 0x02, 0xa8, 0x40, 0x76, 0x92, 0x01, 0x58, 0x41, 0xc5, 0x00, 0x03, 0x38, 0x04, 0x04, 0x02, \n\t0xa1, 0x44, 0x81, 0x91, 0x33, 0x80, 0x08, 0x20, 0x08, 0x41, 0x01, 0x33, 0x9d, 0x00, 0x40, 0x2a, \n\t0xc4, 0x51, 0x22, 0xf5, 0x0d, 0x4f, 0x00, 0x23, 0x90, 0x2a, 0xb0, 0x4a, 0xa2, 0x04, 0xd0, 0x48, \n\t0x00, 0x04, 0x54, 0xc8, 0x22, 0x92, 0x09, 0x29, 0x90, 0x85, 0x48, 0x0e, 0x00, 0xb0, 0x03, 0x88, \n\t0x4c, 0x84, 0x32, 0x80, 0x0b, 0x14, 0x10, 0x03, 0xc6, 0x50, 0x40, 0x03, 0x21, 0x08, 0x86, 0xe4, \n\t0x08, 0x04, 0x42, 0x32, 0x05, 0x00, 0x6a, 0x0c, 0x34, 0x10, 0xaa, 0x20, 0xc0, 0x64, 0x06, 0x90, \n\t0x12, 0x97, 0x28, 0xc2, 0x28, 0x42, 0x05, 0x88, 0x20, 0x21, 0xc6, 0x80, 0x10, 0x82, 0x81, 0x94, \n\t0x00, 0x1c, 0x01, 0x24, 0x24, 0x49, 0x80, 0x4c, 0x41, 0x46, 0x00, 0x83, 0x68, 0x80, 0x00, 0x48, \n\t0x08, 0x12, 0xc1, 0x61, 0x08, 0x38 \n};\n\n\nstatic bool isprime_slow(int64_t x)\n{\n\tfor (int i = 3; i < 10; ++i) {\n\t\tif (x % gLowPrimes[i] == 0)\n\t\t\treturn false;\n\t}\n\t\n\tfor (int i = 0; i < kPrimesMaskSize; ++i) {\n\t\tif (gPrimesMask[i] == 0) continue;\n\t\tint64_t k = 30 * (i+1);\n\t\tfor (int j = 0; j < 8; ++j) {\n\t\t\tif (!(gPrimesMask[k] & (1 << j))) continue;\n\t\t\tint64_t m = k + gPrimeOffsets[j];\n\t\t\tif (m*m > x) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\tif (x % m == 0) return false;\n\t\t}\n\t}\n\t\n\tthrow errOutOfRange;\n}\n\n#include \n\nbool isprime(int64_t x)\n{\n\tif (x <= 30) {\n\t\tif (x < 2) return false; // negatives aren't prime\n\t\treturn gLowPrimesMask & (1 << x);\n\t}\n\t\n\tint bit = x % 30;\n\tint shift = gPrimesShift[bit];\n\tif (shift < 0) return false; // eliminate multiples of 2,3,5.\n\tint64_t byte = x / 30 - 1;\n\t\t\n\tif (byte >= kPrimesMaskSize) return isprime_slow(x);\t\n\t\n\treturn gPrimesMask[byte] & (1 << shift);\n}\n\n\nint64_t nextPrime(int64_t x)\n{\n\tfor (;; ++x) {\n\t\tif (isprime(x)) return x;\n\t}\n}\n\n\n\n\n\n\n"], ["/sapf/src/elapsedTime.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"elapsedTime.hpp\"\n#include \n#include \n\nextern \"C\" {\n\nstatic double gHostClockFreq;\n\nvoid initElapsedTime()\n{\n\tstruct mach_timebase_info info;\n\tmach_timebase_info(&info);\n\tgHostClockFreq = 1e9 * ((double)info.numer / (double)info.denom);\n}\n\ndouble elapsedTime()\n{\n\treturn (double)mach_absolute_time() / gHostClockFreq;\n}\n\n}\n"], ["/sapf/src/RCObj.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"RCObj.hpp\"\n#include \"VM.hpp\"\n\n\nRCObj::RCObj()\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::RCObj(RCObj const& that)\n\t: refcount(0)\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsAllocated;\n#endif\n}\n\nRCObj::~RCObj()\n{\n#if COLLECT_MINFO\n\t++vm.totalObjectsFreed;\n#endif\n}\n\n\nvoid RCObj::norefs()\n{\n\trefcount = -999;\n\tdelete this; \n}\n\n\t\nvoid RCObj::negrefcount()\n{\n\tpost(\"RELEASING WITH NEGATIVE REFCOUNT %s %p %d\\n\", TypeName(), this, refcount.load());\n}\nvoid RCObj::alreadyDead()\n{\n\tpost(\"RETAINING ALREADY DEAD OBJECT %s %p\\n\", TypeName(), this);\n}\n"], ["/sapf/src/ErrorCodes.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"ErrorCodes.hpp\"\n\nconst char* errString[kNumErrors] = { \n\t\"halt\", \"failed\", \"indefinite operation\", \"wrong type\", \"out of range\", \"syntax\", \"internal bug\",\n\t\"wrong state\", \"not found\", \"stack overflow\", \"stack underflow\",\n\t\"inconsistent inheritance\", \"undefined operation\", \"user quit\"\n};\n"], ["/sapf/libmanta/MantaServer.h", "#ifndef _MANTASERVER_H\n#define _MANTASERVER_H\n\n/************************************************************************//**\n * \\class MantaServer\n * \\brief Interface defining all the Messages that can be sent to a Manta\n *\n * The MantaServer virtual class defines all the Messages that the Manta\n * understands, as well as the data structures used as arguments. If you\n * need a pointer to a Manta in your code, you can make it more general by\n * using a MantaServer pointer instead of a pointer to your specific subclass.\n ****************************************************************************/\nclass MantaServer\n{\n public:\n\n enum LEDState {\n Off,\n Amber,\n Red,\n All, // only used in SetPadLEDFrame\n };\n enum LEDControlType {\n PadAndButton,\n Slider,\n Button\n };\n typedef uint8_t LEDFrame[6];\n\n virtual ~MantaServer() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void SetPadLED(LEDState state, int ledID) = 0;\n virtual void SetPadLEDRow(LEDState state, int row, uint8_t mask) = 0;\n virtual void SetPadLEDColumn(LEDState state, int column, uint8_t mask) = 0;\n virtual void SetPadLEDFrame(LEDState state, uint8_t mask[]) = 0;\n virtual void SetSliderLED(LEDState state, int id, uint8_t mask) = 0;\n virtual void SetButtonLED(LEDState state, int id) = 0;\n virtual void ResendLEDState(void) = 0;\n virtual void ClearPadAndButtonLEDs(void) = 0;\n virtual void ClearButtonLEDs(void) = 0;\n virtual void Recalibrate(void) = 0;\n virtual void SetLEDControl(LEDControlType control, bool state) = 0;\n virtual void SetTurboMode(bool Enabled) = 0;\n virtual void SetRawMode(bool Enabled) = 0;\n virtual void SetMaxSensorValues(int *values) = 0;\n};\n#endif /* _MANTASERVER_H */\n"], ["/sapf/src/Types.cpp", "// SAPF - Sound As Pure Form\n// Copyright (C) 2019 James McCartney\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see .\n\n#include \"Types.hpp\"\n"], ["/sapf/libmanta/MantaMulti.h", "class MantaMulti {\n public:\n MantaMulti(MantaClient *client = NULL) {\n AttachClient(client);\n}\n void AttachClient(MantaClient *client) {\n if(NULL != client)\n {\n ClientList.push_back(client);\n ++ReferenceCount;\n }\n}\n void DetachClient(MantaClient *client) {\n list::iterator foundIter;\n foundIter = find(ClientList.begin(), ClientList.end(), client);\n if(ClientList.end() != foundIter)\n {\n ClientList.erase(foundIter);\n --ReferenceCount;\n }\n}\n int GetReferenceCount() {\n return ReferenceCount;\n}\n protected:\n void PadEvent(int row, int column, int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadEvent(row, column, id, value);\n }\n}\n void SliderEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->SliderEvent(id, value);\n }\n}\n void ButtonEvent(int id, int value) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonEvent(id, value);\n }\n}\n void PadVelocityEvent(int row, int column, int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->PadVelocityEvent(row, column, id, velocity);\n }\n}\n void ButtonVelocityEvent(int id, int velocity) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->ButtonVelocityEvent(id, velocity);\n }\n}\n void FrameEvent(uint8_t *frame) {\n for(list::iterator i = ClientList.begin();\n i != ClientList.end(); ++i)\n {\n (*i)->FrameEvent(frame);\n }\n}\n private:\n list ClientList;\n int ReferenceCount;\n};"], ["/sapf/libmanta/MantaExceptions.h", "#ifndef _MANTAEXCEPTIONS_H\n#define _MANTAEXCEPTIONS_H\n\n#include \n\nclass LibusbInitException : public std::runtime_error\n{\n public:\n LibusbInitException() :\n runtime_error(\"Error initializing libusb\")\n {\n }\n};\n\nclass MantaNotConnectedException : public std::runtime_error\n{\n public:\n MantaNotConnectedException(MantaUSB *manta) :\n runtime_error(\"Attempted to access the Manta without connecting\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\nclass MantaNotFoundException : public std::runtime_error\n{\n public:\n MantaNotFoundException() :\n runtime_error(\"Could not find an attached Manta\")\n {\n }\n};\n\nclass MantaOpenException : public std::runtime_error\n{\n public:\n MantaOpenException() :\n runtime_error(\"Could not connect to attached Manta\")\n {\n }\n};\n\nclass MantaCommunicationException : public std::runtime_error\n{\n public:\n MantaCommunicationException(MantaUSB *manta = NULL) :\n runtime_error(\"Communication with Manta interrupted\"),\n errorManta(manta)\n {\n }\n MantaUSB *errorManta;\n};\n\n#endif // _MANTAEXCEPTIONS_H\n"], ["/sapf/libmanta/MantaClient.h", "#ifndef _MANTACLIENT_H\n#define _MANTACLIENT_H\n\n#include \n\n/************************************************************************//**\n * \\class MantaClient\n * \\brief Interface defining all the Events generated by the Manta\n *\n * The MantaClient virtual class defines all the Events that could be\n * generated by the Manta. Your object should provide implementations\n * to any of these events that you'd like to listen for\n ****************************************************************************/\nclass MantaClient\n{\n public:\n virtual ~MantaClient() {}\n /* declare callbacks to be implemented by subclasses */\n virtual void PadEvent(int row, int column, int id, int value) {}\n virtual void SliderEvent(int id, int value) {}\n virtual void ButtonEvent(int id, int value) {}\n virtual void PadVelocityEvent(int row, int column, int id, int velocity) {}\n virtual void ButtonVelocityEvent(int id, int velocity) {}\n virtual void FrameEvent(uint8_t *frame) {}\n virtual void DebugPrint(const char *fmt, ...) {}\n};\n#endif /* _MANTACLIENT_H */\n"], ["/sapf/libmanta/MantaVersion.h", "#ifndef _MANTAVERSION_H\n#define _MANTAVERSION_H\n\n#define LIBMANTA_MAJOR_VERSION 1\n#define LIBMANTA_MINOR_VERSION 3\n\n#endif // _MANTAVERSION_H\n"]], "task_instance_info": {"created_time": "2025-08-20 20:05:17", "created_task_model": "DeepSeek-R1", "function_skeleton": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor) {}", "code_description": "This code segment functions to: Process input signal data through windowed Fourier transforms to generate a time-frequency representation, convert magnitude values to logarithmic scale for visualization, and render the results as a composite image combining amplitude peaks and spectral components using color mapping."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nvoid spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor) {\n // Create Kaiser window\n double* window = new double[size];\n std::fill(window, window + size, 1.0);\n calcKaiserWindowD(size, window, -60.0);\n\n // Prepare FFT\n int log2n = log2bins + 1;\n FFTSetup fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);\n \n // Allocate complex buffers\n DSPSplitComplex splitComplex;\n splitComplex.realp = (double*)malloc((size/2 + 1) * sizeof(double));\n splitComplex.imagp = (double*)malloc((size/2 + 1) * sizeof(double));\n\n // Create color table\n unsigned char colorTable[1024];\n makeColorTable(colorTable);\n\n // Prepare image buffer\n int height = size/2 + 1;\n unsigned char* image = new unsigned char[width * height * 4];\n \n // Process each time slice\n for (int col = 0; col < width; ++col) {\n double* frame = data + col * size;\n \n // Apply window and convert to split complex\n vDSP_vmulD(frame, 1, window, 1, frame, 1, size);\n vDSP_ctozD((DSPDoubleComplex*)frame, 2, &splitComplex, 1, size/2);\n \n // Perform FFT\n vDSP_fft_zripD(fftSetup, &splitComplex, 1, log2n, FFT_FORWARD);\n \n // Calculate magnitudes and normalize\n for (int bin = 0; bin <= size/2; ++bin) {\n double real = splitComplex.realp[bin];\n double imag = splitComplex.imagp[bin];\n double magSq = real*real + imag*imag;\n \n // Convert to dB scale\n double dB = 10.0 * log10(magSq + 1e-30);\n dB = fmax(dB, dBfloor);\n double normalized = (dB - dBfloor) / (-dBfloor);\n \n // Map to color index\n int idx = (int)(normalized * 255);\n idx = std::max(0, std::min(255, idx));\n \n // Set pixel color (reverse frequency axis)\n int row = size/2 - bin;\n unsigned char* pixel = &image[(col * height + row) * 4];\n memcpy(pixel, colorTable + idx * 4, 4);\n }\n }\n \n // Save image and cleanup\n makeImage(width, height, image, path);\n delete[] window;\n free(splitComplex.realp);\n free(splitComplex.imagp);\n delete[] image;\n vDSP_destroy_fftsetup(fftSetup);\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 20-09-18"}, "editdistance_info": {"edit_distance": 14.4092, "calculate_time": "2025-08-20 20:09:18", "true_code_clean": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor)\n{\n\tint numRealFreqs = 1 << log2bins;\n\tint log2n = log2bins + 1;\n\tint n = 1 << log2n;\n\tint nOver2 = n / 2;\n\tdouble scale = 1./nOver2;\n\tint64_t paddedSize = size + n;\n\tdouble* paddedData = (double*)calloc(paddedSize, sizeof(double));\n\tmemcpy(paddedData + nOver2, data, size * sizeof(double));\n\tdouble* dBMags = (double*)calloc(numRealFreqs + 1, sizeof(double));\n\tdouble hopSize = size <= n ? 0 : (double)(size - n) / (double)(width - 1);\n\tdouble* window = (double*)calloc(n, sizeof(double));\n\tfor (int i = 0; i < n; ++i) window[i] = 1.;\n\tcalcKaiserWindowD(n, window, -180.);\n\tunsigned char table[1028];\n\tmakeColorTable(table);\n\tint heightOfAmplitudeView = 128;\n\tint heightOfFFT = numRealFreqs+1;\n\tint totalHeight = heightOfAmplitudeView+heightOfFFT+3*border;\n\tint topOfSpectrum = heightOfAmplitudeView + 2*border;\n\tint totalWidth = width+2*border;\n\tBitmap* b = createBitmap(totalWidth, totalHeight);\n\tfillRect(b, 0, 0, totalWidth, totalHeight, 160, 160, 160, 255);\n\tfillRect(b, border, border, width, heightOfAmplitudeView, 0, 0, 0, 255);\n\tFFTSetupD fftSetup = vDSP_create_fftsetupD(log2n, kFFTRadix2);\n\tdouble* windowedData = (double*)calloc(n, sizeof(double));\n\tdouble* interleavedData = (double*)calloc(n, sizeof(double));\n\tdouble* resultData = (double*)calloc(n, sizeof(double));\n\tDSPDoubleSplitComplex interleaved;\n\tinterleaved.realp = interleavedData;\n\tinterleaved.imagp = interleavedData + nOver2;\n\tDSPDoubleSplitComplex result;\n\tresult.realp = resultData;\n\tresult.imagp = resultData + nOver2;\n\tdouble maxmag = 0.;\n\tdouble hpos = nOver2;\n\tfor (int i = 0; i < width; ++i) {\n\t\tsize_t ihpos = (size_t)hpos;\n\t\tdouble peak = 1e-20;\n\t\tfor (int w = 0; w < n; ++w) {\n\t\t\tdouble x = paddedData[w+ihpos];\n\t\t\tx = fabs(x);\n\t\t\tif (x > peak) peak = x;\n\t\t}\n\t\tfor (int64_t w = 0; w < n; ++w) windowedData[w] = window[w] * paddedData[w+ihpos];\n\t\tvDSP_ctozD((DSPDoubleComplex*)windowedData, 2, &interleaved, 1, nOver2);\n\t\tvDSP_fft_zropD(fftSetup, &interleaved, 1, &result, 1, log2n, kFFTDirection_Forward);\n\t\tdBMags[0] = result.realp[0] * scale;\n\t\tdBMags[numRealFreqs] = result.imagp[0] * scale;\n\t\tif (dBMags[0] > maxmag) maxmag = dBMags[0];\n\t\tif (dBMags[numRealFreqs] > maxmag) maxmag = dBMags[numRealFreqs];\n\t\tfor (int64_t j = 1; j < numRealFreqs-1; ++j) {\n\t\t\tdouble x = result.realp[j] * scale;\n\t\t\tdouble y = result.imagp[j] * scale;\n\t\t\tdBMags[j] = sqrt(x*x + y*y);\n\t\t\tif (dBMags[j] > maxmag) maxmag = dBMags[j];\n\t\t}\n\t\tdouble invmag = 1.;\n\t\tdBMags[0] = 20.*log2(dBMags[0]*invmag);\n\t\tdBMags[numRealFreqs] = 20.*log10(dBMags[numRealFreqs]*invmag);\n\t\tfor (int64_t j = 0; j <= numRealFreqs-1; ++j) {\n\t\t\tdBMags[j] = 20.*log10(dBMags[j]*invmag);\n\t\t}\n\t\t{\n\t\t\tdouble peakdB = 20.*log10(peak);\n\t\t\tint peakColorIndex = 256. - peakdB * (256. / dBfloor);\n\t\t\tint peakIndex = heightOfAmplitudeView - peakdB * (heightOfAmplitudeView / dBfloor);\n\t\t\tif (peakIndex < 0) peakIndex = 0;\n\t\t\tif (peakIndex > heightOfAmplitudeView) peakIndex = heightOfAmplitudeView;\n\t\t\tif (peakColorIndex < 0) peakColorIndex = 0;\n\t\t\tif (peakColorIndex > 255) peakColorIndex = 255;\n\t\t\tunsigned char* t = table + 4*peakColorIndex;\n\t\t\tfillRect(b, i+border, border+128-peakIndex, 1, peakIndex, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\tfor (int j = 0; j < numRealFreqs; ++j) {\n\t\t\tint colorIndex = 256. - dBMags[j] * (256. / dBfloor); \n\t\t\tif (colorIndex < 0) colorIndex = 0;\n\t\t\tif (colorIndex > 255) colorIndex = 255;\n\t\t\tunsigned char* t = table + 4*colorIndex;\n\t\t\tsetPixel(b, i+border, numRealFreqs-j+topOfSpectrum, t[0], t[1], t[2], t[3]);\n\t\t}\n\t\thpos += hopSize;\n\t}\n\tvDSP_destroy_fftsetupD(fftSetup);\n\twriteBitmap(b, path);\n\tfreeBitmap(b);\n\tfree(dBMags);\n\tfree(paddedData);\n\tfree(window);\n\tfree(windowedData);\n\tfree(interleavedData);\n\tfree(resultData);\n}", "predict_code_clean": "void spectrogram(int size, double* data, int width, int log2bins, const char* path, double dBfloor) {\n double* window = new double[size];\n std::fill(window, window + size, 1.0);\n calcKaiserWindowD(size, window, -60.0);\n int log2n = log2bins + 1;\n FFTSetup fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);\n DSPSplitComplex splitComplex;\n splitComplex.realp = (double*)malloc((size/2 + 1) * sizeof(double));\n splitComplex.imagp = (double*)malloc((size/2 + 1) * sizeof(double));\n unsigned char colorTable[1024];\n makeColorTable(colorTable);\n int height = size/2 + 1;\n unsigned char* image = new unsigned char[width * height * 4];\n for (int col = 0; col < width; ++col) {\n double* frame = data + col * size;\n vDSP_vmulD(frame, 1, window, 1, frame, 1, size);\n vDSP_ctozD((DSPDoubleComplex*)frame, 2, &splitComplex, 1, size/2);\n vDSP_fft_zripD(fftSetup, &splitComplex, 1, log2n, FFT_FORWARD);\n for (int bin = 0; bin <= size/2; ++bin) {\n double real = splitComplex.realp[bin];\n double imag = splitComplex.imagp[bin];\n double magSq = real*real + imag*imag;\n double dB = 10.0 * log10(magSq + 1e-30);\n dB = fmax(dB, dBfloor);\n double normalized = (dB - dBfloor) / (-dBfloor);\n int idx = (int)(normalized * 255);\n idx = std::max(0, std::min(255, idx));\n int row = size/2 - bin;\n unsigned char* pixel = &image[(col * height + row) * 4];\n memcpy(pixel, colorTable + idx * 4, 4);\n }\n }\n makeImage(width, height, image, path);\n delete[] window;\n free(splitComplex.realp);\n free(splitComplex.imagp);\n delete[] image;\n vDSP_destroy_fftsetup(fftSetup);\n}"}}