Mercurial > hg > x
comparison sinsyn.cpp @ 5:5f3c32dc6e17
* Adjust comment syntax to permit Doxygen to generate HTML documentation; add Doxyfile
author | Chris Cannam |
---|---|
date | Wed, 06 Oct 2010 15:19:49 +0100 |
parents | fc19d45615d1 |
children | 9b1c0825cc77 |
comparison
equal
deleted
inserted
replaced
4:92ee28024c05 | 5:5f3c32dc6e17 |
---|---|
1 //--------------------------------------------------------------------------- | 1 //--------------------------------------------------------------------------- |
2 | |
3 | 2 |
4 #include "align8.h" | 3 #include "align8.h" |
5 #include "sinsyn.h" | 4 #include "sinsyn.h" |
6 #include "splines.h" | 5 #include "splines.h" |
7 | 6 |
7 /** \file sinsyn.h */ | |
8 | |
8 //--------------------------------------------------------------------------- | 9 //--------------------------------------------------------------------------- |
9 /* | 10 /** |
10 function Sinuoid: original McAuley-Quatieri synthesizer interpolation between two measurement points. | 11 function Sinuoid: original McAuley-Quatieri synthesizer interpolation between two measurement points. |
11 | 12 |
12 In: T: length from measurement point 1 to measurement point 2 | 13 In: T: length from measurement point 1 to measurement point 2 |
13 a1, f1, p2: amplitude, frequency and phase angle at measurement point 1 | 14 a1, f1, p2: amplitude, frequency and phase angle at measurement point 1 |
14 a2, f2, p2: amplitude, frequency and phase angle at measurement point 2 | 15 a2, f2, p2: amplitude, frequency and phase angle at measurement point 2 |
44 f[t]=lf; | 45 f[t]=lf; |
45 la=la+da; | 46 la=la+da; |
46 } | 47 } |
47 }//Sinusoid | 48 }//Sinusoid |
48 | 49 |
49 /* | 50 /** |
50 function Sinuoid: original McAuley-Quatieri synthesizer interpolation between two measurement points, | 51 function Sinuoid: original McAuley-Quatieri synthesizer interpolation between two measurement points, |
51 without returning interpolated sinusoid parameters. | 52 without returning interpolated sinusoid parameters. |
52 | 53 |
53 In: T: length from measurement point 1 to measurement point 2 | 54 In: T: length from measurement point 1 to measurement point 2 |
54 a1, f1, p2: amplitude, frequency and phase angle at measurement point 1 | 55 a1, f1, p2: amplitude, frequency and phase angle at measurement point 1 |
77 la=la+da; | 78 la=la+da; |
78 } | 79 } |
79 }//Sinusoid | 80 }//Sinusoid |
80 | 81 |
81 //--------------------------------------------------------------------------- | 82 //--------------------------------------------------------------------------- |
82 /* | 83 /** |
83 function Sinusoid_direct: synthesizes sinusoid over [CountSt, CountEn) from tronomial coefficients of | 84 function Sinusoid_direct: synthesizes sinusoid over [CountSt, CountEn) from tronomial coefficients of |
84 amplitude and frequency, direct implementation. | 85 amplitude and frequency, direct implementation. |
85 | 86 |
86 In: CountSt, CountEn | 87 In: CountSt, CountEn |
87 aa, ab, ac, ad: trinomial coefficients of amplitude | 88 aa, ab, ac, ad: trinomial coefficients of amplitude |
105 else data[i]=a*cos(ph); | 106 else data[i]=a*cos(ph); |
106 } | 107 } |
107 p1=p1+2*M_PI*i*(fd+i*((fc/2)+i*((fb/3)+i*fa/4))); | 108 p1=p1+2*M_PI*i*(fd+i*((fc/2)+i*((fb/3)+i*fa/4))); |
108 }//Sinusoid | 109 }//Sinusoid |
109 | 110 |
110 /* | 111 /** |
111 function Sinusoid: synthesizes sinusoid over [CountSt, CountEn) from tronomial coefficients of | 112 function Sinusoid: synthesizes sinusoid over [CountSt, CountEn) from tronomial coefficients of |
112 amplitude and frequency, recursive implementation. | 113 amplitude and frequency, recursive implementation. |
113 | 114 |
114 In: CountSt, CountEn | 115 In: CountSt, CountEn |
115 a3, a2, a1, a0: trinomial coefficients of amplitude | 116 a3, a2, a1, a0: trinomial coefficients of amplitude |
173 } | 174 } |
174 } | 175 } |
175 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); | 176 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); |
176 } | 177 } |
177 | 178 |
178 /* | 179 /** |
179 function SinusoidExp: synthesizes complex sinusoid whose derivative log amplitude and frequency are | 180 function SinusoidExp: synthesizes complex sinusoid whose derivative log amplitude and frequency are |
180 trinomials | 181 trinomials |
181 | 182 |
182 In: CountSt, CountEn | 183 In: CountSt, CountEn |
183 a3, a2, a1, a0: trinomial coefficients for the derivative of log amplitude | 184 a3, a2, a1, a0: trinomial coefficients for the derivative of log amplitude |
208 } | 209 } |
209 ea=e0+CountEn*(e1+CountEn*(e2+CountEn*(e3+CountEn*e4))); | 210 ea=e0+CountEn*(e1+CountEn*(e2+CountEn*(e3+CountEn*e4))); |
210 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); | 211 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); |
211 }//SinusoidExp | 212 }//SinusoidExp |
212 | 213 |
213 /* | 214 /** |
214 function SinusoidExp: synthesizes complex sinusoid piece whose derivative logarithm is h[M]'lamda[M]. | 215 function SinusoidExp: synthesizes complex sinusoid piece whose derivative logarithm is h[M]'lamda[M]. |
215 This version also synthesizes its derivative. | 216 This version also synthesizes its derivative. |
216 | 217 |
217 In: h[M][T], dih[M][T]: basis functions and their difference-integrals | 218 In: h[M][T], dih[M][T]: basis functions and their difference-integrals |
218 lamda[M]: coefficients of h[M] | 219 lamda[M]: coefficients of h[M] |
232 tmpexp+=dexp; | 233 tmpexp+=dexp; |
233 ds[t]=s[t]*dR; | 234 ds[t]=s[t]*dR; |
234 } | 235 } |
235 }//SinusoidExp | 236 }//SinusoidExp |
236 | 237 |
237 /* | 238 /** |
238 function SinusoidExp: synthesizes complex sinusoid piece whose derivative logarithm is h[M]'lamda[M]. | 239 function SinusoidExp: synthesizes complex sinusoid piece whose derivative logarithm is h[M]'lamda[M]. |
239 This version does not synthesize its derivative. | 240 This version does not synthesize its derivative. |
240 | 241 |
241 In: dih[M][T]: difference of integrals of basis functions h[M] | 242 In: dih[M][T]: difference of integrals of basis functions h[M] |
242 lamda[M]: coefficients of h[M] | 243 lamda[M]: coefficients of h[M] |
255 for (int m=0; m<M; m++) dexp+=lamda[m]*dih[m][t]; | 256 for (int m=0; m<M; m++) dexp+=lamda[m]*dih[m][t]; |
256 tmpexp+=dexp; | 257 tmpexp+=dexp; |
257 } | 258 } |
258 }//SinusoidExp | 259 }//SinusoidExp |
259 | 260 |
260 /* | 261 /** |
261 function SinusoidExpA: synthesizes complex sinusoid whose log amplitude and frequency are trinomials | 262 function SinusoidExpA: synthesizes complex sinusoid whose log amplitude and frequency are trinomials |
262 | 263 |
263 In: CountSt, CountEn | 264 In: CountSt, CountEn |
264 a3, a2, a1, a0: trinomial coefficients for log amplitude | 265 a3, a2, a1, a0: trinomial coefficients for log amplitude |
265 omg3, omg2, omg1, omg0: trinomial coefficients for angular frequency | 266 omg3, omg2, omg1, omg0: trinomial coefficients for angular frequency |
287 data[i]=exp(cdouble(lea, lph)); | 288 data[i]=exp(cdouble(lea, lph)); |
288 } | 289 } |
289 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); | 290 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); |
290 }//SinusoidExpA | 291 }//SinusoidExpA |
291 | 292 |
292 /* | 293 /** |
293 function SinusoidExpA: synthesizes complex sinusoid whose log amplitude and frequency are trinomials | 294 function SinusoidExpA: synthesizes complex sinusoid whose log amplitude and frequency are trinomials |
294 with phase angle specified at both ends. | 295 with phase angle specified at both ends. |
295 | 296 |
296 In: CountSt, CountEn | 297 In: CountSt, CountEn |
297 a3, a2, a1, a0: trinomial coefficients for log amplitude | 298 a3, a2, a1, a0: trinomial coefficients for log amplitude |
325 double lph=p0+i*(p1+i*(p2+i*(p3+i*p4))); | 326 double lph=p0+i*(p1+i*(p2+i*(p3+i*p4))); |
326 data[i]=exp(cdouble(lea, lph+(i*i*(_q+i*_p)))); | 327 data[i]=exp(cdouble(lea, lph+(i*i*(_q+i*_p)))); |
327 } | 328 } |
328 }//SinusoidExpA | 329 }//SinusoidExpA |
329 | 330 |
330 /* | 331 /** |
331 function SinusoidExpA: synthesizes complex sinusoid piece whose log amplitude is h[M]'p[M] and | 332 function SinusoidExpA: synthesizes complex sinusoid piece whose log amplitude is h[M]'p[M] and |
332 frequency is h[M]'q[M]. This version also synthesizes its derivative. | 333 frequency is h[M]'q[M]. This version also synthesizes its derivative. |
333 | 334 |
334 In: h[M][T], dh[M][T], dih[M][T]: basis functions and their derivatives and difference-integrals | 335 In: h[M][T], dh[M][T], dih[M][T]: basis functions and their derivatives and difference-integrals |
335 p[M], q[M]: real and imaginary parts of coefficients of h[M] | 336 p[M], q[M]: real and imaginary parts of coefficients of h[M] |
349 ds[t]=s[t]*cdouble(drr, dri); | 350 ds[t]=s[t]*cdouble(drr, dri); |
350 tmpph+=dph; | 351 tmpph+=dph; |
351 } | 352 } |
352 }//SinusoidExpA | 353 }//SinusoidExpA |
353 | 354 |
354 /* | 355 /** |
355 function SinusoidExpA: synthesizes complex sinusoid piece whose log amplitude is h[M]'p[M] and | 356 function SinusoidExpA: synthesizes complex sinusoid piece whose log amplitude is h[M]'p[M] and |
356 frequency is h[M]'q[M]. This version does not synthesize its derivative. | 357 frequency is h[M]'q[M]. This version does not synthesize its derivative. |
357 | 358 |
358 In: h[M][T], dih[M][T]: basis functions and their difference-integrals | 359 In: h[M][T], dih[M][T]: basis functions and their difference-integrals |
359 p[M], q[M]: real and imaginary parts of coefficients of h[M] | 360 p[M], q[M]: real and imaginary parts of coefficients of h[M] |
372 s[t]=exp(cdouble(e, tmpph)); | 373 s[t]=exp(cdouble(e, tmpph)); |
373 tmpph+=dph; | 374 tmpph+=dph; |
374 } | 375 } |
375 }//SinusoidExpA | 376 }//SinusoidExpA |
376 | 377 |
377 /* | 378 /** |
378 function SinusoidExpA: synthesizes complex sinusoid piece whose log amplitude is h[M]'p[M] and | 379 function SinusoidExpA: synthesizes complex sinusoid piece whose log amplitude is h[M]'p[M] and |
379 frequency is h[M]'q[M] with phase angle specified at both ends. This version does not synthesize its | 380 frequency is h[M]'q[M] with phase angle specified at both ends. This version does not synthesize its |
380 derivative. | 381 derivative. |
381 | 382 |
382 In: h[M][T], dih[M][T]: basis functions and their difference-integrals | 383 In: h[M][T], dih[M][T]: basis functions and their difference-integrals |
471 } | 472 } |
472 ea=e0+CountEn*(e1+CountEn*(e2+CountEn*(e3+CountEn*e4))); | 473 ea=e0+CountEn*(e1+CountEn*(e2+CountEn*(e3+CountEn*e4))); |
473 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); | 474 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); |
474 } //*/ | 475 } //*/ |
475 | 476 |
476 /* | 477 /** |
477 function Sinusoid: recursive cos-sin generator with trinomial frequency | 478 function Sinusoid: recursive cos-sin generator with trinomial frequency |
478 | 479 |
479 In: CountSt, CountEn | 480 In: CountSt, CountEn |
480 f3, f2, f1, f0: trinomial coefficients of frequency | 481 f3, f2, f1, f0: trinomial coefficients of frequency |
481 ph: initial phase angle at 0 (NOT at CountSt) | 482 ph: initial phase angle at 0 (NOT at CountSt) |
516 tmp=cdddph*cddddph-sdddph*sddddph; sdddph=sdddph*cddddph+cdddph*sddddph; cdddph=tmp; | 517 tmp=cdddph*cddddph-sdddph*sddddph; sdddph=sdddph*cddddph+cdddph*sddddph; cdddph=tmp; |
517 } | 518 } |
518 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); | 519 ph=p0+CountEn*(p1+CountEn*(p2+CountEn*(p3+CountEn*p4))); |
519 }//Sinusoid*/ | 520 }//Sinusoid*/ |
520 | 521 |
521 /* | 522 /** |
522 function Sinusoids: recursive harmonic multi-sinusoid generator | 523 function Sinusoids: recursive harmonic multi-sinusoid generator |
523 | 524 |
524 In: st, en | 525 In: st, en |
525 M: number of partials | 526 M: number of partials |
526 a3[M], a2[M], a1[M], a0[M]: trinomial coefficients for partial amplitudes | 527 a3[M], a2[M], a1[M], a0[M]: trinomial coefficients for partial amplitudes |
602 { | 603 { |
603 } | 604 } |
604 free8(a); | 605 free8(a); |
605 }//Sinusoids*/ | 606 }//Sinusoids*/ |
606 | 607 |
607 /* | 608 /** |
608 function Sinusoid: synthesizes sinusoid piece from trinomial frequency and amplitude coefficients. | 609 function Sinusoid: synthesizes sinusoid piece from trinomial frequency and amplitude coefficients. |
609 | 610 |
610 In: CountSt, CountEn | 611 In: CountSt, CountEn |
611 aa, ab, ac, ad: trinomial coefficients of amplitude. | 612 aa, ab, ac, ad: trinomial coefficients of amplitude. |
612 fa, fb, fc, fd: trinomial coefficients of frequency. | 613 fa, fb, fc, fd: trinomial coefficients of frequency. |
631 if (add) data[i]+=a*cos(ph); | 632 if (add) data[i]+=a*cos(ph); |
632 else data[i]=a*cos(ph); | 633 else data[i]=a*cos(ph); |
633 } | 634 } |
634 }//Sinusoid | 635 }//Sinusoid |
635 | 636 |
636 /* | 637 /** |
637 function Sinusoid: synthesizes sinusoid piece from trinomial frequency and amplitude coefficients, | 638 function Sinusoid: synthesizes sinusoid piece from trinomial frequency and amplitude coefficients, |
638 returning sinusoid coefficients instead of waveform. | 639 returning sinusoid coefficients instead of waveform. |
639 | 640 |
640 In: CountSt, CountEn | 641 In: CountSt, CountEn |
641 aa, ab, ac, ad: trinomial coefficients of amplitude (or log amplitude if LogA=true) | 642 aa, ab, ac, ad: trinomial coefficients of amplitude (or log amplitude if LogA=true) |
669 f[i]=fd+i*(fc+i*(fb+i*fa))+i*(2*q+3*i*p)/(2*M_PI); | 670 f[i]=fd+i*(fc+i*(fb+i*fa))+i*(2*q+3*i*p)/(2*M_PI); |
670 ph[i]=ph0+2*M_PI*i*(fd+i*((fc/2)+i*((fb/3)+i*fa/4)))+i*i*(q+i*p); | 671 ph[i]=ph0+2*M_PI*i*(fd+i*((fc/2)+i*((fb/3)+i*fa/4)))+i*i*(q+i*p); |
671 } | 672 } |
672 }//Sinusoid | 673 }//Sinusoid |
673 | 674 |
674 /* | 675 /** |
675 function Sinusoid: generates trinomial frequency and phase with phase correction. | 676 function Sinusoid: generates trinomial frequency and phase with phase correction. |
676 | 677 |
677 In: CountSt, CountEn | 678 In: CountSt, CountEn |
678 fa, fb, fc, fd: trinomial coefficients of frequency. | 679 fa, fb, fc, fd: trinomial coefficients of frequency. |
679 ph0, ph2: phase angles at 0 and CountEn. | 680 ph0, ph2: phase angles at 0 and CountEn. |
694 f[i]=fd+i*(fc+i*(fb+i*fa))+i*(2*q+3*i*p)/(2*M_PI); | 695 f[i]=fd+i*(fc+i*(fb+i*fa))+i*(2*q+3*i*p)/(2*M_PI); |
695 ph[i]=ph0+2*M_PI*i*(fd+i*((fc/2)+i*((fb/3)+i*fa/4)))+i*i*(q+i*p); | 696 ph[i]=ph0+2*M_PI*i*(fd+i*((fc/2)+i*((fb/3)+i*fa/4)))+i*i*(q+i*p); |
696 } | 697 } |
697 }//Sinusoid | 698 }//Sinusoid |
698 | 699 |
699 /* | 700 /** |
700 function SynthesizeSinusoid: synthesizes a time-varying sinusoid from a sequence of frequencies and amplitudes | 701 function SynthesizeSinusoid: synthesizes a time-varying sinusoid from a sequence of frequencies and amplitudes |
701 | 702 |
702 In: xs[Fr]: measurement points, should be integers although *xs has double type. | 703 In: xs[Fr]: measurement points, should be integers although *xs has double type. |
703 fs[Fr], as[Fr]: sequence of frequencies and amplitudes at xs[Fr] | 704 fs[Fr], as[Fr]: sequence of frequencies and amplitudes at xs[Fr] |
704 phs[0]: initial phase angle at (int)xs[0]. | 705 phs[0]: initial phase angle at (int)xs[0]. |
727 Sinusoid(&xrec[(int)xs[0]-dst], dst-xs[0], 0, a3[0], a2[0], a1[0], a0[0], f3[0], f2[0], f1[0], f0[0], phs[0], add);) | 728 Sinusoid(&xrec[(int)xs[0]-dst], dst-xs[0], 0, a3[0], a2[0], a1[0], a0[0], f3[0], f2[0], f1[0], f0[0], phs[0], add);) |
728 delete[] f3; | 729 delete[] f3; |
729 return xrec; | 730 return xrec; |
730 }//SynthesizeSinusoid | 731 }//SynthesizeSinusoid |
731 | 732 |
732 /* | 733 /** |
733 function ShiftTrinomial: shifts the origin of a trinomial from 0 to T | 734 function ShiftTrinomial: shifts the origin of a trinomial from 0 to T |
734 | 735 |
735 In: a3, a2, a1, a0. | 736 In: a3, a2, a1, a0. |
736 Out: b3, b2, b1, b0, so that a3*x^3+a2*x^2+a1*x+a0=b3(x-T)^3+b2(x-T)^2+b1(x-T)+b0 | 737 Out: b3, b2, b1, b0, so that a3*x^3+a2*x^2+a1*x+a0=b3(x-T)^3+b2(x-T)^2+b1(x-T)+b0 |
737 | 738 |
743 b2=a2+T*3*b3; | 744 b2=a2+T*3*b3; |
744 b1=a1+T*(2*b2-T*3*b3); | 745 b1=a1+T*(2*b2-T*3*b3); |
745 b0=a0+T*(b1-T*(b2-T*b3)); | 746 b0=a0+T*(b1-T*(b2-T*b3)); |
746 }//ShiftTrinomial | 747 }//ShiftTrinomial |
747 | 748 |
748 /* | 749 /** |
749 function SynthesizeSinusoidP: synthesizes a time-varying sinusoid from a sequence of frequencies, | 750 function SynthesizeSinusoidP: synthesizes a time-varying sinusoid from a sequence of frequencies, |
750 amplitudes and phase angles | 751 amplitudes and phase angles |
751 | 752 |
752 In: xs[Fr]: measurement points, should be integers although *xs has double type. | 753 In: xs[Fr]: measurement points, should be integers although *xs has double type. |
753 fs[Fr], as[Fr], phs[Fr]: sequence of frequencies, amplitudes and phase angles at xs[Fr] | 754 fs[Fr], as[Fr], phs[Fr]: sequence of frequencies, amplitudes and phase angles at xs[Fr] |