electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
How to write a cross-fader in ChucK?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2067
Location: Berks County, PA
Audio files: 89

PostPosted: Sat Jul 21, 2018 10:49 am    Post subject: How to write a cross-fader in ChucK?
Subject description: How to write a cross-fader in ChucK?
Reply with quote  Mark this post and the followings unread

How to write a cross-fader in ChucK?

I've done this before, but I can't remember what I did. The brute force approach on the two output channels would be to drop the gain on one and increase it on the other, running code at every sample rate time interval, but that's not very efficient. Attaching some kind of ramp-down or ramp-up envelope generator to the gains would be more efficient. Suggestions or examples? Thanks.

_________________
When the stream is deep
my wild little dog frolics,
when shallow, she drinks.
Back to top
View user's profile Send private message Visit poster's website
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2067
Location: Berks County, PA
Audio files: 89

PostPosted: Sat Jul 21, 2018 11:50 am    Post subject: Reply with quote  Mark this post and the followings unread

Looks like this does the trick:

Code:

// D. Parson, 7/21/2018, rampdemo2.ck
// Crossfade two different waveforms back & forth across left/right
// in a 4-second cycle. See also:
// http://chuck.cs.princeton.edu/doc/examples/basic/envelope.ck

TriOsc tosc => Envelope etl => dac.left ;
tosc => Envelope etr => dac.right ;
SawOsc sosc => Envelope esl => dac.left ;
sosc => Envelope esr => dac.right ;

250 => tosc.freq ;
400 => sosc.freq ;

2000::ms => dur t => etl.duration ;
t => etr.duration ;
t => esl.duration ;
t => esr.duration ;

// infinite time-loop
while( true )
{
    // Ramp up tri on left & saw on right
    etl.keyOn() ;
    etr.keyOff() ;
    esl.keyOff() ;
    esr.keyOn() ;
    2000::ms => now ;
    // Ramp in the opposite direction.
    etl.keyOff() ;
    etr.keyOn() ;
    esl.keyOn() ;
    esr.keyOff() ;
    2000::ms => now ;
}

_________________
When the stream is deep
my wild little dog frolics,
when shallow, she drinks.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use