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
The Trap.
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
lorddust



Joined: Sep 01, 2006
Posts: 6
Location: VA

PostPosted: Thu Oct 12, 2006 9:06 am    Post subject: The Trap.
Subject description: A problem with soundbuffers.
Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Sun Oct 15, 2006 2:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

Howdy,
Have you tried replacing this
Code:
w.closeFile;
with this
Code:
w.closeFile( "" );
? 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
View user's profile Send private message
lorddust



Joined: Sep 01, 2006
Posts: 6
Location: VA

PostPosted: Mon Oct 16, 2006 2:18 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Thu Oct 19, 2006 4:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
lorddust



Joined: Sep 01, 2006
Posts: 6
Location: VA

PostPosted: Thu Oct 19, 2006 6:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
lorddust



Joined: Sep 01, 2006
Posts: 6
Location: VA

PostPosted: Thu Oct 19, 2006 7:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Thu Oct 19, 2006 7:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

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:
Code:
1 => B.loop;


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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 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