Csound Csound-dev Csound-tekno Search About

[Csnd] help with FM synthesis.

Date2010-04-11 00:44
Fromfrancis keyes
Subject[Csnd] help with FM synthesis.
Attachmentsparallel_dfm.jpg  
Hey All, I'm hoping to use csound to impliment the Fm synthesis function as seen in the attached image but I might be in a bit over my head.  However, I suspect this is a relatively simple task for an expert with csound.  Can anyone give me a hand?

Thanks,
Francis

Date2010-04-11 03:56
Fromluis jure
Subject[Csnd] Re: help with FM synthesis.
AttachmentsNone  dobleFM.csd  

Date2010-04-11 05:24
FromJosh Henne
Subject[Csnd] RE: help with FM synthesis.
Hello,
 
If you are looking to do Yamaha FM style (aka Phase modulation) synthesis, here is some basic rough code (without the headers, setup, score, ftable entries) for a simple two operator (oscillator) synth in which the output of one operator controls the instantaneous phase of another operator. In this case the modulator and carrier are made using phasor and table pairs where the phasors scan the tables. Using tables allows you to use different waveforms in the FM (PM) algorithm.
 
See Page 266 of the Csound book, Page 226 of The Computer Music Tutorial. Or you can download The Theory and Technique of Electronic Music by Miller Puckette. Figure 5.15 on page 143 shows the structure of basic phase and frequency modulation instruments using Pure Data patches.
 
instr 101
 
; *** Base frequency taken from midi note converted to Hz
inote cpsmidi ; <-- could be pfield in a score - also see the midi/score interoperability opcodes
imodoffset = 0 ;Modulation offset in Hz - usually seen as a ratio value on FM synths, or it could be based on a semi-tone offset converted to hertz
imodfreq = inote + imodoffset ;<-- adding the frequency offset to the base frequency to set the mod:carrier ratio **NOTE** I find that I cannot use
                                        ; expressions within opcode parameter fields - so I calculate the value I want to use beforehand
 
; ** Modulation Index and Amplitude Envelopes ***
kindexenvelope linseg ia, idur1, ib, idur2 ... in, idurn ;<-- You could use any envelope, linear, curve generator opcode you wish - See Csound Manual
kamplitudeenvelope linseg ia, idur, ib, idur2 ... in, idurn ;**Note that the ADSR opcodes ramp up to a full value of 1 during the attack phase,
  ; , which means you will get a high amount of modulation during the attack portion of the ADSR,
  ; leading to very sharp metallic timbres which you might not always want
 
; *** Modulator Phasor/Table Oscillator **********************
amodphase phasor imodfreq
amodout tablei amodphase, 1, 1 ;<-- Audio out of modulation oscillator **Note see Csound manual entry of tablei opcode to understand why the two
                                            ; ones are there after amodphase
 
; *** Carrier Phasor ****************************
acarphase phasor inote
 
; *** Modulation Index ***
aindexout = ( (amodout * kindexenvelope) + aosc1phase ) ;the output of the modulator is added to the phase of the carrier
 

; *** Carrier Table Oscillator ***

acarout tablei aindexout, 1, 1 ;<-- Audio out of carrier oscillator

out acarout * kamplitudeenvelope ;<-- Audio output of carrier oscillator through amplitude envelope

 

endin


Date: Sat, 10 Apr 2010 20:44:44 -0300
From: fkeymo@gmail.com
To: csound@lists.bath.ac.uk
Subject: [Csnd] help with FM synthesis.

Hey All, I'm hoping to use csound to impliment the Fm synthesis function as seen in the attached image but I might be in a bit over my head.  However, I suspect this is a relatively simple task for an expert with csound.  Can anyone give me a hand?

Thanks,
Francis

Date2010-04-13 02:23
Fromfrancis keyes
Subject[Csnd] Re: RE: help with FM synthesis.
Thanks.  This is super helpfull. I have two questions:

1.  Do you think its best to use the score for the sumation portion of the equation?

2.  I need to invoke this csound score many times from within another c++ program and be able to pass in parameters from the c++ program to csound.  Any thoughts on how this could work?  I looking through the documentation right now but haven't come accross anything.

Thanks so much for you help,
Francis

On Sun, Apr 11, 2010 at 1:24 AM, Josh Henne <jhenneocad@hotmail.com> wrote:
Hello,
 
