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
SndBuff and Arrays
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [15 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
MeCH



Joined: Apr 01, 2010
Posts: 6
Location: Austria

PostPosted: Thu Apr 01, 2010 2:36 am    Post subject: SndBuff and Arrays Reply with quote  Mark this post and the followings unread

Hi, i am new here, and have some questions about chuck. I'm not very good in dealing with chuck, so i ask for your understanding.

My question now: I have to read in sound from a file (with sndbuff) and form a microphone (with adc) into a buffer (max 1.5 sec length). The play and record of the buffer should be solved by an array.
So how can i sample sound into an array with max 1.5 sec length and how can i play that array? How can i store sound from a file or a microphone in that array.

Hope someone can help me.

MeCH
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Thu Apr 01, 2010 3:13 am    Post subject: Reply with quote  Mark this post and the followings unread

welcome MeCH!

In ChucK, arrays (as we normally use the term) are used to store lists of numbers or other things. It isn't practical to use these for audio though, for what you want you should use LiSa (http://chuck.cs.princeton.edu/doc/program/ugen_full.html#LiSa). Check out the tutorial and example links - they'll give you a good start on using this neat UGen.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
MeCH



Joined: Apr 01, 2010
Posts: 6
Location: Austria

PostPosted: Thu Apr 01, 2010 3:33 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi, thanks for the quick answer. I wanted to use LiSa, but i am not allowed to use it. It's an exercise where we must do that with arrays Sad.

Perhaps you can help me solving this with arrays Very Happy Very Happy Very Happy

gz,
MeCH
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Thu Apr 01, 2010 5:34 am    Post subject: Reply with quote  Mark this post and the followings unread

Aha! But if it's an exercise you should solve it by yourself, shouldn't you? Wink

Ok, I'll give you a hint. You can make an array of floats, wait one sample at a time, and use the next() member function in a certain UGen that I'm not going to tell you what it's called... Twisted Evil

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
MeCH



Joined: Apr 01, 2010
Posts: 6
Location: Austria

PostPosted: Thu Apr 01, 2010 6:10 am    Post subject: Reply with quote  Mark this post and the followings unread

Yes, it's an exercise Laughing

But how can i set the array, that it is exectly 1.5 sec?
And i think i must use the pulse generator to get each sample?

gz,
MeCH
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Thu Apr 01, 2010 6:20 am    Post subject: Reply with quote  Mark this post and the followings unread

OK, I'll help you a little bit more Wink

This will give you the exact amount of samples needed for 1.5 seconds:

1.5::second / 1::samp

If you do a loop, and inside wait 1::samp, get the last value from the adc, wait 1::samp, get the last value from the adc and so on, you'll get the correct incoming sample values from the input. To play back, you do the same thing the other way round.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
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: Fri Apr 02, 2010 6:37 am    Post subject: Reply with quote  Mark this post and the followings unread

MeCH wrote:
Hi, thanks for the quick answer. I wanted to use LiSa, but i am not allowed to use it. It's an exercise where we must do that with arrays Sad.

Perhaps you can help me solving this with arrays Very Happy Very Happy Very Happy


I bet you have a teacher named Joerg :-p

Are you still stuck after Antimon's help?

The rules say we can get people un-stuck but we can't do your homework for you, you see.

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



Joined: Apr 03, 2010
Posts: 2
Location: austria

PostPosted: Sat Apr 03, 2010 5:26 am    Post subject: Reply with quote  Mark this post and the followings unread

hey there! I'm also doing this exercise Smile Thanks for your help so far, it really got me forward. But now I'm stuck at "getting the last value of adc". I wanna save this last value in my float-Array, but i don't find out how to get a float value out of my adc-signal...

My chain until now is:
adc => gain => impulse => blackhole;

and i wish it would be possible to do something like this within my loop:
impulse.next $ float => myArray[currentSample];

can you help me/us out one more time?? Embarassed
thx!
Back to top
View user's profile Send private message
muetzenflo



Joined: Apr 03, 2010
Posts: 2
Location: austria

PostPosted: Sat Apr 03, 2010 6:34 am    Post subject: Reply with quote  Mark this post and the followings unread

i think i just found the solution.

Gain g.last() should do the trick Smile
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: Sat Apr 03, 2010 10:48 am    Post subject: Reply with quote  Mark this post and the followings unread

muetzenflo wrote:
i think i just found the solution.

Gain g.last() should do the trick Smile


Bingo! All UGens have a .last(), in fact everything that Gain has is shared by all UGens, including adc and dac.

You're well on your way. Next step! Smile

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



Joined: Apr 01, 2010
Posts: 6
Location: Austria

PostPosted: Fri Apr 09, 2010 3:01 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi, thanks for the help Very Happy

Next question:
I declare an array with:
Code:
(1.5::second/1::samp) $ int => int samplerate;
float buffer[samplerate];


So the array is 65150 Entries big (samplerate for 1.5 sek)

Now i want to record 1.5 sek from the mic, and store it in the buffer.
So i made the function:


Code:
fun void getFromMic()
{
    <<< "Mic" >>>;
   
    adc a;
   

for (0 => int i; i < samplerate; i++ ) {
1::samp;
a.last()  = buffer[i];
}


}


Works not very well Confused
So how can i exacty record 1.5 sek and store it in the buffer?
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Apr 09, 2010 3:47 am    Post subject: Reply with quote  Mark this post and the followings unread

Hmm, I'm not completely sure about this, but perhaps you need to connect the adc to something to have it generate values. Try:

Code:
adc => blackhole


If that doesn't work there may be issues with having ChucK find your audio interface, or selecting the correct input. Do you have several audio inputs? Try running chuck --probe (or the equivalent in MiniAudicle, don't know how that works). There you can see that each input has a number and is on a device. You can do:

Code:
adc.chan(2) => blackhole


if your microphone input is number 2.for instance.

Another thing to try could be to take the audio data from a "normal" UGen like Gain instead:

Code:
adc.chan(2) => Gain g => blackhole;
g.last() => int myValue


Shouldn't be necessary, but there may be some special tricky stuff used for the adc that doesn't work like other UGens. Just a random hunch.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
MeCH



Joined: Apr 01, 2010
Posts: 6
Location: Austria

PostPosted: Sat Apr 10, 2010 1:52 am    Post subject: Reply with quote  Mark this post and the followings unread

I think input form microphone works now.

Is it possible that i must write 1::samp => now; to wait one sample, and not only 1::samp; ?

The next question i have is, how can i replay that array now. It should be the other way, like:

Code:
dac d;

    while (true) {
        for( 0 => int i; i < abspielPuffer.cap() ; i++) {
            abspielPuffer[i];
            1::samp = now;
        }
    }


it's not right, what to do with the dac?
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: Sat Apr 10, 2010 4:54 am    Post subject: Reply with quote  Mark this post and the followings unread

MeCH wrote:

Is it possible that i must write 1::samp => now; to wait one sample, and not only 1::samp; ?


Exactly. "samp" is just a value and you need to express exactly what you want ChucK to do with that value.


Quote:
it's not right, what to do with the dac?


Well, the dac is just there to connect UGens to. There are two UGens that can turn values into audio signals; Step and Impulse. I suggest looking those up in the manual and seeing how far that gets you.

In a way those are like the mirror image of the .last() function which goes the other way around.

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



Joined: Apr 01, 2010
Posts: 6
Location: Austria

PostPosted: Sun Apr 11, 2010 8:24 am    Post subject: Reply with quote  Mark this post and the followings unread

Works all now, thanks a lot for the explanations and tipps. Very Happy
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 [15 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