[Csnd] setting sr to a variable

Hi, all.

I wanted to see if I could set the orchestra sr to the sample rate of a sound file that is going to be read by diskin2 in the orchestra.

I included these lines in the header, hoping they would work:

giSr = filesr("MyFile.wav"))
sr = giSr

giSr is properly evaluated, but sr is set to 0 and Csound crashes. Obviously, this is not so easy as I wished it would be. Is there a reason for this not to work?

In case it's relevant, I'm using Csound 6.18 as distributed by Arch Linux.

Yes, this shouldn’t work, sr is used to set up things prior to runtime and can not be changed without restarting csound. I think the best you could do is to read the sample rate of the file prior to starting csound, then using --sample-rate=[the sample rate] as a commandline flag option.

If within an instrument or a UDO, you could use setksmps, perhaps? Assuming the argument to setksmps could be an i-rate variable as opposed to a literal value?

Yes, I'd guessed as much, thanks for the response.

but setksmps sets the block size, not the sample rate.
i think the only solution is what steven mentioned.

Ah yes, thanks for the correction.