Csound Csound-dev Csound-tekno Search About

"unrolled" note is not identical to that produced with recursion

Date2016-07-06 15:29
From"C. R. Craig"
Subject"unrolled" note is not identical to that produced with recursion
Okay, I’ve puzzled over this one for several months now and I still can’t figure out why the results produced by the two instruments are not the same.  The first instrument, “TEST1”, plays a note consisting of the fundamental and 5 partials with amplitudes, one after another. The second instrument, “TEST2”, uses recursion to achieve its results, but employs the same fundamental, partials, and amplitudes. I’ve tried to make the example as simple as possible.



;-odac


sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

opcode NOTE_RECURSIVE, a, iiiio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  idur,ifreq,iPartialTable,iAmplitudes,index xin
  itablesize = ftlen(iPartialTable)
  iPartial tab_i index,iPartialTable
  iAmp tab_i index,iAmplitudes
  if (index < (itablesize - 1)) then
    iNextPartial tab_i (index+1),iPartialTable
    if iNextPartial != 0 then
      aN NOTE_RECURSIVE ifreq,idur,iPartialTable,iAmplitudes,index+1
    endif
  endif
  aA poscil iAmp,ifreq*iPartial
  xout aA+aN
endop

opcode NOTE,a,iiii
  idur,ifreq,ipartials,iamps xin

  ix init 0

  ip1 tab_i ix,ipartials
  ia1 tab_i ix,iamps
  asig1 poscil ia1,ifreq*ip1

  ip2 tab_i (ix+1),ipartials
  ia2 tab_i (ix+1),iamps
  asig2 poscil ia2,ifreq*ip2

  ip3 tab_i (ix+2),ipartials
  ia3 tab_i (ix+2),iamps
  asig3 poscil ia3,ifreq*ip3

  ip4 tab_i (ix+3),ipartials
  ia4 tab_i (ix+3),iamps
  asig4 poscil ia4,ifreq*ip4

  ip5 tab_i (ix+4),ipartials
  ia5 tab_i (ix+4),iamps
  asig5 poscil ia5,ifreq*ip5

  ip6 tab_i (ix+5),ipartials
  ia6 tab_i (ix+5),iamps
  asig6 poscil ia6,ifreq*ip6

  aout = asig1+asig2+asig3+asig4+asig5+asig6
  xout aout
endop

instr TEST1
  idur = p3
  ifreq = p4
  inumpartials = p5

iPartials ftgenonce 0,0,-6,-2,  1, 2.89,4.95,6.99,8.01,9.02
iAmplitudes ftgenonce 0,0,-6,-2,1, 1/2, 1/3, 1/2, 1/3, 1/4

asig NOTE idur,ifreq,iPartials,iAmplitudes
outs asig*0.1,asig*0.1
endin

instr TEST2
  idur = p3
  ifreq = p4
  inumpartials = p5

iPartials ftgenonce 0,0,-6,-2,  1, 2.89,4.95,6.99,8.01,9.02
iAmplitudes ftgenonce 0,0,-6,-2,1, 1/2, 1/3, 1/2, 1/3, 1/4

asig NOTE_RECURSIVE idur,ifreq,iPartials,iAmplitudes
outs asig*0.1,asig*0.1
endin



i "TEST1" 0 10 220 6
i "TEST2" 10 10 220 6
e



Invoke this with "csound -W -o test_recursion.wav test_recursion.csd” then examine the results with audacity. The results are strikingly different.

thanks,
Robert

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-07-06 15:34
From"C. R. Craig"
SubjectRe: "unrolled" note is not identical to that produced with recursion
Attachmentstest_recursion.csd  
Sorry, didn’t realize one could attach files in emails to the listserv.


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


Robert

