[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Re: Help me map a control rate signal with a buffer
Hi again Dan!
Thanks again for your helpful reply, your method is working like a charm.
I'm mapping a signal in equal temperament onto the same signal as if
played using just intonation. What's great is, I used the MIDI note
value as an index creating the buffer (happened to have that function
lying around), so it has human-readable meaning as well *so proud*.
Here's the code, just in case some Googler will find it useful some day.
Carlo
/*
Code for mapping a signal played by an equal temperament instrument
as if it had been played using just intonation.
Source of Just Intonation intervals: en.wikipedia.org/just_intonation
(c) 2009 Carlo Capocasa.
Released under the MIT license.
*/
var
basefreq = 450,
baseoctave = 6,
scaletones = 12,
just_intonation = [1, 256/243, 9/8, 32/27, 81/64, 4/3, 729/512,
3/2, 128/81, 27/16, 16/9, 243/128],
scale_equal_temperament = {
arg note;
1.0594631 ** note;
},
scale_just = {
arg note;
just_intonation[note];
},
freq = {
arg num, scaleFunction = scale_just;
var
note = num % scaletones,
octave = (num - note) / scaletones,
interval = scaleFunction.(note),
octfreq = basefreq * (2 ** (octave-baseoctave));
octfreq * interval;
},
mapping = (
'just': Buffer.alloc(s,127),
'tempered': Buffer.alloc(s,127)
);
/*
Use this in a synthdef, where freqs is the frequency
of the instrument as control rate:
arg freq;
var mapindex;
mapindex = IndexInBetween.kr(mapping['tempered'],freq);
freq = IndexL.kr(mapping['just'],mapindex);
*/
Dan Stowell wrote:
It's just linear interpolation. e.g. if the input is 12.53 and the
buffer contains [11,12,13] then the output is 1.53, where the "1" is
because it's somewhere between indices numbered 1 and 2, and the ".53"
is reverse-linear-interpolation:
frac = (input-b[1]) / (b[2]-b[1])
Dan
2009/5/3, Carlo Capocasa <theman@xxxxxxxxxxxxxxxxx>:
Hi Dan!
Thanks, that sounds really helpful. Can you explain something about this?
How is the interpolation done, IE how does the program 'know' how far in
between the elements of ~from the signal was at any given point?
Thanks a lot for your reply,
Carlo
Dan Stowell wrote:
Hi Carlo -
One way you can do it is using IndexInBetween to "unmap" your input
into integer slots, and then use IndexL to do the reverse, to "map"
onto your other distribution. This example maps a sort-of-exponential
curve onto a sort-of-sinusoidal curve:
~from = [1, 2, 4, 8, 16];
~to = [0, 1, 0, -1, 0];
x={IndexL.kr(~to.as(LocalBuf),
IndexInBetween.kr(~from.as(LocalBuf),
MouseX.kr(~from.first,~from.last).poll).poll).poll}.play
HTH
Dan
---------- Forwarded message ----------
From: Carlo Capocasa <theman@xxxxxxxxxxxxxxxxx>
Date: 3.5.2009 11:35
Subject: [sc-users] Help me map a control rate signal with a buffer
To: sc-users@xxxxxxxxxxxxxxxx
Hi! Thanks for reading. I'm looking for some help... I need to
re-shape a control rate signal with a mapping function defined by a
series of float (X|Y) values and linear interpolation in-between.
Using a buffer seems to be the most elegant way to do this, could you
kindly point me to Ugens that might do this? IndexInBetween seemed
promising but then the X-Values have to be integers. Thanks!
Carlo
_______________________________________________
sc-users mailing list
info (subscription, etc.):
http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive:
https://listarc.bham.ac.uk/marchives/sc-users/
search:
https://listarc.bham.ac.uk/lists/sc-users/search/
_______________________________________________
sc-users mailing list
info (subscription, etc.):
http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search:
https://listarc.bham.ac.uk/lists/sc-users/search/
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/