This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Language is OpenGL ES, but gist.github.com doesn't know that language | |
// | |
// Approximation is based on multiply/accumulate, because thats the only | |
// thing Videocore can do quickly! | |
precision highp float; | |
float sinf(float x) | |
{ | |
x*=0.159155; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Improved support for Eleduino 1024x600 LCD panel | |
hdmi_group=2 | |
hdmi_mode=87 | |
#Safer option at 50.4MHz pixel clock | |
#hdmi_timings=1024 0 48 32 240 600 0 3 32 13 0 0 0 60 0 50400000 6 | |
#Safer option at data sheet max clock of 65.2 | |
#hdmi_timings=1024 0 48 32 240 600 0 3 32 13 0 0 0 60 0 65200000 6 | |
hdmi_timings=1024 0 48 32 216 600 0 2 14 0 0 0 0 60 0 65200000 6 | |
max_usb_current=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Calculate exp2(x) = 2**x natively in WebAssembly. | |
;; Compiles to 49 bytes of WebAssembly code | |
(module | |
(func $exp2 (param $x f32) (result f32) | |
(local $xf f32) | |
;; Parse result as a float bitfield | |
(f32.reinterpret_i32 | |
(i32.add | |
;; Compute mantissa of result | |
;; Compute polynomial to cover f(x) = 2**23 * ( 2^(x) - 1 ) where 0 <= x < 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module | |
;; Calculate sin(tau x) natively in WebAssembly. | |
;; Compiles to 57 bytes of WebAssembly code | |
;; Uses angle units of 0 to 1 for a circle (useful for synths). Pre-divide by 2*pi to use radians. | |
;; Using Bhaskara I's approximation | |
;; https://en.wikipedia.org/wiki/Bhaskara_I%27s_sine_approximation_formula | |
;; Accurate to about 0.2% | |
(export "sintau" (func $sintau)) | |
(func $sintau (param $x f32) (result f32) | |
(local $s f32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; From https://github.com/vsariola/sointu | |
;; Compiles to 19 bytes of WebAssembly code | |
;; | |
;; Returns pseudorandom numbers in the range 0 to 1 | |
(module | |
(global $randseed (mut i32) (i32.const 1)) | |
(export "rand" (func $rand)) | |
(func $rand (result f32) | |
(set_global $randseed (i32.mul (get_global $randseed) (i32.const 16007))) | |
(f32.div (f32.convert_s/i32 (get_global $randseed)) (f32.const -2147483648)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Calculate log2(x) = ln(x)/ln(2) natively in WebAssembly. | |
;; Compiles to 75 bytes of WebAssembly code | |
(module | |
(export "log2" (func $log2)) | |
(func $log2 (param $x f32) (result f32) | |
(local $x2 f32) | |
(f32.add | |
;; Extract exponent of $x | |
(f32.convert_s/i32 | |
(i32.sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Native implementations of sin, log and exp functions. | |
;; sintau: 41 bytes code, 34 bytes shared code, 24 bytes data | |
;; exp2: 25 bytes code, 34 bytes shared code, 20 bytes data | |
;; log2: 37 bytes code, 34 bytes shared code, 24 bytes data | |
;; Total 137 bytes code, 68 bytes data | |
;; Wasm-opt -Oz tries to optimise out $half by converting to f32.consts, but that actually takes up more space, not less. | |
;; Polynomial coefficients calculated by accompanying python script. | |
;; call $evalpoly parameters will need to be manually changed for different length polynomials. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#%% | |
from sympy import symbols, cos, pi, factor_list | |
from sympy.core.numbers import One | |
from sympy.utilities.lambdify import lambdify | |
from math import sin, pi | |
import numpy as np | |
def chebyshev(func, interval, degree=7, precision=20): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.