[chuck-users] Audio Range and Zero-crossings, Performance, Hashes and Future DIrections
vtatila at mail.student.oulu.fi
Sun Mar 4 08:30:37 EST 2007
I'm new here. I'm a 20 something sight-impaired programmer and musician from
Finland. I've got experience using analogs both virtual and real and know
how to build Reaktor patches as well as program in Java, Perl and C. Now
I've picked up the basics of ChucK and read through the PDF manual that
comes with the program. Looks good and certainly a great deal more
accessible than recent versions of Reaktor if you're using magnification and
a screen reader program. I've got a flurry of questions I'll ask here.
ChucK says it is:
chuck version: 22.214.171.124b (dracula)
exe target: microsoft win32
1. What's the range of the audio float datatype and what would be the best
way to detect zero crossings? My aim is to write a simple app that counts
the samples in the low and high phases of a pulse wave and prints out the
pulse width whenever it changes. If I can also get MIDi input into the app
it would be quite easy to determine how pulse width in percentages changes
as the function of the pulse width knob in my virtual and real analogs,
whose exact values are not documented.
Here's some prototypical code (this is my first real chucK script):
100::ms => dur blockSize; // Processing resolution.
until(adc.last() < 0) // Measure low-phase first.
blockSize => now;
// SAmple counters:
0 => int positive;
0 => int negative;
adc.last() => float sample;
if(sample > 0)
else if(sample < 0)
if(positive > 0) // Measured at least one cycle.
<<< "Width: ", 100 * negative / (negative + positive) >>>;
0 => positive => negative; // Reset counters.
} // else if
// Ignore the pure 0 value.
blockSize => now;
} // while
However, when I run this, the app doesn't ever seem to get past the until
loop. I'm assuming here that samples are floats or doubles from -1 to 1 as
in VST, as I didn't find the range in the manual. Is this correct? IF not,
it's no wonder the code won't work, <smile>. Of course the rather grainy
test processing rate, ten times a sec, affects matters greatly but I don't
ever seem to get negative sample values even in arbitrary audio. The adc and
dac modules do work. IF I patch them together and record from the wave input
I get a delayed copy of the input in the output I guess this is the audio
equivalent of "cat".
2. Why is it that ChucK locks up when I try to process things at the rate of
1::samp? This is what I'd use in the working code but when I try that CPU
usage peaks and I have a hard time killing ChucK. Might ChucK be polling som
system wide keyboard hooks or something. I'm using a screen reader which I
run together with ChucK. I do know it has blocking hooks deep in the OS both
in keyboard handling and graphics i.e. GDI or DirectDraw. The OS is XP Pro
SP2 English and this laptop is an HP NX8220. The reader and magnifier is
Dolphin Supernova 7.03 beta 7.
3. Is there any way to decrease the latency on WIndows platforms for true
realtime MIDI playback and audio processing similar to Reaktor? DirectSound
latency is pretty bad as my audio machine, which isn't this laptop, would
have both WDM kernel streaming and ASIO support in it.
4. How does one use the ZeroX module for detecting zero crossings? What's
the value range and what is the output method of that module called i.e.
which thing should I poll to detect the crossings?
The manual says:
Emits a single pulse at the the zero crossing in the direction of the zero
That path is slightly outdated, by the way. I found the example in:
The example uses the module patchd in the DAC directly, so I never see the
values it produces in processing.
5. Continuing with modules I've discovered that there are the low level
programming constructs, a few basic ugens and then fancy entities that would
be instruments in Reaktor speak and remind me of Korg's physical modelling.
Are additional basic modules going to be added in the future? Ideally, I'd
like, in addition to implementing the constructions as program code, use
ChucK as a more conventional modular synthesizer. Reaktor has got very very
generic modules in it stuff like digital gates and sequential circuits,
multiplexing and demultiplexing, comparators, waveshaping, variable delays,
lookup tables, step sequencers and so on. YOu get the picture. While it is
true that many of these things can be simulated easily and even more
flexibly in program code, that doesn't feel like programming a modular
synth, if you know what I mean. But then again, that might not be the aim of
ChucK. Maybe I could use ChucK itself to model some of those, if that's
possible, inheriting from a ugen that is. Is there example code for
something like that, whose primary focus is not the audio processing itself
as it often is in DSP? I'm not actually much good in higher math.
6. How do you use the array datatype in ChucK as a hash? I read that you can
index the array with strings much like a Perl hash, except that numbres and
strings are totally separate. If I get handed a hashtable whose keys I don't
know beforehand, is there a keys or each function for iterating through the
hash's keyset? Is the hash portion of the array unordered as one might
expect in an implementation e.g. an array of pointers to linked-lists?
Thanks for any help in advance.
And sorry about these complaints, I just thought ChucK would have been a
more complete piece of software than it currently is. Well, it has developed
loads since I read the manual last time and decidedd back then it isn't
quite ready yet, however. Now it is complete enough that I could imagine
using it as a Reaktor and VSt plug substitute for some things. Another bonus
is that it is available for LInux, so one of my friends whose into Linux and
music could use it, too. i've already hyped the prog. I'm much more
comfortable handling memory and doing processing in ChucK or Java than I am
in C++, for instance.
With kind regards Veli-Pekka Tätilä (vtatila at mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
More information about the chuck-users