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
Newbie trying to play back a sound file and having problems
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [8 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: Sat Mar 03, 2007 8:08 am    Post subject: Newbie trying to play back a sound file and having problems Reply with quote  Mark this post and the followings unread

Hi there. Im currently trying to play back a soundfile from the buffer but at a beat at a time but have it playback seemlessly.

I've tried to assertain the no of samples per beat and the duration of one beat and then told chuck to advance time by one beat and move the buffer position forward by the number of samples of one beat to be at the second beat.

The result should be seemless playback that sounds like you has just played the whole file without it being chopped up.

Unfortuntely it doesnt work and although the effect sounds cool, I just cant understand where I'm going wrong....

Also I really want to use floats intstead of integers for more accuracy but float => dur is not compatible .....however, int => dur is?! How can I resolve this?

Here's my code

Code:


150 => int bpm;
150 / 60 => int bps;
44100 / bps => int beatSampleLength; // Assuming the .wav file used has 44100 samples per second (CD Quality)

60::second / bpm => dur t4;  // 60 seconds divided by bpm = Time for 1 beat to pass

t4 * 4.0 => dur t1;   // 4 Beats (1 Bar of 4/4)
t4 * 2.0 => dur t2;   // 2 Beats (1/2 Bar of 4/4)
t4 / 2.0 => dur t8;   // Quaver (1/2 of a crotchet beat -- 8 in bar)
t4 / 4.0 => dur t16;   // Semi-Quaver (1/4 of a crotchet beat -- 16 in bar)
t4 / 8.0 => dur t32;   // Demi-Semi-Quaver (1/8 of a crotchet beat 32 in bar)
t4 / 16.0 => dur t64;   // Hemi-Demi-Semi-Quaver (1/16 of a crotchet beat 64 in bar)

SndBuf buf => dac;

"Beat1(150).wav" => buf.read;   // load the file

0 => buf.pos;   // Reset Buffer Position to 0
// buf.samples; // Prints number of samples in sound file

1 => int x;
x => buf.pos;


for( 0 => int t64play; t64play < 8; t64play++ ) 

{
   0 => buf.loop;
   beatSampleLength::samp => now;
   x + beatSampleLength => x;   // Advance the buffer by a little way
   x => buf.pos;   // Tell the buffer to reposition to integer x
}


Thanks for your help guys.

Rhys[/code]

Last edited by Dr. Spankenstein on Sat Mar 03, 2007 9:14 am; edited 2 times in total
Back to top
View user's profile Send private message
Dr. Spankenstein



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

PostPosted: Sat Mar 03, 2007 8:14 am    Post subject: Reply with quote  Mark this post and the followings unread

ah crap....I've just read the rules about posting code after spotting it! ..but thanks to mosc its now fixed!

Embarassed

I've found that if I change the line

Code:

t4 => now;


to

Code:

beatSampleLength::samp => now;


then it works just great, but that doesnt solve the float => dur as I still cant figure out how to use more accuracte floats.

Last edited by Dr. Spankenstein on Sat Mar 03, 2007 8:48 am; edited 1 time in total
Back to top
View user's profile Send private message
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18197
Location: Durham, NC
Audio files: 212
G2 patch files: 60

PostPosted: Sat Mar 03, 2007 8:41 am    Post subject: Reply with quote  Mark this post and the followings unread

welcome Doc.

You can edit your post. Just click on the little EDIT icon at the upper right of your post.

_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Dr. Spankenstein



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

PostPosted: Sat Mar 03, 2007 10:15 am    Post subject: Reply with quote  Mark this post and the followings unread

Im getting there with this code only it seems to play a little bit more than what I want... Ie. I specify that I want it to playback 2 bars with each bit chopped up into 64ths, it plays it back seemlessly but then loops and plays another beat or so before stopping.

Shouldnt it just play for 2 bars and stop?!

Code:

150 => int bpm;
150 / 60 => int bps;
44100 / bps => int beatSampleLength; // Assuming the .wav file used has 44100 samples per second (CD Quality)
44100 / bps / 16 => int x;

60::second / bpm => dur t4;  // 60 seconds divided by bpm = Time for 1 beat to pass

beatSampleLength::samp * 4.0 => dur t1;   // 4 Beats (1 Bar of 4/4)
beatSampleLength::samp * 2.0 => dur t2;   // 2 Beats (1/2 Bar of 4/4)
beatSampleLength::samp / 2.0 => dur t8;   // Quaver (1/2 of a crotchet beat -- 8 in bar)
beatSampleLength::samp / 4.0 => dur t16;   // Semi-Quaver (1/4 of a crotchet beat -- 16 in bar)
beatSampleLength::samp / 8.0 => dur t32;   // Demi-Semi-Quaver (1/8 of a crotchet beat 32 in bar)
beatSampleLength::samp / 16.0 => dur t64;   // Hemi-Demi-Semi-Quaver (1/16 of a crotchet beat 64 in bar)

SndBuf buf => dac;

"Beat1(150).wav" => buf.read;   // load the file

0 => buf.pos; // Reset Buffer Position to 0
0 => int y;   
// buf.samples; // Prints number of samples in sound file

for( 0 => int t32play; t32play < 128; t32play++ ) 

{
   1 => buf.loop;
   t64 => now;      // Advance time by desired duration
   y + x => y;      // Advance the buffer by a little way
   y => buf.pos;

}


Thanks

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



Joined: Apr 02, 2007
Posts: 72
Location: San Diego, California

PostPosted: Wed Apr 18, 2007 3:14 pm    Post subject: Playing back a sound file... Reply with quote  Mark this post and the followings unread

As far as I can tell this was never answered; probably the OP fixed it and never reported back; I'd be interested in what the solution was if anyone (e.g. ChucKexperT) happens to know...

chuckles!
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 Apr 18, 2007 3:28 pm    Post subject: Reply with quote  Mark this post and the followings unread

Fixed what? This code?

I think the issue here is most likely somwhere in the order in which time is advanced and counters are incremented and so on; errors there tend to give that sort of symptome. I could look into it in more detail but solving that kinda thing -for me- depends on wether at arrives when I'm in "let's solve a fun puzzle" mode. Smile

If that's not what you mean, could you rephrase the question? Is there a error with the board?

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



Joined: Apr 02, 2007
Posts: 72
Location: San Diego, California

PostPosted: Thu Apr 19, 2007 1:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

Oh, I wasn't asking you specifically to solve it! As a newbie I was curious as to whether anyone knew that the problem the guy was complaining about was solved.

In fact it would probably be a good exercise for a newbie like myself to try and figure it out...
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: Fri Apr 20, 2007 3:56 am    Post subject: Reply with quote  Mark this post and the followings unread

Sure. How about you starting, getting as far as you get, then asking questions should you get stuck?
_________________
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 [8 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