Csound wont accept my logic....

2a38b495db7b9a16b9bec3e052eac3c5
0
Advoc 101 Oct 06, 2010 at 09:08

I’m doing a project for my Audio Synthesis class and I’m going for those extra bonus marks. We just started learning how to use Csound for our experiments and we aren’t using any front ends except for QuteCsound which is just a development environment.

I’ve programmed 2 oscillators to play a melody, and one of them is supposed to be a human voice.

I’m trying to use an lfo to add a vibrato to the longer notes in the melody, and so far I’ve not been very successful. I can’t seem to control the depth of the oscillator, only the overall amplitude of it. which is fine. I can deal with that. but if that is going to be the case I only want vibrato on certain notes.. not the whole bloody score. because if I put the lfo amplitude to 0, when I multiply it by my output I get 0 and no sound.

So I wanted to put an if else statement in there to route it for me.

I use the vibrato volume as parameter p6 in the score, after the note frequency and amplitude. I wanted to be able to put 0 in there to have no vibrato.

so the logic goes:
IF the lfo amplitude IS NOT zero,
then multiply the LFO signal into the main output.
ELSE
use the normal output without the LFO

Csound apparently doesn’t like my syntax. it says I dont complete the IF statement, and since that didn’t work. the else statement is invalid.
It also tells me that the { and } characters are illegal ….

any help?

Code:

instr 1     ;human voice, or choir
; setting up parameters for the score

ifreq = p4              ;parameter 4 is freqency
iamp  = p5*32767        ;parameter 5 is amplitude from 0 to 1

; envelope settings to sound like a Staccato human voice. The song is supposed
; to be majestic and stately so the attacks will be accented, with a slow decay
; and quick release of the note for separation.

iatt  = 0.01
idec  = 0.04
irel  = 0.02
islev = 0.8

kenv adsr iatt, idec, islev, irel   ; variable kenv is an ADSR with these variables
                                    ; within it
                                    
kamp = iamp * kenv                  ; adding the envelope to the amplitude

;declaring variables for the lfo, used to simulate vibrato on human voice
;kwobble = p6                       ;paramter 6 is the volume change the LFO does
                                    ;a value of 0 should cause no vibrato (hopefully)
;kcps = 4                           ;rate of LFO in Hz
;itype = 0                          ;type of wave for LFO is sine (type 0)
;ktrem lfo kwobble, kcps, itype     ;define tremolo variable as an LFO with the previous 3 paramters

;note:  I could not get this to work, the LFO type of object does not allow you to set the depth of the LFO
;       only the over volume of the tone.  Despite this I tried to at least use an If Else statement to allow
;       only those notes I wanted vibrato on, but Csound refuses to accept that they are syntactically correct
;       which I believe they are, unless Csound doesn't follow the same syntax as C or C++

;fundamental and partials
apart1 oscil kamp, 1*ifreq, 1       ; fundamental frequency with 4 partials above it
apart2 oscil kamp, 3*ifreq, 1       ; these are odd partials because the human voice
apart3 oscil kamp, 5*ifreq, 1       ; acts like a closed tube
apart4 oscil kamp, 7*ifreq, 1
apart5 oscil kamp, 9*ifreq, 1

iamp1 = 0.6                         ;amplitude of partials decreasing rapidly
iamp2 = 0.2
iamp3 = 0.1
iamp4 = 0.06
iamp5 = 0.04

;if (kwobble != 0) then
    ;acomplex = (iamp1*apart1 + iamp2*apart2 + iamp3*apart3 + iamp4*apart4 + iamp5*apart5) * ktrem
;else
    acomplex    = (iamp1*apart1 + iamp2*apart2 + iamp3*apart3 + iamp4*apart4 + iamp5*apart5)

out acomplex

endin

4 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Oct 06, 2010 at 17:07

First of all, you can use the …[/code[b][/b]] tags on the forum to post code. I haven’t ever heard of Csound before, but on the assumption that it’s supposed to be more or less C syntax, you need to remove the ‘then’. C-style if-statements don’t have a ‘then’. Generally speaking, for problems like this you should consult the docs/manual for the language. That will cover all the details of the syntax. As for the LFO, well I haven’t done much sound synthesis, but you could try blending (interpolating) between the original signal and the LFO-modulated signal according to the desired depth of vibrato. [code]…[/code**] tags on the forum to post code.

I haven’t ever heard of Csound before, but on the assumption that it’s supposed to be more or less C syntax, you need to remove the ‘then’. C-style if-statements don’t have a ‘then’.

Generally speaking, for problems like this you should consult the docs/manual for the language. That will cover all the details of the syntax.

As for the LFO, well I haven’t done much sound synthesis, but you could try blending (interpolating) between the original signal and the LFO-modulated signal according to the desired depth of vibrato.

2a38b495db7b9a16b9bec3e052eac3c5
0
Advoc 101 Oct 07, 2010 at 20:23

I was looking for a widget or something for the proper tags but i didn’t find any, thanks though. I’ll make sure to keep it cleaner from now on.

I actually figured out a different way to do it. I added my ktrem variable to the kamp variable which made it work exactly how I needed it to without needing the if else statement. Apparently Csound is only built on C and doesn’t use any of the same syntax. the ; is for comments for instance. which bugs me.

Mostly I like using the tutorials and online manuals but what they have for this is pretty vague and the examples aren’t modular… they’re terrible.

the syntax is to use the “then” word at the end of the if statement, but the complier kept telling me i was doing it wrong, even though I basically copy/paste’d it into my code. so I didn’t solve the logic issue, but I did solve my problem.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Oct 07, 2010 at 20:36

If you’re serious about learning Csound, you should really look at the manual available here. You won’t be able to get very far without knowing the syntax of the language.

2a38b495db7b9a16b9bec3e052eac3c5
0
Advoc 101 Oct 08, 2010 at 18:16

Yes, definitely. As I said it was just for an assignment. I’ll be working on it more in the coming months and years, but i’ve actually only been poking around for a couple of days. There are tons of frontends made to make use of it, my plan was to learn how to use the code first. The frontend I use just acts as a compiler and it color codes the text for me.