If you are looking to do Yamaha FM style (aka Phase modulation) synthesis, here is some basic rough code (without the headers, setup, score, ftable entries) for a simple two operator (oscillator) synth in which the output of one operator controls the instantaneous phase of another operator. In this case the modulator and carrier are made using phasor and table pairs where the phasors scan the tables. Using tables allows you to use different waveforms in the FM (PM) algorithm.
 
See Page 266 of the Csound book, Page 226 of The Computer Music Tutorial. Or you can download The Theory and Technique of Electronic Music by Miller Puckette. Figure 5.15 on page 143 shows the structure of basic phase and frequency modulation instruments using Pure Data patches.
 
instr 101
 
; *** Base frequency taken from midi note converted to Hz
inote cpsmidi ; <-- could be pfield in a score - also see the midi/score interoperability opcodes
imodoffset = 0 ;Modulation offset in Hz - usually seen as a ratio value on FM synths, or it could be based on a semi-tone offset converted to hertz
imodfreq = inote + imodoffset ;<-- adding the frequency offset to the base frequency to set the mod:carrier ratio **NOTE** I find that I cannot use
                                        ; expressions within opcode parameter fields - so I calculate the value I want to use beforehand
 
; ** Modulation Index and Amplitude Envelopes ***
kindexenvelope linseg ia, idur1, ib, idur2 ... in, idurn ;<-- You could use any envelope, linear, curve generator opcode you wish - See Csound Manual
kamplitudeenvelope linseg ia, idur, ib, idur2 ... in, idurn ;**Note that the ADSR opcodes ramp up to a full value of 1 during the attack phase,
  ; , which means you will get a high amount of modulation during the attack portion of the ADSR,
  ; leading to very sharp metallic timbres which you might not always want
 
; *** Modulator Phasor/Table Oscillator **********************
amodphase phasor imodfreq
amodout tablei amodphase, 1, 1 ;<-- Audio out of modulation oscillator **Note see Csound manual entry of tablei opcode to understand why the two
                                            ; ones are there after amodphase
 
; *** Carrier Phasor ****************************
acarphase phasor inote
 
; *** Modulation Index ***
aindexout = ( (amodout * kindexenvelope) + aosc1phase ) ;the output of the modulator is added to the phase of the carrier
 

; *** Carrier Table Oscillator ***

acarout tablei aindexout, 1, 1 ;<-- Audio out of carrier oscillator

out acarout * kamplitudeenvelope ;<-- Audio output of carrier oscillator through amplitude envelope

 

endin


Date: Sat, 10 Apr 2010 20:44:44 -0300
From: fkeymo@gmail.com
To: csound@lists.bath.ac.uk
Subject: [Csnd] help with FM synthesis.


Hey All, I'm hoping to use csound to impliment the Fm synthesis function as seen in the attached image but I might be in a bit over my head.  However, I suspect this is a relatively simple task for an expert with csound.  Can anyone give me a hand?

Thanks,
Francis


Date2010-04-14 05:42
FromJosh Henne
Subject[Csnd] RE: Re: RE: help with FM synthesis.
Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). You would have to delcare the parameters for each operator you intend to use. It would be easier to think of your instrument in terms of "algorithms". Typically FM synths place operators into configurations where each operator becomes a modulator or carrier depending on how they are "wired" together. Look at soft synths like FM7/FM8, Rhino and of course hardware like the Yamaha DX7 to get an idea of how this works. For example the DX7 uses six operators that are wired into 32 different configurations with some using feedback. FM7, FM8, and Rhino allow you to connect operators into configurations of your own design.
 
You could design a Csound file having one instrument that contains all the FM control parameters as global variables. Each FM algorithm would be it's own instrument - all the algorithms would be controlled by the same global paramaters. The algorithm you select as part of the global variables would control which "instrument" plays during each note. It will be tricky to connect the inputs and outputs of the phasor/table pairs but this is the easiest solution - start with one algorithm and get it working first. To use feedback look at Csound effect instruments like delays and reverb. A more difficult but possibly more flexible method is to use the Zak Patch opcodes to route the outputs of the operators into the algorithms you want.
 
....Of course from there you can add other sound shaping gizmos like distortion, filters, etc.
 
2. Yes you can certainly include a Csound file as part of sourcecode for a program. You can use the Csound Application Programming Interface and the Software Bus Opcodes. I have no experience with these myself but you can find information within the Csound Manual for the bus opcodes. And there is the Csound API reference by Michael Gogins which is found here: http://csound.sourceforge.net/refman.pdf
 
