Csound Csound-dev Csound-tekno Search About

[Csnd] Loading a section of a soundfile to a table

Date2012-05-23 20:58
FromJuan Bordon
Subject[Csnd] Loading a section of a soundfile to a table
Hi,
I'm trying to load a specific fragment of a soundfile into a table. I
notice that GEN1 has a skiptime parameter to set the starting point,
but there isn't a length parameter to set the fragment's end. I found
the same problem loading the sample through opcodes like 'soundin'
Is there a known workaround to solve this situation? I would like to
avoid having to cut the samples prior to execution.
Thanks you very much,
Juan

Date2012-05-23 21:07
FromAdam Puckett
SubjectRe: [Csnd] Loading a section of a soundfile to a table
The "end" would be the size of the table.

On 5/23/12, Juan Bordon  wrote:
> Hi,
> I'm trying to load a specific fragment of a soundfile into a table. I
> notice that GEN1 has a skiptime parameter to set the starting point,
> but there isn't a length parameter to set the fragment's end. I found
> the same problem loading the sample through opcodes like 'soundin'
> Is there a known workaround to solve this situation? I would like to
> avoid having to cut the samples prior to execution.
> Thanks you very much,
> Juan
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>

Date2012-05-23 21:21
FromJuan Bordon
SubjectRe: [Csnd] Loading a section of a soundfile to a table
> The "end" would be the size of the table.

Thanks for the quick answer.
I try to set explicity p3, but it only allows power of 2 values for
the size ("ftable 1: illegal table length"). So I set it to zero
(deferred). Is there a way to crop the table during execution?
Thanks.

Date2012-05-23 21:49
Fromjoachim heintz
SubjectRe: [Csnd] Loading a section of a soundfile to a table
hi juan -

you can copy the part of the deferred table you need to another table,
for instance with vcopy_i. below is an example, which is a slightly
modified version of
http://www.csounds.com/udo/displayOpcode.php?opcode_id=138

hope this helps. best -

	joachim





sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

  opcode FilToBuf, ii, Soopoo
;creates a non deferred function table from a soundfile and returns its
length
Sfilenam, iskip, ifilsel, ichn, iftnum, inorm xin ;filename, skiptime
(default = 0), length of selection to be copied (default 0 = all),
channel (default=1), number of ftable (0=automatic(=default)),
normalization (1=yes, 0=no(=default))
igen       =          (inorm == 0 ? -1 : 1)
ifttmp     ftgen      0, 0, 0, igen, Sfilenam, iskip, 0, ichn
ilen       tableng    ifttmp
ilen       =          (ifilsel == 0 ? ilen : ifilsel * sr)
ift        ftgen      iftnum, 0, -ilen, -2, 0
           vcopy_i    ift, ifttmp, ilen
           ftfree     ifttmp, 0
           xout       ift, ilen
  endop

  instr load_and_play
iFilTab, ilen FilToBuf "fox.wav", .5, 1 ;from 0.5 to 1.5 in the file
           print      ilen ;length of the copied table
p3         =          (ilen/sr) * 2 ;play the table twice
aSnd       poscil3    1, 1/(ilen/sr), iFilTab
           out        aSnd
  endin



i "load_and_play" 0 1





Am 23.05.2012 22:21, schrieb Juan Bordon:
>> The "end" would be the size of the table.
> 
> Thanks for the quick answer.
> I try to set explicity p3, but it only allows power of 2 values for
> the size ("ftable 1: illegal table length"). So I set it to zero
> (deferred). Is there a way to crop the table during execution?
> Thanks.
> 
> 
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 
> 

Date2012-05-23 22:13
FromJuan Bordon
SubjectRe: [Csnd] Loading a section of a soundfile to a table
Thank you very much joachim!

Any other instrument that starts at time 0 could access the table or
is mandatory to introduce some delay in the consumers?
I understand that the "_i" part of the opcode name means that it
executes during initialization, that is enough to guaranteed the
availability of the table data in another instrument that starts at
the same time?