Hello all,
I have a simple gen01-to-loscil routine that uses part of a 24 bit, 48 kHz wav file. Yet when I render the score, the result is slower than the original soundfile. This happens irrespective of the settings in csound5gui's general performance settings (I assume sr & kr in CsInstruments overrides this), and it also happens whether I render from the GUI or from the command line (with or without the -3 flag for 24 bit). Yet sr is defined as 48000. Changing kcps of the loscil to 2 rather than 1 for some reason brings it back to the right speed, but I shouldn't have to do that, no?
I'm sure I'm overlooking something... sorry if it's obvious!
Here's the relevant code:
sr = 48000
kr = 4800
ksmps = 10
nchnls = 1
instr 1
kamp = 30000
kcps = 1 ; keeping this setting makes soundfile play twice as slow
ifn = 1
ibas = 1
a1 loscil kamp, kcps, ifn, ibas
out a1
endin
; gen01, read audio file
f 1 0 262144 1 "flux.wav" 0 4 0
i 1 0 4
e
Thanks!



Stereo source?
Is your 'flux.wav' file in stereo by any chance?
I seem to remember running into this problem with one of my experiments a while back, and I think that was the cause.
A stereo file has two frames that are both played at the sample rate, so if you try to play it mono (as loscil does) at the same sample rate, it reads only one of the two frames each sample period, resulting in half-speed, one octave down.
-- Pete --
that is correct
Pete.G,
You're absolutely right, my file was in stereo, and now that I think of it, your explanation makes complete sense. I guess I could create 2 loscil's, one for each channel, or, as I did before, just make kcps = 2.
Unless there's another opcode that is better for sample playback?
idfield
couple of solutions
Looking at the manual [which often helps... (:-)], I see that loscil has a stereo mode anyway, just by using two output variables. So you could just switch to nchnls=2 and do everything in stereo.
Or if you only need mono, just about any audio editor has a facility for reducing 2 channels to 1, so you could simply generate a mono file.
-- Pete --
stereo generates error
Pete,
Even with the dual output variables, I get the following error:
INIT ERROR in instr 1: stereo loscil cannot read from mono ftable
a1 a2 loscil kamp kcps ifn ibas -1 0 0 -1 0 0
B 0.000 - note deleted. i1 had 1 init errors
And my flux.wav file is in stereo! And the ftable has 0 for channel, which should have it read all channels.
Here's the updated script:
sr = 48000
kr = 4800
ksmps = 10
nchnls = 2
instr 1
kamp = 30000
kcps = 1
ifn = 1
ibas = 1
a1, a2 loscil kamp, kcps, ifn, ibas
outs a1, a2
endin
f 1 0 262144 1 "flux.wav" 0 4 0
i 1 0 4
e
idfield
Heh heh... You're SO right...!
I guess the manual doesn't necessarily help! (:-/)
I took your exact code, and pasted in a handy stereo wav,
and got precisely the same error. I've had troubles with wav vs. aiff before, so I substituted an aiff, with no difference.
Searching around, I can find no way of explicitly generating a "stereo" table (and the log said "reading both channels" anyway), so I guess that's a dead end. Yet Another Csound Bug...
I guess your only choices are to create a mono file, or do what you did originally and fudge the sample rates.
-- Pete --
More...
Thanks for trying, Pete...
I guess the other alternative would be to use soundin or diskin.
I looked at the documentation for ins. Its brief syntax (ar1 ar2 ins) doesn't specify the source of the stereo 'external device or stream', and there's no explanation of how this works. Does it play soundfiles in a directory?
Also, regarding soundin, I am going through csound5gui and noticed that if the gui sr is set to 82000, it overrides the global sr defined in the csd file (in this case 48000), regardless of whether the 'Skip CsOptions' option is checked or not. Any way around this?
idfield