Josh
 

Date: Mon, 12 Apr 2010 22:23:33 -0300
From: fkeymo@gmail.com
To: csound@lists.bath.ac.uk
Subject: [Csnd] Re: RE: help with FM synthesis.

Thanks.  This is super helpfull. I have two questions:

1.  Do you think its best to use the score for the sumation portion of the equation?

2.  I need to invoke this csound score many times from within another c++ program and be able to pass in parameters from the c++ program to csound.  Any thoughts on how this could work?  I looking through the documentation right now but haven't come accross anything.

Thanks so much for you help,
Francis

On Sun, Apr 11, 2010 at 1:24 AM, Josh Henne <jhenneocad@hotmail.com> wrote:
Hello,
 
If you are looking to do Yamaha FM style (aka Phase modulation) synthesis, here is some basic rough code (without the headers, setup, score, ftable entries) for a simple two operator (oscillator) synth in which the output of one operator controls the instantaneous phase of another operator. In this case the modulator and carrier are made using phasor and table pairs where the phasors scan the tables. Using tables allows you to use different waveforms in the FM (PM) algorithm.
 
See Page 266 of the Csound book, Page 226 of The Computer Music Tutorial. Or you can download The Theory and Technique of Electronic Music by Miller Puckette. Figure 5.15 on page 143 shows the structure of basic phase and frequency modulation instruments using Pure Data patches.
 
instr 101
 
; *** Base frequency taken from midi note converted to Hz
inote cpsmidi ; <-- could be pfield in a score - also see the midi/score interoperability opcodes
imodoffset = 0 ;Modulation offset in Hz - usually seen as a ratio value on FM synths, or it could be based on a semi-tone offset converted to hertz
imodfreq = inote + imodoffset ;<-- adding the frequency offset to the base frequency to set the mod:carrier ratio **NOTE** I find that I cannot use
                                        ; expressions within opcode parameter fields - so I calculate the value I want to use beforehand
 
; ** Modulation Index and Amplitude Envelopes ***
kindexenvelope linseg ia, idur1, ib, idur2 ... in, idurn ;<-- You could use any envelope, linear, curve generator opcode you wish - See Csound Manual
kamplitudeenvelope linseg ia, idur, ib, idur2 ... in, idurn ;**Note that the ADSR opcodes ramp up to a full value of 1 during the attack phase,
  ; , which means you will get a high amount of modulation during the attack portion of the ADSR,
  ; leading to very sharp metallic timbres which you might not always want
 
; *** Modulator Phasor/Table Oscillator **********************
amodphase phasor imodfreq
amodout tablei amodphase, 1, 1 ;<-- Audio out of modulation oscillator **Note see Csound manual entry of tablei opcode to understand why the two
                                            ; ones are there after amodphase
 
; *** Carrier Phasor ****************************
acarphase phasor inote
 
; *** Modulation Index ***
aindexout = ( (amodout * kindexenvelope) + aosc1phase ) ;the output of the modulator is added to the phase of the carrier
 

; *** Carrier Table Oscillator ***

acarout tablei aindexout, 1, 1 ;<-- Audio out of carrier oscillator

out acarout * kamplitudeenvelope ;<-- Audio output of carrier oscillator through amplitude envelope

 

endin


Date: Sat, 10 Apr 2010 20:44:44 -0300
From: fkeymo@gmail.com
To: csound@lists.bath.ac.uk
Subject: [Csnd] help with FM synthesis.


Hey All, I'm hoping to use csound to impliment the Fm synthesis function as seen in the attached image but I might be in a bit over my head.  However, I suspect this is a relatively simple task for an expert with csound.  Can anyone give me a hand?

Thanks,
Francis


Date2010-04-14 06:09
FromRene Djack
Subject[Csnd] Re: RE: Re: RE: help with FM synthesis.
AttachmentsDX7_h.orc  DX7_Algo1_analoog.csd  DX7_Algo2_AnaFat1.csd  DX7_Algo3_Moog2.csd  
Hi,

Here some dx7 patches

from  http://www.adp-gmbh.ch/csound/dx7/index.html

Best
René

