I'm totally new to this. I'm using "the csound book," but i've gotten it from a library, with no cd. Anyway, I'm stuck trying to load a sound saved on my computer using the loscil opcode. How do I tell the program where to find this file?
Thanks in advance for your help.



Feeding sound to loscil
The (fairly) general rule in Csound is that waveforms and other curves are obtained from function tables. (Not universal, as opcodes like 'in' can read directly from a file or stream.) A function table is normally specified in the Score file or section, though you can also use the equivalent 'ftgen' opcode in the Orchestra part.
Function tables are referenced by number, and in the case of loscil this is the third parameter in the opcode statement. It will use whatever is in that table as its waveform.
Probably the easiest way to get a sound file into the function table is with a GEN01 statement in the Score file. This takes the filename (in quotes) as the fifth parameter in the score 'f' statement (the preceding ones being standard score table parameters, with the table number itself being the first). The size of the table (3rd parameter) normally has to be a power of two, but *if* you just want to play the sound straight through with loscil you can leave the size zero and it will be obtained from the actual length of the file. If you do this, though, you can't set loop points and such in the sample.
For example, here's a test .orc file I ran:
instr 1
kamp = 30000
kcps = 440
ifn = 1
ibas = 440
; Play the audio sample stored in Table #1.
a1 loscil kamp, kcps, ifn, ibas
out a1
endin
and the corresponding table statement in the .sco file is:
;f# time size func filename skiptime format channel
f1 0 0 1 "Ray1.wav" 0 0 0
There are various nasties with loscil that aren't explained very well -- or not at all -- in the docs. For a start, loscil works best with an "instrument-style" AIFF source file (i.e. one that has a base frequency encoded in it) so that it knows how to adjust for the 'kcps' value you supply. If the AIFF doesn't have that parameter, or it's a WAV file, you *must* set a suitable value for 'ibas'. You can set it anyway, and if you do, loscil will use the supplied value rather than the one in the file. If you simply want to play the sound at the pitch it was recorded, set ibas and kcps to the same (arbitrary) value.
I've also found [though somebody may be able to educate me here] that you can't use a WAV file and add loop points in the loscil call. It's been a while now, but I remember trying everything and in the end converting the WAV to an AIFF to get looping ability.
You will also have to pre-specify the size as a power-of-two, larger than the number of samples in the file. This will doubtless also give you a silent tail at the end, which you'll have to adjust for with note length.
Does that make sense, or does it just add to the confusion...? (:-/)