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
How can I set the buf.pos as a float? - Please help
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
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Tue Mar 06, 2007 11:01 am    Post subject: How can I set the buf.pos as a float? - Please help Reply with quote  Mark this post and the followings unread

I looking to change the buffer position as I'm playing back certain parts of a wav file. However, I cant seem to find a way to adjust the buffer's position buf.pos to represent a float.

There must be a way of doing this as it seems a little backwards otherwise?

Thanks

Rhys
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Mar 06, 2007 1:01 pm    Post subject: Reply with quote  Mark this post and the followings unread

Well;

buf.pos() should return the current position in samples (as a int since we don't have partial samples; interpolation not withstanding.

buf.samples() should return the length in samples (same deal but it's more obvious that it will be a int).

Deviding the length by the current position should get you a number between 0 and 1 that will already be a float. If you are going the opposite direction you need to remember to cast to int or ChucK will complain (because there are no partial samples, again).

This actually isn't backwards at all, it's just a perspective and a very usefull one at that.

Does that help?

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Wed Mar 07, 2007 9:25 am    Post subject: Reply with quote  Mark this post and the followings unread

If I'm being honest I'm still not understanding this procedure.

I can have all the accuracy of a float until I come to relate it to buf.pos as understandably Chuck doesnt interpolate between samples making .5 of a sample a non existant thing.

So how would I round up to the nearest sample when >.5 and down to the nearest sample when <.5? Therefore making it an int that buf.pos would understand?

Or is there a much simpler way to read from different parts of the buffer and I'm making this a bit convoluted?

Thanks

Rhys
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Mar 07, 2007 1:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

Dr. Spankenstein wrote:
If I'm being honest I'm still not understanding this procedure.


No problem, we'll get there.


Quote:
I can have all the accuracy of a float until I come to relate it to buf.pos as understandably Chuck doesnt interpolate between samples making .5 of a sample a non existant thing.


Right, exactly.


Quote:
So how would I round up to the nearest sample when >.5 and down to the nearest sample when <.5? Therefore making it an int that buf.pos would understand?


You can simply cast to int which will round it for you as it goes;

153.421 $ int => myugen.parameter;

(here the dollar is pronounced as "cast to")

If you realy need that much controll over rounding the standard library has more speciffic ways of rounding in it's math functions. If those won't do you could even perform a modulus 1 on your float, then base conclusions on the remainder. At that point we are talking about very slight differences though; rounding up or down by half a sample refers to a very short period of time and detailed controll is only nesicary in some cases... But yeah, if you need that it's there for you.

Quote:

Or is there a much simpler way to read from different parts of the buffer and I'm making this a bit convoluted?


I'm not realy sure what you are going for here. I find the buf to be very simple myself. It's dealt with as just a string of values; you specifie where you want to start and at what rate you want to play it back and everything follows from that.

If you could be more precise in what you need we can try to figure out a way to get there.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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
AmbiphonicDSP

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 through 2009 by electro-music.com - Conditions Of Use