2010/4/14 Josh Henne <jhenneocad@hotmail.com>
Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). You would have to delcare the parameters for each operator you intend to use. It would be easier to think of your instrument in terms of "algorithms". Typically FM synths place operators into configurations where each operator becomes a modulator or carrier depending on how they are "wired" together. Look at soft synths like FM7/FM8, Rhino and of course hardware like the Yamaha DX7 to get an idea of how this works. For example the DX7 uses six operators that are wired into 32 different configurations with some using feedback. FM7, FM8, and Rhino allow you to connect operators into configurations of your own design.
 
You could design a Csound file having one instrument that contains all the FM control parameters as global variables. Each FM algorithm would be it's own instrument - all the algorithms would be controlled by the same global paramaters. The algorithm you select as part of the global variables would control which "instrument" plays during each note. It will be tricky to connect the inputs and outputs of the phasor/table pairs but this is the easiest solution - start with one algorithm and get it working first. To use feedback look at Csound effect instruments like delays and reverb. A more difficult but possibly more flexible method is to use the Zak Patch opcodes to route the outputs of the operators into the algorithms you want.
 
....Of course from there you can add other sound shaping gizmos like distortion, filters, etc.
 
2. Yes you can certainly include a Csound file as part of sourcecode for a program. You can use the Csound Application Programming Interface and the Software Bus Opcodes. I have no experience with these myself but you can find information within the Csound Manual for the bus opcodes. And there is the Csound API reference by Michael Gogins which is found here: http://csound.sourceforge.net/refman.pdf
 
Josh
 

Date: Mon, 12 Apr 2010 22:23:33 -0300
From: fkeymo@gmail.com
To: csound@lists.bath.ac.uk
Subject: [Csnd] Re: RE: help with FM synthesis.

Thanks.  This is super helpfull. I have two questions:

1.  Do you think its best to use the score for the sumation portion of the equation?

2.  I need to invoke this csound score many times from within another c++ program and be able to pass in parameters from the c++ program to csound.  Any thoughts on how this could work?  I looking through the documentation right now but haven't come accross anything.

Thanks so much for you help,
Francis

On Sun, Apr 11, 2010 at 1:24 AM, Josh Henne <jhenneocad@hotmail.com> wrote:
Hello,
 
If you are looking to do Yamaha FM style (aka Phase modulation) synthesis, here is some basic rough code (without the headers, setup, score, ftable entries) for a simple two operator (oscillator) synth in which the output of one operator controls the instantaneous phase of another operator. In this case the modulator and carrier are made using phasor and table pairs where the phasors scan the tables. Using tables allows you to use different waveforms in the FM (PM) algorithm.
 
See Page 266 of the Csound book, Page 226 of The Computer Music Tutorial. Or you can download The Theory and Technique of Electronic Music by Miller Puckette. Figure 5.15 on page 143 shows the structure of basic phase and frequency modulation instruments using Pure Data patches.
 
instr 101
 
; *** Base frequency taken from midi note converted to Hz
inote cpsmidi ; <-- could be pfield in a score - also see the midi/score interoperability opcodes
imodoffset = 0 ;Modulation offset in Hz - usually seen as a ratio value on FM synths, or it could be based on a semi-tone offset converted to hertz
imodfreq = inote + imodoffset ;<-- adding the frequency offset to the base frequency to set the mod:carrier ratio **NOTE** I find that I cannot use
                                        ; expressions within opcode parameter fields - so I calculate the value I want to use beforehand
 
; ** Modulation Index and Amplitude Envelopes ***
kindexenvelope linseg ia, idur1, ib, idur2 ... in, idurn ;<-- You could use any envelope, linear, curve generator opcode you wish - See Csound Manual
kamplitudeenvelope linseg ia, idur, ib, idur2 ... in, idurn ;**Note that the ADSR opcodes ramp up to a full value of 1 during the attack phase,
  ; , which means you will get a high amount of modulation during the attack portion of the ADSR,
  ; leading to very sharp metallic timbres which you might not always want
 
; *** Modulator Phasor/Table Oscillator **********************
amodphase phasor imodfreq
amodout tablei amodphase, 1, 1 ;<-- Audio out of modulation oscillator **Note see Csound manual entry of tablei opcode to understand why the two
                                            ; ones are there after amodphase
 
; *** Carrier Phasor ****************************
acarphase phasor inote
 
; *** Modulation Index ***
aindexout = ( (amodout * kindexenvelope) + aosc1phase ) ;the output of the modulator is added to the phase of the carrier
 

