Yes, you don't need the abs.  At first I was using floor and wanted to
truncate toward zero, but after changing to round the abs is not doing
anything.  Pardon my haste!  (I was in a meeting and trying to multitask,
but this was a dropout :-) )

On Mon, Sep 14, 2020 at 8:49 PM Sam Pluta <spl...@gmail.com> wrote:

> Didn’t put what a was:
>
> a = (2**3-1);
>
> {SinOsc.ar(200)}.plot;
> {(SinOsc.ar(200)*a).round/a}.plot;
> {b = SinOsc.ar(200); (b.abs*a).round/a*(2*(b>0).asInteger-1)}.plot;
>
> On September 14, 2020 at 10:25:30 PM, Sam Pluta (spl...@gmail.com) wrote:
>
> Awesome. Thanks Julius! Is there a reason why it won’t work without the
> abs:
>
> bitcrusher(nbits,x) = x *(scaler) : round : /(scaler);
>
> Sorry to foul this forum with SC code, but the plots look the same:
>
> {SinOsc.ar(200)}.plot;
>
> {(SinOsc.ar(200)*a).round/a}.plot;
>
> {b = SinOsc.ar(200); (b.abs*a).round/a*(2*(b>0).asInteger-1)}.plot;
>
> Stay safe out there in Cali. Yikes.
>
> Sam
>
> On September 14, 2020 at 9:50:19 PM, Julius Smith (julius.sm...@gmail.com)
> wrote:
>
> Tested!:
>
> import("stdfaust.lib");
>
> nbits = hslider("NBITS",8,0,16,1);
> scaler = float(2^nbits-1);
> round(x) = floor(x+0.5);
> bitcrusher(nbits,x) = x : abs : *(scaler) : round : /(scaler) *
> (2*(x>0)-1.0);
> process = os.oscrs(300) : bitcrusher(nbits);
>
>
> On Mon, Sep 14, 2020 at 6:40 PM Julius Smith <julius.sm...@gmail.com>
> wrote:
>
>> Hi Sam,
>>
>> What I wrote was for integers.  For floats, you want something like this:
>>
>> scaler = float(2^nbits-1);
>> bitcrusher(nbits) = abs : *(scaler) : round : /(scaler) : *(>(0)*2-1); //
>> (put sign bit back in at the end)
>>
>> (not tested)
>>
>>
>> On Mon, Sep 14, 2020 at 5:29 PM Sam Pluta <spl...@gmail.com> wrote:
>>
>>> Didn’t mean to send this only to Julius. What am I doing wrong:
>>>
>>> import("stdfaust.lib”);
>>> nbits = 7;
>>> process = (os.osc(200)&(2^(nbits)-1))*0.1;
>>>
>>> Just kind of blips on and off for me.
>>>
>>> Sam
>>>
>>>
>>> On September 14, 2020 at 5:08:40 PM, Julius Smith (
>>> julius.sm...@gmail.com) wrote:
>>>
>>> No problem:
>>>
>>> process = &(2^(nbits)-1);
>>>
>>> On Mon, Sep 14, 2020 at 11:30 AM Súton <doctorsu...@gmail.com> wrote:
>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Faudiostream-users mailing list
>>>> Faudiostream-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>>>>
>>>
>>>
>>> --
>>> "Anybody who knows all about nothing knows everything" -- Leonard
>>> Susskind
>>> _______________________________________________
>>> Faudiostream-users mailing list
>>> Faudiostream-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>>>
>>> _______________________________________________
>>> Faudiostream-users mailing list
>>> Faudiostream-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/faudiostream-users
>>>
>>
>>
>> --
>> "Anybody who knows all about nothing knows everything" -- Leonard Susskind
>>
>
>
> --
> "Anybody who knows all about nothing knows everything" -- Leonard Susskind
>
>

-- 
"Anybody who knows all about nothing knows everything" -- Leonard Susskind
_______________________________________________
Faudiostream-users mailing list
Faudiostream-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to