Single Cycle Waveforms - many f tables

Hello. I have code I believe is heading in right direction. I want to listen to single cycle waveforms, one after another. Explore?
My code works but bothers me. I feel I should not need an f table for every .WAV file. I believe one strategy might be to deallocate an f-table and specify a new input file while the other one is playing. I would need a total of two f-tables for this strategy.
I could not come up with a way to use only two f-tables. Here is the code that works. I believe the secret lies in knowing how to write the score.
It it possible to use two f-tables to play a number of sample files, one after another? Is there a better way?

gkfrq   init    880
gkamp   init    10000

		instr 	101					
a1 		loscil  gkamp, gkfrq, 1  ; sample-based looping oscillator
		out 	a1
		endin

		instr 	102					
a1 		loscil  gkamp, gkfrq, 2  ; sample-based looping oscillator
		out 	a1
		endin

. . . etc. (defined 8 instruments)

; f# Ti Sz  G#
f 1  0  0   1   "AKWF_tannerin_0001.wav" 0 0 0
f 2  0  0   1   "AKWF_tannerin_0002.wav" 0 0 0
f 3  0  0   1   "AKWF_tannerin_0003.wav" 0 0 0
f 4  0  0   1   "AKWF_tannerin_0004.wav" 0 0 0
f 5  0  0   1   "AKWF_theremin_0001.wav" 0 0 0
f 6  0  0   1   "AKWF_theremin_0002.wav" 0 0 0
f 7  0  0   1   "AKWF_theremin_0003.wav" 0 0 0
f 8  0  0   1   "AKWF_theremin_0004.wav" 0 0 0
;inst	        start	duration
i 101.1     	1       3
i 102.1     	4       3
i 103.1     	7       3
i 104.1     	10      3
i 105.1     	13      3
i 106.1     	16      3
i 107.1     	19      3
i 108.1     	22      3

i’d say if the sound files are not too large, and you need to have them
in ftables (rather than using diskin), it is a good idea to put each
sound in a seperate table (as you did). you can automatize this process
by the directory opcode and a while loop.

i don’t see why you use two instruments instead of one, passing the
table number as p4:
loscil gkamp, gkfrq, p4

best -
joachim

Hi there, welcome! It’s not uncommon for my Csound projects to have many f-tables of WAV files.
Piggybacking off what Joachim said, here’s example code of using the directory opcode and a while loop from the Cabbage forum. That way you don’t need to hand code each f-table.

While I agree 200% with the advice given, if you were to persist with your approach there is a tablecopy opcode that you might use. And also note that tables can be created in the orchestra using ftgen

Thank you all. There are some things about CSound that I am still trying to get my head around. The possibility that CSound can see what’s coming and prepare for it. The implication being that this preparation is done in a background thread. Perhaps even look ahead (in the score)?

I see there is the ability to deallocate tables from the score. I did not know about ftgen. This reinforces the notion that a smooth performance is one that efficiently manages resources if a lot of tables are needed. Management that possibly needs done ahead of time.

I wound up using a single table for all of the waveforms and there did not seem to be any noticeable gap between them.

I think the directory read strategy is the right way to go. That way I don’t have to rewrite the score for every new group of waveforms.