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 
Live streaming at radio.electro-music.com

  host / artist show at your time
  EdisonRex Edison's Electronic Review
Please visit the chat
 Forum index » DIY Hardware and Software » Supercollider
Using VOsc to simulate bandlimited wavetable synthesis
Post new topic   Reply to topic Moderators: v-un-v
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
dewdrop_world



Joined: Aug 28, 2006
Posts: 858
Location: Guangzhou, China
Audio files: 4

PostPosted: Mon Jun 02, 2008 11:12 am    Post subject: Using VOsc to simulate bandlimited wavetable synthesis
Subject description: Useful technique to save cpu
Reply with quote  Mark this post and the followings unread

The trouble with wavetable synthesis is that if the wavetable's spectrum is very rich (lots of harmonics), the fundamental frequency must be kept low enough to avoid aliasing. The highest fundamental frequency that will not produce aliasing is the Nyquist frequency divided by the highest partial number. If the wavetable contains 50 partials, an oscillator using that table should not go above 22050 / 50 = 441 or approximately A above middle C. That's a rather small range to be useful.

Alternately, the wavetable could be constructed with a lower number of partials, but that means low-frequency notes would have a dull sound.

What I do instead is build a series of wavetables, each with progressively fewer partials. Then, I map the fundamental on to the appropriate buffer. VOsc interpolates automatically between adjacent buffers so the sound transitions smoothly over several octaves' range.

This function populates the wavetables. Each buffer has half the partials of the preceding buffer, so that one octave maps onto one buffer.

Code:
f = { |numbufs, server, numFrames, lowFreq, spectrumFunc|
   numbufs = numbufs ? 8;
   server = server ? Server.default;
   numFrames = numFrames ? 2048;
      // default is sawtooth
   spectrumFunc = spectrumFunc ? { |numharm| (1..numharm).reciprocal };
   lowFreq = lowFreq ? 131;
   
   Buffer.allocConsecutive(numbufs, server, numFrames, 1, { |buf, i|
      var   numharm = (server.sampleRate * 0.5 / lowFreq).asInteger;
      lowFreq = lowFreq * 2;
      buf.sine1Msg(spectrumFunc.(numharm));
   });
};

b = f.value(8, s, 2048);


Then, the synthdef can use base-two logarithms to determine the right buffer for the frequency. The frequency here sweeps over some five octaves while the perceived spectrum remains a more or less consistent sawtooth.

Code:
a = {
   var   freq = LinExp.kr(SinOsc.kr(0.25), -1.0, 1.0, 50, 2000),
      basefreq = 131,   // base frequency of first buffer
      numOctaves = 7,
      numbufs = 8,
         // note that subtraction of logs corresponds to division of original values
      freqmap = ((log2(freq) - log2(basefreq)) * (numbufs / numOctaves))
         .clip(0, numbufs - 1.001),
      bufbase = b.first.bufnum;
   
   VOsc.ar(bufbase + freqmap, freq, mul: 0.1) ! 2
}.play;

a.free;


VOsc3 takes three frequency inputs, allowing easy detuning for fatter sounds.

Code:
a = {
   var   freq = LinExp.kr(SinOsc.kr(0.25), -1.0, 1.0, 50, 2000),
      basefreq = 131,   // base frequency of first buffer
      numOctaves = 7,
      numbufs = 8,
         // note that subtraction of logs corresponds to division of original values
      freqmap = ((log2(freq) - log2(basefreq)) * (numbufs / numOctaves))
         .clip(0, numbufs - 1.001),
      bufbase = b.first.bufnum;
   
   VOsc3.ar(bufbase + freqmap, freq, freq * 0.997, freq * 1.003, mul: 0.1) ! 2
}.play;

a.free;


Compare this with Saw.ar, which admittedly is less code, but it takes about 50% more CPU (about 1.5% on my macbook pro vs 1% for the VOsc3 example). If you are playing thick chords, the CPU savings of wavetable synthesis becomes really noticeable and leaves you processing power left over for effect processing to get even more richness.

Code:
a = {
   var   freq = LinExp.kr(SinOsc.kr(0.25), -1.0, 1.0, 50, 2000);
   
   (Mix(Saw.ar(freq * [1, 0.997, 1.003])) * 0.1) ! 2;
}.play;

a.free;

// clean up buffers when done
b.free;

_________________
ddw online: http://www.dewdrop-world.net
sc3 online: http://supercollider.sourceforge.net
Back to top
View user's profile Send private message Visit poster's website AIM Address
Maks



Joined: Jan 14, 2009
Posts: 8
Location: United States
Audio files: 1

PostPosted: Wed Jan 14, 2009 3:46 am    Post subject: Reply with quote  Mark this post and the followings unread

thanks for this
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: v-un-v
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 » Supercollider
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
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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