Andrej's 8bit waveshaper waveform draw-generate-edit-export tool

Input

Paste your array contents to load them for editing (must be 256 bits separated with commas):



Math function input

You can input a math function (with x as your argument) and it will be rendered to an array of 256 byte-sized integers. The x values that the function will be calculated for are [-1, 1], in 1/128 increments (x = -1, -0.9921875, ... , 0.9921875-, 1).
The results will be scaled so that 1~128 and -1~-127, rounded to integers and capped at [-128, 127].

The parser is Silent Matt's JavaScript Expression Evaluator. You can check out the syntax right here:

Syntax

Variables and constants

You can use these variables and constants in your function.

Name Description
x independent variable - function argument
xs x scaled by pi (xs = x * pi), so trigonometric functions' period becomes [-1, 1]
s minimum step of our function: 1/256
pi 3.141592653589793
e Euler's number (2.7182818284)
phi Golden ratio (1.6180339887498)

Functions

The parser has several built-in “functions” that are actually operators. The only difference from an outside point of view, is that they cannot be called with multiple arguments and they are evaluated by the simplify method if their arguments are constant.

Function Description
sin(x) Sine of x (x is in radians)
cos(x) Cosine of x (x is in radians)
tan(x) Tangent of x (x is… well, you know)
asin(x) Arc sine of x (in radians)
acos(x) Arc cosine of x (in radians)
atan(x) Arc tangent of x (in radians)
sqrt(x) Square root of x. Result is NaN (Not a Number) if x is negative.
log(x) Natural logarithm of x (not base-10). It’s log instead of ln because that’s what JavaScript calls it.
abs(x) Absolute value (magnatude) of x
ceil(x) Ceiling of x — the smallest integer that’s >= x.
floor(x) Floor of x — the largest integer that’s <= x
round(x) X, rounded to the nearest integer, using “gradeschool rounding”.
exp(x) ex (exponential/antilogarithm function with base e)

Pre-defined functions

Besides the “operator” functions, there are several pre-defined functions. You can provide your own, by binding variables to normal JavaScript functions. These are not evaluated by simplify.

Function Description
random(n) Get a random number in the range [0, n). If n is zero, or not provided, it defaults to 1.
fac(n) n! (factorial of n: “n * (n-1) * (n-2) * … * 2 * 1″)
min(a,b,…) Get the smallest (“minimum”) number in the list
max(a,b,…) Get the largest (“maximum”) number in the list
pyt(a, b) Pythagorean function, i.e. the c in “c2 = a2 + b2
pow(x, y) xy. This is exactly the same as “x^y”. It’s just provided since it’s in the Math object from JavaScript
atan2(y, x) arc tangent of x/y. i.e. the angle between (0, 0) and (x, y) in radians.
f(x) =

Waveform drawing

Click [and drag] to draw your waveform. A click inside of a column places a square in it. Each column has exactly one square inside of it. The waveform must include a square in each column.



Waveform export

Click to export your drawn waveform to ASCII code you can paste into your array initializer in C.



License

Waveshaper waveform editor and generator
Copyright (C) 2015 Andrej Radović (r.andrej@gmail.com) except for JavaScript Expression Evaluator (Copyright (C) Matthew Crumley)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
gpl logo