hey Casper thanks! I think the issue may also be in the statement

if (i%iMax > jCount ) 0.0 =>s.gain;

which is not the same as 

if (now%iMax > jCount ) 0.0 =>s.gain;

because I don't think "now" increments at the same rate as i (I wonder if now increments one sample at a time, rather than .1 ms at a time, then they become equivalent, thus your fix.). Anyway, not sure--haveto try this at home.

Cheers,

Charlie

On Thu, Jan 31, 2019 at 12:00 PM <chuck-users-request@lists.cs.princeton.edu> wrote:
Send chuck-users mailing list submissions to
        chuck-users@lists.cs.princeton.edu

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
or, via email, send a message with subject or body 'help' to
        chuck-users-request@lists.cs.princeton.edu

You can reach the person managing the list at
        chuck-users-owner@lists.cs.princeton.edu

When replying, please edit your Subject line so it is more specific
than "Re: Contents of chuck-users digest..."
Today's Topics:

   1. Re: two similar shreds with different results (Casper Schipper)



---------- Forwarded message ----------
From: Casper Schipper <casper.schipper@gmail.com>
To: ChucK Users Mailing List <chuck-users@lists.cs.princeton.edu>
Cc: 
Bcc: 
Date: Thu, 31 Jan 2019 09:31:01 +0100
Subject: Re: [chuck-users] two similar shreds with different results
Hi Charlie,

I think I found it: .1::ms is not the same as 1::samp
You do in both scripts .1 ::ms => now, but in the second variant, this means now will have increased by 4.1 samples, instead of 1 unit (depending on your samplerate).
I could get the same sound from both scripts by changing .1::ms => now to samp => now;

Best,
Casper

On 27 Jan 2019, at 14:58, Charlie <taos.points@gmail.com> wrote:

Hey folks, I'm puzzled why these two shreds don't make the same sound. I created a simple bit crusher using an integer as an index and then using time as an index; I thought these were equivalent but they aren't. I wonder if this is because the integer increments at a  different rate than the sampling rate? Any guidance on this gratefully received! Thanks,

Charlie 

First shred:
//---------------------------------------------

SinOsc s => dac;

110 => s.freq;

0 => int i;
250 => int iMax;
0 => int jCount;

while (true) {
i++;

// if (i%130 == 0 || i%201 ==0 || i% 737 == 0) 0 =>s.gain;
    if (i%iMax > jCount ) 0.0 =>s.gain;
jCount++;
if (jCount > iMax) 0 => jCount;
// 1::samp => now;
    .1::ms => now;
1 => s.gain;

}

//---------------------------------------------

second shred:

//---------------------------------------------

SinOsc s => dac;

110 => s.freq;

0::samp => dur jMin;
250::samp => dur iMax;
0::samp => dur jCount;
1::samp => dur jDelta;

while (true) {

if (now%iMax > jCount ) 0.0 =>s.gain;
jCount+jDelta => jCount;
if (jCount > iMax) jMin => jCount;
.1::ms => now;
1 => s.gain;

}


//---------------------------------------------


_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users