electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
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
Shepard Tones
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jbum



Joined: Oct 24, 2006
Posts: 26
Location: Los Angeles

PostPosted: Wed Nov 01, 2006 3:24 pm    Post subject: Shepard Tones
Subject description: Example code for the barberpole effect.
Reply with quote  Mark this post and the followings unread

If you haven't heard shepard tones before, try this out. Fun little audio illusion of a never-ending portamento.

Code:


// Shepard Tones (or barberpole illusion)
// - Jim Bumgardner

10 => int numSheps;            // number of oscillators
20 => float sweepSeconds;      // seconds for each sweep
20 => float baseFreq;          // base frequency
7  => float shepOctaves;       // octaves travelled
20 => float controlFrequency;  // How often we change frequency per second
30 => float durationOfPiece;   // Duration of entire piece in seconds...
1  => int descend;             // Descending or Ascending?

fun void shepSteps(float offset)
{
   float amp;
   SinOsc s => dac;
   now+offset::second => time start;
   do
   {
     // ts = elapsed time in seconds since start of barberpole
     (now-start)/(1::second) => float ts;
     (ts - sweepSeconds*Math.floor(ts / sweepSeconds)) => ts;

      // Use to assign frequency & gain
      Math.sin(ts*pi/sweepSeconds)/numSheps => s.gain;
     if (descend)
       baseFreq*Math.pow(2,shepOctaves*(1-ts/sweepSeconds)) => s.freq;
     else
       baseFreq*Math.pow(2,shepOctaves*ts/sweepSeconds) => s.freq;
   } while ((1.0/controlFrequency)::second=>now);
}

for (0 => int i; i < numSheps; ++i)
{
  spork ~ shepSteps(i*sweepSeconds/numSheps);
}

durationOfPiece::second=>now;

_________________
<a href="http://www.krazydad.com/">krazydad.com</a>
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 [1 Post]
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