> On Jul 6, 2016, at 7:29 AM, C. R. Craig  wrote:
> 
> Okay, I’ve puzzled over this one for several months now and I still can’t figure out why the results produced by the two instruments are not the same.  The first instrument, “TEST1”, plays a note consisting of the fundamental and 5 partials with amplitudes, one after another. The second instrument, “TEST2”, uses recursion to achieve its results, but employs the same fundamental, partials, and amplitudes. I’ve tried to make the example as simple as possible.
> 
> 
> 
> ;-odac
> 
> 
> sr = 44100
> ksmps = 32
> nchnls = 2
> 0dbfs  = 1
> 
> opcode NOTE_RECURSIVE, a, iiiio
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>  idur,ifreq,iPartialTable,iAmplitudes,index xin
>  itablesize = ftlen(iPartialTable)
>  iPartial tab_i index,iPartialTable
>  iAmp tab_i index,iAmplitudes
>  if (index < (itablesize - 1)) then
>    iNextPartial tab_i (index+1),iPartialTable
>    if iNextPartial != 0 then
>      aN NOTE_RECURSIVE ifreq,idur,iPartialTable,iAmplitudes,index+1
>    endif
>  endif
>  aA poscil iAmp,ifreq*iPartial
>  xout aA+aN
> endop
> 
> opcode NOTE,a,iiii
>  idur,ifreq,ipartials,iamps xin
> 
>  ix init 0
> 
>  ip1 tab_i ix,ipartials
>  ia1 tab_i ix,iamps
>  asig1 poscil ia1,ifreq*ip1
> 
>  ip2 tab_i (ix+1),ipartials
>  ia2 tab_i (ix+1),iamps
>  asig2 poscil ia2,ifreq*ip2
> 
>  ip3 tab_i (ix+2),ipartials
>  ia3 tab_i (ix+2),iamps
>  asig3 poscil ia3,ifreq*ip3
> 
>  ip4 tab_i (ix+3),ipartials
>  ia4 tab_i (ix+3),iamps
>  asig4 poscil ia4,ifreq*ip4
> 
>  ip5 tab_i (ix+4),ipartials
>  ia5 tab_i (ix+4),iamps
>  asig5 poscil ia5,ifreq*ip5
> 
>  ip6 tab_i (ix+5),ipartials
>  ia6 tab_i (ix+5),iamps
>  asig6 poscil ia6,ifreq*ip6
> 
>  aout = asig1+asig2+asig3+asig4+asig5+asig6
>  xout aout
> endop
> 
> instr TEST1
>  idur = p3
>  ifreq = p4
>  inumpartials = p5
> 
> iPartials ftgenonce 0,0,-6,-2,  1, 2.89,4.95,6.99,8.01,9.02
> iAmplitudes ftgenonce 0,0,-6,-2,1, 1/2, 1/3, 1/2, 1/3, 1/4
> 
> asig NOTE idur,ifreq,iPartials,iAmplitudes
> outs asig*0.1,asig*0.1
> endin
> 
> instr TEST2
>  idur = p3
>  ifreq = p4
>  inumpartials = p5
> 
> iPartials ftgenonce 0,0,-6,-2,  1, 2.89,4.95,6.99,8.01,9.02
> iAmplitudes ftgenonce 0,0,-6,-2,1, 1/2, 1/3, 1/2, 1/3, 1/4
> 
> asig NOTE_RECURSIVE idur,ifreq,iPartials,iAmplitudes
> outs asig*0.1,asig*0.1
> endin
> 
> 
> 
> i "TEST1" 0 10 220 6
> i "TEST2" 10 10 220 6
> e
> 
> 
> 
> Invoke this with "csound -W -o test_recursion.wav test_recursion.csd” then examine the results with audacity. The results are strikingly different.
> 
> thanks,
> Robert
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-07-06 17:29
FromVictor Lazzarini
SubjectRe: "unrolled" note is not identical to that produced with recursion
Your first and second parameters are swapped in the recursive call:

 aN NOTE_RECURSIVE ifreq,idur,iPartialTable,iAmplitudes,index+1

but you expect:

 idur,ifreq,iPartialTable,iAmplitudes,index xin
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 6 Jul 2016, at 15:34, C. R. Craig  wrote:
> 
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-07-06 17:43
From"C. R. Craig"
SubjectRe: "unrolled" note is not identical to that produced with recursion
Holy crap! I can’t believe I’ve wasted such a huge amount of time before asking for another pair of eyes!!

Thank you *so* much!

Robert

> On Jul 6, 2016, at 9:29 AM, Victor Lazzarini  wrote:
> 
> Your first and second parameters are swapped in the recursive call:
> 
> aN NOTE_RECURSIVE ifreq,idur,iPartialTable,iAmplitudes,index+1
> 
> but you expect:
> 
> idur,ifreq,iPartialTable,iAmplitudes,index xin
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952 
> 
>> On 6 Jul 2016, at 15:34, C. R. Craig  wrote:
>> 
>> 
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-07-06 17:46
FromT Lopez
SubjectRe: "unrolled" note is not identical to that produced with recursion

Happens to all of us...difficult to be objective with our own projects, especially code.

On 6 Jul 2016 18:43, "C. R. Craig" <robert@craig-woods.net> wrote:
Holy crap! I can’t believe I’ve wasted such a huge amount of time before asking for another pair of eyes!!

Thank you *so* much!

Robert

> On Jul 6, 2016, at 9:29 AM, Victor Lazzarini <Victor.Lazzarini@NUIM.IE> wrote:
>
> Your first and second parameters are swapped in the recursive call:
>
> aN NOTE_RECURSIVE ifreq,idur,iPartialTable,iAmplitudes,index+1
>
> but you expect:
>
> idur,ifreq,iPartialTable,iAmplitudes,index xin
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
>> On 6 Jul 2016, at 15:34, C. R. Craig <robert@CRAIG-WOODS.NET> wrote:
>>
>> <test_recursion.csd>
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-07-06 19:41
FromVictor Lazzarini
SubjectRe: "unrolled" note is not identical to that produced with recursion
No worries. I only realised after I added some tracing to see what the frequencies were.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 6 Jul 2016, at 17:43, C. R. Craig  wrote:
> 
> Holy crap! I can’t believe I’ve wasted such a huge amount of time before asking for another pair of eyes!!
> 
> Thank you *so* much!
> 
> Robert
> 
>> On Jul 6, 2016, at 9:29 AM, Victor Lazzarini  wrote:
>> 
>> Your first and second parameters are swapped in the recursive call:
>> 
>> aN NOTE_RECURSIVE ifreq,idur,iPartialTable,iAmplitudes,index+1
>> 
>> but you expect:
>> 
>> idur,ifreq,iPartialTable,iAmplitudes,index xin
>> ========================
>> Dr Victor Lazzarini
>> Dean of Arts, Celtic Studies and Philosophy,
>> Maynooth University,
>> Maynooth, Co Kildare, Ireland
>> Tel: 00 353 7086936
>> Fax: 00 353 1 7086952 
>> 
>>> On 6 Jul 2016, at 15:34, C. R. Craig  wrote:
>>> 
>>> 
>> 
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>       https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here