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 
 Forum index » DIY Hardware and Software » ChucK programming language
Floating-point Exception Error?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 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: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Sat Nov 04, 2006 10:46 am    Post subject:  Floating-point Exception Error?
Subject description: What caused it?
Reply with quote  Mark this post and the followings unread

today i'm working on a code..
and it caused floatingpoint exception error
(make chuck quit, and miniAudicle die)

what caused that?
this is the code:

Code:
TriOsc s1 => NRev r => dac;
TriOsc s2 => r;
0.4 => r.gain;
0 => int x => int y;
while (true) {
   (x + 7) % y => int newx;
   (y + 11) % x => int newy;
   Std.mtof(x + 40) => s1.freq;
   Std.mtof(y + 40) => s2.freq;
   400 :: ms => now;
   newx => x; newy => y;
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23500
Location: The Netherlands, Enschede
Audio files: 262
G2 patch files: 320

PostPosted: Sat Nov 04, 2006 11:40 am    Post subject: Reply with quote  Mark this post and the followings unread

Probably the % x and % y operations. the % operation performs a division to calculate a remainder and initially x and y are zero. A division by zero is not allowed (undefined) and results in an exception.

It is not really nice that the software dies on that tho.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
jbum



Joined: Oct 24, 2006
Posts: 26
Location: Los Angeles

PostPosted: Sat Nov 04, 2006 11:46 am    Post subject: Reply with quote  Mark this post and the followings unread

(This was crossposted with the previous msg...)

The crashing is triggered by a division by zero in these two lines:

Code:

   (x + 7) % y => int newx;
   (y + 11) % x => int newy;


I should point out a couple of things:

1) Since x and y start at zero, newx and newy will always evaluate to zero using this code. It is quite likely that (% x) is triggering a divide by zero, due to ChucK's implementation of modulo. I tried initializinng x and y to a larger value, and it seemed to get a little further before crashing, but it still crashed, because eventually, x and y take on a value of zero.

2) The precedence of the ChucK operator (=>) seems too high to me. Invariablly, I have to put parenthesis around everything I am passing to it... e.g.

(x * y) => value

as opposed to

x * 7 => value

Here's a version that works okay, by avoiding zero...

Code:

TriOsc s1 => NRev r => dac;
TriOsc s2 => r;
0.4 => r.gain;
0 => int x => int y;
while (true) {
   if (x == 0)
   100 => x;
   if (y == 0)
   100 => y;
   ((x + 7) % y) => int newx;
   ((y + 11) % x) => int newy;
   Std.mtof(40) => s1.freq;
   Std.mtof(40) => s2.freq;
   400 :: ms => now;
   newx => x; newy => y;
}

_________________
<a href="http://www.krazydad.com/">krazydad.com</a>
Back to top
View user's profile Send private message Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Sun Nov 05, 2006 3:06 pm    Post subject: Reply with quote  Mark this post and the followings unread

ohhhhhhhhh hahhhhahahha yessss...
i forgot about that...

hooooo... hahahhaahah oh how could i forget.. ?
but i understand.. it was 4am at that time and i'm a little drunk. Embarassed
- - -

it turned out to be this..
thanks for helping.
this is one of my experiment on the melody part.

Code:
Mandolin s1 => PRCRev r;
Mandolin s2 => r;
r => dac;
s1 => pan2 p1 => dac;
s2 => pan2 p2 => dac;
-1 => p1.pan;
1 => p2.pan;

[4.0, 1, 0.5, 0.5, 2, 1, 1] @=> float rhythm1[];
0.4 :: second => dur beat;

0.1 => r.gain;
0.5 => s1.gain;
0.5 => s2.gain;
1=> r.mix;
0 => int x => int y;
int newx, newy;
int t;
while (true) {
   if (x == 0)
   25 => x;
   if (y == 0)
   13 => y;
   ((x + maybe * 3 + 2) % y) => newx;
   ((y + 7) % x) => newy;
   Std.mtof(x + 64) => s1.freq;
   Std.mtof(y + 40) => s2.freq;
   
   newx => x; newy => y;
   
   s1.pluck(1); s2.pluck(0.7);
   rhythm1[t % rhythm1.cap()] * .5 :: beat => now;
   
   t++;
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 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


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