| Author |
Message |
vze26m98

Joined: Jun 12, 2011 Posts: 6 Location: GWB
|
Posted: Sun Jun 12, 2011 1:52 pm Post subject:
Writing Single Samples to the DAC |
 |
|
Hi all-
A newbie question, but I don't think I've found an answer or example code.
The thread on distortion was very interesting:
http://electro-music.com/forum/topic-19287.html
but it seems that it writes samples to the DAC in a way that doesn't break free of a "vector-consciousness" if I could put it in so free a way.
What I'd like to do is something like this:
| Code: | do {
Float 0.75 => dac;
0.125::second => now;
} while (true);
|
which would write a single sample of value 0.75 to the DAC every 1/8 second.
Is this at all possible with ChucK? Or do I have to do something like Kijjaz' examples where I interpose a "sample-level" function between a Ugen and the DAC?
Best wishes, Charles |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3371 Location: Sweden
Audio files: 211
G2 patch files: 92
|
Posted: Mon Jun 13, 2011 12:27 am Post subject:
|
 |
|
it would be interesting to know more about what you're aiming at (I admit I've only skimmed the distortion thread) - what do you want to output the other 44096 samples per second?
You can't override the dac and set an absolute value at specific times, but you can route stuff through a Step ugen:
Warning: nasty sound - don't listen to this with headphones
| Code: |
Step s => dac;
0::second => dur t;
do {
if (t >= 0.125::second) {
0::second => t;
0.75 => s.next;
} else {
// do what you want to do when not outputting 0.75
0 => s.next;
}
1::samp => now;
} while (true);
|
In this example I set the output to 0.75 for the duration of one sample (1::samp, which is often 1/44100 second), ane zero otherwise. If you want to take the output from some other ugen, you can route that to blackhole and take samples from it using last():
| Code: | Step s => dac;
SinOsc sinOsc => blackhole;
0::second => dur t;
do {
if (t >= 0.125::second) {
0::second => t;
0.75 => s.next;
} else {
sinOsc.last() => s.next;
}
1::samp => now;
} while (true);
|
/Stefan _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music Last edited by Antimon on Mon Jun 13, 2011 12:32 am; edited 1 time in total |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3371 Location: Sweden
Audio files: 211
G2 patch files: 92
|
Posted: Mon Jun 13, 2011 12:31 am Post subject:
|
 |
|
Note that especially the first example will output a nasty spiky sound that you shouldn't listen to with headphones... _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music |
|
|
Back to top
|
|
 |
vze26m98

Joined: Jun 12, 2011 Posts: 6 Location: GWB
|
Posted: Mon Jun 13, 2011 3:42 am Post subject:
|
 |
|
Hi Stephan-
Thanks for your interest in my question, which really wasn't well put.
At its most general, I guess I'm trying to figure out how to write my own Ugens in ChucK, as opposed to C++. I saw this post, but so far haven't been able to acertain whether progress has been made since 2007:
http://electro-music.com/forum/topic-20269.html
My interest is ChucK stems not so much from its livecoding features, but the ability to write at the sample level, and not be encumbered by a callback and a view of the world that's not immediately bigger than a vector of audio.
Your example code is very helpful, and I'll have some fun studying it.
Best wishes, Charles |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3371 Location: Sweden
Audio files: 211
G2 patch files: 92
|
Posted: Mon Jun 13, 2011 4:08 am Post subject:
|
 |
|
Ah, I had a feeling I didn't quite understand what you were aiming at.
Anyway, I have used Step succesfully for setting output "by hand", though rather than generating audio I've used it for setting control voltages on my MOTU audio interface outputs. I think it ought to be the preferred UGen for making real-time calculated audio too though, unless you're making heavier processing of audio like convolutions or other stuff, in which case you could probably make good use of LiSa (live sampler) with a short sample buffer.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music |
|
|
Back to top
|
|
 |
vze26m98

Joined: Jun 12, 2011 Posts: 6 Location: GWB
|
Posted: Mon Jun 13, 2011 5:31 am Post subject:
|
 |
|
Hi Stephan-
Appears this code doesn't actually produce sound:
| Code: | Step s => dac;
0::second => dur t;
do {
if (t >= 0.125::second) {
0::second => t;
0.75 => s.next;
} else {
// do what you want to do when not outputting 0.75
0 => s.next;
}
1::samp => now;
} while (true);
|
It looks like the duration "t" isn't being updated for some reason.
Also, I wonder why you don't/couldn't use Impulse for some of this work?
Best, Charles |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3371 Location: Sweden
Audio files: 211
G2 patch files: 92
|
Posted: Mon Jun 13, 2011 5:50 am Post subject:
|
 |
|
Oops! Sorry. I was going to mention that I couldn't actually run these live, since the sound interface here doesn't work. :oops: I checked them with chuck --silent. My excuse is that I'm leaving the final bug fixes as an exercise to the reader. ;)
t isn't updated because I forgot to add to it, try this:
| Code: |
Step s => dac;
0::second => dur t;
do {
if (t >= 0.125::second) {
0::second => t;
0.75 => s.next;
} else {
// do what you want to do when not outputting 0.75
0 => s.next;
}
1::samp => now;
t + 1::samp => t;
} while (true);
|
I've never tried Impulse, but you're right - for this example it would make sense (after reading the docs). I think Impulse is mainly usable for incidental triggering effects rather than waveshaping. _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music |
|
|
Back to top
|
|
 |
|