<br><br><div class="gmail_quote">2008/5/18 Atte André Jensen <<a href="mailto:atte.jensen@gmail.com">atte.jensen@gmail.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi<br>
</blockquote><div><br>Hey, Atte!<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
I'd like to resample a 44100 signal to something like 10K *and* hear the alias noise. Also I'd like to resample to lower bitdepth, something like 8 or 6 bit.<br>
</blockquote><div><br>Cool, me too. Morning coffee is a bit late today but it's a Sunday and there's a nice ChucK puzzle to go with it. Oh, and it's nice coffee :¬)<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
1) How it that most efficiently done with chuck?<br>
</blockquote><div><br>Well, quantising in time (sample rate) is without any doubt done most easily by writing the .last() of some signal to the .next of a Step at the required period. <br><br>Quantising in amplitude (bit depth) means rounding. I think my proposal below might be quite efficient but I'm not 100% sure there. It does work fine though and Std has several other rounding schemes you may wish to try for CPU performance and/or sound quality.<br>
<br>Here you go; This example should be quite clear and suitable for extending for your own purposes, I think, but if I'm wrong please do shout.<br>=============================<br>//replace with more interesting signal.<br>
SinOsc my_signal => blackhole;<br><br>Step resampled => dac;<br><br>resample();<br>//remove shred to quit....<br><br><br>fun void resample()<br> {<br> //8 KHz<br> ms / 8 => dur re_samp_rate;<br> <br> //set bits here<br>
8 => int bits;<br> <br> //calculate the maximum integer value of the signal's amplitude at this bitdepth<br> Math.pow(2, bits) * .5 => float scale;<br> //division is expensive and we only need to do it once<br>
1/scale => float downscale;<br> <br> while(true)<br> {<br> //digital clipping<br> if (my_signal.last() > 1) 1 => resampled.next;<br> else if (my_signal.last() < -1) -1 => resampled.next;<br>
<br> else<br> {<br> //cast to int for cheep&cheerful rounding<br> //then multiply back into the range<br> //write result to output<br> downscale * ( (my_signal.last() * scale) $ int) => resampled.next;<br>
<br> }<br> <br> //samplerate is implicid in controll-rate<br> re_samp_rate => now;<br> }<br> }<br>===================<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
2) I event thought it might be possible for me to implement this as a real UGen. My plan would be to start from one of the simple UGens (gain), and expand/modify from there, but before even looking into the chuck source, is there any documentation about doing this? Should I expect this to be more effective in implenenting in chuck-code, and if so about how much? Also. supposed I actually succed in making something that works, could it be included in future chuck-releases?<br>
</blockquote><div><br>Me too!<br><br>I'd also like the following to work but it seems like I can extend Step but the result will -for some strange reason- not be a Ugen. I'm not the greatest OOP wizard but I really feel that if I extend Ugen the result should be a Ugen as well. Right now we can extend it but not actually do anything with the result.<br>
<br>========================<br>//example code, doesn't actually work<br><br>//this is the offending line<br>LowRezNoise n => dac;<br><br>minute => now;<br><br><br>class LowRezNoise extends Step<br> {<br> <br>
ms => dur rate;<br> <br> spork ~ fakeTick();<br> <br> fun void freq( float input)<br> {<br> second / input => rate;<br> }<br> <br> fun void fakeTick()<br> {<br> <br>
while(1)<br> {<br> Std.rand2f(-1,1) => this.next;<br> <br> rate => now;<br> }<br> }<br> <br> }<br>====================<br></div></div><br>Hope that helps?<br>
<br>Yours,<br>Kas.<br>