electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks GalleryGallery 
 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
Implementing mass + spring + stiffness in ChucK
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
kijjaz



Joined: Sep 20, 2004
Posts: 409
Location: bangkok, thailand
Audio files: 2

PostPosted: Sat Mar 08, 2008 11:26 am    Post subject: Implementing mass + spring + stiffness in ChucK
Subject description: a test project again!
Reply with quote  Mark this post and the followings unread

I'm having fun imagining things up again hehehe..
so this time i'm gonna simulate a model of masses and springs found in many physical modelling theories.
(but I didn't follow the standard rules -_-')

anyway, i haven't implement "spring K" yet,
so now, the way to adjust is to change the mass of each node.

I still haven't implemented lots of things,
but now it's becoming more easy-to-use..
(although i make it feedback as hell sometimes, i'll learn how to control it more)

here's the code testing that each node works..
and energy transfer from node to node seems to work well (although i'm not sure it's a logical way in physics.. ok, whatever,
let's hear it out first..)


kijjaz-SpringMassGains-0.1-testing.ck
 Description:
mass-spring simulation 0.1 testing

Download
 Filename:  kijjaz-SpringMassGains-0.1-testing.ck
 Filesize:  2.59 KB
 Downloaded:  20 Time(s)

Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 409
Location: bangkok, thailand
Audio files: 2

PostPosted: Sat Mar 08, 2008 11:50 am    Post subject: Reply with quote  Mark this post and the followings unread

i've changed the energy transfer model.
warning: this example does blow up sometimes!


kijjaz-SpringMassGains-0.2-testing.ck
 Description:
mass-spring simulation

Download
 Filename:  kijjaz-SpringMassGains-0.2-testing.ck
 Filesize:  2.6 KB
 Downloaded:  11 Time(s)

Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 409
Location: bangkok, thailand
Audio files: 2

PostPosted: Sat Mar 08, 2008 12:11 pm    Post subject: Reply with quote  Mark this post and the followings unread

This one succeeded in a bell-like sound creation.


kijjaz-SpringMassGains-0.2-testing02.ck
 Description:
mass-spring simulation

Download
 Filename:  kijjaz-SpringMassGains-0.2-testing02.ck
 Filesize:  2.64 KB
 Downloaded:  19 Time(s)

Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 409
Location: bangkok, thailand
Audio files: 2

PostPosted: Sun Mar 09, 2008 10:53 am    Post subject: Reply with quote  Mark this post and the followings unread

Just to update more:
I've been improving and trying to make an interesting control code..
but I usually get a lot of feedback going on..
today, I've got many takes that is feedbacking a lot all the time,
so I feed the signal into a limiter then an overdrive (that also do the limiting)
after that, I reverse the sound, and it happens to be quite enjoyable.

You can visit www.myspace.com/kijjaz to have a listen. the name of the track is What Vibraphone.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 409
Location: bangkok, thailand
Audio files: 2

PostPosted: Thu Mar 27, 2008 8:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

I have just extracted the main model of the oscillation from the above model.
and try to test if it can play with musical frequencies.
now this model has worked well enough.
before really releasing, I decided to share the code with you all to test out.

This is from my attempt to create a sine wave oscillator without any help from chuck's basic oscillator.
this is mainly from Step (for setting constant parameters) and Gains (for sustaining / transfering of values)

Code:
// kijjaz's mass-spring oscillator model version 0.1 testing

// note: from the original idea of Gain p=>p; Gain v=>v; v=>p; Gain a=>v; idea

/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Impulse p_kick => Gain p => Gain p_smoothness => p; // a particle stays at the same position
Impulse v_kick => Gain v => Gain v_smoothness => v; // and has a steady velocity
v => Gain v_mult => p; // a particle move with velocity
// (for musical reason)
Gain a => Gain a_mult => v; // the velocity changes with accelleration
Step m; // mass of the particle
1 => m.next;
Step resolution; // simulation resolution (default = sample rate)
second / samp => resolution.next;
samp / second => v_kick.gain;


// calculate a = -p/(m x resolution)
p => a;
m => a;
resolution => a;
a.op(4);
a.gain(-1);

// - - - test code
p => Dyno master => dac; // use p as the oscillator
master.gain(1); // set master gain and limit the output
master.limit();
master.thresh(.9);
master.ratio(10000);

1 => m.next; // reset mass to 1 as default
1.0 - 1.0/8000 => v_smoothness.gain; // decay of sound

for(int i; i < 24 + 1; i++)
{
    Math.pow(Std.mtof(i), 2) => v_mult.gain; // setting actual freq by pow with 2
    v_kick.next(2); // kick the velocity
    .5::second => now;
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Inventor



Joined: Oct 13, 2007
Posts: 828
Location: Florida, USA
Audio files: 37

PostPosted: Fri Mar 28, 2008 10:25 am    Post subject: Reply with quote  Mark this post and the followings unread

I don't follow what you're doing there, kij, but it sure sounds good to me!
_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor



Joined: Oct 13, 2007
Posts: 828
Location: Florida, USA
Audio files: 37

PostPosted: Fri Mar 28, 2008 8:14 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yes, I follow your code better now that I have had a chance to study it, kijjaz. It helped me to realize that I can do the same thing with a neural net. The weights are gains, and the activation functions are dyno limiters. A feedforward neural net is straightforward to construct this way and would execute quickly in ChucK. I will have to code this up...
_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 409
Location: bangkok, thailand
Audio files: 2

PostPosted: Sun Mar 30, 2008 6:18 am    Post subject: Reply with quote  Mark this post and the followings unread

Wow thanks Inventor.
I'll try to expand the code more.
It'd become a handy experimental tool i hope.
(and so great it's CPU-efficient)

connecting this kind of unit would already produce FM and PM from sine wave already.

I still can't figure out how to make it vibrate at a specified frequency.
Who can tell me how? hahhhahha
I need to go back and read about simple harmonic and calculus from highschool -_-"
those would help me out.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Frostburn



Joined: Dec 12, 2007
Posts: 166
Location: Finland
Audio files: 5

PostPosted: Sun Mar 30, 2008 8:44 am    Post subject: Reply with quote  Mark this post and the followings unread

Have you read the Wikipedia article ?
I think it covers most of it.

Of course when we're dealing with sampling rates some corrections need to be made on high frequencies but that depends on the implementation of the differential equation in question.

ChucK's BiQuad with a resonance is actually a model for a stiff spring with a mass and it makes that correction with sampling rates automatically.

_________________
In Serendipity We Trust
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 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 » 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
Buy N Save

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, 2004, 2005, 2006 and 2007 by electro-music.com