; *** Carrier Table Oscillator ***

acarout tablei aindexout, 1, 1 ;<-- Audio out of carrier oscillator

out acarout * kamplitudeenvelope ;<-- Audio output of carrier oscillator through amplitude envelope

 

endin


Date: Sat, 10 Apr 2010 20:44:44 -0300
From: fkeymo@gmail.com
To: csound@lists.bath.ac.uk
Subject: [Csnd] help with FM synthesis.


Hey All, I'm hoping to use csound to impliment the Fm synthesis function as seen in the attached image but I might be in a bit over my head.  However, I suspect this is a relatively simple task for an expert with csound.  Can anyone give me a hand?

Thanks,
Francis



Date2010-04-14 10:21
FromVictor Lazzarini
Subject[Csnd] Re: RE: Re: RE: help with FM synthesis.
I'm not sure what you mean by this, but Csound can do that equation alright. There is nothing in it that suggests otherwise. In fact one of the responses to the original mail shows a code example doing DFM.

If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi has written a module in it that does it.
Or you can read Russell Pinkston's chapter in the Csound Book.

Victor

On 14 Apr 2010, at 05:42, Josh Henne wrote:

Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). 


Date2010-04-14 13:10
FromJosh Henne
Subject[Csnd] RE: Re: RE: Re: RE: help with FM synthesis.
Hi Victor, sorry about that I was referring to the summation portion of the equation because I am not sure if we could change tthe number of operators on the fly, bu yeah the rest of the equation could be put in as an expression.

Josh


From: Victor.Lazzarini@nuim.ie
To: csound@lists.bath.ac.uk
Date: Wed, 14 Apr 2010 10:21:21 +0100
Subject: [Csnd] Re: RE: Re: RE: help with FM synthesis.

I'm not sure what you mean by this, but Csound can do that equation alright. There is nothing in it that suggests otherwise. In fact one of the responses to the original mail shows a code example doing DFM.

If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi has written a module in it that does it.
Or you can read Russell Pinkston's chapter in the Csound Book.

Victor

On 14 Apr 2010, at 05:42, Josh Henne wrote:

Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). 


Date2010-04-14 14:23
FromVictor Lazzarini
Subject[Csnd] Re: RE: Re: RE: Re: RE: help with FM synthesis.
As far as I can see, each operator is a separate instrument and you can have as many of these as you'd like (depending of course if you want to do RT or not). The summation is performed by csound, behind the scenes.


On 14 Apr 2010, at 13:10, Josh Henne wrote:

Hi Victor, sorry about that I was referring to the summation portion of the equation because I am not sure if we could change tthe number of operators on the fly, bu yeah the rest of the equation could be put in as an expression.

Josh


From: Victor.Lazzarini@nuim.ie
To: csound@lists.bath.ac.uk
Date: Wed, 14 Apr 2010 10:21:21 +0100
Subject: [Csnd] Re: RE: Re: RE: help with FM synthesis.

I'm not sure what you mean by this, but Csound can do that equation alright. There is nothing in it that suggests otherwise. In fact one of the responses to the original mail shows a code example doing DFM.

If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi has written a module in it that does it.
Or you can read Russell Pinkston's chapter in the Csound Book.

Victor

On 14 Apr 2010, at 05:42, Josh Henne wrote:

Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). 




Date2010-04-14 16:03
Fromfrancis keyes
Subject[Csnd] Re: Re: RE: Re: RE: Re: RE: help with FM synthesis.
I've been doing the sumation in the score by just doing something like this (opN = 3):

f1    0    16384    10    1
;            p4    p5    p6    p7    p8    p9
;            amp    pch    N1    N2    I1    I2
i1    0    1.5    -12    8.00    1    3    2    3
i1    0    .    .    .    2    3    2    1
i1    0    .    .    3.00    5    3    4    8


Does that seem resonable?
A more dynamic way to do this without adding and removing lines from the score would be nice...

On Wed, Apr 14, 2010 at 10:23 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
As far as I can see, each operator is a separate instrument and you can have as many of these as you'd like (depending of course if you want to do RT or not). The summation is performed by csound, behind the scenes.


On 14 Apr 2010, at 13:10, Josh Henne wrote:

Hi Victor, sorry about that I was referring to the summation portion of the equation because I am not sure if we could change tthe number of operators on the fly, bu yeah the rest of the equation could be put in as an expression.

