Table of Contents

Math expression parser

Motivation

In order to fill a wavetable with waves, a tool is needed to make this task as simple and effective as possible. So the idea to do it with the help of some math was born. An expression parser takes a formula as input and after evaluation all wavetable data gets visualized and can be dumped to the blofeld.

How it works

Two variables are set automatically, that is:

x moves from 0.0 to 1.0 for all 128 samples in a wave.a y moves from 0.0 to 1.0 for each table entry in the range [0..64]

Overview of implemented operators

Example expressions

Gaussian tone burst

Gauss-Funktion für einen Vektor http://etools.fernuni.ch/matlab/matlab3/de/html/loops_learningObject4.html

Mittelwert m und Standardabweichung s

s=0.5
m=pi/2

4/(2*sqrt(2*pi)) * exp(-1/2*((x*pi-m)/s)^2) * sin(16*pi*x)

Implementation

GCMathParser is a Cocoa class © 2006-2008 Graham Cox

It uses ZExpParser MacZoop expression parser

The Xcode project compiles fine, just set SDKROOT = macosx and replace cString with UTF8String (in general is a much better choice when converting arbitrary NSStrings into 8-bit representations)

GCMathParser* parser = [GCMathParser parser];
NSString* expression = @"sin(x)";
for (int sampleIndex = 0; sampleIndex < 64; sampleIndex++) {
	double x = sampleIndex / 64.;
    [parser setSymbolValue:x forKey:@"x"];
    wave[sampleIndex] = [parser evaluate:expression];
}

Another parser on the web is https://github.com/davedelong/DDMathParser