Author |
Message |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Sat Mar 03, 2007 8:08 am Post subject:
Newbie trying to play back a sound file and having problems |
 |
|
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
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Sat Mar 03, 2007 8:14 am Post subject:
|
 |
|
ah crap....I've just read the rules about posting code after spotting it! ..but thanks to mosc its now fixed!
I've found that if I change the line
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
|
|
 |
mosc
Site Admin

Joined: Jan 31, 2003 Posts: 18235 Location: Durham, NC
Audio files: 222
G2 patch files: 60
|
Posted: Sat Mar 03, 2007 8:41 am Post subject:
|
 |
|
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
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Sat Mar 03, 2007 10:15 am Post subject:
|
 |
|
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
|
|
 |
chuckles
Joined: Apr 02, 2007 Posts: 72 Location: San Diego, California
|
Posted: Wed Apr 18, 2007 3:14 pm Post subject:
Playing back a sound file... |
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Apr 18, 2007 3:28 pm Post subject:
|
 |
|
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.
If that's not what you mean, could you rephrase the question? Is there a error with the board? _________________ Kassen |
|
Back to top
|
|
 |
chuckles
Joined: Apr 02, 2007 Posts: 72 Location: San Diego, California
|
Posted: Thu Apr 19, 2007 1:30 pm Post subject:
|
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Apr 20, 2007 3:56 am Post subject:
|
 |
|
Sure. How about you starting, getting as far as you get, then asking questions should you get stuck? _________________ Kassen |
|
Back to top
|
|
 |
|