[flocking] Possible bug in flocking.

derek riemer Derek.Riemer at Colorado.EDU
Fri Mar 13 23:48:47 EDT 2015


I don't know why, but this code seems to cause browsers to hang and then 
kill the current script in the playground.
What I was trying to do is make a decent sounding tone that would be 
easy to listen to with the sym we are doing. A pure sin wave works, but 
it isn't as nice on the ears as what types of sounds we have with 
instruments. Anyway, the code is below.
Thanks,
Derek

         // A bank of oscillators added together filtered with a band 
filter.
         var harmonics = [1, 4, 5, 6, 7, 8],
             ugenTypes = ["flock.ugen.saw", "flock.ugen.saw"],
             fundamentalMultiplier = 440,
             maxFreq = flock.enviro.shared.audioSettings.rates.audio / 
4; // Highest harmonic shouldn't be more than a quarter of the Nyquist 
frequency.

         var makeHarmonic = function (ugenTypes, fundamental, harmonic, 
octave, maxAmp) {
             var freqScale = (harmonic * octave),
                 ugen = flock.choose(ugenTypes);

             return {
                 ugen: "flock.ugen.filter.biquad.bp",
                 freq:500,
                 q: 3.0,
                 source: {
                     ugen: ugen,
                     freq: fundamental * freqScale,
                     mul: maxAmp / freqScale
                 }
             };
         };

         var makeHarmonics = function (fundamental) {
             var sources = [],
                 freqs = [];

             $.each(harmonics, function (i, harmonic) {
                 var freq = fundamental,
                     octave = 1;

                 while (freq <= maxFreq) {
                     var ugenDef = makeHarmonic(ugenTypes, fundamental, 
harmonic, octave, 0.1);
                     freq = ugenDef.freq;
                     if (freq <= maxFreq && freqs.indexOf(freq) === -1) {
                         freqs.push(freq);
                         sources.push(ugenDef);
                     }
                     octave++;
                 }
             });

             return sources;
         };

         var synth = flock.synth({
             synthDef: {
                 id: "adder",
                 ugen: "flock.ugen.sum",
                 sources: makeHarmonics(fundamentalMultiplier)
             }
         });

         synth.enviro.asyncScheduler.repeat(0.5, function () {
             var fundamental = (fundamentalMultiplier * Math.random()) + 60;
             synth.input("adder.sources", makeHarmonics(fundamental));
         });

-- 
------------------------------------------------------------------------


    Derek Riemer

Department of Computer science Undergrad, proud CILA member, music 
lover, avid skier, and much more.

"Not everything that is faced can be changed, but nothing can be changed 
until it is faced." - James Baldwin

email me at derek.riemer at colorado.edu <mailto:derek.riemer at colorado.edu>
Phone: (303) 906-2194

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idrc.ocad.ca/pipermail/flocking/attachments/20150313/530f4b12/attachment.html>


More information about the flocking mailing list