Josh


From: Victor.Lazzarini@nuim.ie
To: csound@lists.bath.ac.uk
Date: Wed, 14 Apr 2010 10:21:21 +0100
Subject: [Csnd] Re: RE: Re: RE: help with FM synthesis.

I'm not sure what you mean by this, but Csound can do that equation alright. There is nothing in it that suggests otherwise. In fact one of the responses to the original mail shows a code example doing DFM.

If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi has written a module in it that does it.
Or you can read Russell Pinkston's chapter in the Csound Book.

Victor

On 14 Apr 2010, at 05:42, Josh Henne wrote:

Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). 





Date2010-04-14 16:34
FromVictor Lazzarini
Subject[Csnd] Re: Re: Re: RE: Re: RE: Re: RE: help with FM synthesis.
yes, that is reasonable. Depending on your environment, you can script it (if you are using for instance Python or QuteCsound), you can also use MIDI or Open Sound Control (with 'event' opcodes), you can type scorelines at the standard input, etc., if you want something more dynamic.

Victor

On 14 Apr 2010, at 16:03, francis keyes wrote:

I've been doing the sumation in the score by just doing something like this (opN = 3):

f1    0    16384    10    1
;            p4    p5    p6    p7    p8    p9
;            amp    pch    N1    N2    I1    I2
i1    0    1.5    -12    8.00    1    3    2    3
i1    0    .    .    .    2    3    2    1
i1    0    .    .    3.00    5    3    4    8


Does that seem resonable?
A more dynamic way to do this without adding and removing lines from the score would be nice...

On Wed, Apr 14, 2010 at 10:23 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
As far as I can see, each operator is a separate instrument and you can have as many of these as you'd like (depending of course if you want to do RT or not). The summation is performed by csound, behind the scenes.


On 14 Apr 2010, at 13:10, Josh Henne wrote:

Hi Victor, sorry about that I was referring to the summation portion of the equation because I am not sure if we could change tthe number of operators on the fly, bu yeah the rest of the equation could be put in as an expression.

Josh


From: Victor.Lazzarini@nuim.ie
To: csound@lists.bath.ac.uk
Date: Wed, 14 Apr 2010 10:21:21 +0100
Subject: [Csnd] Re: RE: Re: RE: help with FM synthesis.

I'm not sure what you mean by this, but Csound can do that equation alright. There is nothing in it that suggests otherwise. In fact one of the responses to the original mail shows a code example doing DFM.

If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi has written a module in it that does it.
Or you can read Russell Pinkston's chapter in the Csound Book.

Victor

On 14 Apr 2010, at 05:42, Josh Henne wrote:

Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). 






Date2010-04-14 21:26
Fromfrancis keyes
Subject[Csnd] Re: Re: Re: Re: RE: Re: RE: Re: RE: help with FM synthesis.
I'm calling csound from another c++ program.  Right now my interaction is like this:

-generate parameters
-write paramters to temporary score file tmp.sco
-use system("csound -d my-inst.orc tmp.sco > /dev/null 2>&1"); to generate test.wav
-process test.wav with another library (marsyas)
-repeat, overwriting tmp.sco and test.wav

The problem is that I need to do this roughly 50000 times or more, so I want to illiminate the writing of files to disk.  I'm looking a the csound api right now but there doesn't seem to be any examples kicking around so I'm finding it a bit of a tough nut to crack...
Maybe inputting the score from stdin in the system command would work to get rid of tmp.sco...
Is there a way to have csound write test.wav to memory instead of the disk?


On Wed, Apr 14, 2010 at 12:34 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
yes, that is reasonable. Depending on your environment, you can script it (if you are using for instance Python or QuteCsound), you can also use MIDI or Open Sound Control (with 'event' opcodes), you can type scorelines at the standard input, etc., if you want something more dynamic.

Victor

On 14 Apr 2010, at 16:03, francis keyes wrote:

I've been doing the sumation in the score by just doing something like this (opN = 3):

f1    0    16384    10    1
;            p4    p5    p6    p7    p8    p9
;            amp    pch    N1    N2    I1    I2
i1    0    1.5    -12    8.00    1    3    2    3
i1    0    .    .    .    2    3    2    1
i1    0    .    .    3.00    5    3    4    8


Does that seem resonable?
A more dynamic way to do this without adding and removing lines from the score would be nice...

