[chuck-users] function for creating 8 bit waveforms from expressions

Steve Morris steve at judgement.com
Sat Dec 28 16:51:40 EST 2013


For the record I don't mean to "Curse the Darkness". I am merely helping to
set expectations. I think the developers have done more than enough by
releasing ChucK open source. It is a wonderful tool and it is pretty high
quality bug wise. There is no reason however to pretend that ChucK is well
supported, at least where advanced functionality is concerned, and it is
not a criticism of the authors and developers to say so. This is not
unusual with open source software. The developers have their priorities and
their own lives to lead and are under no obligation to do anything
different. It's not like they get paid for this. The level of support is
just an important piece of information to have when you are considering
using Chuck. If you need a lot of support you might do better to consider
other similar tools. There are many available and some have more extensive
support.

-steve



On Fri, Dec 27, 2013 at 7:13 PM, Joel Matthys <jwmatthys at yahoo.com> wrote:

> On 12/27/2013 05:08 PM, Steve Morris wrote:
>
>>
>> It is a mystery to many of us exactly why users are not allowed to know
>> how to do this. Questions to this list are basically ignored except by
>> other users. I suspect that ChucK developers don't read this list and the
>> real point of this list is to hope users will support each other and stop
>> bothering the developers. It is also possible that there are no real
>> developers, that ChucK development consists of an occasional  grad student
>> who shows interest for a while then moves on to more productive endeavors.
>>
>>
> There is a ChuGen example in the examples/extend folder; it's extremely
> straight-forward. I know the devs read this list, but honestly this is
> exactly the kind of question we as a community should be able to help with.
> Let's light some candles rather than curse the darkness.
>
> Now, ChuGen takes floats in the range [-1,1] for its calculations, but you
> want to work on 8-bit ints, so you'll have to have functions that convert
> itof and ftoi. Then you can write your expression to work on those samples
> directly. A Phasor UGen then provides the 0-1 samples in. Try this:
>
> --
> // ChuGen
> // Create new UGens by performing audio-rate processing in ChucK
>
> class MyFunc extends Chugen
> {
>     8 => int _b; // default 8 bits
>
>     fun float tick(float in)
>     {
>         ftoi (in, _b) => int ival; // convert in sample to int
>         my_expression(ival) % (1 << _b) => int fval; //calculate and mod
> into range
>         return (itof (fval, _b)); // convert back to float
>     }
>
>     // your custom expression goes here
>     fun int my_expression (int t)
>     {
>         return t * ( t >> 8 * ( t >>15 | t >> 8) & 20 | ( t >>19) * 5 >> t
> | t >> 3);
>     }
>
>     // helper function to convert float [0,1] to b bits
>     fun int ftoi (float in, int b)
>     {
>         return (in * (1 << b)) $ int;
>     }
>
>     // helper function to convert b bit integer to float [-1,1]
>     fun float itof (int in, int b)
>     {
>         return (in * 1.0 / (1 << (b-1))) - 1;
>     }
>
>     // allow user to set number of bits
>     fun void bits (int b)
>     {
>         b => _b;
>     }
> }
>
> // phasor powers the function with numbers ascending 0-1
> Phasor p => MyFunc f => dac;
> 1 => p.freq;
>
> while(true) 1::second => now;
>
> /// END ///
>
> Joel
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20131228/b359c7e9/attachment.htm>


More information about the chuck-users mailing list