electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
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
Cast from dur to int?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
moudi



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

PostPosted: Tue Nov 07, 2006 2:36 pm    Post subject: Cast from dur to int?
Subject description: struggling with SndBuf
Reply with quote  Mark this post and the followings unread

hi all

I'm doing some stuff with SndBuf and now i wonder how i can start the sample with a specific duaration offset.
eg: play the wav from pos(44100), this means it starts at 0:01.000 (if the wav is recorded with 44.1).
since the .pos and .samples parameters are integers i need somehow to convert the duration to an integer wich represents the count of samples.
i didn't find any functions in the std package nor works the casting operator $ for this kind of data (wich seems logical to me).

so, has anybody a good idea how to do that or knows some "special hidden feature Laughing " wich can help me?

im thankful for every hint.
(probably i'm outing me as the biggest newbie ever Rolling Eyes )
/moudi
Back to top
View user's profile Send private message Visit poster's website
blue hell
Site Admin


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

PostPosted: Tue Nov 07, 2006 2:42 pm    Post subject: Re: Cast from dur to int?
Subject description: struggling with SndBuf
Reply with quote  Mark this post and the followings unread

moudi wrote:

(probably i'm outing me as the biggest newbie ever


Guess not Very Happy

http://electro-music.com/forum/topic-14239.html , that's what you meant right ?

_________________
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
Kassen
Janitor
Janitor


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

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

I think so but this is a slightly different problem then just pure conversion of dur to int.

As soon as you are dealing with SndBuf you need to talk about "samples" from the perspective of the buffer. Exactly how long such a sample "lasts" depends on the playback rate of the buffer.

So; if your playback rate is two you should multiply your amount of samples that you start at by .5 if you want to stay consistent with regard to the time skipped by the buffer (meaning you will start at a different point in the wave...). The buffer can run in reverse too, sadly that doesn't give you negative time Wink

It's takes a bit of thought but it's quite powerfull and the math is very simple.

I think it's best to calculate your sample rate at the top of the file if you want to refer to samp as a duration, BTW. This allows you to make programs that keep playing nicely if you are later forced to reduce ChucK's sample rate because of cpu limitations.

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



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

PostPosted: Tue Nov 07, 2006 4:41 pm    Post subject: Re: Cast from dur to int?
Subject description: struggling with SndBuf
Reply with quote  Mark this post and the followings unread

Blue Hell wrote:

http://electro-music.com/forum/topic-14239.html , that's what you meant right ?

OMG, it looks like i'll have to use the search function before i'll post some sh*t next time Embarassed!

thanks a lot for your kindly patience with me, i think i got it now.
/moudi
Back to top
View user's profile Send private message Visit poster's website
blue hell
Site Admin


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

PostPosted: Tue Nov 07, 2006 6:06 pm    Post subject: Re: Cast from dur to int?
Subject description: struggling with SndBuf
Reply with quote  Mark this post and the followings unread

moudi wrote:
OMG, it looks like i'll have to use the search function before i'll post some sh*t next time Embarassed!

I can desorient the sheer imagedness off the forum comprehended, sight on first. Madness, and it goes on (there are hours for that). Read all is best, and remember. 1

So that's all quite understandable Very Happy
Quote:
i think i got it now.i

Tthat's a good thing Exclamation (be sure though to go into Kassen's details as well)

1 : sorry, must have been programming a bit too much today, or something, promise I 'll get some sleep now, erm, soon.

_________________
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
Kassen
Janitor
Janitor


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

PostPosted: Wed Nov 08, 2006 7:00 am    Post subject: Reply with quote  Mark this post and the followings unread

Except that there is a bit of a error in my notre; if you play the buffer twice as fast a second will of cource take twice as many samples (of the buffer) not .5

Silly me.

The rest stands; a sample's duration of the buffer is a variable unit of time which is good and powerfull but needs care or it'll sound out of sync.

_________________
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 [6 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