Irregular Sine Waves

For general discussion related FlowStone
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Irregular Sine Waves

Post by martinvicanek »

Spogg, your sketches look quite similar to what phase modulation does. What am I missing?
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Irregular Sine Waves

Post by tulamide »

@Spogg, @Kg

From your descriptions I recognize that you fully understood what I am thinking about. Indeed the waveform cycle (period, or under whatever name this is known) wouldn't change in length. Instead just the inner data would move according to some rules, so that only the charcteristic of the cycle is changed, but not extended, stretched or shrunk.

I will try my best to get some kind of math graph that would do this graphically. Maybe the math can be transformed into dsp code (or even asm optimized!).

Only problem is, I'm more of an artist and less of a mathematician :lol:
"There lies the dog buried" (German saying translated literally)
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: Irregular Sine Waves

Post by Spogg »

This took me all afternoon.
It ain't great but it does "the thing" and at least you can hear the effect of the wave shape change.

Do not laugh :lol:

Cheers

Spogg
Attachments
Crazy stupid sine zero crossing thing.fsm
The name says it all.
(1.15 MiB) Downloaded 939 times
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Irregular Sine Waves

Post by adamszabo »

It crashes flowstone instantly for me
BobF
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: Irregular Sine Waves

Post by BobF »

Hello gang,

Works perfect on mine, FS306.....

Spogg, I really like this but, musically the spectrum is very close to a sawtooth or narrow pulse. What do you think? Still a great idea though.
Better than anything I have come up with as yet!

Later then, BobF
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: Irregular Sine Waves

Post by Spogg »

Thank you to all who gave feedback!

@Martin

Yes this is phase or frequency modulation. The challenge was really to recreate the exact waveform range outlined by tulamide. The rate at which a wavetable is read out, or the rate at which a wave is created, will determine the skew of the wave when modulated during a single cycle. The real tricky part is defining and creating the exact variation in time of the modulation to get the desired waveshape.
Of couse, I do know that it's not so much the exact shape of the wave that will determine the sound. That would be down to the spectrum and how it changes over time and can sound the same for many different wave shapes. I believe tulamide wanted to hear the effect of his pre-defined wave-shape variation so that was my goal here.

@adamszabo

Sorry but I can't help with the crash. My thing was made with the full FS 3.08.1 so could that be an issue? I found that sometimes a schematic crashes FS when double clicking the file but if I open FS first then load it then FS will work. That's all I can offer...

@Bob

I would say the actual sound produced could be done in many different ways; it's just the harmonic variations as you alter the wave symmetry that could be specific to this technique. You may well get the same sonic impression by filtering a PWM square wave for instance, as you imply.

To all:

The schematic is the result of trying to meet a challenge and isn't very good for real musical use. It has limitations and imperfections that remind me of analogue circuitry (which is my personal background).
The variation of pitch was a big problem for me. Based on some more sketches I did there should be some maths which can define the exact law between pitch variation and symmetry, but I'm not a maths guy so I tried all sorts of functions and the best I found was 1/x for correcting the frequency.
I'm quite certain that someone here can make something far more elegant and based on proper mathematics, but it's not me!

Cheers

Spogg
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Irregular Sine Waves

Post by adamszabo »

Spogg wrote:Sorry but I can't help with the crash. My thing was made with the full FS 3.08.1 so could that be an issue? I found that sometimes a schematic crashes FS when double clicking the file but if I open FS first then load it then FS will work. That's all I can offer...


I think the problem might be that you saved the project with your audio output being active. Now if I open your schematic, my audio drivers will be different and it will want to open asio4all or something else, which might crash here and there is no way for me to stop it. Therefor all schematics should be saved with audio output disabled :)
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Irregular Sine Waves

Post by tulamide »

@adam
Yes, it is saved with DS Out being active. Also, there's a Ruby error, because a RubyEdit gets initialized after values arrive. I'll wait if Spogg re-uploads, else I'll upload a version with audio off.

@Spogg

Thank you!That is exactly what I was hoping for. It is a bit unstable and not completely smooth on the transitions, but for a first try it is good enough to hear the sound changes. Now imagine this modulated and played with multiple oscillators. Oh man, I need to find a formula!
"There lies the dog buried" (German saying translated literally)
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: Irregular Sine Waves

Post by Spogg »

Hey sorry guys!

I simply didn't know about that rule!

Here it is again with the audio out not selected...

Cheers

Spogg
Attachments
Crazy stupid sine zero crossing thing.fsm
Audio out not selected on this one!
(1.15 MiB) Downloaded 927 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Irregular Sine Waves

Post by tulamide »

I asked in another forum, that is about game making. The people there are very open and helpful, and I know a lot of graphic artists, but also quite some musicians are reading there. I asked for a formula or a way to get to a formula. This is the response that I think has the best chance to get translated into dsp/asm (to generate an algorithmic oscillator), and I post it in full, hoping we will get this going together:

Well you can't build the function you're talking about out of sin/cos, because by definition both are even/odd functions with a special relationship to geometry, while your function would be asymmetrical and has no real physical significance. This kind of hints any attempt at building them from a sum/series of sin/cos harmonics (a Fourier series) would require A LOT of harmonics to approximate the shape, and to begin with you'd need a way to define your function.

What I would suggest is to build a function with cubic splines. I don't really have time to work out the math but it's not difficult.

Basically set it up so that you define the points (-1,0),(m,0),(1,0) which are the "left","center","right" of the wave (all the points where it crosses the X axis). m is a parameter you control to set where the "middle" will be where m is somewhere in the interval (-1,1), with m=0 giving something akin to a sine wave, and any values different than 0 shifting the point left or right. Then you set up your function S(x) as a piece-wise function

S(x):

if(x<m) S0(x)=a0+b0(x)+c0(x)^2+d0(x)^3
if(x>=m) S1(x)=a1+b1(x-m)+c1(x-m)^2+d1(x-m)^3

then you'd need to solve for all 8 parameters a0,a1,b0,b1,c0,c1,d0,d1

you'd do this by adding constraints onto S(x), like the following to get 8 equations in 8 unknowns (note the ' and '' indicate 1st and 2nd derivatives)

S(-1)=0
S(m)=0
S(1)=0
S0(m)=S1(m)
S0'(m)=S1'(m)
S0''(m)=S1''(m)

with additional constraints to ensure the function is smooth when it's periodic
S0'(-1)=S1'(1)

S0''(-1)=S1''(1)

you could also just set S0'(-1)=S1'(1)=K instead of the condition i wrote last, allowing you to explicitly set the slope to K at the endpoints.

OR

maybe if you want to mimic sine waves you could set S0'(m)=S1'(m)=-S0'(-1), but this could be weird. Generally playing with the periodic constraints will help you control things nicely.

Note that you need to give the function x values in the range [-1,1], or else you'll get weird output since this is basically just cubic polynomials that are infinitely increasing or decreasing past a range. So if you want to pass in a value that behaves periodically you have to remap it periodically to the [-1,1] range, similar to how an angle like 720 deg.=360 deg.=0 deg. That part should be easy to figure out.

Obviously you'll need to work out all the math to efficiently set all the 8 parameters for the function based on any given m.

This is the best idea I have to offer, I've never seen any function like the one you want, and this one wont perfectly reconstruct a sine wave for m=0, but it'll be something close and fast to evaluate, as-well as offers the capability to control the derivatives with additional parameters.

To be honest i have no idea what it'll sound like so if you work it out i'd be interested to hear :) I assume it'll just start to exemplify strange harmonics as you shift the center, since this is what it'll be doing to the Fourier series
"There lies the dog buried" (German saying translated literally)
Post Reply