Author |
Message |
lorddust
Joined: Sep 01, 2006 Posts: 6 Location: VA
|
Posted: Thu Oct 12, 2006 9:06 am Post subject:
The Trap. Subject description: A problem with soundbuffers. |
 |
|
I am writing a program that will take in external sound and output it. While this is going on i wish for it to check if a key has been hit, if it has then it will record a section(25::ms) of the current input to a file named loop and then loop it indefinatly. but ive run into a few problems. The main one is that the file is not closing and therfore is not looping
My code looks like this:
Code: | adc => gain G => dac;
sndbuf B => G;
dac => gain g => WvOut w => blackhole;
1 => G.gain;
KBHit kb;
while ( true )
{
25::ms => now;
kb => now;
while( kb.more() )
{
<<< "Trap Start", kb.getchar() >>>;
spork ~ Trap();
50::ms => now;
"loop.wav" => B.read;
<<<"Done">>>;
}
}
fun void Trap()
{
"loop.wav" => w.wavFilename;
<<<"Traping: ", w.filename()>>>;
1 => g.gain;
25::ms => now;
w.closeFile;
<<<"File Closed:">>>;
}
|
Does anyone know whats up? |
|
Back to top
|
|
 |
spencer

Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Sun Oct 15, 2006 2:50 pm Post subject:
|
 |
|
Howdy,
Have you tried replacing this with this ? Without the parentheses, you are just referencing the function itself, without actually calling the function. The double quotes between the parentheses are there only because the function's definition requires a string argument, but this argument is not actually used for anything.
hope this helps,
spencer |
|
Back to top
|
|
 |
lorddust
Joined: Sep 01, 2006 Posts: 6 Location: VA
|
Posted: Mon Oct 16, 2006 2:18 pm Post subject:
|
 |
|
That was the problem thanks.. now i'm confused about sndbuf use..
i want it to load the sound that is caught and then play it in a loop..
right now it loads it but does not play it.
New code is..
Code: | adc => gain G => dac;
sndbuf B => G;
dac => gain g => WvOut w => blackhole;
0 => g.gain;
1 => G.gain;
KBHit kb;
while ( true )
{
25::ms => now;
kb => now;
while( kb.more() )
{
<<< "Trap Start", kb.getchar() >>>;
spork ~ Trap();
50::ms => now;
"loop.wav" => B.read;
<<<"Done">>>;
1.0 => B.play;
}
}
fun void Trap()
{
"loop.wav" => w.wavFilename;
<<<"Traping: ", w.filename()>>>;
1 => g.gain;
25::ms => now;
w.closeFile("loop.wav");
<<<"File Closed:">>>;
}
|
|
|
Back to top
|
|
 |
spencer

Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Thu Oct 19, 2006 4:15 pm Post subject:
|
 |
|
thats interesting, this works on my machine... are you using command line chuck, or are you using miniAudicle or Audicle?
(Cool patch by the way, it sounds neat when I run it.)
spencer |
|
Back to top
|
|
 |
lorddust
Joined: Sep 01, 2006 Posts: 6 Location: VA
|
Posted: Thu Oct 19, 2006 6:32 pm Post subject:
|
 |
|
Command Line ChucK;
Everything runs ok except that the sound that is traped doesn't repeat after being traped.. does it do that on your system? i can't see any logic errors so i'd love to know why it doesn't work maybe where i create my sndbuf is incorrect.
Edit BTW: the idea behind this was so the me and my friend could layer various sounds (our voices and instruments) on live without using "samples" once i get this working rihgt on my pc i hope to add the ability to change the sample duration on the fly as well as having multiple file(think channels) to save various loops to. |
|
Back to top
|
|
 |
lorddust
Joined: Sep 01, 2006 Posts: 6 Location: VA
|
Posted: Thu Oct 19, 2006 7:00 pm Post subject:
|
 |
|
I finally got it working on my machine..
new code is:
Code: | adc => gain G => dac;
sndbuf B => gain sndGain => G;
dac => gain g => WvOut w => blackhole;
0 => g.gain;
1 => G.gain;
0.5 => sndGain.gain;
KBHit kb;
while ( true )
{
25::ms => now;
kb => now;
while( kb.more() )
{
<<< "Trap Start", kb.getchar() >>>;
spork ~ Trap();
2::second => now;
<<<"Done">>>;
spork ~ Loopz();
}
}
fun void Trap()
{
"loop.wav" => w.wavFilename;
<<<"Traping: ", w.filename()>>>;
1 => g.gain;
1::second => now;
w.closeFile("loop.wav");
<<<"File Closed:">>>;
}
fun void Loopz()
{
"loop.wav" => B.read;
1.0 => B.play;
while( true )
{
0 => B.pos;
B.length() => now;
}
} |
Main problem now is that if i press a key again the sounds seem to save over each other and cause wierd gain and fuzz.. |
|
Back to top
|
|
 |
spencer

Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Thu Oct 19, 2006 7:35 pm Post subject:
|
 |
|
Ahhh, I see. I didn't know you were trying to loop the sound repeatedly.
Note that sndbuf has a "loop" member, so I think you can make it loop automatically like this:
This way you wouldnt even need to spork the Loopz function.
if you wanted to avoid saving the sound over itself each time, I can think of a few solutions.
- unchuck B from G right before you record, and chuck it back right after. The disadvantage to this is that during the 25 ms where the WvOut is recording, you wont hear your looping sample.
- instead of this: Code: | dac => gain g => WvOut w => blackhole; | do this: Code: | adc => gain g => WvOut w => blackhole; | this way, you will only pick up the adc signal in your record patch, and not get any playback signal in the mix.
spencer |
|
Back to top
|
|
 |
|