# Re: [sc-users] Fourier sync problem

```hi, here is the rewrite:

// Fourier Synthesis: square
(
f = { arg freq = 330;
var size = 14;			// try different sizes of the sine stack
var a = Array.series(size, 1, 2).postln; // a list with the odd numbers

a.collect({|it, i|
SinOsc.ar(freq * it, 0, 1/it);
}).sum // mix
/ size // loudness scale
}
)

x = f.play;
x.set(\freq, exprand(100, 5000));
x.free; x= f.scope;
f.freqscope(1);
f.plot(5/440)

bests, H

On 16-Dec-2014, at 7:16 AM, user_weego wrote:

> If I was at a real computer I coult test it and try to rewrite the code to be a bit more concise.
>   Since I hardly believe that 4 sines dont synch, i'd suspect that you are executing the synth 3 times, _almost_ at once. See inline comments below
>
> On Dec 7, 2014, at 19:30, vdkunz@xxxxxxxxxxxx wrote:
>
>>
>> Dear All,
>>
>> The following code snippet does not synchronise and result in a "near" square wave with overshoots:
>>
>> // Fourier Synthesis: square
>> (
>> var a, b, c, d, e, f, freq;
>> freq = 440;
>> a = {SinOsc.ar(freq: freq, phase: 0, mul: 1)};
>> b = {SinOsc.ar(freq: (freq*3), phase: 0, mul: (1/3))};
>> c = {SinOsc.ar(freq: (freq*5), phase: 0, mul: (1/5))};
>> d = {SinOsc.ar(freq: (freq*7), phase: 0, mul: (1/7))};
>> e = {SinOsc.ar(freq: (freq*9), phase: 0, mul: (1/9))};
>> f = {4/pi*(a + b + c + d + e) * 0.5};
> // why the signal * 4/pi*0.5? That is ca. 6.28 x louder than normal.
>> f.play;
>> f.freqscope.scope(1);
>> f.scope(1);
> // These 3; only one shd be executed at a time.
>> )
>>
>> Anyone knows why and how to solve it? For the purpose of demonstration I would hold on to the concept of adding sine waves.
>>
>> I also found that, if I do not multiply the f variable by 0.5, I get quite some distortion.
>>
>> Furthermore, what could be done to trigger the scope to show one to five cycles?
> .plot(5/440) instead of .scope should do that.
>>
>> Dominik
>
> Hth,
> Hannes

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/

```