| Author |
Message |
MeCH
Joined: Apr 01, 2010 Posts: 6 Location: Austria
|
Posted: Thu Apr 01, 2010 2:36 am Post subject:
SndBuff and Arrays |
 |
|
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
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Apr 01, 2010 3:13 am Post subject:
|
 |
|
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
|
|
 |
MeCH
Joined: Apr 01, 2010 Posts: 6 Location: Austria
|
Posted: Thu Apr 01, 2010 3:33 am Post subject:
|
 |
|
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 .
Perhaps you can help me solving this with arrays
gz,
MeCH |
|
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Apr 01, 2010 5:34 am Post subject:
|
 |
|
Aha! But if it's an exercise you should solve it by yourself, shouldn't you?
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...
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
|
Back to top
|
|
 |
MeCH
Joined: Apr 01, 2010 Posts: 6 Location: Austria
|
Posted: Thu Apr 01, 2010 6:10 am Post subject:
|
 |
|
Yes, it's an exercise
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
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Apr 01, 2010 6:20 am Post subject:
|
 |
|
OK, I'll help you a little bit more
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Apr 02, 2010 6:37 am Post subject:
|
 |
|
| 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 .
Perhaps you can help me solving this with arrays
|
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
|
|
 |
muetzenflo
Joined: Apr 03, 2010 Posts: 2 Location: austria
|
Posted: Sat Apr 03, 2010 5:26 am Post subject:
|
 |
|
hey there! I'm also doing this exercise 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??
thx! |
|
|
Back to top
|
|
 |
muetzenflo
Joined: Apr 03, 2010 Posts: 2 Location: austria
|
Posted: Sat Apr 03, 2010 6:34 am Post subject:
|
 |
|
i think i just found the solution.
Gain g.last() should do the trick  |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sat Apr 03, 2010 10:48 am Post subject:
|
 |
|
| muetzenflo wrote: | i think i just found the solution.
Gain g.last() should do the trick  |
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!  _________________ Kassen |
|
|
Back to top
|
|
 |
MeCH
Joined: Apr 01, 2010 Posts: 6 Location: Austria
|
Posted: Fri Apr 09, 2010 3:01 am Post subject:
|
 |
|
Hi, thanks for the help
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
So how can i exacty record 1.5 sek and store it in the buffer? |
|
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Fri Apr 09, 2010 3:47 am Post subject:
|
 |
|
Hmm, I'm not completely sure about this, but perhaps you need to connect the adc to something to have it generate values. Try:
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
|
|
 |
MeCH
Joined: Apr 01, 2010 Posts: 6 Location: Austria
|
Posted: Sat Apr 10, 2010 1:52 am Post subject:
|
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sat Apr 10, 2010 4:54 am Post subject:
|
 |
|
| 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
|
|
 |
MeCH
Joined: Apr 01, 2010 Posts: 6 Location: Austria
|
Posted: Sun Apr 11, 2010 8:24 am Post subject:
|
 |
|
Works all now, thanks a lot for the explanations and tipps.  |
|
|
Back to top
|
|
 |
|