Hello again,

I'm working on some basic (micro)tuning code as part of the learning
process. I've hit a snag with something that's probably quite basic.

I've implemented the tuning as an array of constant signals in parallel and
I'm using ba.take() to grab the appropriate one for the current note, but
it's failing at compile time with a "pattern matching error" that I'm
struggling to interpret. Google searches suggest other people have run into
the same problem but none of them seemed to contain a solution.

A minimal (non-)working example is attached -- would anyone be kind enough
to have a quick look and see if they can spot what's wrong? I've added
comments indicating the key lines.

Cheers,

Rich
import("stdfaust.lib");

gain = nentry("gain", 1, 0, 1, 0.01) * en.adsr(0.0, 0.1, 0.7, 1.0, gate);
freq = hslider("freq", 440, 50, 1000, 0.01);
gate = button("gate") : en.adsr(0.01, 0.01, 0.9, 0.1);

midiKey = ba.hz2midikey(freq);  // get the MIDI key number from the freq
zeroNote = 8.1758;                              // Hz value of MIDI key zero.
centRatio = 1.00057778951;              // 2^(1/1200)

///////////////////////////////////////////////////////////////////////////////
// This is the list of cents values for the tuning
///////////////////////////////////////////////////////////////////////////////
tuning = (0.0, 120.0, 240.0, 360.0, 480.0, 480.0, 600.0, 720.0, 840.0, 960.0, 
1080.0, 1200.0);

numNotes = ba.count(tuning);
oct = floor(midiKey / numNotes);

///////////////////////////////////////////////////////////////////////////////
// Here I want to use pc (which has int values 0-11) to look up
// a cents value in "tuning" (defined above).
// This creates a compile-time "pattern matching failed" error.
///////////////////////////////////////////////////////////////////////////////
pc = midiKey % numNotes;
numCents = ba.take(pc + 1, tuning);                                             
// <-- COMPILATION FAILS HERE                           

gFreq = zeroNote * pow(2, oct) * pow(centRatio, numCents);

process = os.osc(gFreq) * gate * gain  <: _,_;


_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to