On Wed, Apr 14, 2010 at 10:23 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
As far as I can see, each operator is a separate instrument and you can have as many of these as you'd like (depending of course if you want to do RT or not). The summation is performed by csound, behind the scenes.


On 14 Apr 2010, at 13:10, Josh Henne wrote:

Hi Victor, sorry about that I was referring to the summation portion of the equation because I am not sure if we could change tthe number of operators on the fly, bu yeah the rest of the equation could be put in as an expression.

Josh


From: Victor.Lazzarini@nuim.ie
To: csound@lists.bath.ac.uk
Date: Wed, 14 Apr 2010 10:21:21 +0100
Subject: [Csnd] Re: RE: Re: RE: help with FM synthesis.

I'm not sure what you mean by this, but Csound can do that equation alright. There is nothing in it that suggests otherwise. In fact one of the responses to the original mail shows a code example doing DFM.

If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi has written a module in it that does it.
Or you can read Russell Pinkston's chapter in the Csound Book.

Victor

On 14 Apr 2010, at 05:42, Josh Henne wrote:

Hi Francis,
 
To answer your questions:
 
1. I don't think Csound can do what this equation suggests (I may be wrong). 







Date2010-04-14 21:53
FromRory Walsh
Subject[Csnd] Re: Re: Re: Re: Re: RE: Re: RE: Re: RE: help with FM synthesis.
Unfortunately you must write your score/orc to disk even if using the
API. You can send score events from the API to Csound. Here's an
example in C together with a csd file. You must add a path to csound.h
and link to csound32. Let me know if you have any problems. Of course
this might not help you at all, I haven't been following this thread
closely!

Rory.



#include 
#include "csound.h"

/*-------------------------------------------------------------
//performance thread function prototype
//------------------------------------------------------------*/
uintptr_t csThread(void *clientData);

/*-------------------------------------------------------------
//userData structure declaration
//------------------------------------------------------------*/
typedef struct {
int result;
CSOUND* csound;
int PERF_STATUS;
}userData;

