Hello fellow csounders,
noob here. I’m still confused about csound - to a degree where it’s even hard to formulate proper questions. This one is about arrays and function tables, I’ve been reading the manual, floss, tried google, searched the forum and can’t get the most basic thing done: loading a audio sample into an array
Now, what I would do in any of the other languages that I’m somewhat familiar with (java, js, python etc.) is:
- read audio file and split it into snippets, save all snippets into array
- iterate over snippet-array, analyze dominant pitch of each snippet and save to pitch-array (index of pitch array = index of respective snippet in snippet-array, or use a 2dim-array)
- find all snippets with a given pitch by iterating over pitch-array and play back as desired
now here the question / problem:
afaik in csound I can not directly read a soundfile to an array, correct? the only way I found to get audio sample data into an array is by loading it into a function table first, then copy it to array with copyf2array-opcode (which alone raises quite some init / perf time confusion for me).
this is what I tried (in various ways):
<CsoundSynthesizer> <CsOptions> -n -d </CsOptions> <CsInstruments> ; Initialize the global variables. sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 gkFirstCyclePassed = 0 gSSamplePath = "any_sound_file.wav" ; maybe fox.wav ;) giSampleTable ftgen 0, 0, 0, -1, gSSamplePath, 0, 0, 0 ;READ FILE AND SPLIT TO ARRAY instr 99 gkSampleArray init ftlen(giSampleTable) if gkFirstCyclePassed == 0 then copyf2array gkSampleArray, giSampleTable printks "----- array length: %i\n", 1, lenarray(gkSampleArray) gkFirstCyclePassed = 1 endif endin </CsInstruments> <CsScore> i99 0 z </CsScore> </CsoundSynthesizer>
it throws an error at startup:
Deferred-size ftable 101.000000 load not available at perf time.INIT ERROR in instr 99 (opcode copyf2array.k) line 25: No table for copy2ftab
this suggests that the function table is not available at perf time? is it really? I can very well play it back in another instrument using poscil3 for example, is this not perf time? what am I missing?
or am I approaching this wrong? would a seasoned csounder instantly come up with a more appropriate way of dealing with the sample data in this case? Mixing ftables and arrays also seems a bit wrong but after reading about ftables, I strongly wish to be working with arrays (as this is what I’m more familiar with).
any hints will be highly appreciated! thanks in advance!