//------------------------------------------------------------
// main function
//------------------------------------------------------------
int main(int argc, char *argv[])
{
MYFLT userInput[5]={1,0,0,0,0};

void* ThreadID;
userData* ud;
int i;
ud = (userData *)malloc(sizeof(userData));

/* number of pfields expected by instrument 1 */
int numpFields = 5;

MYFLT* pvalue;
/* create string array to pass a input arguments */
int noOfArgs = 2;
char** inputArgs = (char **) malloc(sizeof(char*)*(2));
inputArgs[0] = "csound";
inputArgs[1] = "example5.csd";

csoundInitialize(&noOfArgs, &inputArgs, 0);
ud->csound=csoundCreate(NULL);
ud->result=csoundCompile(ud->csound,noOfArgs,inputArgs);
if(!ud->result)
  {
  ud->PERF_STATUS=1;
  ThreadID = csoundCreateThread(csThread, (void*)ud);
  }
else{
printf("csoundCompiled returned an error");
return 0;
}


printf("\n Enter a score event with 5 p-fields. iNo starttime duration
amp freq\n");
printf("Send a message to instrument 0 to quit\n");
while(userInput[0]>0)
     {
     for(i=0;i<5;i++){
	    /* retreive user data */
	    scanf("%f", &userInput[i]);
	    }
	 /* send score event to Csound. Send score events to instrument 20! */
     csoundScoreEvent(ud->csound, 'i', userInput, 5);
     }

ud->PERF_STATUS=0;
csoundDestroy(ud->csound);
free(ud);
free(inputArgs);
return 1;
}

//-------------------------------------------------------------
//definition of our performance thread function
//-------------------------------------------------------------
uintptr_t csThread(void *data)
{
	userData* udata = (userData*)data;
     	if(!udata->result)
        {
             while((csoundPerformKsmps(udata->csound) == 0)
			&&(udata->PERF_STATUS==1));
		csoundDestroy(udata->csound);
        }
	udata->PERF_STATUS = 0;
      return 1;
}

//=========================================================


-odevaudio -b10 -g ;for windows
;-+rtaudio=alsa -odac ;for linux


sr = 44100
ksmps = 64
nchnls = 1

/* you may need to edit the CsOptions
in order to run this example.  */

instr 10
;dummy instrument
endin

instr 20
kamp expon p4, p3, 0.001
a1 oscil kamp, p5, 1
out a1
endin



f1 0 1024 10 1
i10 0 1000




Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2010-04-14 22:04
FromMichael Gogins
Subject[Csnd] Re: Re: Re: Re: Re: RE: Re: RE: Re: RE: help with FM synthesis.
You can write the audio to memory by accessing the output buffer
(MYFLT *CppSound.getSpout()) and processing audio by repeated calls
(CppSound.performKsmps()). You could just push the contents of spout
into a std::vector object.

You can set the orc and sco using CppSound, but you must export them
to disk to perform.

If you already have a running orchestra, you also can input score
events without having to export them to disk using
CppSound.inputMessage(std::string scoreLines).

Hope this helps,
Mike

P.S. ask more questions if you like.

On Wed, Apr 14, 2010 at 4:26 PM, francis keyes  wrote:
> I'm calling csound from another c++ program.  Right now my interaction is
> like this:
>
> -generate parameters
> -write paramters to temporary score file tmp.sco
> -use system("csound -d my-inst.orc tmp.sco > /dev/null 2>&1"); to generate
> test.wav
> -process test.wav with another library (marsyas)
> -repeat, overwriting tmp.sco and test.wav
>
> The problem is that I need to do this roughly 50000 times or more, so I want
> to illiminate the writing of files to disk.  I'm looking a the csound api
> right now but there doesn't seem to be any examples kicking around so I'm
> finding it a bit of a tough nut to crack...
> Maybe inputting the score from stdin in the system command would work to get
> rid of tmp.sco...
> Is there a way to have csound write test.wav to memory instead of the disk?
>
>
> On Wed, Apr 14, 2010 at 12:34 PM, Victor Lazzarini
>  wrote:
>>
>> yes, that is reasonable. Depending on your environment, you can script it
>> (if you are using for instance Python or QuteCsound), you can also use MIDI
>> or Open Sound Control (with 'event' opcodes), you can type scorelines at the
>> standard input, etc., if you want something more dynamic.
>> Victor
>> On 14 Apr 2010, at 16:03, francis keyes wrote:
>>
>> I've been doing the sumation in the score by just doing something like
>> this (opN = 3):
>>
>> f1    0    16384    10    1
>> ;            p4    p5    p6    p7    p8    p9
>> ;            amp    pch    N1    N2    I1    I2
>> i1    0    1.5    -12    8.00    1    3    2    3
>> i1    0    .    .    .    2    3    2    1
>> i1    0    .    .    3.00    5    3    4    8
>>
>>
>> Does that seem resonable?
>> A more dynamic way to do this without adding and removing lines from the
>> score would be nice...
>>
>> On Wed, Apr 14, 2010 at 10:23 AM, Victor Lazzarini
>>  wrote:
>>>
>>> As far as I can see, each operator is a separate instrument and you can
>>> have as many of these as you'd like (depending of course if you want to do
>>> RT or not). The summation is performed by csound, behind the scenes.
>>>
>>> On 14 Apr 2010, at 13:10, Josh Henne wrote:
>>>
>>> Hi Victor, sorry about that I was referring to the summation portion of
>>> the equation because I am not sure if we could change tthe number of
>>> operators on the fly, bu yeah the rest of the equation could be put in as an
>>> expression.
>>>
>>> Josh
>>>
>>> ________________________________
>>> From: Victor.Lazzarini@nuim.ie
>>> To: csound@lists.bath.ac.uk
>>> Date: Wed, 14 Apr 2010 10:21:21 +0100
>>> Subject: [Csnd] Re: RE: Re: RE: help with FM synthesis.
>>>
>>> I'm not sure what you mean by this, but Csound can do that equation
>>> alright. There is nothing in it that suggests otherwise. In fact one of the
>>> responses to the original mail shows a code example doing DFM.
>>> If anyone wants off-the-shelf DX7 emulations, just use blue. Steven Yi
>>> has written a module in it that does it.
>>> Or you can read Russell Pinkston's chapter in the Csound Book.
>>> Victor
>>> On 14 Apr 2010, at 05:42, Josh Henne wrote:
>>>
>>> Hi Francis,
>>>
>>> To answer your questions:
>>>
>>> 1. I don't think Csound can do what this equation suggests (I may be
>>> wrong).
>>>
>>>
>>
>>
>
>



-- 
Michael Gogins
Irreducible Productions
http://www.michael-gogins.com
Michael dot Gogins at gmail dot com


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"